Skip to content

Commit afe6ef8

Browse files
committed
Reword
1 parent 1980493 commit afe6ef8

File tree

1 file changed

+55
-52
lines changed

1 file changed

+55
-52
lines changed

components/phpunit_bridge.rst

Lines changed: 55 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,9 @@ It comes with the following features:
2828
constraints to apply; 2. running tests in parallel when a test suite is split
2929
in several phpunit.xml files; 3. recording and replaying skipped tests;
3030

31-
* Provides polyfills for methods that are not available in older version of
32-
PHPUnit
33-
34-
* Provide namespaced class name for older version of PHPUnit
35-
36-
* Makes compatible testSuite with both PHPUnit 8 and previous version by
37-
removing typehint on `setUp` and `tearDown` methods.
31+
* It allows to create tests that are compatible with multiple PHPUnit versions
32+
(because it provides polyfills for missing methods, namespaced aliases for
33+
non-namespaced classes, etc.).
3834

3935
Installation
4036
------------
@@ -379,46 +375,50 @@ Running the following command will display the full stack trace:
379375
380376
$ SYMFONY_DEPRECATIONS_HELPER='/Doctrine\\Common\\ClassLoader is deprecated\./' ./vendor/bin/simple-phpunit
381377
382-
Testing with multiple version of PHPUnit
383-
----------------------------------------
378+
Testing with Multiple PHPUnit Versions
379+
--------------------------------------
384380

385-
Use Case
386-
~~~~~~~~
381+
When testing a library that has to be compatible with several versions of PHP,
382+
the test suite cannot use the latest versions of PHPUnit because:
383+
384+
* PHPUnit 8 deprecated several methods in favor of other methods which are not
385+
available in older versions (e.g. PHPUnit 4);
386+
* PHPUnit 8 added the ``void`` return type to the ``setUp()`` method, which is
387+
not compatible with PHP 5.5;
388+
* PHPUnit switched to namespaced classes starting from PHPUnit 6, so tests must
389+
work with and without namespaces.
390+
391+
Polyfills for the Unavailable Methods
392+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
393+
394+
.. versionadded:: 4.4
395+
396+
This feature was introduced in Symfony 4.4.
387397

388-
When testing a library that have to be compatible with serveral version of PHP
389-
at the same time (like Symfony does), because of dependencies, the test suite
390-
have to be tested by differentes version of PHPUnit. Unfortunatly, writing a
391-
code compatible with a too wide range of version is not possible. ie:
392-
- several function in PHPUnit 8 are deprecated but the replacements methods
393-
didn't exists int PHPUnit 4.
394-
- PHPUnit 8 added return typehint in method ``setUp(): void`` which is not
395-
compatible with PHP 5.5.
396-
- PHPUnit switch to namespaced class starting from PHPUnit 6. Tests have to
397-
handle both case with/without namespaces.
398-
399-
Polyfill for the methods
400-
~~~~~~~~~~~~~~~~~~~~~~~~
401-
402-
When using the command ``simple-phpunit``, PHPUnit Bridge injects pollyfills
403-
for most of methods from the class ``TestCase`` and ``Assert`` in order to
404-
write Test cases even compatible with PHPUnit 4. Some of those methods are
405-
``expectException``, ``expectExcpetionMessage``, ``expectExceptionCode``,
406-
``createPartialMock``, ``assertEqualsWithDelta``, ``assertContainsEquals``, ...
407-
408-
Remove void return typehint
409-
~~~~~~~~~~~~~~~~~~~~~~~~~~~
410-
411-
When running the command ``simple-phpunit`` with the env variable
412-
``SYMFONY_PHPUNIT_REMOVE_RETURN_TYPEHINT=1`` the PHPUnit bridge will alterate
413-
the code of PHPUnit to remove the return typehint (introduced in PHPUnit 8)
414-
from methods ``setUp``, ``tearDown``, ``setUpBeforeClass`` and
415-
``tearDownAfterClass``. Thuse allows you to write a Test compatible with both
416-
PHP 5 and PHPUnit 8.
417-
418-
An alternative, is to use the trait :class:`Symfony\Bridge\PhpUnit\SetUpTearDownTrait`.
419-
This trait will provide the right signature for the methods ``setUp``, ``tearDown``,
420-
``setUpBeforeClass`` and ``tearDownAfterClass`` and delegates the call to the methods
421-
``doSetUp``, ``doTearDown``, ``doSetUpBeforeClass`` and ``doTearDownAfterClass``::
398+
When using the ``simple-phpunit`` script, PHPUnit Bridge injects polyfills for
399+
most methods of the ``TestCase`` and ``Assert`` classes (e.g. ``expectException()``,
400+
``expectExcpetionMessage()``, ``assertContainsEquals``, etc.). This allows writing
401+
test cases using the latest best practices while still remaining compatible with
402+
older PHPUnit versions.
403+
404+
Removing the Void Return Type
405+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
406+
407+
.. versionadded:: 4.4
408+
409+
This feature was introduced in Symfony 4.4.
410+
411+
When running the ``simple-phpunit`` script with the ``SYMFONY_PHPUNIT_REMOVE_RETURN_TYPEHINT``
412+
environment variable set to ``1``, the PHPUnit bridge will alter the code of
413+
PHPUnit to remove the return type (introduced in PHPUnit 8) from ``setUp()``,
414+
``tearDown()``, ``setUpBeforeClass()`` and ``tearDownAfterClass()`` methods.
415+
This allows you to write a test compatible with both PHP 5 and PHPUnit 8.
416+
417+
Alternatively, you can use the trait :class:`Symfony\Bridge\PhpUnit\SetUpTearDownTrait`,
418+
which provides the right signature for the ``setUp()``, ``tearDown()``,
419+
``setUpBeforeClass()`` and ``tearDownAfterClass()`` methods and delegates the
420+
call to the ``doSetUp()``, ``doTearDown()``, ``doSetUpBeforeClass()`` and
421+
``doTearDownAfterClass()`` methods::
422422

423423
use PHPUnit\Framework\TestCase;
424424
use Symfony\Bridge\PhpUnit\SetUpTearDownTrait;
@@ -436,18 +436,21 @@ This trait will provide the right signature for the methods ``setUp``, ``tearDow
436436

437437
protected function doSetup(): void
438438
{
439-
// Visibility and return typehint of method is free.
439+
// visibility and return type-hint of method is free
440440
}
441441
}
442442

443+
Using Namespaced PHPUnit Classes
444+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
445+
446+
.. versionadded:: 4.4
443447

444-
Use namespaced class
445-
~~~~~~~~~~~~~~~~~~~~
448+
This feature was introduced in Symfony 4.4.
446449

447-
The PHPUnit bridge adds namespaced class aliases for most of PHPUnit class
448-
declared in the old fashion way (ie. ``PHPUnit_Framework_Assert``), allowing
449-
you to always use the namespaced class declaration even when the test is
450-
executed with PHPUnit 4.
450+
The PHPUnit bridge adds namespaced class aliases for most of the PHPUnit classes
451+
declared without namespaces (e.g. ``PHPUnit_Framework_Assert``), allowing you to
452+
always use the namespaced class declaration even when the test is executed with
453+
PHPUnit 4.
451454

452455
Time-sensitive Tests
453456
--------------------

0 commit comments

Comments
 (0)