From d2902b7880086ab71e2657bc97bd2d7593fbafed Mon Sep 17 00:00:00 2001 From: Brett McBride Date: Thu, 2 May 2024 17:05:37 +1000 Subject: [PATCH 1/3] replace after annotation with attribute PHPUnit 11 emits a deprecation warning when using annotations (@after), and they will not work in PHPUnit 12. Changing this means that the "after" functionality will not work in phpunit versions < 10, but it also should not cause an error. Users directly calling "restoreEnvironmentVariables()" would be fine, I think. See https://github.com/sebastianbergmann/phpunit/issues/4502 --- src/EnvironmentVariables.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/EnvironmentVariables.php b/src/EnvironmentVariables.php index 46db532..c1e85e3 100644 --- a/src/EnvironmentVariables.php +++ b/src/EnvironmentVariables.php @@ -12,10 +12,9 @@ trait EnvironmentVariables private $environmentVariables = []; /** - * @after - * * @return void */ + #[\PHPUnit\Framework\Attributes\After] protected function restoreEnvironmentVariables() { foreach ($this->environmentVariables as $variable => $value) { From a402c55f0ea8d6b7b4512c0aac7d4dcabe513697 Mon Sep 17 00:00:00 2001 From: Brett McBride Date: Fri, 3 May 2024 09:24:12 +1000 Subject: [PATCH 2/3] adding back annotation phpunit 11 seems happy with both an annotation + attribute, and doesn't emit a deprecation warning for me. This should be backwards and forwards compatible --- src/EnvironmentVariables.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/EnvironmentVariables.php b/src/EnvironmentVariables.php index c1e85e3..c1dca01 100644 --- a/src/EnvironmentVariables.php +++ b/src/EnvironmentVariables.php @@ -12,6 +12,8 @@ trait EnvironmentVariables private $environmentVariables = []; /** + * @after + * * @return void */ #[\PHPUnit\Framework\Attributes\After] From 670a96bf884f2a8679619a8a5766026d638f7a6b Mon Sep 17 00:00:00 2001 From: Brett McBride Date: Fri, 3 May 2024 09:28:32 +1000 Subject: [PATCH 3/3] phpstan ignore missing attribute --- phpstan.neon.dist | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/phpstan.neon.dist b/phpstan.neon.dist index c0d765e..bafebcc 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -23,3 +23,9 @@ parameters: - message: '#Call to an undefined static method \S+#' path: tests/Support/RunkitTest.php + + # PHPUnit 10+ attributes not available in earlier versions + - + message: '#Attribute class PHPUnit\\Framework\\Attributes\\After does not exist\.#' + paths: + - src/EnvironmentVariables.php