Skip to content

Commit

Permalink
Fixed a fatal TypeError when an incorrect file path is given as secon…
Browse files Browse the repository at this point in the history
…d argument
  • Loading branch information
LANGERGabrielle committed Apr 30, 2019
1 parent 1f66fc1 commit c9fe4f0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
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".

0 comments on commit c9fe4f0

Please sign in to comment.