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
848
848
849
849
Under the hood, a PHPUnit listener injects the mocked functions in the tested
850
850
classes' 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.
855
861
856
862
.. code-block :: xml
857
863
@@ -867,6 +873,16 @@ the namespaces of the tested classes in your ``phpunit.xml.dist``.
867
873
</listener >
868
874
</listeners >
869
875
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
+
870
886
Modified PHPUnit script
871
887
-----------------------
872
888
You can’t perform that action at this time.
0 commit comments