From b5a087b1e7da63c4922819ee93f7d34720adcfdd Mon Sep 17 00:00:00 2001 From: Gabriel Langer Date: Tue, 30 Apr 2019 23:19:30 +0200 Subject: [PATCH] Fixed a fatal TypeError when an incorrect file path is given as second argument --- src/TextUI/Command.php | 11 ++++++++++- tests/end-to-end/cli/test-file-not-found.phpt | 12 ++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 tests/end-to-end/cli/test-file-not-found.phpt diff --git a/src/TextUI/Command.php b/src/TextUI/Command.php index 9b66bc19272..9d67b68c84d 100644 --- a/src/TextUI/Command.php +++ b/src/TextUI/Command.php @@ -778,7 +778,16 @@ 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'] = ''; } diff --git a/tests/end-to-end/cli/test-file-not-found.phpt b/tests/end-to-end/cli/test-file-not-found.phpt new file mode 100644 index 00000000000..97a2c7ee617 --- /dev/null +++ b/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-- +