From d8ed303bee786ca6f6f284b7b33ec51e505e14fa Mon Sep 17 00:00:00 2001 From: Marko Petrovic Date: Sun, 31 Dec 2023 09:21:08 +0100 Subject: [PATCH] resolve both relative and absolute paths --- src/TextUI/Configuration/Cli/Builder.php | 17 +++++++++++-- .../cli/log-events-text-invalid-argument.phpt | 24 +++++++++++++++++++ ...-events-verbose-text-invalid-argument.phpt | 24 +++++++++++++++++++ 3 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 tests/end-to-end/cli/log-events-text-invalid-argument.phpt create mode 100644 tests/end-to-end/cli/log-events-verbose-text-invalid-argument.phpt diff --git a/src/TextUI/Configuration/Cli/Builder.php b/src/TextUI/Configuration/Cli/Builder.php index 034656bf7a6..9e303b46b45 100644 --- a/src/TextUI/Configuration/Cli/Builder.php +++ b/src/TextUI/Configuration/Cli/Builder.php @@ -15,6 +15,7 @@ use function getcwd; use function is_file; use function is_numeric; +use function realpath; use function sprintf; use PHPUnit\Runner\TestSuiteSorter; use SebastianBergmann\CliParser\Exception as CliParserException; @@ -803,12 +804,24 @@ public function fromParameters(array $parameters): Configuration break; case '--log-events-text': - $logEventsText = $option[1]; + $path = $option[1]; + $realPath = realpath($path); + + if (!$realPath) { + throw new Exception("Specified path: {$path} can't be resolved"); + } + $logEventsText = $realPath; break; case '--log-events-verbose-text': - $logEventsVerboseText = $option[1]; + $path = $option[1]; + $realPath = realpath($path); + + if (!$realPath) { + throw new Exception("Specified path: {$path} can't be resolved"); + } + $logEventsVerboseText = $realPath; break; } diff --git a/tests/end-to-end/cli/log-events-text-invalid-argument.phpt b/tests/end-to-end/cli/log-events-text-invalid-argument.phpt new file mode 100644 index 00000000000..1362b641765 --- /dev/null +++ b/tests/end-to-end/cli/log-events-text-invalid-argument.phpt @@ -0,0 +1,24 @@ +--TEST-- +phpunit --no-output --log-events-text logfile.txt +--FILE-- +run($_SERVER['argv']); + +print file_get_contents($traceFile); + +unlink($traceFile); +--EXPECTF-- +PHPUnit 10.5.3 by Sebastian Bergmann and contributors. + +Specified path: dasdasdasdasd/dasdasdsa.log can't be resolved diff --git a/tests/end-to-end/cli/log-events-verbose-text-invalid-argument.phpt b/tests/end-to-end/cli/log-events-verbose-text-invalid-argument.phpt new file mode 100644 index 00000000000..ad2962385c5 --- /dev/null +++ b/tests/end-to-end/cli/log-events-verbose-text-invalid-argument.phpt @@ -0,0 +1,24 @@ +--TEST-- +phpunit --no-output --log-events-verbose-text logfile.txt +--FILE-- +run($_SERVER['argv']); + +print file_get_contents($traceFile); + +unlink($traceFile); +--EXPECTF-- +PHPUnit 10.5.3 by Sebastian Bergmann and contributors. + +Specified path: dasdasdasdasd/dasdasdsa.log can't be resolved