Skip to content

Commit 4e3930a

Browse files
committed
Inplementing the file matcher
1 parent 6f99ddc commit 4e3930a

File tree

3 files changed

+27
-11
lines changed

3 files changed

+27
-11
lines changed

src/TextUI/Configuration/SourceFilter.php

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

12+
use PHPUnit\Util\FileMatcher;
13+
use PHPUnit\Util\FileMatcherRegex;
14+
15+
1216
/**
1317
* @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit
1418
*
@@ -18,19 +22,23 @@ final class SourceFilter
1822
{
1923
private static ?self $instance = null;
2024

25+
private Source $source;
26+
2127
/**
22-
* @var array<non-empty-string, true>
28+
* @var list<FileMatcherRegex>
2329
*/
24-
private readonly array $map;
30+
private array $includeDirectoryRegexes;
31+
32+
/**
33+
* @var list<FileMatcherRegex>
34+
*/
35+
private array $excludeDirectoryRegexes;
2536

2637
public static function instance(): self
2738
{
2839
if (self::$instance === null) {
29-
self::$instance = new self(
30-
(new SourceMapper)->map(
31-
Registry::get()->source(),
32-
),
33-
);
40+
$source = Registry::get()->source();
41+
return new self($source);
3442
}
3543

3644
return self::$instance;
@@ -39,13 +47,21 @@ public static function instance(): self
3947
/**
4048
* @param array<non-empty-string, true> $map
4149
*/
42-
public function __construct(array $map)
50+
public function __construct(Source $source)
4351
{
44-
$this->map = $map;
52+
$this->source = $source;
53+
$this->includeDirectoryRegexes = array_map(function (FilterDirectory $directory) {
54+
return FileMatcher::toRegEx($directory->path());
55+
}, $source->includeDirectories()->asArray());
56+
$this->excludeDirectoryRegexes = array_map(function (FilterDirectory $directory) {
57+
return FileMatcher::toRegEx($directory->path());
58+
}, $source->excludeDirectories()->asArray());
4559
}
4660

4761
public function includes(string $path): bool
4862
{
63+
foreach ($this->source->includeDirectories() as $directory) {
64+
}
4965
return isset($this->map[$path]);
5066
}
5167
}

src/Util/FileMatcher.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public static function toRegEx(string $glob): FileMatcherRegex
6868
/**
6969
* @param list<token> $tokens
7070
*/
71-
public static function mapToRegex(array $tokens): FileMatcherRegex
71+
private static function mapToRegex(array $tokens): FileMatcherRegex
7272
{
7373
$regex = '';
7474

tests/unit/TextUI/SourceFilterTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,6 @@ public static function provider(): array
265265
#[DataProvider('provider')]
266266
public function testDeterminesWhetherFileIsIncluded(bool $expected, string $file, Source $source): void
267267
{
268-
$this->assertSame($expected, (new SourceFilter((new SourceMapper)->map($source)))->includes($file));
268+
$this->assertSame($expected, (new SourceFilter($source))->includes($file));
269269
}
270270
}

0 commit comments

Comments
 (0)