Skip to content

Commit 94827c5

Browse files
committed
feature #7074 [PhpUnitBridge] Doc for @expectedDeprecation & new configuration env vars (nicolas-grekas)
This PR was merged into the master branch. Discussion ---------- [PhpUnitBridge] Doc for @expectedDeprecation & new configuration env vars Related to symfony/symfony#20255 & symfony/symfony#20256 Commits ------- a1682de [PhpUnitBridge] Doc for @expectedDeprecation & new configuration env vars
2 parents 152aecc + a1682de commit 94827c5

File tree

1 file changed

+36
-3
lines changed

1 file changed

+36
-3
lines changed

components/phpunit_bridge.rst

+36-3
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ It comes with the following features:
1818

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

21-
* Provides a ``ClockMock`` helper class for time-sensitive tests.
21+
* Provides a ``ClockMock`` and ``DnsMock`` helper classes for time or network-sensitive tests.
2222

23-
* Provides a modified version of phpunit that does not embed ``symfony/yaml`` nor
23+
* Provides a modified version of PHPUnit that does not embed ``symfony/yaml`` nor
2424
``prophecy`` to prevent any conflicts with these dependencies.
2525

2626
Installation
@@ -133,6 +133,28 @@ completely disable the deprecation helper. This is useful to make use of the
133133
rest of features provided by this component without getting errors or messages
134134
related to deprecations.
135135

136+
Write Assertions about Deprecations
137+
-----------------------------------
138+
139+
When adding deprecations to your code, you might like writing tests that verify
140+
that they are triggered as required. To do so, the bridge provides the
141+
``@expectedDeprecation`` annotation that you can use on your test methods.
142+
It requires you to pass the expected message, given in the same format than for
143+
the `PHPUnit's assertStringMatchesFormat()`_ method. If you expect more than one
144+
deprecation message for a given test method, you can use the annotation several
145+
times (order matters)::
146+
147+
/**
148+
* @group legacy
149+
* @expectedDeprecation This "%s" method is deprecated.
150+
* @expectedDeprecation The second argument of the "%s" method is deprecated.
151+
*/
152+
public function testDeprecatedCode()
153+
{
154+
@trigger_error('This "Foo" method is deprecated.', E_USER_DEPRECATED);
155+
@trigger_error('The second argument of the "Bar" method is deprecated.', E_USER_DEPRECATED);
156+
}
157+
136158
Time-sensitive Tests
137159
--------------------
138160

@@ -340,7 +362,7 @@ its ``bin/simple-phpunit`` command. It has the following features:
340362

341363
* Does not embed ``symfony/yaml`` nor ``prophecy`` to prevent any conflicts with
342364
these dependencies;
343-
* Uses PHPUnit 4.8 when run with PHP <=5.5 and PHPUnit 5.1 when run with PHP >=5.6;
365+
* Uses PHPUnit 4.8 when run with PHP <=5.5 and PHPUnit 5.3 when run with PHP >=5.6;
344366
* Collects and replays skipped tests when the ``SYMFONY_PHPUNIT_SKIPPED_TESTS``
345367
env var is defined: the env var should specify a file name that will be used for
346368
storing skipped tests on a first run, and replay them on the second run;
@@ -358,8 +380,19 @@ If you have installed the bridge through Composer, you can run it by calling e.g
358380
359381
$ vendor/bin/simple-phpunit
360382
383+
.. tip::
384+
385+
Set the ``SYMFONY_PHPUNIT_VERSION`` env var to e.g. ``5.5`` to change the
386+
base version of PHPUnit to ``5.5`` instead of the default ``5.3``.
387+
388+
.. tip::
389+
390+
Set the ``SYMFONY_PHPUNIT_REMOVE`` env var to ``symfony/yaml`` if you need
391+
``prophecy`` but not ``symfony/yaml``.
392+
361393
.. _PHPUnit: https://phpunit.de
362394
.. _`PHPUnit event listener`: https://phpunit.de/manual/current/en/extending-phpunit.html#extending-phpunit.PHPUnit_Framework_TestListener
395+
.. _`PHPUnit's assertStringMatchesFormat()`: https://phpunit.de/manual/current/en/appendixes.assertions.html#appendixes.assertions.assertStringMatchesFormat
363396
.. _`PHP error handler`: http://php.net/manual/en/book.errorfunc.php
364397
.. _`environment variable`: https://phpunit.de/manual/current/en/appendixes.configuration.html#appendixes.configuration.php-ini-constants-variables
365398
.. _Packagist: https://packagist.org/packages/symfony/phpunit-bridge

0 commit comments

Comments
 (0)