Skip to content

Commit

Permalink
resolve both relative and absolute paths
Browse files Browse the repository at this point in the history
  • Loading branch information
marac19901990 committed Dec 31, 2023
1 parent 6d16518 commit d8ed303
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 2 deletions.
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("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;
}
Expand Down
24 changes: 24 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,24 @@
--TEST--
phpunit --no-output --log-events-text logfile.txt
--FILE--
<?php declare(strict_types=1);
$traceFile = 'dasdasdasdasd/dasdasdsa.log';

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

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

(new PHPUnit\TextUI\Application)->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
24 changes: 24 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,24 @@
--TEST--
phpunit --no-output --log-events-verbose-text logfile.txt
--FILE--
<?php declare(strict_types=1);
$traceFile = 'dasdasdasdasd/dasdasdsa.log';

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

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

(new PHPUnit\TextUI\Application)->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

0 comments on commit d8ed303

Please sign in to comment.