File tree Expand file tree Collapse file tree 1 file changed +20
-4
lines changed Expand file tree Collapse file tree 1 file changed +20
-4
lines changed Original file line number Diff line number Diff 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
840840classes' 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+
860876Modified PHPUnit script
861877-----------------------
862878
You can’t perform that action at this time.
0 commit comments