Skip to content

Commit f008948

Browse files
authored
Added simple check for glob paths in config.path value (#951)
1 parent af004cf commit f008948

File tree

5 files changed

+83
-8
lines changed

5 files changed

+83
-8
lines changed

lib/Extension/RunnerExtension.php

+27-7
Original file line numberDiff line numberDiff line change
@@ -518,16 +518,36 @@ private function relativizeConfigPath(Container $container): void
518518
return;
519519
}
520520

521-
$container->setParameter(self::PARAM_PATH, array_map(function (string $path) use ($container) {
521+
$normalizedPaths = array_map(static function (string $path) use ($container) {
522522
if (Path::isAbsolute($path)) {
523-
return $path;
523+
return [$path];
524524
}
525525

526-
return Path::join([
527-
dirname($container->getParameter(CoreExtension::PARAM_CONFIG_PATH)),
528-
$path
529-
]);
530-
}, $paths));
526+
if (str_contains($path, '*') || str_contains($path, '?')) {
527+
$globPaths = glob($path, GLOB_NOSORT);
528+
529+
if (empty($globPaths)) {
530+
return [];
531+
}
532+
533+
return array_map(static function (string $path) use ($container) {
534+
return Path::join([
535+
dirname($container->getParameter(CoreExtension::PARAM_CONFIG_PATH)),
536+
$path
537+
]);
538+
}, $globPaths);
539+
}
540+
541+
return [
542+
Path::join([
543+
dirname($container->getParameter(CoreExtension::PARAM_CONFIG_PATH)),
544+
$path
545+
])
546+
];
547+
}, $paths);
548+
$flattenedPaths = array_merge(...$normalizedPaths);
549+
550+
$container->setParameter(self::PARAM_PATH, $flattenedPaths);
531551
}
532552

533553
private function registerExecutors(Container $container): void

tests/System/RunTest.php

+12-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
class RunTest extends SystemTestCase
1818
{
1919
/**
20-
* It should use a speified, valid, configuration.
20+
* It should use a specified, valid, configuration.
2121
*/
2222
public function testSpecifiedConfig(): void
2323
{
@@ -78,6 +78,17 @@ public function testCommandWithNoPath(): void
7878
$this->assertStringContainsString('You must either specify', $process->getErrorOutput());
7979
}
8080

81+
/**
82+
* It should resolve glob paths to match multiple files.
83+
*/
84+
public function testCommandWithGlobPath(): void
85+
{
86+
$process = $this->phpbench('run benchmarks/set7/*/');
87+
$this->assertExitCode(0, $process);
88+
$this->assertStringContainsString('benchNothing2', $process->getErrorOutput());
89+
$this->assertStringContainsString('benchNothing3', $process->getErrorOutput());
90+
}
91+
8192
public function testCommandWithMultiplePaths(): void
8293
{
8394
$process = $this->phpbench('run benchmarks/set4/NothingBench.php benchmarks/set1/BenchmarkBench.php');
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the PHPBench package
5+
*
6+
* (c) Daniel Leech <daniel@dantleech.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*
11+
*/
12+
13+
namespace PhpBench\Tests\System\benchmarks\set7\nested1;
14+
15+
class Nothing2Bench
16+
{
17+
public function benchNothing2(): void
18+
{
19+
}
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the PHPBench package
5+
*
6+
* (c) Daniel Leech <daniel@dantleech.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*
11+
*/
12+
13+
namespace PhpBench\Tests\System\benchmarks\set7\nested2;
14+
15+
class Nothing3Bench
16+
{
17+
public function benchNothing3(): void
18+
{
19+
}
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"runner.bootstrap": "../../bootstrap/foobar.bootstrap",
3+
"runner.path": "../../benchmarks/set7/*/"
4+
}

0 commit comments

Comments
 (0)