Skip to content

Commit 7a52bd5

Browse files
committed
Merge branch '5.2' into 5.3
* 5.2: [PHPUnit-Bridge] Troubleshooting
2 parents cbfcc4a + ba07138 commit 7a52bd5

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

components/phpunit_bridge.rst

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff 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
850850
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.
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+
870886
Modified PHPUnit script
871887
-----------------------
872888

0 commit comments

Comments
 (0)