13
13
14
14
use PHPUnit \Framework \TestCase ;
15
15
use PHPUnit \Framework \Warning ;
16
+ use PHPUnit \Util \Annotation \Registry ;
16
17
use PHPUnit \Util \Test ;
17
18
18
19
/**
@@ -66,9 +67,6 @@ public function startTest($test)
66
67
return ;
67
68
}
68
69
69
- $ r = new \ReflectionProperty (Test::class, 'annotationCache ' );
70
- $ r ->setAccessible (true );
71
-
72
70
$ covers = $ sutFqcn ;
73
71
if (!\is_array ($ sutFqcn )) {
74
72
$ covers = [$ sutFqcn ];
@@ -78,15 +76,42 @@ public function startTest($test)
78
76
}
79
77
}
80
78
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
+
81
93
$ cache = $ r ->getValue ();
82
94
$ cache = array_replace_recursive ($ cache , [
83
95
\get_class ($ test ) => [
84
96
'covers ' => $ covers ,
85
97
],
86
98
]);
99
+
87
100
$ r ->setValue (Test::class, $ cache );
88
101
}
89
102
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
+
90
115
private function findSutFqcn ($ test )
91
116
{
92
117
if ($ this ->sutFqcnResolver ) {
0 commit comments