1313
1414use PHPUnit \Framework \TestCase ;
1515use PHPUnit \Framework \Warning ;
16+ use PHPUnit \Util \Annotation \Registry ;
1617
1718/**
1819 * PHP 5.3 compatible trait-like shared implementation.
@@ -70,9 +71,6 @@ public function startTest($test)
7071 $ testClass = \PHPUnit_Util_Test::class;
7172 }
7273
73- $ r = new \ReflectionProperty ($ testClass , 'annotationCache ' );
74- $ r ->setAccessible (true );
75-
7674 $ covers = $ sutFqcn ;
7775 if (!\is_array ($ sutFqcn )) {
7876 $ covers = array ($ sutFqcn );
@@ -82,6 +80,20 @@ public function startTest($test)
8280 }
8381 }
8482
83+ if (class_exists (Registry::class)) {
84+ $ this ->addCoversForDocBlockInsideRegistry ($ test , $ covers );
85+
86+ return ;
87+ }
88+
89+ $ this ->addCoversForClassToAnnotationCache ($ testClass , $ test , $ covers );
90+ }
91+
92+ private function addCoversForClassToAnnotationCache ($ testClass , $ test , $ covers )
93+ {
94+ $ r = new \ReflectionProperty ($ testClass , 'annotationCache ' );
95+ $ r ->setAccessible (true );
96+
8597 $ cache = $ r ->getValue ();
8698 $ cache = array_replace_recursive ($ cache , array (
8799 \get_class ($ test ) => array (
@@ -91,6 +103,18 @@ public function startTest($test)
91103 $ r ->setValue ($ testClass , $ cache );
92104 }
93105
106+ private function addCoversForDocBlockInsideRegistry ($ test , $ covers )
107+ {
108+ $ docBlock = Registry::getInstance ()->forClassName (\get_class ($ test ));
109+
110+ $ symbolAnnotations = new \ReflectionProperty ($ docBlock , 'symbolAnnotations ' );
111+ $ symbolAnnotations ->setAccessible (true );
112+
113+ $ symbolAnnotations ->setValue ($ docBlock , array_replace ($ docBlock ->symbolAnnotations (), array (
114+ 'covers ' => $ covers ,
115+ )));
116+ }
117+
94118 private function findSutFqcn ($ test )
95119 {
96120 if ($ this ->sutFqcnResolver ) {
0 commit comments