Skip to content

Commit a320038

Browse files
sylfabrexabbuh
authored andcommitted
Unexpected PHP behavior
1 parent 93a2b20 commit a320038

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

components/phpunit_bridge.rst

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,27 @@ namespaces in the ``phpunit.xml`` file, as done for example in the
515515
</listener>
516516
</listeners>
517517
</phpunit>
518+
519+
Under the hood, a PHPUnit listener injects the mocked functions in the tested
520+
classes' namespace. In order to work as expected, the listener has to run before
521+
the tested class ever runs. By default, the mocked functions are created when the
522+
annotation are found and the corresponding tests are run. Depending on how your
523+
tests are constructed, this might be too late. In this case, you will need to declare
524+
the namespaces of the tested classes in your phpunit.xml.dist
525+
526+
.. code-block:: xml
527+
528+
<!-- phpunit.xml.dist -->
529+
<!-- ... -->
530+
<listeners>
531+
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener">
532+
<arguments>
533+
<array>
534+
<element key="time-sensitive"><string>Acme\MyClassTest</string></element>
535+
</array>
536+
</arguments>
537+
</listener>
538+
</listeners>
518539
519540
Modified PHPUnit script
520541
-----------------------

0 commit comments

Comments
 (0)