Skip to content

Commit c78095c

Browse files
committed
PHPT: Trigger runner warning on fatal-error in SKIPIF
1 parent c524a5a commit c78095c

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed

src/Runner/Phpt/TestCase.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
use function preg_replace;
2828
use function preg_split;
2929
use function realpath;
30+
use function sprintf;
3031
use function str_contains;
3132
use function str_starts_with;
3233
use function strncasecmp;
@@ -349,6 +350,15 @@ private function shouldTestBeSkipped(array $sections, array $settings): bool
349350
$output = $this->runCodeInLocalSandbox($skipIfCode);
350351
}
351352

353+
if (str_contains($output, 'Fatal error:')) {
354+
EventFacade::emitter()->testRunnerTriggeredPhpunitWarning(
355+
sprintf(
356+
'SKIPIF section triggered a fatal error: %s',
357+
$output,
358+
),
359+
);
360+
}
361+
352362
if (strncasecmp('skip', ltrim($output), 4) === 0) {
353363
$message = '';
354364

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
--TEST--
2+
https://github.com/sebastianbergmann/phpunit/issues/6311
3+
--SKIPIF--
4+
<?php declare(strict_types=1);
5+
require __DIR__ . '/some/non/existing/file.php';
6+
7+
--FILE--
8+
<?php declare(strict_types=1);
9+
10+
echo "hello world\n";
11+
--EXPECT--
12+
hello world

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
--TEST--
2+
https://github.com/sebastianbergmann/phpunit/issues/6311
3+
--FILE--
4+
<?php declare(strict_types=1);
5+
$_SERVER['argv'][] = '--do-not-cache-result';
6+
$_SERVER['argv'][] = '--no-configuration';
7+
$_SERVER['argv'][] = __DIR__ . '/../phpt/phpt-invalid-require.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 fatal error:
24+
Warning: require(%afile.php): Failed to open stream: No such file or directory in Standard input code on line %d
25+
%A

0 commit comments

Comments
 (0)