Skip to content

Commit ba07138

Browse files
committed
Merge branch '4.4' into 5.2
* 4.4: [PHPUnit-Bridge] Troubleshooting
2 parents 9ac723a + ac90ac8 commit ba07138

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

components/phpunit_bridge.rst

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -838,10 +838,16 @@ namespaces in the ``phpunit.xml`` file, as done for example in the
838838
839839
Under the hood, a PHPUnit listener injects the mocked functions in the tested
840840
classes' namespace. In order to work as expected, the listener has to run before
841-
the tested class ever runs. By default, the mocked functions are created when the
842-
annotation are found and the corresponding tests are run. Depending on how your
843-
tests are constructed, this might be too late. In this case, you will need to declare
844-
the namespaces of the tested classes in your ``phpunit.xml.dist``.
841+
the tested class ever runs.
842+
843+
By default, the mocked functions are created when the annotation are found and
844+
the corresponding tests are run. Depending on how your tests are constructed,
845+
this might be too late.
846+
847+
You can either:
848+
849+
* Declare the namespaces of the tested classes in your ``phpunit.xml.dist``;
850+
* Register the namespaces at the end of the ``config/bootstrap.php`` file.
845851

846852
.. code-block:: xml
847853
@@ -857,6 +863,16 @@ the namespaces of the tested classes in your ``phpunit.xml.dist``.
857863
</listener>
858864
</listeners>
859865
866+
::
867+
868+
// config/bootstrap.php
869+
use Symfony\Bridge\PhpUnit\ClockMock;
870+
871+
// ...
872+
if ('test' === $_SERVER['APP_ENV']) {
873+
ClockMock::register('Acme\\MyClassTest\\');
874+
}
875+
860876
Modified PHPUnit script
861877
-----------------------
862878

0 commit comments

Comments
 (0)