@@ -789,24 +789,42 @@ namespaces in the ``phpunit.xml`` file, as done for example in the
789789
790790 Under the hood, a PHPUnit listener injects the mocked functions in the tested
791791classes' namespace. In order to work as expected, the listener has to run before
792- the tested class ever runs. By default, the mocked functions are created when the
793- annotation are found and the corresponding tests are run. Depending on how your
794- tests are constructed, this might be too late. In this case, you will need to declare
795- the namespaces of the tested classes in your ``phpunit.xml.dist ``.
792+ the tested class ever runs.
793+
794+ By default, the mocked functions are created when the annotation are found and
795+ the corresponding tests are run. Depending on how your tests are constructed,
796+ this might be too late.
797+
798+ You can either:
799+ * Declare the namespaces of the tested classes in your ``phpunit.xml.dist ``.
800+ * Register the namespaces at the end of the ``config/bootstrap.php `` file.
796801
797802.. code-block :: xml
798803
799804 <!-- phpunit.xml.dist -->
800- <!-- ... -->
801- <listeners >
802- <listener class =" Symfony\Bridge\PhpUnit\SymfonyTestsListener" >
803- <arguments >
804- <array >
805- <element key =" time-sensitive" ><string >Acme\MyClassTest</string ></element >
806- </array >
807- </arguments >
808- </listener >
809- </listeners >
805+ <phpunit
806+ bootstrap =" config/bootstrap.php"
807+ >
808+ <!-- ... -->
809+ <listeners >
810+ <listener class =" Symfony\Bridge\PhpUnit\SymfonyTestsListener" >
811+ <arguments >
812+ <array >
813+ <element key =" time-sensitive" ><string >Acme\MyClassTest</string ></element >
814+ </array >
815+ </arguments >
816+ </listener >
817+ </listeners >
818+ </phpunit >
819+
820+ .. code-block :: php
821+
822+ <!-- config/bootstrap.php -->
823+ use Symfony\Bridge\PhpUnit\ClockMock;
824+
825+ if ('test' === $_SERVER['APP_ENV']) {
826+ ClockMock::register('Acme\\MyClassTest\\');
827+ }
810828
811829 Modified PHPUnit script
812830-----------------------
0 commit comments