1313
1414use PHPUnit \Framework \TestCase ;
1515use PHPUnit \Framework \Warning ;
16+ use PHPUnit \Util \Annotation \Registry ;
1617use PHPUnit \Util \Test ;
1718
1819/**
@@ -66,9 +67,6 @@ public function startTest($test)
6667 return ;
6768 }
6869
69- $ r = new \ReflectionProperty (Test::class, 'annotationCache ' );
70- $ r ->setAccessible (true );
71-
7270 $ covers = $ sutFqcn ;
7371 if (!\is_array ($ sutFqcn )) {
7472 $ covers = [$ sutFqcn ];
@@ -78,15 +76,42 @@ public function startTest($test)
7876 }
7977 }
8078
79+ if (class_exists (Registry::class)) {
80+ $ this ->addCoversForDocBlockInsideRegistry ($ test , $ covers );
81+
82+ return ;
83+ }
84+
85+ $ this ->addCoversForClassToAnnotationCache ($ test , $ covers );
86+ }
87+
88+ private function addCoversForClassToAnnotationCache ($ test , $ covers )
89+ {
90+ $ r = new \ReflectionProperty (Test::class, 'annotationCache ' );
91+ $ r ->setAccessible (true );
92+
8193 $ cache = $ r ->getValue ();
8294 $ cache = array_replace_recursive ($ cache , [
8395 \get_class ($ test ) => [
8496 'covers ' => $ covers ,
8597 ],
8698 ]);
99+
87100 $ r ->setValue (Test::class, $ cache );
88101 }
89102
103+ private function addCoversForDocBlockInsideRegistry ($ test , $ covers )
104+ {
105+ $ docBlock = Registry::getInstance ()->forClassName (\get_class ($ test ));
106+
107+ $ symbolAnnotations = new \ReflectionProperty ($ docBlock , 'symbolAnnotations ' );
108+ $ symbolAnnotations ->setAccessible (true );
109+
110+ $ symbolAnnotations ->setValue ($ docBlock , array_replace ($ docBlock ->symbolAnnotations (), [
111+ 'covers ' => $ covers ,
112+ ]));
113+ }
114+
90115 private function findSutFqcn ($ test )
91116 {
92117 if ($ this ->sutFqcnResolver ) {
0 commit comments