Skip to content
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

Fixed a fatal TypeError when an incorrect file path is given as second argument #3674

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/TextUI/Command.php
Expand Up @@ -778,7 +778,17 @@ protected function handleArguments(array $argv): void
}

if (isset($this->options[1][1])) {
$this->arguments['testFile'] = \realpath($this->options[1][1]);
$testFile = \realpath($this->options[1][1]);

if ($testFile === false) {
$this->exitWithErrorMessage(
\sprintf(
'Cannot open file "%s".',
$this->options[1][1]
)
);
}
$this->arguments['testFile'] = $testFile;
} else {
$this->arguments['testFile'] = '';
}
Expand Down
12 changes: 12 additions & 0 deletions tests/end-to-end/cli/test-file-not-found.phpt
@@ -0,0 +1,12 @@
--TEST--
Test incorrect testFile is reported
--ARGS--
--no-configuration tests nonExistingFile.php
--FILE--
<?php declare(strict_types=1);
require __DIR__ . '/../../bootstrap.php';
PHPUnit\TextUI\Command::main();
--EXPECTF--
PHPUnit %s by Sebastian Bergmann and contributors.

Cannot open file "nonExistingFile.php".