@@ -18,7 +18,11 @@ It comes with the following features:
18
18
19
19
* Displays the stack trace of a deprecation on-demand;
20
20
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).
22
26
23
27
Installation
24
28
------------
37
41
38
42
Once the component installed, it automatically registers a
39
43
`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:
42
46
43
47
.. image :: /images/components/phpunit_bridge/report.png
44
48
@@ -75,9 +79,9 @@ There are four ways to mark a test as legacy:
75
79
76
80
* (**Recommended **) Add the ``@group legacy `` annotation to its class or method;
77
81
78
- * Make its class start with the ``Legacy `` prefix;
82
+ * Make its class name start with the ``Legacy `` prefix;
79
83
80
- * Make its method start with ``testLegacy ``;
84
+ * Make its method name start with ``testLegacy `` instead of `` test ``;
81
85
82
86
* Make its data provider start with ``provideLegacy `` or ``getLegacy ``.
83
87
@@ -154,23 +158,21 @@ when using public continuous integration services like `Travis CI`_.
154
158
Clock Mocking
155
159
~~~~~~~~~~~~~
156
160
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() ``.
160
164
161
165
To use the ``ClockMock `` class in your test, you can:
162
166
163
167
* (**Recommended **) Add the ``@group time-sensitive `` annotation to its class or
164
168
method;
165
169
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.
169
173
170
174
As a result, the following is guarenteed to work and is no longer a transient
171
- test:
172
-
173
- .. code-block :: php
175
+ test::
174
176
175
177
use Symfony\Component\Stopwatch\Stopwatch;
176
178
@@ -193,11 +195,13 @@ test:
193
195
194
196
And that's all!
195
197
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.
201
205
202
206
Troubleshooting
203
207
~~~~~~~~~~~~~~~
@@ -209,7 +213,7 @@ class name (FQCN) is ``App\Tests\Watch\DummyWatchTest``, it assumes the tested
209
213
class FQCN is ``App\Watch\DummyWatch ``.
210
214
211
215
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
213
217
:doc: `HttpKernel Component </components/http_kernel/introduction >`:
214
218
215
219
.. code-block :: xml
0 commit comments