Skip to content

Commit 8169ab1

Browse files
committed
Merge branch '4.3' into 4.4
* 4.3: Inform about how to use new DateTime() when Clock Mocking
2 parents 3638360 + 83f5939 commit 8169ab1

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

components/phpunit_bridge.rst

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -409,11 +409,15 @@ Clock Mocking
409409
~~~~~~~~~~~~~
410410

411411
The :class:`Symfony\\Bridge\\PhpUnit\\ClockMock` class provided by this bridge
412-
allows you to mock the PHP's built-in time functions ``time()``,
413-
``microtime()``, ``sleep()``, ``usleep()`` and ``gmdate()``. Additionally the function
414-
``date()`` is mocked so it uses the mocked time if no timestamp is specified.
412+
allows you to mock the PHP's built-in time functions ``time()``, ``microtime()``,
413+
``sleep()``, ``usleep()`` and ``gmdate()``. Additionally the function ``date()``
414+
is mocked so it uses the mocked time if no timestamp is specified.
415+
415416
Other functions with an optional timestamp parameter that defaults to ``time()``
416-
will still use the system time instead of the mocked time.
417+
will still use the system time instead of the mocked time. This means that you
418+
may need to change some code in your tests. For example, instead of ``new DateTime()``,
419+
you should use ``DateTime::createFromFormat('U', time())`` to use the mocked
420+
``time()`` function.
417421

418422
To use the ``ClockMock`` class in your test, add the ``@group time-sensitive``
419423
annotation to its class or methods. This annotation only works when executing

0 commit comments

Comments
 (0)