Skip to content

PHPT: Trigger runner warning on fatal-error in SKIPIF #6312

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/Runner/Phpt/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use function preg_replace;
use function preg_split;
use function realpath;
use function sprintf;
use function str_contains;
use function str_starts_with;
use function strncasecmp;
Expand Down Expand Up @@ -349,6 +350,24 @@ 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,
),
);
}

if (strncasecmp('skip', ltrim($output), 4) === 0) {
$message = '';

Expand Down
2 changes: 2 additions & 0 deletions tests/_files/skip-if-requires-code-coverage-driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

if (!extension_loaded('xdebug')) {
print 'skip: This test requires a code coverage driver';

return;
}

if (version_compare(phpversion('xdebug'), '3.1', '>=') && in_array('coverage', xdebug_info('mode'), true)) {
Expand Down
12 changes: 12 additions & 0 deletions tests/end-to-end/_files/phpt-skipif-invalid-require.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
--TEST--
https://github.com/sebastianbergmann/phpunit/issues/6311
--SKIPIF--
<?php declare(strict_types=1);
require __DIR__ . '/some/non/existing/file.php';

--FILE--
<?php declare(strict_types=1);

echo "hello world\n";
--EXPECT--
hello world
11 changes: 11 additions & 0 deletions tests/end-to-end/_files/phpt-skipif-parse-error.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
--TEST--
https://github.com/sebastianbergmann/phpunit/issues/5991
--SKIPIF--
<?php
if (rand(0,1)) // intentional PHP Parse error (missing opening curly brace)
}
--FILE--
<?php declare(strict_types=1);
echo 'hello world';
--EXPECTF--
hello world
28 changes: 28 additions & 0 deletions tests/end-to-end/regression/5991.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
--TEST--
https://github.com/sebastianbergmann/phpunit/issues/5991
--FILE--
<?php declare(strict_types=1);
$_SERVER['argv'][] = '--do-not-cache-result';
$_SERVER['argv'][] = '--no-configuration';
$_SERVER['argv'][] = __DIR__ . '/../_files/phpt-skipif-parse-error.phpt';

require_once __DIR__ . '/../../bootstrap.php';

(new PHPUnit\TextUI\Application)->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) SKIPIF 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.
27 changes: 27 additions & 0 deletions tests/end-to-end/regression/6311.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
--TEST--
https://github.com/sebastianbergmann/phpunit/issues/6311
--FILE--
<?php declare(strict_types=1);
$_SERVER['argv'][] = '--do-not-cache-result';
$_SERVER['argv'][] = '--no-configuration';
$_SERVER['argv'][] = __DIR__ . '/../_files/phpt-skipif-invalid-require.phpt';

require_once __DIR__ . '/../../bootstrap.php';

(new PHPUnit\TextUI\Application)->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) SKIPIF section triggered a fatal error:
Warning: require(%afile.php): Failed to open stream: No such file or directory in Standard input code on line %d

Fatal error: Uncaught Error: Failed opening required%a
%A
Loading