diff --git a/src/Runner/Phpt/TestCase.php b/src/Runner/Phpt/TestCase.php index 5d2bafe2f14..308b42a3e0b 100644 --- a/src/Runner/Phpt/TestCase.php +++ b/src/Runner/Phpt/TestCase.php @@ -350,23 +350,7 @@ private function shouldTestBeSkipped(array $sections, array $settings): bool $output = $this->runCodeInLocalSandbox($skipIfCode); } - if (str_contains($output, 'Parse error:')) { - EventFacade::emitter()->testRunnerTriggeredPhpunitWarning( - sprintf( - 'SKIPIF section triggered a parse error: %s', - $output, - ), - ); - } - - if (str_contains($output, 'Fatal error:')) { - EventFacade::emitter()->testRunnerTriggeredPhpunitWarning( - sprintf( - 'SKIPIF section triggered a fatal error: %s', - $output, - ), - ); - } + $this->triggerRunnerWarningOnPhpErrors('SKIPIF', $output); if (strncasecmp('skip', ltrim($output), 4) === 0) { $message = ''; @@ -448,19 +432,21 @@ private function runClean(array $sections, bool $collectCoverage): void $cleanCode = (new Renderer)->render($this->filename, $sections['CLEAN']); if ($this->shouldRunInSubprocess($sections, $cleanCode)) { - $result = JobRunnerRegistry::run( + $jobResult = JobRunnerRegistry::run( new Job( $cleanCode, $this->settings($collectCoverage), ), ); - EventFacade::emitter()->childProcessFinished($result->stdout(), $result->stderr()); + $output = $jobResult->stdout(); - return; + EventFacade::emitter()->childProcessFinished($jobResult->stdout(), $jobResult->stderr()); + } else { + $output = $this->runCodeInLocalSandbox($cleanCode); } - $this->runCodeInLocalSandbox($cleanCode); + $this->triggerRunnerWarningOnPhpErrors('CLEAN', $output); } /** @@ -698,4 +684,27 @@ private function settings(bool $collectCoverage): array return $settings; } + + private function triggerRunnerWarningOnPhpErrors(string $section, string $output): void + { + if (str_contains($output, 'Parse error:')) { + EventFacade::emitter()->testRunnerTriggeredPhpunitWarning( + sprintf( + '%s section triggered a parse error: %s', + $section, + $output, + ), + ); + } + + if (str_contains($output, 'Fatal error:')) { + EventFacade::emitter()->testRunnerTriggeredPhpunitWarning( + sprintf( + '%s section triggered a fatal error: %s', + $section, + $output, + ), + ); + } + } } diff --git a/tests/end-to-end/_files/phpt-clean-parse-error.phpt b/tests/end-to-end/_files/phpt-clean-parse-error.phpt new file mode 100644 index 00000000000..d9d370b1735 --- /dev/null +++ b/tests/end-to-end/_files/phpt-clean-parse-error.phpt @@ -0,0 +1,11 @@ +--TEST-- +https://github.com/sebastianbergmann/phpunit/issues/5991 +--CLEAN-- +run($_SERVER['argv']); +--EXPECTF-- +PHPUnit %s by Sebastian Bergmann and contributors. + +Runtime: %s + +. 1 / 1 (100%) + +Time: %s, Memory: %s + +There was 1 PHPUnit test runner warning: + +1) CLEAN section triggered a parse error: +Parse error: Unmatched '}' in Standard input code on line 3 + + +OK, but there were issues! +Tests: 1, Assertions: 1, PHPUnit Warnings: 1.