Skip to content

Commit 64c3077

Browse files
staabmsebastianbergmann
authored andcommitted
PHPT: Trigger runner warning on parse-error in CLEAN
1 parent ba17ca7 commit 64c3077

File tree

3 files changed

+45
-4
lines changed

3 files changed

+45
-4
lines changed

src/Runner/Phpt/TestCase.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -432,19 +432,21 @@ private function runClean(array $sections, bool $collectCoverage): void
432432
$cleanCode = (new Renderer)->render($this->filename, $sections['CLEAN']);
433433

434434
if ($this->shouldRunInSubprocess($sections, $cleanCode)) {
435-
$result = JobRunnerRegistry::run(
435+
$jobResult = JobRunnerRegistry::run(
436436
new Job(
437437
$cleanCode,
438438
$this->settings($collectCoverage),
439439
),
440440
);
441441

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

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

447-
$this->runCodeInLocalSandbox($cleanCode);
449+
$this->triggerWarningOnPhpErrors('CLEAN', $output);
448450
}
449451

450452
/**
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)