From b63dfd6029f455af2e845b7274756e1c3a28a5fb Mon Sep 17 00:00:00 2001 From: Sylvain Date: Sat, 25 Aug 2018 22:21:06 +0200 Subject: [PATCH 1/6] Unexpected PHP behavior Following up on symfony/symfony#28259 --- components/phpunit_bridge.rst | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/components/phpunit_bridge.rst b/components/phpunit_bridge.rst index 30cca07b7a2..4570d8cd5e9 100644 --- a/components/phpunit_bridge.rst +++ b/components/phpunit_bridge.rst @@ -473,6 +473,13 @@ namespaces in the ``phpunit.xml`` file, as done for example in the + +Under the hood, this component defines time and dns functions in the tested +class namespace when the annotated test is run. Because of a PHP unexpected +behavior (see https://bugs.php.net/bug.php?id=64346), a test may pass when +run alone but fail when run in a tests suite if the tested class is used +before these time and dns functions are defined. Configuring the mocked +namespaces in the ``phpunit.xml`` file may solve this issue too. Modified PHPUnit script ----------------------- From ba48ce9cd85a1444c32383ae261b906475116f3a Mon Sep 17 00:00:00 2001 From: Sylvain Date: Thu, 11 Oct 2018 15:44:11 +0200 Subject: [PATCH 2/6] Update phpunit_bridge.rst --- components/phpunit_bridge.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/phpunit_bridge.rst b/components/phpunit_bridge.rst index 4570d8cd5e9..65fb0750aee 100644 --- a/components/phpunit_bridge.rst +++ b/components/phpunit_bridge.rst @@ -479,7 +479,7 @@ class namespace when the annotated test is run. Because of a PHP unexpected behavior (see https://bugs.php.net/bug.php?id=64346), a test may pass when run alone but fail when run in a tests suite if the tested class is used before these time and dns functions are defined. Configuring the mocked -namespaces in the ``phpunit.xml`` file may solve this issue too. +namespaces in the ``phpunit.xml`` file may solve this issue too (see https://github.com/symfony/symfony/blob/master/src/Symfony/Component/HttpKernel/phpunit.xml.dist for an example). Modified PHPUnit script ----------------------- From 0c838c784894bf71f5710919671c61d2c7bb60e9 Mon Sep 17 00:00:00 2001 From: Sylvain Date: Sun, 11 Nov 2018 19:04:44 +0100 Subject: [PATCH 3/6] Nicolas Grekas review --- components/phpunit_bridge.rst | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/components/phpunit_bridge.rst b/components/phpunit_bridge.rst index 65fb0750aee..b8fd20aad72 100644 --- a/components/phpunit_bridge.rst +++ b/components/phpunit_bridge.rst @@ -474,12 +474,25 @@ namespaces in the ``phpunit.xml`` file, as done for example in the -Under the hood, this component defines time and dns functions in the tested -class namespace when the annotated test is run. Because of a PHP unexpected -behavior (see https://bugs.php.net/bug.php?id=64346), a test may pass when -run alone but fail when run in a tests suite if the tested class is used -before these time and dns functions are defined. Configuring the mocked -namespaces in the ``phpunit.xml`` file may solve this issue too (see https://github.com/symfony/symfony/blob/master/src/Symfony/Component/HttpKernel/phpunit.xml.dist for an example). +Under the hood, a PHPUnit listener injects the mocked functions in the tested +classes' namespace. In order to work as expected, the listener has to run before +the tested class ever runs. By default, the mocked functions are created when the +annotation are found and the corresponding tests are run. Depending on how your +tests are constructed, this might be too late. In this case, you will need to declare +the namespaces of the tested classes in your phpunit.xml.dist + +```` + + + + + Acme\MyClassTest + + + + + +```` Modified PHPUnit script ----------------------- From a6dc0d79db9653544dd1488928183d889acd04b5 Mon Sep 17 00:00:00 2001 From: Sylvain Date: Sun, 11 Nov 2018 19:06:02 +0100 Subject: [PATCH 4/6] Typo --- components/phpunit_bridge.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/components/phpunit_bridge.rst b/components/phpunit_bridge.rst index b8fd20aad72..3a49e48cd5f 100644 --- a/components/phpunit_bridge.rst +++ b/components/phpunit_bridge.rst @@ -482,7 +482,8 @@ tests are constructed, this might be too late. In this case, you will need to de the namespaces of the tested classes in your phpunit.xml.dist ```` - + + From 338d9b583b832c91e559ae55373d45d7e9083cd9 Mon Sep 17 00:00:00 2001 From: Sylvain Date: Thu, 15 Nov 2018 15:40:25 +0100 Subject: [PATCH 5/6] using .. code-block:: xml --- components/phpunit_bridge.rst | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/components/phpunit_bridge.rst b/components/phpunit_bridge.rst index 3a49e48cd5f..ff320ff7eee 100644 --- a/components/phpunit_bridge.rst +++ b/components/phpunit_bridge.rst @@ -481,19 +481,18 @@ annotation are found and the corresponding tests are run. Depending on how your tests are constructed, this might be too late. In this case, you will need to declare the namespaces of the tested classes in your phpunit.xml.dist -```` - +.. code-block:: xml + + - - - Acme\MyClassTest - - - + + + Acme\MyClassTest + + + - -```` Modified PHPUnit script ----------------------- From 3cadb425b2cd2f1c73c89880808a59dbf98268e5 Mon Sep 17 00:00:00 2001 From: Sylvain Date: Thu, 15 Nov 2018 15:47:23 +0100 Subject: [PATCH 6/6] missing line --- components/phpunit_bridge.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/components/phpunit_bridge.rst b/components/phpunit_bridge.rst index ff320ff7eee..9bbd83a9ec6 100644 --- a/components/phpunit_bridge.rst +++ b/components/phpunit_bridge.rst @@ -482,6 +482,7 @@ tests are constructed, this might be too late. In this case, you will need to de the namespaces of the tested classes in your phpunit.xml.dist .. code-block:: xml +