Skip to content

Commit 7bee150

Browse files
Merge branch '12.3'
2 parents 0b15820 + 21703b1 commit 7bee150

File tree

3 files changed

+69
-21
lines changed

3 files changed

+69
-21
lines changed

src/Runner/Phpt/TestCase.php

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -350,23 +350,7 @@ private function shouldTestBeSkipped(array $sections, array $settings): bool
350350
$output = $this->runCodeInLocalSandbox($skipIfCode);
351351
}
352352

353-
if (str_contains($output, 'Parse error:')) {
354-
EventFacade::emitter()->testRunnerTriggeredPhpunitWarning(
355-
sprintf(
356-
'SKIPIF section triggered a parse error: %s',
357-
$output,
358-
),
359-
);
360-
}
361-
362-
if (str_contains($output, 'Fatal error:')) {
363-
EventFacade::emitter()->testRunnerTriggeredPhpunitWarning(
364-
sprintf(
365-
'SKIPIF section triggered a fatal error: %s',
366-
$output,
367-
),
368-
);
369-
}
353+
$this->triggerRunnerWarningOnPhpErrors('SKIPIF', $output);
370354

371355
if (strncasecmp('skip', ltrim($output), 4) === 0) {
372356
$message = '';
@@ -448,19 +432,21 @@ private function runClean(array $sections, bool $collectCoverage): void
448432
$cleanCode = (new Renderer)->render($this->filename, $sections['CLEAN']);
449433

450434
if ($this->shouldRunInSubprocess($sections, $cleanCode)) {
451-
$result = JobRunnerRegistry::run(
435+
$jobResult = JobRunnerRegistry::run(
452436
new Job(
453437
$cleanCode,
454438
$this->settings($collectCoverage),
455439
),
456440
);
457441

458-
EventFacade::emitter()->childProcessFinished($result->stdout(), $result->stderr());
442+
$output = $jobResult->stdout();
459443

460-
return;
444+
EventFacade::emitter()->childProcessFinished($jobResult->stdout(), $jobResult->stderr());
445+
} else {
446+
$output = $this->runCodeInLocalSandbox($cleanCode);
461447
}
462448

463-
$this->runCodeInLocalSandbox($cleanCode);
449+
$this->triggerRunnerWarningOnPhpErrors('CLEAN', $output);
464450
}
465451

466452
/**
@@ -698,4 +684,27 @@ private function settings(bool $collectCoverage): array
698684

699685
return $settings;
700686
}
687+
688+
private function triggerRunnerWarningOnPhpErrors(string $section, string $output): void
689+
{
690+
if (str_contains($output, 'Parse error:')) {
691+
EventFacade::emitter()->testRunnerTriggeredPhpunitWarning(
692+
sprintf(
693+
'%s section triggered a parse error: %s',
694+
$section,
695+
$output,
696+
),
697+
);
698+
}
699+
700+
if (str_contains($output, 'Fatal error:')) {
701+
EventFacade::emitter()->testRunnerTriggeredPhpunitWarning(
702+
sprintf(
703+
'%s section triggered a fatal error: %s',
704+
$section,
705+
$output,
706+
),
707+
);
708+
}
709+
}
701710
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
--TEST--
2+
https://github.com/sebastianbergmann/phpunit/issues/5991
3+
--CLEAN--
4+
<?php
5+
if (rand(0,1)) // intentional PHP Parse error (missing opening curly brace)
6+
}
7+
--FILE--
8+
<?php declare(strict_types=1);
9+
echo 'hello world';
10+
--EXPECTF--
11+
hello world
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
--TEST--
2+
https://github.com/sebastianbergmann/phpunit/issues/5991
3+
--FILE--
4+
<?php declare(strict_types=1);
5+
$_SERVER['argv'][] = '--do-not-cache-result';
6+
$_SERVER['argv'][] = '--no-configuration';
7+
$_SERVER['argv'][] = __DIR__ . '/../_files/phpt-clean-parse-error.phpt';
8+
9+
require_once __DIR__ . '/../../bootstrap.php';
10+
11+
(new PHPUnit\TextUI\Application)->run($_SERVER['argv']);
12+
--EXPECTF--
13+
PHPUnit %s by Sebastian Bergmann and contributors.
14+
15+
Runtime: %s
16+
17+
. 1 / 1 (100%)
18+
19+
Time: %s, Memory: %s
20+
21+
There was 1 PHPUnit test runner warning:
22+
23+
1) CLEAN section triggered a parse error:
24+
Parse error: Unmatched '}' in Standard input code on line 3
25+
26+
27+
OK, but there were issues!
28+
Tests: 1, Assertions: 1, PHPUnit Warnings: 1.

0 commit comments

Comments
 (0)