From 0fdf96971624ad079b4c3259c5a8a6aa4a1e3e0d Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Sat, 23 Aug 2025 11:10:58 +0200 Subject: [PATCH 1/6] Take #[IgnorePhpunitDeprecations] attribute into account for test runner deprecations --- src/Event/Emitter/DispatchingEmitter.php | 7 +++++++ src/Metadata/Parser/AnnotationParser.php | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Event/Emitter/DispatchingEmitter.php b/src/Event/Emitter/DispatchingEmitter.php index 4f0083efb7b..f7b1f3a2bc2 100644 --- a/src/Event/Emitter/DispatchingEmitter.php +++ b/src/Event/Emitter/DispatchingEmitter.php @@ -1208,6 +1208,13 @@ public function testSuiteFinished(TestSuite $testSuite): void */ public function testRunnerTriggeredPhpunitDeprecation(string $message): void { + try { + if (TestMethodBuilder::fromCallStack()->metadata()->isIgnorePhpunitDeprecations()->isNotEmpty()) { + return; + } + } catch (NoTestCaseObjectOnCallStackException) { + } + $this->dispatcher->dispatch( new TestRunner\DeprecationTriggered( $this->telemetryInfo(), diff --git a/src/Metadata/Parser/AnnotationParser.php b/src/Metadata/Parser/AnnotationParser.php index 185e8c6343a..2ed7926b472 100644 --- a/src/Metadata/Parser/AnnotationParser.php +++ b/src/Metadata/Parser/AnnotationParser.php @@ -186,14 +186,14 @@ public function forClass(string $className): MetadataCollection if (!empty($result) && !isset(self::$deprecationEmittedForClass[$className]) && !str_starts_with($className, 'PHPUnit\TestFixture')) { + self::$deprecationEmittedForClass[$className] = true; + EventFacade::emitter()->testRunnerTriggeredPhpunitDeprecation( sprintf( 'Metadata found in doc-comment for class %s. Metadata in doc-comments is deprecated and will no longer be supported in PHPUnit 12. Update your test code to use attributes instead.', $className, ), ); - - self::$deprecationEmittedForClass[$className] = true; } return MetadataCollection::fromArray($result); From 7811933a3bd6c305e131193a724d4549ad112a82 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Sat, 23 Aug 2025 11:18:19 +0200 Subject: [PATCH 2/6] Reflect endless loop preventing fix in AnnotationParser->forMethod() --- src/Metadata/Parser/AnnotationParser.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Metadata/Parser/AnnotationParser.php b/src/Metadata/Parser/AnnotationParser.php index 2ed7926b472..6917230404a 100644 --- a/src/Metadata/Parser/AnnotationParser.php +++ b/src/Metadata/Parser/AnnotationParser.php @@ -429,6 +429,8 @@ public function forMethod(string $className, string $methodName): MetadataCollec if (!empty($result) && !isset(self::$deprecationEmittedForMethod[$className . '::' . $methodName]) && !str_starts_with($className, 'PHPUnit\TestFixture')) { + self::$deprecationEmittedForMethod[$className . '::' . $methodName] = true; + EventFacade::emitter()->testRunnerTriggeredPhpunitDeprecation( sprintf( 'Metadata found in doc-comment for method %s::%s(). Metadata in doc-comments is deprecated and will no longer be supported in PHPUnit 12. Update your test code to use attributes instead.', @@ -436,8 +438,6 @@ public function forMethod(string $className, string $methodName): MetadataCollec $methodName, ), ); - - self::$deprecationEmittedForMethod[$className . '::' . $methodName] = true; } return MetadataCollection::fromArray($result); From 759e7c6f37d83a8052da27872dc33d738be7c54d Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Sat, 23 Aug 2025 11:36:08 +0200 Subject: [PATCH 3/6] Added regression test to prevent endless loop in subprocess --- tests/end-to-end/regression/6304.phpt | 29 +++++++++++++++++++ .../regression/6304/Issue6304Test.php | 25 ++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 tests/end-to-end/regression/6304.phpt create mode 100644 tests/end-to-end/regression/6304/Issue6304Test.php diff --git a/tests/end-to-end/regression/6304.phpt b/tests/end-to-end/regression/6304.phpt new file mode 100644 index 00000000000..6d93b859d26 --- /dev/null +++ b/tests/end-to-end/regression/6304.phpt @@ -0,0 +1,29 @@ +--TEST-- +https://github.com/sebastianbergmann/phpunit/issues/6304 +--FILE-- +run($_SERVER['argv']); +--EXPECTF-- +PHPUnit %s by Sebastian Bergmann and contributors. + +Runtime: %s + +. 1 / 1 (100%) + +Time: %s, Memory: %s MB + +There were 2 PHPUnit test runner deprecations: + +1) Metadata found in doc-comment for class Issue6304Test. Metadata in doc-comments is deprecated and will no longer be supported in PHPUnit 12. Update your test code to use attributes instead. + +2) Metadata found in doc-comment for class Issue6304Test. Metadata in doc-comments is deprecated and will no longer be supported in PHPUnit 12. Update your test code to use attributes instead. + +OK, but there were issues! +Tests: 1, Assertions: 1, PHPUnit Deprecations: 2. diff --git a/tests/end-to-end/regression/6304/Issue6304Test.php b/tests/end-to-end/regression/6304/Issue6304Test.php new file mode 100644 index 00000000000..434b1f924c4 --- /dev/null +++ b/tests/end-to-end/regression/6304/Issue6304Test.php @@ -0,0 +1,25 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ +use PHPUnit\Framework\TestCase; + +/** + * @group test + * + * @runTestsInSeparateProcesses + */ +final class Issue6304Test extends TestCase +{ + public function testOne(): void + { + $this->assertTrue(true); + } +} From de30e8e8cde86f68199e34826e640ccb216d44ae Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Sat, 23 Aug 2025 11:45:16 +0200 Subject: [PATCH 4/6] Test runner deprecations can be ignored --- tests/end-to-end/regression/6329.phpt | 22 ++++++++++++++ .../regression/6329/Issue6329Test.php | 30 +++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 tests/end-to-end/regression/6329.phpt create mode 100644 tests/end-to-end/regression/6329/Issue6329Test.php diff --git a/tests/end-to-end/regression/6329.phpt b/tests/end-to-end/regression/6329.phpt new file mode 100644 index 00000000000..d0dd04cc298 --- /dev/null +++ b/tests/end-to-end/regression/6329.phpt @@ -0,0 +1,22 @@ +--TEST-- +https://github.com/sebastianbergmann/phpunit/issues/6329 +--FILE-- +run($_SERVER['argv']); +--EXPECTF-- +PHPUnit %s by Sebastian Bergmann and contributors. + +Runtime: %s + +. 1 / 1 (100%) + +Time: %s, Memory: %s MB + +OK (1 test, 1 assertion) diff --git a/tests/end-to-end/regression/6329/Issue6329Test.php b/tests/end-to-end/regression/6329/Issue6329Test.php new file mode 100644 index 00000000000..b626a7373dd --- /dev/null +++ b/tests/end-to-end/regression/6329/Issue6329Test.php @@ -0,0 +1,30 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use PHPUnit\Event\Facade as EventFacade; +use PHPUnit\Framework\Attributes\IgnorePhpunitDeprecations; +use PHPUnit\Framework\Attributes\RunTestsInSeparateProcesses; +use PHPUnit\Framework\TestCase; + +#[RunTestsInSeparateProcesses] +final class Issue6329Test extends TestCase +{ + #[IgnorePhpunitDeprecations] + public function testOne(): void + { + EventFacade::emitter()->testRunnerTriggeredPhpunitDeprecation( + 'A runner deprecation!', + ); + + $this->assertTrue(true); + } +} From f16098c5e3cac1d6a0ecd18bc71ff826ebc087d1 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Sat, 23 Aug 2025 11:54:11 +0200 Subject: [PATCH 5/6] test method level metadata --- .../{6304.phpt => 6304-class-metadata.phpt} | 6 ++--- .../regression/6304-method-metadata.phpt | 27 +++++++++++++++++++ ...est.php => Issue6304ClassMetadataTest.php} | 2 +- .../6304/Issue6304MethodMetadataTest.php | 25 +++++++++++++++++ .../regression/6329/Issue6329Test.php | 1 - 5 files changed, 56 insertions(+), 5 deletions(-) rename tests/end-to-end/regression/{6304.phpt => 6304-class-metadata.phpt} (57%) create mode 100644 tests/end-to-end/regression/6304-method-metadata.phpt rename tests/end-to-end/regression/6304/{Issue6304Test.php => Issue6304ClassMetadataTest.php} (88%) create mode 100644 tests/end-to-end/regression/6304/Issue6304MethodMetadataTest.php diff --git a/tests/end-to-end/regression/6304.phpt b/tests/end-to-end/regression/6304-class-metadata.phpt similarity index 57% rename from tests/end-to-end/regression/6304.phpt rename to tests/end-to-end/regression/6304-class-metadata.phpt index 6d93b859d26..4cdf9d6ebe4 100644 --- a/tests/end-to-end/regression/6304.phpt +++ b/tests/end-to-end/regression/6304-class-metadata.phpt @@ -5,7 +5,7 @@ https://github.com/sebastianbergmann/phpunit/issues/6304 $_SERVER['argv'][] = '--do-not-cache-result'; $_SERVER['argv'][] = '--no-configuration'; $_SERVER['argv'][] = '--display-phpunit-deprecations'; -$_SERVER['argv'][] = __DIR__ . '/6304/Issue6304Test.php'; +$_SERVER['argv'][] = __DIR__ . '/6304/Issue6304ClassMetadataTest.php'; require __DIR__ . '/../../bootstrap.php'; @@ -21,9 +21,9 @@ Time: %s, Memory: %s MB There were 2 PHPUnit test runner deprecations: -1) Metadata found in doc-comment for class Issue6304Test. Metadata in doc-comments is deprecated and will no longer be supported in PHPUnit 12. Update your test code to use attributes instead. +1) Metadata found in doc-comment for class Issue6304ClassMetadataTest. Metadata in doc-comments is deprecated and will no longer be supported in PHPUnit 12. Update your test code to use attributes instead. -2) Metadata found in doc-comment for class Issue6304Test. Metadata in doc-comments is deprecated and will no longer be supported in PHPUnit 12. Update your test code to use attributes instead. +2) Metadata found in doc-comment for class Issue6304ClassMetadataTest. Metadata in doc-comments is deprecated and will no longer be supported in PHPUnit 12. Update your test code to use attributes instead. OK, but there were issues! Tests: 1, Assertions: 1, PHPUnit Deprecations: 2. diff --git a/tests/end-to-end/regression/6304-method-metadata.phpt b/tests/end-to-end/regression/6304-method-metadata.phpt new file mode 100644 index 00000000000..0c1a5f13cd1 --- /dev/null +++ b/tests/end-to-end/regression/6304-method-metadata.phpt @@ -0,0 +1,27 @@ +--TEST-- +https://github.com/sebastianbergmann/phpunit/issues/6304 +--FILE-- +run($_SERVER['argv']); +--EXPECTF-- +PHPUnit %s by Sebastian Bergmann and contributors. + +Runtime: %s + +. 1 / 1 (100%) + +Time: %s, Memory: %s MB + +There was 1 PHPUnit test runner deprecation: + +1) Metadata found in doc-comment for method Issue6304MethodMetadataTest::testOne(). Metadata in doc-comments is deprecated and will no longer be supported in PHPUnit 12. Update your test code to use attributes instead. + +OK, but there were issues! +Tests: 1, Assertions: 1, PHPUnit Deprecations: 1. diff --git a/tests/end-to-end/regression/6304/Issue6304Test.php b/tests/end-to-end/regression/6304/Issue6304ClassMetadataTest.php similarity index 88% rename from tests/end-to-end/regression/6304/Issue6304Test.php rename to tests/end-to-end/regression/6304/Issue6304ClassMetadataTest.php index 434b1f924c4..9bbebe955fd 100644 --- a/tests/end-to-end/regression/6304/Issue6304Test.php +++ b/tests/end-to-end/regression/6304/Issue6304ClassMetadataTest.php @@ -16,7 +16,7 @@ * * @runTestsInSeparateProcesses */ -final class Issue6304Test extends TestCase +final class Issue6304ClassMetadataTest extends TestCase { public function testOne(): void { diff --git a/tests/end-to-end/regression/6304/Issue6304MethodMetadataTest.php b/tests/end-to-end/regression/6304/Issue6304MethodMetadataTest.php new file mode 100644 index 00000000000..35cf1ac33eb --- /dev/null +++ b/tests/end-to-end/regression/6304/Issue6304MethodMetadataTest.php @@ -0,0 +1,25 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ +use PHPUnit\Framework\TestCase; + +final class Issue6304MethodMetadataTest extends TestCase +{ + /** + * @group test + * + * @runTestsInSeparateProcesses + */ + public function testOne(): void + { + $this->assertTrue(true); + } +} diff --git a/tests/end-to-end/regression/6329/Issue6329Test.php b/tests/end-to-end/regression/6329/Issue6329Test.php index b626a7373dd..03b22c9b947 100644 --- a/tests/end-to-end/regression/6329/Issue6329Test.php +++ b/tests/end-to-end/regression/6329/Issue6329Test.php @@ -9,7 +9,6 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ - use PHPUnit\Event\Facade as EventFacade; use PHPUnit\Framework\Attributes\IgnorePhpunitDeprecations; use PHPUnit\Framework\Attributes\RunTestsInSeparateProcesses; From e99b5931f234ac9c04d18a336fb136c371491466 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Sat, 23 Aug 2025 12:19:18 +0200 Subject: [PATCH 6/6] Test runner deprecation from subprocess --- ...t => 6329-runner-deprecation-ignored.phpt} | 2 +- .../regression/6329-runner-deprecation.phpt | 27 +++++++++++++++++++ ...hp => Issue6329DeprecationIgnoredTest.php} | 2 +- .../6329/Issue6329DeprecationTest.php | 27 +++++++++++++++++++ 4 files changed, 56 insertions(+), 2 deletions(-) rename tests/end-to-end/regression/{6329.phpt => 6329-runner-deprecation-ignored.phpt} (88%) create mode 100644 tests/end-to-end/regression/6329-runner-deprecation.phpt rename tests/end-to-end/regression/6329/{Issue6329Test.php => Issue6329DeprecationIgnoredTest.php} (92%) create mode 100644 tests/end-to-end/regression/6329/Issue6329DeprecationTest.php diff --git a/tests/end-to-end/regression/6329.phpt b/tests/end-to-end/regression/6329-runner-deprecation-ignored.phpt similarity index 88% rename from tests/end-to-end/regression/6329.phpt rename to tests/end-to-end/regression/6329-runner-deprecation-ignored.phpt index d0dd04cc298..44cfb498ef7 100644 --- a/tests/end-to-end/regression/6329.phpt +++ b/tests/end-to-end/regression/6329-runner-deprecation-ignored.phpt @@ -5,7 +5,7 @@ https://github.com/sebastianbergmann/phpunit/issues/6329 $_SERVER['argv'][] = '--do-not-cache-result'; $_SERVER['argv'][] = '--no-configuration'; $_SERVER['argv'][] = '--display-phpunit-deprecations'; -$_SERVER['argv'][] = __DIR__ . '/6329/Issue6329Test.php'; +$_SERVER['argv'][] = __DIR__ . '/6329/Issue6329DeprecationIgnoredTest.php'; require __DIR__ . '/../../bootstrap.php'; diff --git a/tests/end-to-end/regression/6329-runner-deprecation.phpt b/tests/end-to-end/regression/6329-runner-deprecation.phpt new file mode 100644 index 00000000000..e727b2c4e3e --- /dev/null +++ b/tests/end-to-end/regression/6329-runner-deprecation.phpt @@ -0,0 +1,27 @@ +--TEST-- +https://github.com/sebastianbergmann/phpunit/issues/6329 +--FILE-- +run($_SERVER['argv']); +--EXPECTF-- +PHPUnit %s by Sebastian Bergmann and contributors. + +Runtime: %s + +. 1 / 1 (100%) + +Time: %s, Memory: %s MB + +There was 1 PHPUnit test runner deprecation: + +1) A runner deprecation! + +OK, but there were issues! +Tests: 1, Assertions: 1, PHPUnit Deprecations: 1. diff --git a/tests/end-to-end/regression/6329/Issue6329Test.php b/tests/end-to-end/regression/6329/Issue6329DeprecationIgnoredTest.php similarity index 92% rename from tests/end-to-end/regression/6329/Issue6329Test.php rename to tests/end-to-end/regression/6329/Issue6329DeprecationIgnoredTest.php index 03b22c9b947..17ffa46ab2d 100644 --- a/tests/end-to-end/regression/6329/Issue6329Test.php +++ b/tests/end-to-end/regression/6329/Issue6329DeprecationIgnoredTest.php @@ -15,7 +15,7 @@ use PHPUnit\Framework\TestCase; #[RunTestsInSeparateProcesses] -final class Issue6329Test extends TestCase +final class Issue6329DeprecationIgnoredTest extends TestCase { #[IgnorePhpunitDeprecations] public function testOne(): void diff --git a/tests/end-to-end/regression/6329/Issue6329DeprecationTest.php b/tests/end-to-end/regression/6329/Issue6329DeprecationTest.php new file mode 100644 index 00000000000..5a1c9d9c6d3 --- /dev/null +++ b/tests/end-to-end/regression/6329/Issue6329DeprecationTest.php @@ -0,0 +1,27 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ +use PHPUnit\Event\Facade as EventFacade; +use PHPUnit\Framework\Attributes\RunTestsInSeparateProcesses; +use PHPUnit\Framework\TestCase; + +#[RunTestsInSeparateProcesses] +final class Issue6329DeprecationTest extends TestCase +{ + public function testOne(): void + { + EventFacade::emitter()->testRunnerTriggeredPhpunitDeprecation( + 'A runner deprecation!', + ); + + $this->assertTrue(true); + } +}