Skip to content

Commit d203855

Browse files
committed
Changed separated process runner templates to return object instead of array allowing class template to return array of objects when refactored.
1 parent 4d6a8c6 commit d203855

File tree

4 files changed

+24
-15
lines changed

4 files changed

+24
-15
lines changed

src/Framework/TestRunner/SeparateProcessTestRunner.php

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use function file_get_contents;
1515
use function get_include_path;
1616
use function hrtime;
17+
use function is_array;
1718
use function is_file;
1819
use function restore_error_handler;
1920
use function serialize;
@@ -252,22 +253,28 @@ static function (int $errno, string $errstr, string $errfile, int $errline): nev
252253
}
253254

254255
if ($childResult !== false) {
255-
if (!empty($childResult['output'])) {
256-
$output = $childResult['output'];
256+
if (!is_array($childResult)) {
257+
$childResult = [$childResult];
257258
}
258259

259-
Facade::instance()->forward($childResult['events']);
260-
PassedTests::instance()->import($childResult['passedTests']);
260+
foreach ($childResult as $result) {
261+
if (!empty($result->output)) {
262+
$output = $result->output;
263+
}
261264

262-
assert($test instanceof TestCase);
265+
Facade::instance()->forward($result->events);
266+
PassedTests::instance()->import($result->passedTests);
267+
268+
assert($test instanceof TestCase);
263269

264-
$test->setResult($childResult['testResult']);
265-
$test->addToAssertionCount($childResult['numAssertions']);
270+
$test->setResult($result->testResult);
271+
$test->addToAssertionCount($result->numAssertions);
266272

267-
if (CodeCoverage::instance()->isActive() && $childResult['codeCoverage'] instanceof \SebastianBergmann\CodeCoverage\CodeCoverage) {
268-
CodeCoverage::instance()->codeCoverage()->merge(
269-
$childResult['codeCoverage'],
270-
);
273+
if (CodeCoverage::instance()->isActive() && $result->codeCoverage instanceof \SebastianBergmann\CodeCoverage\CodeCoverage) {
274+
CodeCoverage::instance()->codeCoverage()->merge(
275+
$result->codeCoverage,
276+
);
277+
}
271278
}
272279
}
273280

src/Framework/TestRunner/templates/class.tpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ function __phpunit_run_isolated_test()
105105
file_put_contents(
106106
'{processResultFile}',
107107
serialize(
108-
[
108+
(object)[
109109
'testResult' => $test->result(),
110110
'codeCoverage' => {collectCodeCoverageInformation} ? CodeCoverage::instance()->codeCoverage() : null,
111111
'numAssertions' => $test->numberOfAssertionsPerformed(),

src/Framework/TestRunner/templates/method.tpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ function __phpunit_run_isolated_test()
105105
file_put_contents(
106106
'{processResultFile}',
107107
serialize(
108-
[
108+
(object)[
109109
'testResult' => $test->result(),
110110
'codeCoverage' => {collectCodeCoverageInformation} ? CodeCoverage::instance()->codeCoverage() : null,
111111
'numAssertions' => $test->numberOfAssertionsPerformed(),

tests/end-to-end/regression/5884/tests/FooTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,11 @@ public function testStreamToNonWritableFileWithPHPUnitErrorHandler(): void
6161

6262
// Now verify the original file is unchanged.
6363
$contents = file_get_contents($filename);
64-
$this->assertSame('foo', $contents);
6564

6665
chmod($filename, 0o755);
6766
unlink($filename);
67+
68+
$this->assertSame('foo', $contents);
6869
}
6970

7071
#[WithoutErrorHandler]
@@ -85,10 +86,11 @@ public function testStreamToNonWritableFileWithoutPHPUnitErrorHandler(): void
8586

8687
// Now verify the original file is unchanged.
8788
$contents = file_get_contents($filename);
88-
$this->assertSame('foo', $contents);
8989

9090
chmod($filename, 0o755);
9191
unlink($filename);
92+
93+
$this->assertSame('foo', $contents);
9294
}
9395

9496
public function testStreamToInvalidFile(): void

0 commit comments

Comments
 (0)