From c9fe4f0ba704d8ff45eab1fb0d195870180c4202 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 | 12 +++++++++++- tests/end-to-end/cli/test-file-not-found.phpt | 12 ++++++++++++ 2 files changed, 23 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..e801368d351 100644 --- a/src/TextUI/Command.php +++ b/src/TextUI/Command.php @@ -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'] = ''; } 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-- +