Skip to content

Explain better how to enable the ClockMock annotation #7503

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 15, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 18 additions & 7 deletions components/phpunit_bridge.rst
Original file line number Diff line number Diff line change
Expand Up @@ -165,16 +165,27 @@ The :class:`Symfony\\Bridge\\PhpUnit\\ClockMock` class provided by this bridge
allows you to mock the PHP's built-in time functions ``time()``,
``microtime()``, ``sleep()`` and ``usleep()``.

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

* (**Recommended**) Add the ``@group time-sensitive`` annotation to its class or
method;
.. code-block:: xml

<!-- phpunit.xml.dist -->
<!-- ... -->
<listeners>
<listener class="\Symfony\Bridge\PhpUnit\SymfonyTestsListener" />
</listeners>

.. note::

* Register it manually by calling ``ClockMock::register(__CLASS__)`` and
``ClockMock::withClockMock(true)`` before the test and
``ClockMock::withClockMock(false)`` after the test.
If you don't want to use the ``@group time-sensitive`` annotation, you can
register the ``ClockMock`` class manually by calling
``ClockMock::register(__CLASS__)`` and ``ClockMock::withClockMock(true)``
before the test and ``ClockMock::withClockMock(false)`` after the test.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about using then instead of repeating and? That might be easier to read.

Copy link
Member Author

@javiereguiluz javiereguiluz Apr 15, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand. We say: "do XX and YY before ... and ZZ after ..." Which "and" should I replace by "then" ? Thanks!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would propose:

[...] register the ``ClockMock`` class manually by calling
``ClockMock::register(__CLASS__)`` and ``ClockMock::withClockMock(true)``
before the test then ``ClockMock::withClockMock(false)`` after the test.

wdyt?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the new version is less readable 🤓 And this part is hard to read, don't you think? --> the test then

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah it would deserve a comma after test, but I trust you to choose the best way (that includes ignoring my comment :) ).

Copy link
Member Author

@javiereguiluz javiereguiluz Apr 15, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right ... let mergers (@xabbuh ?) deal with this decision and change it if needed :)


As a result, the following is guarenteed to work and is no longer a transient
As a result, the following is guaranteed to work and is no longer a transient
test::

use Symfony\Component\Stopwatch\Stopwatch;
Expand Down