Skip to content

Commit 194b3b6

Browse files
authored
chore: phpunit missing deprecation triggers (#7059)
1 parent dddd3ee commit 194b3b6

File tree

20 files changed

+144
-1
lines changed

20 files changed

+144
-1
lines changed

.github/patches/phpunit.patch

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
diff --git a/src/Runner/ErrorHandler.php b/src/Runner/ErrorHandler.php
2+
index 54f35aa41..94a2bb600 100644
3+
--- a/src/Runner/ErrorHandler.php
4+
+++ b/src/Runner/ErrorHandler.php
5+
@@ -59,6 +59,11 @@ final class ErrorHandler
6+
private ?int $originalErrorReportingLevel = null;
7+
private readonly Source $source;
8+
9+
+ /**
10+
+ * @var list<array{int, string, string, int}>
11+
+ */
12+
+ private array $globalDeprecations = [];
13+
+
14+
/**
15+
* @var ?array{functions: list<non-empty-string>, methods: list<array{className: class-string, methodName: non-empty-string}>}
16+
*/
17+
@@ -197,6 +202,23 @@ public function __invoke(int $errorNumber, string $errorString, string $errorFil
18+
return false;
19+
}
20+
21+
+ public function deprecationHandler(int $errorNumber, string $errorString, string $errorFile, int $errorLine): bool
22+
+ {
23+
+ $this->globalDeprecations[] = [$errorNumber, $errorString, $errorFile, $errorLine];
24+
+
25+
+ return true;
26+
+ }
27+
+
28+
+ public function registerDeprecationHandler(): void
29+
+ {
30+
+ set_error_handler([self::$instance, 'deprecationHandler'], E_USER_DEPRECATED);
31+
+ }
32+
+
33+
+ public function restoreDeprecationHandler(): void
34+
+ {
35+
+ restore_error_handler();
36+
+ }
37+
+
38+
public function enable(): void
39+
{
40+
if ($this->enabled) {
41+
@@ -213,6 +235,7 @@ public function enable(): void
42+
43+
$this->enabled = true;
44+
$this->originalErrorReportingLevel = error_reporting();
45+
+ $this->triggerGlobalDeprecations();
46+
47+
error_reporting($this->originalErrorReportingLevel & self::UNHANDLEABLE_LEVELS);
48+
}
49+
@@ -422,4 +445,11 @@ private function stackTrace(): string
50+
51+
return $buffer;
52+
}
53+
+
54+
+ private function triggerGlobalDeprecations(): void
55+
+ {
56+
+ foreach ($this->globalDeprecations ?? [] as $d) {
57+
+ $this->__invoke(...$d);
58+
+ }
59+
+ }
60+
}
61+
diff --git a/src/TextUI/Application.php b/src/TextUI/Application.php
62+
index ca6da7005..d8965d41b 100644
63+
--- a/src/TextUI/Application.php
64+
+++ b/src/TextUI/Application.php
65+
@@ -178,8 +178,12 @@ public function run(array $argv): int
66+
67+
EventFacade::instance()->seal();
68+
69+
+ ErrorHandler::instance()->registerDeprecationHandler();
70+
+
71+
$testSuite = $this->buildTestSuite($configuration);
72+
73+
+ ErrorHandler::instance()->restoreDeprecationHandler();
74+
+
75+
$this->executeCommandsThatRequireTheTestSuite($configuration, $cliConfiguration, $testSuite);
76+
77+
if ($testSuite->isEmpty() && !$configuration->hasCliArguments() && $configuration->testSuite()->isEmpty()) {

.github/workflows/ci.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -862,6 +862,8 @@ jobs:
862862
composer global link .
863863
- name: Clear test app cache
864864
run: tests/Fixtures/app/console cache:clear --ansi
865+
- name: Patch phpunit
866+
run: git apply --directory vendor/phpunit/phpunit .github/patches/phpunit.patch
865867
- name: Run PHPUnit tests
866868
run: vendor/bin/phpunit --fail-on-deprecation --display-deprecations
867869

@@ -906,7 +908,7 @@ jobs:
906908
- name: Clear test app cache
907909
run: tests/Fixtures/app/console cache:clear --ansi
908910
- name: Run PHPUnit tests
909-
run: vendor/bin/phpunit
911+
run: vendor/bin/phpunit --fail-on-deprecation
910912

911913
behat-symfony-next:
912914
name: Behat (PHP ${{ matrix.php }}) (Symfony dev)

phpunit.xml.dist

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@
2929
</groups>
3030

3131
<source ignoreSuppressionOfDeprecations="true" ignoreIndirectDeprecations="true" baseline="phpunit.baseline.xml">
32+
<deprecationTrigger>
33+
<function>trigger_deprecation</function>
34+
<method>Doctrine\Deprecations\Deprecation::trigger</method>
35+
<method>Doctrine\Deprecations\Deprecation::delegateTriggerToBackend</method>
36+
</deprecationTrigger>
3237
<include>
3338
<directory>.</directory>
3439
</include>

src/Doctrine/Common/phpunit.xml.dist

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99
</testsuite>
1010
</testsuites>
1111
<source>
12+
<deprecationTrigger>
13+
<function>trigger_deprecation</function>
14+
<method>Doctrine\Deprecations\Deprecation::trigger</method>
15+
<method>Doctrine\Deprecations\Deprecation::delegateTriggerToBackend</method>
16+
</deprecationTrigger>
1217
<include>
1318
<directory>./</directory>
1419
</include>

src/Doctrine/Odm/phpunit.xml.dist

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@
1111
</testsuite>
1212
</testsuites>
1313
<source>
14+
<deprecationTrigger>
15+
<function>trigger_deprecation</function>
16+
<method>Doctrine\Deprecations\Deprecation::trigger</method>
17+
<method>Doctrine\Deprecations\Deprecation::delegateTriggerToBackend</method>
18+
</deprecationTrigger>
1419
<include>
1520
<directory>./</directory>
1621
</include>

src/Doctrine/Orm/phpunit.xml.dist

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@
1111
</testsuite>
1212
</testsuites>
1313
<source>
14+
<deprecationTrigger>
15+
<function>trigger_deprecation</function>
16+
<method>Doctrine\Deprecations\Deprecation::trigger</method>
17+
<method>Doctrine\Deprecations\Deprecation::delegateTriggerToBackend</method>
18+
</deprecationTrigger>
1419
<include>
1520
<directory>./</directory>
1621
</include>

src/Elasticsearch/phpunit.xml.dist

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
</testsuite>
1010
</testsuites>
1111
<source>
12+
<deprecationTrigger>
13+
<function>trigger_deprecation</function>
14+
</deprecationTrigger>
1215
<include>
1316
<directory>./</directory>
1417
</include>

src/GraphQl/phpunit.xml.dist

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
</testsuite>
1010
</testsuites>
1111
<source>
12+
<deprecationTrigger>
13+
<function>trigger_deprecation</function>
14+
</deprecationTrigger>
1215
<include>
1316
<directory>./</directory>
1417
</include>

src/HttpCache/phpunit.xml.dist

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
</testsuite>
1010
</testsuites>
1111
<source>
12+
<deprecationTrigger>
13+
<function>trigger_deprecation</function>
14+
</deprecationTrigger>
1215
<include>
1316
<directory>./</directory>
1417
</include>

src/Hydra/phpunit.xml.dist

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
</testsuite>
1010
</testsuites>
1111
<source>
12+
<deprecationTrigger>
13+
<function>trigger_deprecation</function>
14+
</deprecationTrigger>
1215
<include>
1316
<directory>./</directory>
1417
</include>

src/JsonApi/phpunit.xml.dist

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
</testsuites>
1111
<coverage/>
1212
<source>
13+
<deprecationTrigger>
14+
<function>trigger_deprecation</function>
15+
</deprecationTrigger>
1316
<include>
1417
<directory>./</directory>
1518
</include>

src/JsonSchema/phpunit.xml.dist

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
</testsuite>
1010
</testsuites>
1111
<source>
12+
<deprecationTrigger>
13+
<function>trigger_deprecation</function>
14+
</deprecationTrigger>
1215
<include>
1316
<directory>./</directory>
1417
</include>

src/Laravel/phpunit.xml.dist

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
</testsuites>
1919
<coverage/>
2020
<source>
21+
<deprecationTrigger>
22+
<function>trigger_deprecation</function>
23+
</deprecationTrigger>
2124
<include>
2225
<directory>./</directory>
2326
</include>

src/Metadata/phpunit.xml.dist

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99
</testsuite>
1010
</testsuites>
1111
<source>
12+
<deprecationTrigger>
13+
<function>trigger_deprecation</function>
14+
<method>Doctrine\Deprecations\Deprecation::trigger</method>
15+
<method>Doctrine\Deprecations\Deprecation::delegateTriggerToBackend</method>
16+
</deprecationTrigger>
1217
<include>
1318
<directory>./</directory>
1419
</include>

src/OpenApi/phpunit.xml.dist

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
</testsuite>
1010
</testsuites>
1111
<source>
12+
<deprecationTrigger>
13+
<function>trigger_deprecation</function>
14+
</deprecationTrigger>
1215
<include>
1316
<directory>./</directory>
1417
</include>

src/RamseyUuid/phpunit.xml.dist

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
</testsuite>
1010
</testsuites>
1111
<source>
12+
<deprecationTrigger>
13+
<function>trigger_deprecation</function>
14+
</deprecationTrigger>
1215
<include>
1316
<directory>./</directory>
1417
</include>

src/Serializer/phpunit.xml.dist

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
</testsuite>
1010
</testsuites>
1111
<source>
12+
<deprecationTrigger>
13+
<function>trigger_deprecation</function>
14+
</deprecationTrigger>
1215
<include>
1316
<directory>./</directory>
1417
</include>

src/State/phpunit.xml.dist

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
</testsuites>
1111
<coverage/>
1212
<source>
13+
<deprecationTrigger>
14+
<function>trigger_deprecation</function>
15+
</deprecationTrigger>
1316
<include>
1417
<directory>./</directory>
1518
</include>

src/Symfony/phpunit.xml.dist

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
</testsuite>
1010
</testsuites>
1111
<source>
12+
<deprecationTrigger>
13+
<function>trigger_deprecation</function>
14+
</deprecationTrigger>
1215
<include>
1316
<directory>./</directory>
1417
</include>

src/Validator/phpunit.xml.dist

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
</testsuite>
1010
</testsuites>
1111
<source>
12+
<deprecationTrigger>
13+
<function>trigger_deprecation</function>
14+
</deprecationTrigger>
1215
<include>
1316
<directory>./</directory>
1417
</include>

0 commit comments

Comments
 (0)