Skip to content

Commit 378e5ee

Browse files
Closes #6111
1 parent dc21e01 commit 378e5ee

File tree

7 files changed

+50
-23
lines changed

7 files changed

+50
-23
lines changed

ChangeLog-10.5.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ All notable changes of the PHPUnit 10.5 release series are documented in this fi
88

99
* [#6103](https://github.com/sebastianbergmann/phpunit/issues/6103): Output from test run in separate process is printed twice
1010
* [#6109](https://github.com/sebastianbergmann/phpunit/issues/6109): Skipping a test in a before-class method crashes JUnit XML logger
11+
* [#6111](https://github.com/sebastianbergmann/phpunit/issues/6111): Deprecations cause `SourceMapper` to scan all `<source/>` files
1112

1213
## [10.5.41] - 2025-01-13
1314

src/Logging/TestDox/TestResult/TestResultCollector.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ public function testTriggeredDeprecation(DeprecationTriggered $event): void
232232
return;
233233
}
234234

235-
if ($this->source->restrictDeprecations() && !(new SourceFilter)->includes($this->source, $event->file())) {
235+
if ($this->source->restrictDeprecations() && !SourceFilter::instance()->includes($event->file())) {
236236
return;
237237
}
238238

@@ -253,7 +253,7 @@ public function testTriggeredNotice(NoticeTriggered $event): void
253253
return;
254254
}
255255

256-
if ($this->source->restrictNotices() && !(new SourceFilter)->includes($this->source, $event->file())) {
256+
if ($this->source->restrictNotices() && !SourceFilter::instance()->includes($event->file())) {
257257
return;
258258
}
259259

@@ -274,7 +274,7 @@ public function testTriggeredWarning(WarningTriggered $event): void
274274
return;
275275
}
276276

277-
if ($this->source->restrictWarnings() && !(new SourceFilter)->includes($this->source, $event->file())) {
277+
if ($this->source->restrictWarnings() && !SourceFilter::instance()->includes($event->file())) {
278278
return;
279279
}
280280

@@ -299,7 +299,7 @@ public function testTriggeredPhpDeprecation(PhpDeprecationTriggered $event): voi
299299
return;
300300
}
301301

302-
if ($this->source->restrictDeprecations() && !(new SourceFilter)->includes($this->source, $event->file())) {
302+
if ($this->source->restrictDeprecations() && !SourceFilter::instance()->includes($event->file())) {
303303
return;
304304
}
305305

@@ -320,7 +320,7 @@ public function testTriggeredPhpNotice(PhpNoticeTriggered $event): void
320320
return;
321321
}
322322

323-
if ($this->source->restrictNotices() && !(new SourceFilter)->includes($this->source, $event->file())) {
323+
if ($this->source->restrictNotices() && !SourceFilter::instance()->includes($event->file())) {
324324
return;
325325
}
326326

@@ -341,7 +341,7 @@ public function testTriggeredPhpWarning(PhpWarningTriggered $event): void
341341
return;
342342
}
343343

344-
if ($this->source->restrictWarnings() && !(new SourceFilter)->includes($this->source, $event->file())) {
344+
if ($this->source->restrictWarnings() && !SourceFilter::instance()->includes($event->file())) {
345345
return;
346346
}
347347

src/Runner/Baseline/Generator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public function testTriggeredIssue(DeprecationTriggered|NoticeTriggered|PhpDepre
6666
return;
6767
}
6868

69-
if ($this->restrict($event) && !(new SourceFilter)->includes($this->source, $event->file())) {
69+
if ($this->restrict($event) && !SourceFilter::instance()->includes($event->file())) {
7070
return;
7171
}
7272

src/Runner/TestResult/Collector.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ public function testTriggeredDeprecation(DeprecationTriggered $event): void
367367
return;
368368
}
369369

370-
if ($this->source->restrictDeprecations() && !(new SourceFilter)->includes($this->source, $event->file())) {
370+
if ($this->source->restrictDeprecations() && !SourceFilter::instance()->includes($event->file())) {
371371
return;
372372
}
373373

@@ -403,7 +403,7 @@ public function testTriggeredPhpDeprecation(PhpDeprecationTriggered $event): voi
403403
return;
404404
}
405405

406-
if ($this->source->restrictDeprecations() && !(new SourceFilter)->includes($this->source, $event->file())) {
406+
if ($this->source->restrictDeprecations() && !SourceFilter::instance()->includes($event->file())) {
407407
return;
408408
}
409409

@@ -466,7 +466,7 @@ public function testTriggeredNotice(NoticeTriggered $event): void
466466
return;
467467
}
468468

469-
if ($this->source->restrictNotices() && !(new SourceFilter)->includes($this->source, $event->file())) {
469+
if ($this->source->restrictNotices() && !SourceFilter::instance()->includes($event->file())) {
470470
return;
471471
}
472472

@@ -498,7 +498,7 @@ public function testTriggeredPhpNotice(PhpNoticeTriggered $event): void
498498
return;
499499
}
500500

501-
if ($this->source->restrictNotices() && !(new SourceFilter)->includes($this->source, $event->file())) {
501+
if ($this->source->restrictNotices() && !SourceFilter::instance()->includes($event->file())) {
502502
return;
503503
}
504504

@@ -530,7 +530,7 @@ public function testTriggeredWarning(WarningTriggered $event): void
530530
return;
531531
}
532532

533-
if ($this->source->restrictWarnings() && !(new SourceFilter)->includes($this->source, $event->file())) {
533+
if ($this->source->restrictWarnings() && !SourceFilter::instance()->includes($event->file())) {
534534
return;
535535
}
536536

@@ -562,7 +562,7 @@ public function testTriggeredPhpWarning(PhpWarningTriggered $event): void
562562
return;
563563
}
564564

565-
if ($this->source->restrictWarnings() && !(new SourceFilter)->includes($this->source, $event->file())) {
565+
if ($this->source->restrictWarnings() && !SourceFilter::instance()->includes($event->file())) {
566566
return;
567567
}
568568

src/TextUI/Configuration/SourceFilter.php

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,36 @@
1616
*/
1717
final class SourceFilter
1818
{
19-
public function includes(Source $source, string $path): bool
19+
private static ?self $instance = null;
20+
21+
/**
22+
* @psalm-var array<non-empty-string, true>
23+
*/
24+
private readonly array $map;
25+
26+
public static function instance(): self
27+
{
28+
if (self::$instance === null) {
29+
self::$instance = new self(
30+
(new SourceMapper)->map(
31+
Registry::get()->source(),
32+
),
33+
);
34+
}
35+
36+
return self::$instance;
37+
}
38+
39+
/**
40+
* @psalm-param array<non-empty-string, true> $map
41+
*/
42+
public function __construct(array $map)
2043
{
21-
$files = (new SourceMapper)->map($source);
44+
$this->map = $map;
45+
}
2246

23-
return isset($files[$path]);
47+
public function includes(string $path): bool
48+
{
49+
return isset($this->map[$path]);
2450
}
2551
}

src/TextUI/Output/Default/ProgressPrinter/ProgressPrinter.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public function testTriggeredNotice(NoticeTriggered $event): void
106106
}
107107

108108
if ($this->source->restrictNotices() &&
109-
!(new SourceFilter)->includes($this->source, $event->file())) {
109+
!SourceFilter::instance()->includes($event->file())) {
110110
return;
111111
}
112112

@@ -124,7 +124,7 @@ public function testTriggeredPhpNotice(PhpNoticeTriggered $event): void
124124
}
125125

126126
if ($this->source->restrictNotices() &&
127-
!(new SourceFilter)->includes($this->source, $event->file())) {
127+
!SourceFilter::instance()->includes($event->file())) {
128128
return;
129129
}
130130

@@ -142,7 +142,7 @@ public function testTriggeredDeprecation(DeprecationTriggered $event): void
142142
}
143143

144144
if ($this->source->restrictDeprecations() &&
145-
!(new SourceFilter)->includes($this->source, $event->file())) {
145+
!SourceFilter::instance()->includes($event->file())) {
146146
return;
147147
}
148148

@@ -160,7 +160,7 @@ public function testTriggeredPhpDeprecation(PhpDeprecationTriggered $event): voi
160160
}
161161

162162
if ($this->source->restrictDeprecations() &&
163-
!(new SourceFilter)->includes($this->source, $event->file())) {
163+
!SourceFilter::instance()->includes($event->file())) {
164164
return;
165165
}
166166

@@ -188,7 +188,7 @@ public function testTriggeredWarning(WarningTriggered $event): void
188188
}
189189

190190
if ($this->source->restrictWarnings() &&
191-
!(new SourceFilter)->includes($this->source, $event->file())) {
191+
!SourceFilter::instance()->includes($event->file())) {
192192
return;
193193
}
194194

@@ -206,7 +206,7 @@ public function testTriggeredPhpWarning(PhpWarningTriggered $event): void
206206
}
207207

208208
if ($this->source->restrictWarnings() &&
209-
!(new SourceFilter)->includes($this->source, $event->file())) {
209+
!SourceFilter::instance()->includes($event->file())) {
210210
return;
211211
}
212212

tests/unit/TextUI/SourceFilterTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,6 @@ public static function provider(): array
223223
#[DataProvider('provider')]
224224
public function testDeterminesWhetherFileIsIncluded(bool $expected, string $file, Source $source): void
225225
{
226-
$this->assertSame($expected, (new SourceFilter)->includes($source, $file));
226+
$this->assertSame($expected, (new SourceFilter((new SourceMapper)->map($source)))->includes($file));
227227
}
228228
}

0 commit comments

Comments
 (0)