diff --git a/ChangeLog-8.5.md b/ChangeLog-8.5.md index a65e6a61928..754affa9620 100644 --- a/ChangeLog-8.5.md +++ b/ChangeLog-8.5.md @@ -2,6 +2,12 @@ All notable changes of the PHPUnit 8.5 release series are documented in this file using the [Keep a CHANGELOG](https://keepachangelog.com/) principles. +## [8.5.34] - 2023-MM-DD + +### Changed + +* The child processes used for process isolation now use temporary files to communicate their result to the parent process + ## [8.5.33] - 2023-02-27 ### Fixed @@ -268,6 +274,7 @@ All notable changes of the PHPUnit 8.5 release series are documented in this fil * [#3967](https://github.com/sebastianbergmann/phpunit/issues/3967): Cannot double interface that extends interface that extends `\Throwable` * [#3968](https://github.com/sebastianbergmann/phpunit/pull/3968): Test class run in a separate PHP process are passing when `exit` called inside +[8.5.34]: https://github.com/sebastianbergmann/phpunit/compare/8.5.33...8.5 [8.5.33]: https://github.com/sebastianbergmann/phpunit/compare/8.5.32...8.5.33 [8.5.32]: https://github.com/sebastianbergmann/phpunit/compare/8.5.31...8.5.32 [8.5.31]: https://github.com/sebastianbergmann/phpunit/compare/8.5.30...8.5.31 diff --git a/src/Framework/TestCase.php b/src/Framework/TestCase.php index 0973056679e..889d8db40fb 100644 --- a/src/Framework/TestCase.php +++ b/src/Framework/TestCase.php @@ -59,6 +59,8 @@ use function strlen; use function strpos; use function substr; +use function sys_get_temp_dir; +use function tempnam; use function trim; use function var_export; use DeepCopy\DeepCopy; @@ -801,6 +803,7 @@ public function run(TestResult $result = null): TestResult $codeCoverageFilter = "'." . $codeCoverageFilter . ".'"; $configurationFilePath = $GLOBALS['__PHPUNIT_CONFIGURATION_FILE'] ?? ''; + $processResultFile = tempnam(sys_get_temp_dir(), 'phpunit_'); $var = [ 'composerAutoload' => $composerAutoload, @@ -824,6 +827,7 @@ public function run(TestResult $result = null): TestResult 'codeCoverageFilter' => $codeCoverageFilter, 'configurationFilePath' => $configurationFilePath, 'name' => $this->getName(false), + 'processResultFile' => $processResultFile, ]; if (!$runEntireClass) { @@ -833,7 +837,7 @@ public function run(TestResult $result = null): TestResult $template->setVar($var); $php = AbstractPhpProcess::factory(); - $php->runTestJob($template->render(), $this, $result); + $php->runTestJob($template->render(), $this, $result, $processResultFile); } else { $result->run($this); } diff --git a/src/Util/PHP/AbstractPhpProcess.php b/src/Util/PHP/AbstractPhpProcess.php index 8706ae1a118..fc6bc6f14d2 100644 --- a/src/Util/PHP/AbstractPhpProcess.php +++ b/src/Util/PHP/AbstractPhpProcess.php @@ -15,6 +15,8 @@ use function array_merge; use function assert; use function escapeshellarg; +use function file_exists; +use function file_get_contents; use function ini_get_all; use function restore_error_handler; use function set_error_handler; @@ -24,6 +26,7 @@ use function strrpos; use function substr; use function trim; +use function unlink; use function unserialize; use __PHP_Incomplete_Class; use ErrorException; @@ -174,16 +177,23 @@ public function getTimeout(): int * * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException */ - public function runTestJob(string $job, Test $test, TestResult $result): void + public function runTestJob(string $job, Test $test, TestResult $result, string $processResultFile): void { $result->startTest($test); - $_result = $this->runJob($job); + $processResult = ''; + $_result = $this->runJob($job); + + if (file_exists($processResultFile)) { + $processResult = file_get_contents($processResultFile); + + @unlink($processResultFile); + } $this->processChildResult( $test, $result, - $_result['stdout'], + $processResult, $_result['stderr'] ); } diff --git a/src/Util/PHP/Template/TestCaseClass.tpl b/src/Util/PHP/Template/TestCaseClass.tpl index bfcaed7fdcf..2ec3b9c33cc 100644 --- a/src/Util/PHP/Template/TestCaseClass.tpl +++ b/src/Util/PHP/Template/TestCaseClass.tpl @@ -70,13 +70,16 @@ function __phpunit_run_isolated_test() } } - print serialize( - [ - 'testResult' => $test->getResult(), - 'numAssertions' => $test->getNumAssertions(), - 'result' => $result, - 'output' => $output - ] + file_put_contents( + '{processResultFile}', + serialize( + [ + 'testResult' => $test->getResult(), + 'numAssertions' => $test->getNumAssertions(), + 'result' => $result, + 'output' => $output + ] + ) ); } diff --git a/src/Util/PHP/Template/TestCaseMethod.tpl b/src/Util/PHP/Template/TestCaseMethod.tpl index 94545ff8705..b0a692d941e 100644 --- a/src/Util/PHP/Template/TestCaseMethod.tpl +++ b/src/Util/PHP/Template/TestCaseMethod.tpl @@ -73,13 +73,16 @@ function __phpunit_run_isolated_test() } } - print serialize( - [ - 'testResult' => $test->getResult(), - 'numAssertions' => $test->getNumAssertions(), - 'result' => $result, - 'output' => $output - ] + file_put_contents( + '{processResultFile}', + serialize( + [ + 'testResult' => $test->getResult(), + 'numAssertions' => $test->getNumAssertions(), + 'result' => $result, + 'output' => $output + ] + ) ); }