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..6917230404a 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); @@ -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); diff --git a/tests/end-to-end/regression/6304-class-metadata.phpt b/tests/end-to-end/regression/6304-class-metadata.phpt new file mode 100644 index 00000000000..4cdf9d6ebe4 --- /dev/null +++ b/tests/end-to-end/regression/6304-class-metadata.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 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 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/Issue6304ClassMetadataTest.php b/tests/end-to-end/regression/6304/Issue6304ClassMetadataTest.php new file mode 100644 index 00000000000..9bbebe955fd --- /dev/null +++ b/tests/end-to-end/regression/6304/Issue6304ClassMetadataTest.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 Issue6304ClassMetadataTest extends TestCase +{ + public function testOne(): void + { + $this->assertTrue(true); + } +} 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-runner-deprecation-ignored.phpt b/tests/end-to-end/regression/6329-runner-deprecation-ignored.phpt new file mode 100644 index 00000000000..44cfb498ef7 --- /dev/null +++ b/tests/end-to-end/regression/6329-runner-deprecation-ignored.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-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/Issue6329DeprecationIgnoredTest.php b/tests/end-to-end/regression/6329/Issue6329DeprecationIgnoredTest.php new file mode 100644 index 00000000000..17ffa46ab2d --- /dev/null +++ b/tests/end-to-end/regression/6329/Issue6329DeprecationIgnoredTest.php @@ -0,0 +1,29 @@ + + * + * 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 Issue6329DeprecationIgnoredTest extends TestCase +{ + #[IgnorePhpunitDeprecations] + public function testOne(): void + { + EventFacade::emitter()->testRunnerTriggeredPhpunitDeprecation( + 'A runner deprecation!', + ); + + $this->assertTrue(true); + } +} 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); + } +}