DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

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

Posted on • Updated 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)

All DEV content is created by the community!

Hey, if you're landing here for the first time, you should know that this website is a global community of folks who blog about their experiences to help folks like you out.

Sign up now if you're curious. It's free!