13
13
14
14
use PHPUnit \Framework \TestCase ;
15
15
use PHPUnit \Framework \Warning ;
16
+ use PHPUnit \Util \Annotation \Registry ;
16
17
17
18
/**
18
19
* PHP 5.3 compatible trait-like shared implementation.
@@ -70,9 +71,6 @@ public function startTest($test)
70
71
$ testClass = \PHPUnit_Util_Test::class;
71
72
}
72
73
73
- $ r = new \ReflectionProperty ($ testClass , 'annotationCache ' );
74
- $ r ->setAccessible (true );
75
-
76
74
$ covers = $ sutFqcn ;
77
75
if (!\is_array ($ sutFqcn )) {
78
76
$ covers = array ($ sutFqcn );
@@ -82,6 +80,20 @@ public function startTest($test)
82
80
}
83
81
}
84
82
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
+
85
97
$ cache = $ r ->getValue ();
86
98
$ cache = array_replace_recursive ($ cache , array (
87
99
\get_class ($ test ) => array (
@@ -91,6 +103,18 @@ public function startTest($test)
91
103
$ r ->setValue ($ testClass , $ cache );
92
104
}
93
105
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
+
94
118
private function findSutFqcn ($ test )
95
119
{
96
120
if ($ this ->sutFqcnResolver ) {
0 commit comments