Codeception / AspectMock

The most powerful and flexible mocking framework for PHPUnit / Codeception.
MIT License
790 stars 129 forks source link

AspectMock don't mock DateTime object #163

Closed tupikoff closed 3 years ago

tupikoff commented 6 years ago

I have a problem with mocking php Datetime object. Does AspectMock work correctly with global php objects?

code

$datetime = test::double(DateTime::class, ['format' => '1979-06-18']);
$date = (new DateTime())->format('Y-m-d');
$datetime->verifyInvoked('format');
$this->assertEquals('1979-06-18', $date);

will raise

Expected DateTime::format to be invoked but it never occurred
pablowillians commented 5 years ago

I'm currently using Chronos instead of using \DateTime, because I had the same problem trying to double \DateTime class

Naktibalda commented 3 years ago

This is a missing feature of goaop: https://github.com/goaop/framework/issues/188