Skip to content

Commit b29cc60

Browse files
committed
CS fixes
1 parent f0007f4 commit b29cc60

File tree

2 files changed

+33
-26
lines changed

2 files changed

+33
-26
lines changed

src/TextUI/Configuration/SourceFilter.php

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,15 @@
99
*/
1010
namespace PHPUnit\TextUI\Configuration;
1111

12-
use Webmozart\Glob\Glob;
1312
use function array_map;
13+
use function basename;
14+
use function dirname;
15+
use function preg_match;
16+
use function rtrim;
17+
use function sprintf;
18+
use function str_ends_with;
19+
use function str_starts_with;
20+
use Webmozart\Glob\Glob;
1421

1522
/**
1623
* @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit
@@ -44,6 +51,23 @@ public static function instance(): self
4451
return self::$instance;
4552
}
4653

54+
/**
55+
* Convert the directory filter to a glob.
56+
*
57+
* To ensure that `foo/**` will match `foo/bar.php` we match both the
58+
* globstar and the wildcard.
59+
*/
60+
public static function toGlob(FilterDirectory $directory): string
61+
{
62+
$path = rtrim($directory->path(), '/');
63+
64+
return sprintf(
65+
'{(%s)|(%s)}',
66+
Glob::toRegEx(sprintf('%s/**/*', $path), 0, ''),
67+
Glob::toRegEx(sprintf('%s/*', $path), 0, ''),
68+
);
69+
}
70+
4771
public function __construct(Source $source)
4872
{
4973
$this->source = $source;
@@ -63,8 +87,9 @@ public function __construct(Source $source)
6387
public function includes(string $path): bool
6488
{
6589
$included = false;
66-
$dirPath = rtrim(dirname($path), '/') . '/';
90+
$dirPath = rtrim(dirname($path), '/') . '/';
6791
$filename = basename($path);
92+
6893
foreach ($this->source->includeFiles() as $file) {
6994
if ($file->path() === $path) {
7095
$included = true;
@@ -92,23 +117,6 @@ public function includes(string $path): bool
92117
return $included;
93118
}
94119

95-
/**
96-
* Convert the directory filter to a glob.
97-
*
98-
* To ensure that `foo/**` will match `foo/bar.php` we match both the
99-
* globstar and the wildcard.
100-
*/
101-
public static function toGlob(FilterDirectory $directory): string
102-
{
103-
$path = rtrim($directory->path(), '/');
104-
105-
return sprintf(
106-
'{(%s)|(%s)}',
107-
Glob::toRegEx(sprintf('%s/**/*', $path), 0, ''),
108-
Glob::toRegEx(sprintf('%s/*', $path), 0, ''),
109-
);
110-
}
111-
112120
private static function filenameMatches(FilterDirectory $directory, string $filename): bool
113121
{
114122
return str_starts_with($filename, $directory->prefix()) && str_ends_with($filename, $directory->suffix());

tests/unit/TextUI/SourceFilterTest.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
*/
1010
namespace PHPUnit\TextUI\Configuration;
1111

12-
use function json_encode;
13-
use function sprintf;
1412
use PHPUnit\Framework\Attributes\CoversClass;
1513
use PHPUnit\Framework\Attributes\DataProvider;
1614
use PHPUnit\Framework\Attributes\Small;
@@ -324,7 +322,7 @@ public static function provider(): array
324322
),
325323
],
326324
// this seems rather more like a bug
327-
//'globstar with any single char prefix includes sibling files' => [
325+
// 'globstar with any single char prefix includes sibling files' => [
328326
// [
329327
// self::fixturePath('a/PrefixSuffix.php') => false,
330328
// self::fixturePath('a/c/PrefixSuffix.php') => true,
@@ -341,7 +339,7 @@ public static function provider(): array
341339
// ],
342340
// ),
343341
// ),
344-
//],
342+
// ],
345343
'globstar with any more than a single char prefix does not include sibling files' => [
346344
[
347345
self::fixturePath('a/PrefixSuffix.php') => false,
@@ -432,12 +430,13 @@ public static function provider(): array
432430
public function testDeterminesWhetherFileIsIncluded(array $expectations, Source $source): void
433431
{
434432
$expected = [];
435-
$actual = [];
433+
$actual = [];
434+
436435
foreach ($expectations as $file => $shouldInclude) {
437436
$this->assertFileExists($file);
438437
$expected[$file] = $shouldInclude;
439-
$actual[$file] = (new SourceFilter($source))->includes($file);
438+
$actual[$file] = (new SourceFilter($source))->includes($file);
440439
}
441-
self::assertEquals($expected, $actual);
440+
$this->assertEquals($expected, $actual);
442441
}
443442
}

0 commit comments

Comments
 (0)