DEV Community

M. Alexandre J-S William ELISÉ
M. Alexandre J-S William ELISÉ

Posted on • Edited on

Answer: Mocking The Time used by all instances of DateTime for testing purposes

You should stub the DateTime methods you need in your tests to return expected values.

$stub = $this->getMock('DateTime');
$stub->expects($this->any())
     ->method('theMethodYouNeedToReturnACertainValue')
     ->will($this->returnValue('your certain value'));

See https://phpunit.de/manual/current/en/test-doubles.html

If you cannot stub the methods because they are hardcoded into your code, have a look at

which explains…

Top comments (0)