Skip to content

Commit a840753

Browse files
committed
minor #7503 Explain better how to enable the ClockMock annotation (javiereguiluz)
This PR was merged into the 2.8 branch. Discussion ---------- Explain better how to enable the ClockMock annotation This fixes #7500. Commits ------- 13baa4d Explain better how to enable the ClockMock annotation
2 parents d09611e + 13baa4d commit a840753

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

components/phpunit_bridge.rst

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -165,16 +165,27 @@ The :class:`Symfony\\Bridge\\PhpUnit\\ClockMock` class provided by this bridge
165165
allows you to mock the PHP's built-in time functions ``time()``,
166166
``microtime()``, ``sleep()`` and ``usleep()``.
167167

168-
To use the ``ClockMock`` class in your test, you can:
168+
To use the ``ClockMock`` class in your test, add the ``@group time-sensitive``
169+
annotation to its class or methods. This annotation only works when executing
170+
PHPUnit using the ``vendor/bin/simple-phpunit`` script or when registering the
171+
following listener in your PHPUnit configuration:
169172

170-
* (**Recommended**) Add the ``@group time-sensitive`` annotation to its class or
171-
method;
173+
.. code-block:: xml
174+
175+
<!-- phpunit.xml.dist -->
176+
<!-- ... -->
177+
<listeners>
178+
<listener class="\Symfony\Bridge\PhpUnit\SymfonyTestsListener" />
179+
</listeners>
180+
181+
.. note::
172182

173-
* Register it manually by calling ``ClockMock::register(__CLASS__)`` and
174-
``ClockMock::withClockMock(true)`` before the test and
175-
``ClockMock::withClockMock(false)`` after the test.
183+
If you don't want to use the ``@group time-sensitive`` annotation, you can
184+
register the ``ClockMock`` class manually by calling
185+
``ClockMock::register(__CLASS__)`` and ``ClockMock::withClockMock(true)``
186+
before the test and ``ClockMock::withClockMock(false)`` after the test.
176187

177-
As a result, the following is guarenteed to work and is no longer a transient
188+
As a result, the following is guaranteed to work and is no longer a transient
178189
test::
179190

180191
use Symfony\Component\Stopwatch\Stopwatch;

0 commit comments

Comments
 (0)