Skip to content

Commit 27e3b9c

Browse files
staabmsebastianbergmann
authored andcommitted
PHPT: Trigger runner warning on parse-error in SKIPIF
1 parent 74f0318 commit 27e3b9c

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

src/Runner/Phpt/TestCase.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,15 @@ 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+
353362
if (str_contains($output, 'Fatal error:')) {
354363
EventFacade::emitter()->testRunnerTriggeredPhpunitWarning(
355364
sprintf(
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+
--SKIPIF--
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

tests/end-to-end/regression/5991.phpt

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-skipif-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) SKIPIF 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)