Skip to content

@runClassInSeparateProcess has the same effect as @runTestsInSeparateProcesses #5230

Open
@sebastianbergmann

Description

As previously reported in #3258, @runClassInSeparateProcess has the same effect as @runTestsInSeparateProcesses.

Unless I am mistaken (which I may well be), this can be proven by applying ...

diff --git a/tests/end-to-end/regression/2724/SeparateClassRunMethodInNewProcessTest.php b/tests/end-to-end/regression/2724/SeparateClassRunMethodInNewProcessTest.php
index c62c030be..4bbaf9c7d 100644
--- a/tests/end-to-end/regression/2724/SeparateClassRunMethodInNewProcessTest.php
+++ b/tests/end-to-end/regression/2724/SeparateClassRunMethodInNewProcessTest.php
@@ -46,4 +46,12 @@ public function testTestMethodIsRunInSeparateProcess(): void
         $this->assertNotSame(self::INITIAL_PARENT_PROCESS_ID, self::$parentProcessId);
         $this->assertNotSame(self::$processId, self::$parentProcessId);
     }
+
+    /**
+     * @depends testTestMethodIsRunInSeparateProcess
+     */
+    public function testTestMethodIsRunInSameProcessAsOtherTestMethodsOfThisTestClass(): void
+    {
+        $this->assertSame(self::$processId, \getmypid());
+    }
 }

... to augment an existing test:

./phpunit tests/end-to-end/regression/2724-diff-pid-from-parent-process.phpt                                         
PHPUnit 9.6.3-21-g9da10e7e66 by Sebastian Bergmann and contributors.

Runtime:       PHP 8.2.3
Configuration: /usr/local/src/phpunit/phpunit.xml

F                                                                   1 / 1 (100%)

Time: 00:00.262, Memory: 4.00 MB

There was 1 failure:

1) /usr/local/src/phpunit/tests/end-to-end/regression/2724-diff-pid-from-parent-process.phpt
Failed asserting that string matches format description.
--- Expected
+++ Actual
@@ @@
 PHPUnit 9.6.3-21-g9da10e7e66 by Sebastian Bergmann and contributors.
 
-.                                                                   1 / 1 (100%)
+.F                                                                  2 / 2 (100%)
 
 Time: 00:00.156, Memory: 4.00 MB
 
-OK (1 test, 3 assertions)
+There was 1 failure:
+
+1) SeparateClassRunMethodInNewProcessTest::testTestMethodIsRunInSameProcessAsOtherTestMethodsOfThisTestClass
+Failed asserting that 260001 is identical to 1.
+
+/usr/local/src/phpunit/tests/end-to-end/regression/2724/SeparateClassRunMethodInNewProcessTest.php:55
+
+FAILURES!
+Tests: 2, Assertions: 4, Failures: 1.

/usr/local/src/phpunit/tests/end-to-end/regression/2724-diff-pid-from-parent-process.phpt:17
/usr/local/src/phpunit/src/Framework/TestSuite.php:684
/usr/local/src/phpunit/src/TextUI/TestRunner.php:653
/usr/local/src/phpunit/src/TextUI/Command.php:144
/usr/local/src/phpunit/src/TextUI/Command.php:97

FAILURES!
Tests: 1, Assertions: 1, Failures: 1.

If I understand the above correctly, then, indeed, testTestMethodIsRunInSeparateProcess() and testTestMethodIsRunInSameProcessAsOtherTestMethodsOfThisTestClass() are run in two separate processes and not in a single separate process.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature/process-isolationIssues related to running tests in separate PHP processesfeature/test-runnerCLI test runnertype/bugSomething is brokenversion/10Something affects PHPUnit 10version/11Something affects PHPUnit 11

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions