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 @@ -848,10 +848,16 @@ namespaces in the ``phpunit.xml`` file, as done for example in the
848848
849849 Under the hood, a PHPUnit listener injects the mocked functions in the tested
850850classes' namespace. In order to work as expected, the listener has to run before
851- the tested class ever runs. By default, the mocked functions are created when the
852- annotation are found and the corresponding tests are run. Depending on how your
853- tests are constructed, this might be too late. In this case, you will need to declare
854- the namespaces of the tested classes in your ``phpunit.xml.dist ``.
851+ the tested class ever runs.
852+
853+ By default, the mocked functions are created when the annotation are found and
854+ the corresponding tests are run. Depending on how your tests are constructed,
855+ this might be too late.
856+
857+ You can either:
858+
859+ * Declare the namespaces of the tested classes in your ``phpunit.xml.dist ``;
860+ * Register the namespaces at the end of the ``config/bootstrap.php `` file.
855861
856862.. code-block :: xml
857863
@@ -867,6 +873,16 @@ the namespaces of the tested classes in your ``phpunit.xml.dist``.
867873 </listener >
868874 </listeners >
869875
876+ ::
877+
878+ // config/bootstrap.php
879+ use Symfony\Bridge\PhpUnit\ClockMock;
880+
881+ // ...
882+ if ('test' === $_SERVER['APP_ENV']) {
883+ ClockMock::register('Acme\\MyClassTest\\');
884+ }
885+
870886Modified PHPUnit script
871887-----------------------
872888
You can’t perform that action at this time.
0 commit comments