Skip to content

Commit 239372e

Browse files
Implement filtered reporting of deprecations based on self, direct, indirect triggers
1 parent 715a465 commit 239372e

File tree

30 files changed

+595
-2
lines changed

30 files changed

+595
-2
lines changed

phpunit.xsd

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@
3636
<xs:attribute name="ignoreSuppressionOfPhpNotices" type="xs:boolean" default="false"/>
3737
<xs:attribute name="ignoreSuppressionOfWarnings" type="xs:boolean" default="false"/>
3838
<xs:attribute name="ignoreSuppressionOfPhpWarnings" type="xs:boolean" default="false"/>
39+
<xs:attribute name="ignoreSelfDeprecations" type="xs:boolean" default="false"/>
40+
<xs:attribute name="ignoreDirectDeprecations" type="xs:boolean" default="false"/>
41+
<xs:attribute name="ignoreIndirectDeprecations" type="xs:boolean" default="false"/>
3942
</xs:complexType>
4043
<xs:group name="sourcePathGroup">
4144
<xs:sequence>

src/Runner/TestResult/Collector.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,18 @@ public function testTriggeredDeprecation(DeprecationTriggered $event): void
354354
return;
355355
}
356356

357+
if ($this->source->ignoreSelfDeprecations() && $event->trigger()->isSelf()) {
358+
return;
359+
}
360+
361+
if ($this->source->ignoreDirectDeprecations() && $event->trigger()->isDirect()) {
362+
return;
363+
}
364+
365+
if ($this->source->ignoreIndirectDeprecations() && $event->trigger()->isIndirect()) {
366+
return;
367+
}
368+
357369
if (!$this->source->ignoreSuppressionOfDeprecations() && $event->wasSuppressed()) {
358370
return;
359371
}
@@ -390,6 +402,18 @@ public function testTriggeredPhpDeprecation(PhpDeprecationTriggered $event): voi
390402
return;
391403
}
392404

405+
if ($this->source->ignoreSelfDeprecations() && $event->trigger()->isSelf()) {
406+
return;
407+
}
408+
409+
if ($this->source->ignoreDirectDeprecations() && $event->trigger()->isDirect()) {
410+
return;
411+
}
412+
413+
if ($this->source->ignoreIndirectDeprecations() && $event->trigger()->isIndirect()) {
414+
return;
415+
}
416+
393417
if (!$this->source->ignoreSuppressionOfPhpDeprecations() && $event->wasSuppressed()) {
394418
return;
395419
}

src/TextUI/Configuration/Merger.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -732,6 +732,9 @@ public function merge(CliConfiguration $cliConfiguration, XmlConfiguration $xmlC
732732
$xmlConfiguration->source()->ignoreSuppressionOfWarnings(),
733733
$xmlConfiguration->source()->ignoreSuppressionOfPhpWarnings(),
734734
$xmlConfiguration->source()->deprecationTriggers(),
735+
$xmlConfiguration->source()->ignoreSelfDeprecations(),
736+
$xmlConfiguration->source()->ignoreDirectDeprecations(),
737+
$xmlConfiguration->source()->ignoreIndirectDeprecations(),
735738
),
736739
$testResultCacheFile,
737740
$coverageClover,

src/TextUI/Configuration/Value/Source.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@
3535
private bool $ignoreSuppressionOfPhpNotices;
3636
private bool $ignoreSuppressionOfWarnings;
3737
private bool $ignoreSuppressionOfPhpWarnings;
38+
private bool $ignoreSelfDeprecations;
39+
private bool $ignoreDirectDeprecations;
40+
private bool $ignoreIndirectDeprecations;
3841

3942
/**
4043
* @psalm-var array{functions: list<non-empty-string>, methods: list<non-empty-string>}
@@ -45,7 +48,7 @@
4548
* @psalm-param non-empty-string $baseline
4649
* @psalm-param array{functions: list<non-empty-string>, methods: list<non-empty-string>} $deprecationTriggers
4750
*/
48-
public function __construct(?string $baseline, bool $ignoreBaseline, FilterDirectoryCollection $includeDirectories, FileCollection $includeFiles, FilterDirectoryCollection $excludeDirectories, FileCollection $excludeFiles, bool $restrictDeprecations, bool $restrictNotices, bool $restrictWarnings, bool $ignoreSuppressionOfDeprecations, bool $ignoreSuppressionOfPhpDeprecations, bool $ignoreSuppressionOfErrors, bool $ignoreSuppressionOfNotices, bool $ignoreSuppressionOfPhpNotices, bool $ignoreSuppressionOfWarnings, bool $ignoreSuppressionOfPhpWarnings, array $deprecationTriggers)
51+
public function __construct(?string $baseline, bool $ignoreBaseline, FilterDirectoryCollection $includeDirectories, FileCollection $includeFiles, FilterDirectoryCollection $excludeDirectories, FileCollection $excludeFiles, bool $restrictDeprecations, bool $restrictNotices, bool $restrictWarnings, bool $ignoreSuppressionOfDeprecations, bool $ignoreSuppressionOfPhpDeprecations, bool $ignoreSuppressionOfErrors, bool $ignoreSuppressionOfNotices, bool $ignoreSuppressionOfPhpNotices, bool $ignoreSuppressionOfWarnings, bool $ignoreSuppressionOfPhpWarnings, array $deprecationTriggers, bool $ignoreSelfDeprecations, bool $ignoreDirectDeprecations, bool $ignoreIndirectDeprecations)
4952
{
5053
$this->baseline = $baseline;
5154
$this->ignoreBaseline = $ignoreBaseline;
@@ -64,6 +67,9 @@ public function __construct(?string $baseline, bool $ignoreBaseline, FilterDirec
6467
$this->ignoreSuppressionOfWarnings = $ignoreSuppressionOfWarnings;
6568
$this->ignoreSuppressionOfPhpWarnings = $ignoreSuppressionOfPhpWarnings;
6669
$this->deprecationTriggers = $deprecationTriggers;
70+
$this->ignoreSelfDeprecations = $ignoreSelfDeprecations;
71+
$this->ignoreDirectDeprecations = $ignoreDirectDeprecations;
72+
$this->ignoreIndirectDeprecations = $ignoreIndirectDeprecations;
6773
}
6874

6975
/**
@@ -178,4 +184,19 @@ public function deprecationTriggers(): array
178184
{
179185
return $this->deprecationTriggers;
180186
}
187+
188+
public function ignoreSelfDeprecations(): bool
189+
{
190+
return $this->ignoreSelfDeprecations;
191+
}
192+
193+
public function ignoreDirectDeprecations(): bool
194+
{
195+
return $this->ignoreDirectDeprecations;
196+
}
197+
198+
public function ignoreIndirectDeprecations(): bool
199+
{
200+
return $this->ignoreIndirectDeprecations;
201+
}
181202
}

src/TextUI/Configuration/Xml/DefaultConfiguration.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ public static function create(): self
5656
'functions' => [],
5757
'methods' => [],
5858
],
59+
false,
60+
false,
61+
false,
5962
),
6063
new CodeCoverage(
6164
false,

src/TextUI/Configuration/Xml/Loader.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,9 @@ private function source(string $filename, DOMXPath $xpath): Source
259259
$ignoreSuppressionOfPhpNotices = false;
260260
$ignoreSuppressionOfWarnings = false;
261261
$ignoreSuppressionOfPhpWarnings = false;
262+
$ignoreSelfDeprecations = false;
263+
$ignoreDirectDeprecations = false;
264+
$ignoreIndirectDeprecations = false;
262265

263266
$element = $this->element($xpath, 'source');
264267

@@ -279,6 +282,9 @@ private function source(string $filename, DOMXPath $xpath): Source
279282
$ignoreSuppressionOfPhpNotices = $this->getBooleanAttribute($element, 'ignoreSuppressionOfPhpNotices', false);
280283
$ignoreSuppressionOfWarnings = $this->getBooleanAttribute($element, 'ignoreSuppressionOfWarnings', false);
281284
$ignoreSuppressionOfPhpWarnings = $this->getBooleanAttribute($element, 'ignoreSuppressionOfPhpWarnings', false);
285+
$ignoreSelfDeprecations = $this->getBooleanAttribute($element, 'ignoreSelfDeprecations', false);
286+
$ignoreDirectDeprecations = $this->getBooleanAttribute($element, 'ignoreDirectDeprecations', false);
287+
$ignoreIndirectDeprecations = $this->getBooleanAttribute($element, 'ignoreIndirectDeprecations', false);
282288
}
283289

284290
$deprecationTriggers = [
@@ -316,6 +322,9 @@ private function source(string $filename, DOMXPath $xpath): Source
316322
$ignoreSuppressionOfWarnings,
317323
$ignoreSuppressionOfPhpWarnings,
318324
$deprecationTriggers,
325+
$ignoreSelfDeprecations,
326+
$ignoreDirectDeprecations,
327+
$ignoreIndirectDeprecations,
319328
);
320329
}
321330

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,18 @@ public function testTriggeredDeprecation(DeprecationTriggered $event): void
139139
return;
140140
}
141141

142+
if ($this->source->ignoreSelfDeprecations() && $event->trigger()->isSelf()) {
143+
return;
144+
}
145+
146+
if ($this->source->ignoreDirectDeprecations() && $event->trigger()->isDirect()) {
147+
return;
148+
}
149+
150+
if ($this->source->ignoreIndirectDeprecations() && $event->trigger()->isIndirect()) {
151+
return;
152+
}
153+
142154
if ($this->source->restrictDeprecations() &&
143155
!(new SourceFilter)->includes($this->source, $event->file())) {
144156
return;
@@ -157,6 +169,18 @@ public function testTriggeredPhpDeprecation(PhpDeprecationTriggered $event): voi
157169
return;
158170
}
159171

172+
if ($this->source->ignoreSelfDeprecations() && $event->trigger()->isSelf()) {
173+
return;
174+
}
175+
176+
if ($this->source->ignoreDirectDeprecations() && $event->trigger()->isDirect()) {
177+
return;
178+
}
179+
180+
if ($this->source->ignoreIndirectDeprecations() && $event->trigger()->isIndirect()) {
181+
return;
182+
}
183+
160184
if ($this->source->restrictDeprecations() &&
161185
!(new SourceFilter)->includes($this->source, $event->file())) {
162186
return;

tests/_files/configuration_codecoverage.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
33
xsi:noNamespaceSchemaLocation="../../phpunit.xsd">
4-
<source baseline=".phpunit/baseline.xml">
4+
<source baseline=".phpunit/baseline.xml" ignoreSelfDeprecations="true" ignoreDirectDeprecations="true" ignoreIndirectDeprecations="true">
55
<include>
66
<directory suffix=".php">/path/to/files</directory>
77
<file>/path/to/file</file>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="../../../../../phpunit.xsd"
4+
bootstrap="vendor/autoload.php"
5+
>
6+
<testsuites>
7+
<testsuite name="default">
8+
<directory>tests</directory>
9+
</testsuite>
10+
</testsuites>
11+
12+
<source ignoreSuppressionOfDeprecations="true">
13+
<include>
14+
<directory>src</directory>
15+
</include>
16+
</source>
17+
</phpunit>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php declare(strict_types=1);
2+
/*
3+
* This file is part of PHPUnit.
4+
*
5+
* (c) Sebastian Bergmann <[email protected]>
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
10+
namespace PHPUnit\TestFixture\SelfDirectIndirect;
11+
12+
use function trigger_error;
13+
14+
final class FirstPartyClass
15+
{
16+
public function method(): true
17+
{
18+
(new ThirdPartyClass)->method();
19+
20+
@trigger_error('deprecation in first-party code', E_USER_DEPRECATED);
21+
22+
return true;
23+
}
24+
}

0 commit comments

Comments
 (0)