From 82f8c837886262e0b6e0ef86a989e3219ada2c3d Mon Sep 17 00:00:00 2001 From: Umherirrender Date: Sat, 14 Dec 2024 00:23:40 +0100 Subject: [PATCH] Allow use of @preCondition and @postCondition PHPUnit annotations New in PHPUnit 9.1 https://github.com/sebastianbergmann/phpunit/issues/4148 Change-Id: Ie147e7446e8edf1febf56cab7f69e0c33584395d --- .../Commenting/FunctionAnnotationsSniff.php | 2 ++ .../Sniffs/Commenting/PhpunitAnnotationsSniff.php | 15 +++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/MediaWiki/Sniffs/Commenting/FunctionAnnotationsSniff.php b/MediaWiki/Sniffs/Commenting/FunctionAnnotationsSniff.php index 0640b5b..2f270fa 100644 --- a/MediaWiki/Sniffs/Commenting/FunctionAnnotationsSniff.php +++ b/MediaWiki/Sniffs/Commenting/FunctionAnnotationsSniff.php @@ -113,6 +113,8 @@ class FunctionAnnotationsSniff implements Sniff { // are listed above '@afterclass' => '@afterClass', '@beforeclass' => '@beforeClass', + '@precondition' => '@preCondition', + '@postcondition' => '@postCondition', '@codecoverageignore' => '@codeCoverageIgnore', '@covernothing' => '@coverNothing', '@coversnothing' => '@coversNothing', diff --git a/MediaWiki/Sniffs/Commenting/PhpunitAnnotationsSniff.php b/MediaWiki/Sniffs/Commenting/PhpunitAnnotationsSniff.php index 492e751..67699c7 100644 --- a/MediaWiki/Sniffs/Commenting/PhpunitAnnotationsSniff.php +++ b/MediaWiki/Sniffs/Commenting/PhpunitAnnotationsSniff.php @@ -46,6 +46,9 @@ class PhpunitAnnotationsSniff implements Sniff { '@before' => true, '@beforeClass' => true, + '@preCondition' => true, + '@postCondition' => true, + '@covers' => true, '@cover' => [ '@covers', 'SingularCover' ], @@ -107,6 +110,8 @@ class PhpunitAnnotationsSniff implements Sniff { '@afterClass', '@before', '@beforeClass', + '@preCondition', + '@postCondition', ]; /** @@ -134,6 +139,16 @@ class PhpunitAnnotationsSniff implements Sniff { 'message' => 'setUp functions (*SetUpBeforeClass)', 'code' => 'NotSetUpBeforeClassFunction', ], + '@preCondition' => [ + 'regex' => '/PreConditions$/', + 'message' => 'assertPreConditions functions (*PreConditions)', + 'code' => 'NotAssertPreConditionsFunction', + ], + '@postCondition' => [ + 'regex' => '/PostConditions$/', + 'message' => 'assertPostConditions functions (*PostConditions)', + 'code' => 'NotAssertPostConditionsFunction', + ], '*' => [ 'regex' => '/^(?:test|provide)|Provider$/', 'message' => 'test functions',