Skip to content

Commit

Permalink
Closes #6111
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Jan 28, 2025
1 parent dc21e01 commit 378e5ee
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 23 deletions.
1 change: 1 addition & 0 deletions ChangeLog-10.5.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ All notable changes of the PHPUnit 10.5 release series are documented in this fi

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

## [10.5.41] - 2025-01-13

Expand Down
12 changes: 6 additions & 6 deletions src/Logging/TestDox/TestResult/TestResultCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ public function testTriggeredDeprecation(DeprecationTriggered $event): void
return;
}

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

Expand All @@ -253,7 +253,7 @@ public function testTriggeredNotice(NoticeTriggered $event): void
return;
}

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

Expand All @@ -274,7 +274,7 @@ public function testTriggeredWarning(WarningTriggered $event): void
return;
}

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

Expand All @@ -299,7 +299,7 @@ public function testTriggeredPhpDeprecation(PhpDeprecationTriggered $event): voi
return;
}

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

Expand All @@ -320,7 +320,7 @@ public function testTriggeredPhpNotice(PhpNoticeTriggered $event): void
return;
}

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

Expand All @@ -341,7 +341,7 @@ public function testTriggeredPhpWarning(PhpWarningTriggered $event): void
return;
}

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

Expand Down
2 changes: 1 addition & 1 deletion src/Runner/Baseline/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function testTriggeredIssue(DeprecationTriggered|NoticeTriggered|PhpDepre
return;
}

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

Expand Down
12 changes: 6 additions & 6 deletions src/Runner/TestResult/Collector.php
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ public function testTriggeredDeprecation(DeprecationTriggered $event): void
return;
}

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

Expand Down Expand Up @@ -403,7 +403,7 @@ public function testTriggeredPhpDeprecation(PhpDeprecationTriggered $event): voi
return;
}

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

Expand Down Expand Up @@ -466,7 +466,7 @@ public function testTriggeredNotice(NoticeTriggered $event): void
return;
}

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

Expand Down Expand Up @@ -498,7 +498,7 @@ public function testTriggeredPhpNotice(PhpNoticeTriggered $event): void
return;
}

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

Expand Down Expand Up @@ -530,7 +530,7 @@ public function testTriggeredWarning(WarningTriggered $event): void
return;
}

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

Expand Down Expand Up @@ -562,7 +562,7 @@ public function testTriggeredPhpWarning(PhpWarningTriggered $event): void
return;
}

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

Expand Down
32 changes: 29 additions & 3 deletions src/TextUI/Configuration/SourceFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,36 @@
*/
final class SourceFilter
{
public function includes(Source $source, string $path): bool
private static ?self $instance = null;

/**
* @psalm-var array<non-empty-string, true>
*/
private readonly array $map;

public static function instance(): self
{
if (self::$instance === null) {
self::$instance = new self(
(new SourceMapper)->map(
Registry::get()->source(),
),
);
}

return self::$instance;
}

/**
* @psalm-param array<non-empty-string, true> $map
*/
public function __construct(array $map)
{
$files = (new SourceMapper)->map($source);
$this->map = $map;
}

return isset($files[$path]);
public function includes(string $path): bool
{
return isset($this->map[$path]);
}
}
12 changes: 6 additions & 6 deletions src/TextUI/Output/Default/ProgressPrinter/ProgressPrinter.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public function testTriggeredNotice(NoticeTriggered $event): void
}

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

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

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

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

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

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

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

Expand Down Expand Up @@ -188,7 +188,7 @@ public function testTriggeredWarning(WarningTriggered $event): void
}

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

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

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

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/TextUI/SourceFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,6 @@ public static function provider(): array
#[DataProvider('provider')]
public function testDeterminesWhetherFileIsIncluded(bool $expected, string $file, Source $source): void
{
$this->assertSame($expected, (new SourceFilter)->includes($source, $file));
$this->assertSame($expected, (new SourceFilter((new SourceMapper)->map($source)))->includes($file));
}
}

0 comments on commit 378e5ee

Please sign in to comment.