diff --git a/ChangeLog-9.6.md b/ChangeLog-9.6.md index bbe94625200..de708d42051 100644 --- a/ChangeLog-9.6.md +++ b/ChangeLog-9.6.md @@ -2,6 +2,12 @@ All notable changes of the PHPUnit 9.6 release series are documented in this file using the [Keep a CHANGELOG](https://keepachangelog.com/) principles. +## [9.6.13] - 2023-MM-DD + +### Changed + +* The child processes used for process isolation now use temporary files to communicate their result to the parent process + ## [9.6.12] - 2023-09-12 ### Changed @@ -89,6 +95,7 @@ All notable changes of the PHPUnit 9.6 release series are documented in this fil * [#5064](https://github.com/sebastianbergmann/phpunit/issues/5064): Deprecate `PHPUnit\Framework\TestCase::getMockClass()` * [#5132](https://github.com/sebastianbergmann/phpunit/issues/5132): Deprecate `Test` suffix for abstract test case classes +[9.6.13]: https://github.com/sebastianbergmann/phpunit/compare/9.6.12...9.6 [9.6.12]: https://github.com/sebastianbergmann/phpunit/compare/9.6.11...9.6.12 [9.6.11]: https://github.com/sebastianbergmann/phpunit/compare/9.6.10...9.6.11 [9.6.10]: https://github.com/sebastianbergmann/phpunit/compare/9.6.9...9.6.10 diff --git a/src/Framework/TestCase.php b/src/Framework/TestCase.php index 380759b6d17..3a67f5dd126 100644 --- a/src/Framework/TestCase.php +++ b/src/Framework/TestCase.php @@ -60,6 +60,8 @@ use function sprintf; 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; @@ -924,6 +926,7 @@ public function run(TestResult $result = null): TestResult $codeCoverageCacheDirectory = "'." . $codeCoverageCacheDirectory . ".'"; $configurationFilePath = $GLOBALS['__PHPUNIT_CONFIGURATION_FILE'] ?? ''; + $processResultFile = tempnam(sys_get_temp_dir(), 'phpunit_'); $var = [ 'composerAutoload' => $composerAutoload, @@ -950,6 +953,7 @@ public function run(TestResult $result = null): TestResult 'codeCoverageFilter' => $codeCoverageFilter, 'configurationFilePath' => $configurationFilePath, 'name' => $this->getName(false), + 'processResultFile' => $processResultFile, ]; if (!$runEntireClass) { @@ -959,7 +963,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 5b34055af23..0405d1f3350 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 95035e50521..0486d116433 100644 --- a/src/Util/PHP/Template/TestCaseClass.tpl +++ b/src/Util/PHP/Template/TestCaseClass.tpl @@ -58,7 +58,7 @@ function __phpunit_run_isolated_test() $test = new {className}('{name}', unserialize('{data}'), '{dataName}'); $test->setDependencyInput(unserialize('{dependencyInput}')); - $test->setInIsolation(TRUE); + $test->setInIsolation(true); ob_end_clean(); $test->run($result); @@ -68,6 +68,7 @@ function __phpunit_run_isolated_test() } ini_set('xdebug.scream', '0'); + @rewind(STDOUT); /* @ as not every STDOUT target stream is rewindable */ if ($stdout = @stream_get_contents(STDOUT)) { $output = $stdout . $output; @@ -78,13 +79,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 da824e7206e..067934dbcf2 100644 --- a/src/Util/PHP/Template/TestCaseMethod.tpl +++ b/src/Util/PHP/Template/TestCaseMethod.tpl @@ -71,6 +71,7 @@ function __phpunit_run_isolated_test() } ini_set('xdebug.scream', '0'); + @rewind(STDOUT); /* @ as not every STDOUT target stream is rewindable */ if ($stdout = @stream_get_contents(STDOUT)) { $output = $stdout . $output; @@ -81,13 +82,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/tests/end-to-end/regression/1348.phpt b/tests/end-to-end/regression/1348.phpt index a00913c768f..977dbb73995 100644 --- a/tests/end-to-end/regression/1348.phpt +++ b/tests/end-to-end/regression/1348.phpt @@ -1,11 +1,9 @@ --TEST-- https://github.com/sebastianbergmann/phpunit/issues/1348 ---XFAIL-- -https://github.com/sebastianbergmann/phpunit/issues/5356 --SKIPIF--