Symfony Testing - ClockMock / DateTime Symfony Testing - ClockMock / DateTime symfony symfony

Symfony Testing - ClockMock / DateTime


The ClockMock doesn't work for new \DateTime() but only on time-based PHP function.

From the announcement of the features:

This means that you don't need to make a single change in your original code, except when using new DateTime(), which must be replaced by DateTime::createFromFormat('U', time()) to use the mocked time() function.

So try as suggested: replace any DateTime object creation with the named-constructor with the time function.

Hope this help