Skip to content

Commit

Permalink
[PhpUnitBridge] Doc for @expectedDeprecation & new configuration env …
Browse files Browse the repository at this point in the history
…vars
  • Loading branch information
nicolas-grekas committed Oct 21, 2016
1 parent b2d38b2 commit 845d094
Showing 1 changed file with 36 additions and 3 deletions.
39 changes: 36 additions & 3 deletions components/phpunit_bridge.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ It comes with the following features:

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

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

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

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

Write Assertions about Deprecations
-----------------------------------

When adding deprecations to your code, you might like writting tests that verify
that they are triggered as required. To do so, the bridge provides the
``@expectedDeprecation`` annotation that you can use on your test methods,
alongside with the expected message, given in the same format than for the
`PHPUnit assertStringMatchesFormat()`_ method. If you expect more than one
deprecation messages for a given test method, you can use the annotation several
times (order matters)::

/**
* @group legacy
* @expectedDeprecation This "%s" method is deprecated.
* @expectedDeprecation The second argument of the "%s" method is deprecated.
*/
public function testDeprecatedCode()
{
@trigger_error('This "Foo" method is deprecated.', E_USER_DEPRECATED);
@trigger_error('The second argument of the "Bar" method is deprecated.', E_USER_DEPRECATED);
}

Time-sensitive Tests
--------------------

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

* Does not embed ``symfony/yaml`` nor ``prophecy`` to prevent any conflicts with
these dependencies;
* Uses PHPUnit 4.8 when run with PHP <=5.5 and PHPUnit 5.1 when run with PHP >=5.6;
* Uses PHPUnit 4.8 when run with PHP <=5.5 and PHPUnit 5.3 when run with PHP >=5.6;
* Collects and replays skipped tests when the ``SYMFONY_PHPUNIT_SKIPPED_TESTS``
env var is defined: the env var should specify a file name that will be used for
storing skipped tests on a first run, and replay them on the second run;
Expand All @@ -358,8 +380,19 @@ If you have installed the bridge through Composer, you can run it by calling e.g
$ vendor/bin/simple-phpunit
.. tip::

Set the ``SYMFONY_PHPUNIT_VERSION`` env var to e.g. ``5.5`` to change the
base version of PHPUnit to ``5.5`` instead of the default ``5.3``.

.. tip::

Set the ``SYMFONY_PHPUNIT_REMOVE`` env var to ``symfony/yaml`` if you need
``prophecy`` but not ``symfony/yaml``.

.. _PHPUnit: https://phpunit.de
.. _`PHPUnit event listener`: https://phpunit.de/manual/current/en/extending-phpunit.html#extending-phpunit.PHPUnit_Framework_TestListener
.. _`PHPUnit assertStringMatchesFormat()`: https://phpunit.de/manual/current/en/appendixes.assertions.html#appendixes.assertions.assertStringMatchesFormat
.. _`PHP error handler`: http://php.net/manual/en/book.errorfunc.php
.. _`environment variable`: https://phpunit.de/manual/current/en/appendixes.configuration.html#appendixes.configuration.php-ini-constants-variables
.. _Packagist: https://packagist.org/packages/symfony/phpunit-bridge
Expand Down

0 comments on commit 845d094

Please sign in to comment.