Skip to content

Commit ca960e1

Browse files
committed
[PHPUnit-Bridge] Troubleshooting
1 parent 707580e commit ca960e1

File tree

1 file changed

+32
-14
lines changed

1 file changed

+32
-14
lines changed

components/phpunit_bridge.rst

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -809,24 +809,42 @@ namespaces in the ``phpunit.xml`` file, as done for example in the
809809
810810
Under the hood, a PHPUnit listener injects the mocked functions in the tested
811811
classes' namespace. In order to work as expected, the listener has to run before
812-
the tested class ever runs. By default, the mocked functions are created when the
813-
annotation are found and the corresponding tests are run. Depending on how your
814-
tests are constructed, this might be too late. In this case, you will need to declare
815-
the namespaces of the tested classes in your ``phpunit.xml.dist``.
812+
the tested class ever runs.
813+
814+
By default, the mocked functions are created when the annotation are found and
815+
the corresponding tests are run. Depending on how your tests are constructed,
816+
this might be too late.
817+
818+
You can either:
819+
* Declare the namespaces of the tested classes in your ``phpunit.xml.dist``.
820+
* Register the namespaces at the end of the ``config/bootstrap.php`` file.
816821

817822
.. code-block:: xml
818823
819824
<!-- phpunit.xml.dist -->
820-
<!-- ... -->
821-
<listeners>
822-
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener">
823-
<arguments>
824-
<array>
825-
<element key="time-sensitive"><string>Acme\MyClassTest</string></element>
826-
</array>
827-
</arguments>
828-
</listener>
829-
</listeners>
825+
<phpunit
826+
bootstrap="config/bootstrap.php"
827+
>
828+
<!-- ... -->
829+
<listeners>
830+
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener">
831+
<arguments>
832+
<array>
833+
<element key="time-sensitive"><string>Acme\MyClassTest</string></element>
834+
</array>
835+
</arguments>
836+
</listener>
837+
</listeners>
838+
</phpunit>
839+
840+
.. code-block::
841+
842+
<!-- config/bootstrap.php -->
843+
use Symfony\Bridge\PhpUnit\ClockMock;
844+
845+
if ('test' === $_SERVER['APP_ENV']) {
846+
ClockMock::register('Acme\\MyClassTest\\');
847+
}
830848
831849
Modified PHPUnit script
832850
-----------------------

0 commit comments

Comments
 (0)