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

--log-events-text and --log-events-verbose-text CLI options do not handle absolute and relative paths #5633

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions src/TextUI/Configuration/Cli/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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("The path \"{$path}\" specified for the --log-events-text option could not be resolved");
}
$logEventsText = $realPath;

break;

case '--log-events-verbose-text':
$logEventsVerboseText = $option[1];
$path = $option[1];
$realPath = realpath($path);

if (!$realPath) {
throw new Exception("The path \"{$path}\" specified for the --log-events-verbose-text option could not be resolved");
}
$logEventsVerboseText = $realPath;

break;
}
Expand Down
19 changes: 19 additions & 0 deletions tests/end-to-end/cli/log-events-text-invalid-argument.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
--TEST--
Test fails with invalid path
--FILE--
<?php declare(strict_types=1);
$traceFile = sys_get_temp_dir() . '/invalid-directory/invalid.file';

$_SERVER['argv'][] = '--do-not-cache-result';
$_SERVER['argv'][] = '--no-configuration';
$_SERVER['argv'][] = '--no-output';
$_SERVER['argv'][] = '--log-events-text';
$_SERVER['argv'][] = $traceFile;

require __DIR__ . '/../../bootstrap.php';

(new PHPUnit\TextUI\Application)->run($_SERVER['argv']);
--EXPECTF--
PHPUnit %s by Sebastian Bergmann and contributors.

The path "%s" specified for the --log-events-text option could not be resolved
19 changes: 19 additions & 0 deletions tests/end-to-end/cli/log-events-verbose-text-invalid-argument.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
--TEST--
Test fails with invalid path
--FILE--
<?php declare(strict_types=1);
$traceFile = sys_get_temp_dir() . '/invalid-directory/invalid.file';

$_SERVER['argv'][] = '--do-not-cache-result';
$_SERVER['argv'][] = '--no-configuration';
$_SERVER['argv'][] = '--no-output';
$_SERVER['argv'][] = '--log-events-verbose-text';
$_SERVER['argv'][] = $traceFile;

require __DIR__ . '/../../bootstrap.php';

(new PHPUnit\TextUI\Application)->run($_SERVER['argv']);
--EXPECTF--
PHPUnit %s by Sebastian Bergmann and contributors.

The path "%s" specified for the --log-events-verbose-text option could not be resolved