Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0e56ff9

Browse filesBrowse files
committed
[#6273] Proofread of the new PHPUnit Bridge docs
1 parent 4decfa9 commit 0e56ff9
Copy full SHA for 0e56ff9

File tree

Expand file treeCollapse file tree

1 file changed

+24
-20
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+24
-20
lines changed

‎components/phpunit_bridge.rst

Copy file name to clipboardExpand all lines: components/phpunit_bridge.rst
+24-20Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ It comes with the following features:
1818

1919
* Displays the stack trace of a deprecation on-demand;
2020

21-
* Provides a `ClockMock` mock class for time-sensitive tests.
21+
* Provides a ``ClockMock`` helper class for time-sensitive tests.
22+
23+
.. versionadded:: 2.7
24+
The PHPUnit Bridge was introduced in Symfony 2.7. It is however possible to
25+
install the bridge in any Symfony application (even 2.3).
2226

2327
Installation
2428
------------
@@ -37,8 +41,8 @@ Usage
3741

3842
Once the component installed, it automatically registers a
3943
`PHPUnit event listener`_ which in turn registers a `PHP error handler`_
40-
called ``DeprecationErrorHandler``. After running your PHPUnit tests, you will
41-
get a report similar to this one:
44+
called :class:`Symfony\\Bridge\\PhpUnit\\DeprecationErrorHandler`. After
45+
running your PHPUnit tests, you will get a report similar to this one:
4246

4347
.. image:: /images/components/phpunit_bridge/report.png
4448

@@ -75,9 +79,9 @@ There are four ways to mark a test as legacy:
7579

7680
* (**Recommended**) Add the ``@group legacy`` annotation to its class or method;
7781

78-
* Make its class start with the ``Legacy`` prefix;
82+
* Make its class name start with the ``Legacy`` prefix;
7983

80-
* Make its method start with ``testLegacy``;
84+
* Make its method name start with ``testLegacy`` instead of ``test``;
8185

8286
* Make its data provider start with ``provideLegacy`` or ``getLegacy``.
8387

@@ -154,23 +158,21 @@ when using public continuous integration services like `Travis CI`_.
154158
Clock Mocking
155159
~~~~~~~~~~~~~
156160

157-
The ``ClockMock`` class provided by this bridge allows you to mock the PHP's
158-
built-in time functions ``time()``, ``microtime()``, ``sleep()`` and
159-
``usleep()``.
161+
The :class:`Symfony\\Bridge\\PhpUnit\\ClockMock` class provided by this bridge
162+
allows you to mock the PHP's built-in time functions ``time()``,
163+
``microtime()``, ``sleep()`` and ``usleep()``.
160164

161165
To use the ``ClockMock`` class in your test, you can:
162166

163167
* (**Recommended**) Add the ``@group time-sensitive`` annotation to its class or
164168
method;
165169

166-
* Register it manually by calling ``\Symfony\Bridge\PhpUnit\ClockMock::register(true)``
167-
(before the test) and ``Symfony\Bridge\PhpUnit\ClockMock::register(false)``
168-
(after the test).
170+
* Register it manually by calling ``ClockMock::register(__CLASS__)`` and
171+
``ClockMock::withClockMock(true)`` before the test and
172+
``ClockMock::withClockMock(false)`` after the test.
169173

170174
As a result, the following is guarenteed to work and is no longer a transient
171-
test:
172-
173-
.. code-block:: php
175+
test::
174176

175177
use Symfony\Component\Stopwatch\Stopwatch;
176178

@@ -193,11 +195,13 @@ test:
193195

194196
And that's all!
195197

196-
An added bonus of using the ``ClockMock`` class is that time passes instantly.
197-
Using PHP's ``sleep(10)`` will make your test wait for 10 actual seconds (more
198-
or less). In contrast, the ``ClockMock`` class advances the internal clock the
199-
given number of seconds without actually waiting that time, so your test will
200-
execute 10 seconds faster.
198+
.. tip::
199+
200+
An added bonus of using the ``ClockMock`` class is that time passes
201+
instantly. Using PHP's ``sleep(10)`` will make your test wait for 10
202+
actual seconds (more or less). In contrast, the ``ClockMock`` class
203+
advances the internal clock the given number of seconds without actually
204+
waiting that time, so your test will execute 10 seconds faster.
201205

202206
Troubleshooting
203207
~~~~~~~~~~~~~~~
@@ -209,7 +213,7 @@ class name (FQCN) is ``App\Tests\Watch\DummyWatchTest``, it assumes the tested
209213
class FQCN is ``App\Watch\DummyWatch``.
210214

211215
If this convention doesn't work for your application, you can also configure
212-
the mocked namespaces in the `phpunit.xml` file, as done for example in the
216+
the mocked namespaces in the ``phpunit.xml`` file, as done for example in the
213217
:doc:`HttpKernel Component </components/http_kernel/introduction>`:
214218

215219
.. code-block:: xml

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.