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
838
838
839
839
Under the hood, a PHPUnit listener injects the mocked functions in the tested
840
840
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.
845
851
846
852
.. code-block :: xml
847
853
@@ -857,6 +863,16 @@ the namespaces of the tested classes in your ``phpunit.xml.dist``.
857
863
</listener >
858
864
</listeners >
859
865
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
+
860
876
Modified PHPUnit script
861
877
-----------------------
862
878
You can’t perform that action at this time.
0 commit comments