Marking a PHPUnit test with @runInSeparateProcess eventually causes some infinite loop.
Using phpunit.php, the first thing is to load the composer autoloader:
--- a/tests/phpunit/bootstrap.php +++ b/tests/phpunit/bootstrap.php @@ -14,6 +14,10 @@ EOF; require_once __DIR__ . "/phpunit.php"; } +if ( file_exists( __DIR__ . '/../../vendor/autoload.php' ) ) { + define( 'PHPUNIT_COMPOSER_INSTALL', __DIR__ . '/../../vendor/autoload.php' ); +} + class MediaWikiPHPUnitBootstrap { public function __destruct() { // Return to real wiki db, so profiling data is preserved
Then I wrote a basic test case:
--- a/tests/phpunit/tests/MediaWikiTestCaseTest.php +++ b/tests/phpunit/tests/MediaWikiTestCaseTest.php @@ -181,4 +181,12 @@ class MediaWikiTestCaseTest extends MediaWikiTestCase { $this->assertSame( $logger1, $logger2 ); } + + /** + * @runInSeparateProcess + * @preserveGlobalState disabled + */ + public function testItCanRunTestInSeparateProcess() { + $this->assertTrue( true, 'Must support @runInSeparateProcess' ); + } }
Running it with:
$ php tests/phpunit/phpunit.php tests/phpunit/tests/MediaWikiTestCaseTest.php --filter testItCanRunTestInSeparateProcess --debug Using PHP 7.0.27-0+deb9u1 PHPUnit 6.5.8 by Sebastian Bergmann and contributors. Test 'MediaWikiTestCaseTest::testItCanRunTestInSeparateProcess' started
Process:
8114 pts/1 Ss 0:00 \_ bash 9442 pts/1 S+ 0:00 | \_ php tests/phpunit/phpunit.php tests/phpun 9445 pts/1 S+ 0:00 | \_ sh -c '/usr/bin/php7.0' 9446 pts/1 S+ 1:14 | \_ /usr/bin/php7.0 10112 pts/1 S+ 0:00 | \_ sh -c '/usr/bin/php7.0' 10113 pts/1 R+ 0:10 | \_ /usr/bin/php7.0
It looks like it is running the whole suite and eventually shell out to itself to run it again.