Skip to content

Commit

Permalink
Merge branch '8.5' into 9.6
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Sep 16, 2023
2 parents a122c2e + 3291172 commit 9b37b06
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 23 deletions.
7 changes: 7 additions & 0 deletions ChangeLog-9.6.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion src/Framework/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand All @@ -950,6 +953,7 @@ public function run(TestResult $result = null): TestResult
'codeCoverageFilter' => $codeCoverageFilter,
'configurationFilePath' => $configurationFilePath,
'name' => $this->getName(false),
'processResultFile' => $processResultFile,
];

if (!$runEntireClass) {
Expand All @@ -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);
}
Expand Down
16 changes: 13 additions & 3 deletions src/Util/PHP/AbstractPhpProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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'],
);
}
Expand Down
20 changes: 12 additions & 8 deletions src/Util/PHP/Template/TestCaseClass.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand All @@ -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
]
)
);
}

Expand Down
18 changes: 11 additions & 7 deletions src/Util/PHP/Template/TestCaseMethod.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
]
)
);
}

Expand Down
6 changes: 2 additions & 4 deletions tests/end-to-end/regression/1348.phpt
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
--TEST--
https://github.com/sebastianbergmann/phpunit/issues/1348
--XFAIL--
https://github.com/sebastianbergmann/phpunit/issues/5356
--SKIPIF--
<?php declare(strict_types=1);
if (defined('HHVM_VERSION') || defined('PHPDBG_VERSION')) {
print 'skip: PHP runtime required';
if (defined('STDOUT')) {
print 'skip: PHP < 8.3 required';
}
--FILE--
<?php declare(strict_types=1);
Expand Down

0 comments on commit 9b37b06

Please sign in to comment.