Skip to content

Commit 8eeadb5

Browse files
Inform about how to use new DateTime() when Clock Mocking
1 parent de1f9a8 commit 8eeadb5

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

components/phpunit_bridge.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,9 @@ The :class:`Symfony\\Bridge\\PhpUnit\\ClockMock` class provided by this bridge
412412
allows you to mock the PHP's built-in time functions ``time()``,
413413
``microtime()``, ``sleep()``, ``usleep()`` and ``gmdate()``. Additionally the function
414414
``date()`` is mocked so it uses the mocked time if no timestamp is specified.
415+
416+
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.
417+
415418
Other functions with an optional timestamp parameter that defaults to ``time()``
416419
will still use the system time instead of the mocked time.
417420

0 commit comments

Comments
 (0)