1313
1414namespace CodeIgniter \AutoReview ;
1515
16+ use PHPUnit \Framework \Attributes \DataProvider ;
1617use FilesystemIterator ;
18+ use PHPUnit \Framework \Attributes \Group ;
1719use PHPUnit \Framework \TestCase ;
1820use RecursiveDirectoryIterator ;
1921use RecursiveIteratorIterator ;
22+ use ReflectionAttribute ;
2023use ReflectionClass ;
2124use SplFileInfo ;
2225
2326/**
2427 * @internal
25- *
26- * @group AutoReview
2728 */
29+ #[Group('AutoReview ' )]
2830final class FrameworkCodeTest extends TestCase
2931{
3032 /**
3133 * Cache of discovered test class names.
3234 */
3335 private static array $ testClasses = [];
3436
35- private static array $ recognizedGroupAnnotations = [
37+ private static array $ recognizedGroupAttributeNames = [
3638 'AutoReview ' ,
3739 'CacheLive ' ,
3840 'DatabaseLive ' ,
@@ -41,11 +43,10 @@ final class FrameworkCodeTest extends TestCase
4143 ];
4244
4345 /**
44- * @dataProvider provideEachTestClassHasCorrectGroupAnnotation
45- *
4646 * @param class-string $class
4747 */
48- public function testEachTestClassHasCorrectGroupAnnotation (string $ class ): void
48+ #[DataProvider('provideEachTestClassHasCorrectGroupAttributeName ' )]
49+ public function testEachTestClassHasCorrectGroupAttributeName (string $ class ): void
4950 {
5051 $ reflection = new ReflectionClass ($ class );
5152
@@ -55,27 +56,31 @@ public function testEachTestClassHasCorrectGroupAnnotation(string $class): void
5556 return ;
5657 }
5758
58- $ docComment = ( string ) $ reflection ->getDocComment ( );
59- $ this ->assertNotEmpty ($ docComment , sprintf ('[%s] Test class is missing a class-level PHPDoc . ' , $ class ));
59+ $ attributes = $ reflection ->getAttributes (Group::class );
60+ $ this ->assertNotEmpty ($ attributes , sprintf ('[%s] Test class is missing a #[Group] attribute . ' , $ class ));
6061
61- preg_match_all ('/@group (\S+)/ ' , $ docComment , $ matches );
62- array_shift ($ matches );
63- $ this ->assertNotEmpty ($ matches [0 ], sprintf ('[%s] Test class is missing a @group annotation. ' , $ class ));
62+ $ unrecognizedGroups = array_diff (
63+ array_map (static function (ReflectionAttribute $ attribute ): string {
64+ $ groupAttribute = $ attribute ->newInstance ();
65+ assert ($ groupAttribute instanceof Group);
6466
65- $ unrecognizedGroups = array_diff ($ matches [0 ], self ::$ recognizedGroupAnnotations );
67+ return $ groupAttribute ->name ();
68+ }, $ attributes ),
69+ self ::$ recognizedGroupAttributeNames
70+ );
6671 $ this ->assertEmpty ($ unrecognizedGroups , sprintf (
67- "[%s] Unexpected @group annotation %s: \n%s \nExpected annotations to be in \"%s \". " ,
72+ "[%s] Unexpected #[Group] attribute %s: \n%s \nExpected group names to be in \"%s \". " ,
6873 $ class ,
6974 count ($ unrecognizedGroups ) > 1 ? 's ' : '' ,
7075 implode ("\n" , array_map (
71- static fn (string $ group ): string => sprintf (' * @group %s ' , $ group ),
76+ static fn (string $ group ): string => sprintf (' * #[Group( \' %s \' )] ' , $ group ),
7277 $ unrecognizedGroups
7378 )),
74- implode (', ' , self ::$ recognizedGroupAnnotations )
79+ implode (', ' , self ::$ recognizedGroupAttributeNames )
7580 ));
7681 }
7782
78- public static function provideEachTestClassHasCorrectGroupAnnotation (): iterable
83+ public static function provideEachTestClassHasCorrectGroupAttributeName (): iterable
7984 {
8085 foreach (self ::getTestClasses () as $ class ) {
8186 yield $ class => [$ class ];
0 commit comments