26
26
use PHPUnit \Runner \Extension \Facade ;
27
27
use PHPUnit \Runner \Extension \ParameterCollection ;
28
28
use PHPUnit \TextUI \Configuration \Configuration ;
29
+ use Symfony \Bridge \PhpUnit \Attribute \DnsSensitive ;
30
+ use Symfony \Bridge \PhpUnit \Attribute \TimeSensitive ;
29
31
use Symfony \Bridge \PhpUnit \Extension \EnableClockMockSubscriber ;
30
32
use Symfony \Bridge \PhpUnit \Extension \RegisterClockMockSubscriber ;
31
33
use Symfony \Bridge \PhpUnit \Extension \RegisterDnsMockSubscriber ;
@@ -50,35 +52,51 @@ public function bootstrap(Configuration $configuration, Facade $facade, Paramete
50
52
51
53
$ facade ->registerSubscriber (new RegisterClockMockSubscriber ($ reader ));
52
54
$ facade ->registerSubscriber (new EnableClockMockSubscriber ($ reader ));
53
- $ facade ->registerSubscriber (new class implements ErroredSubscriber {
55
+ $ facade ->registerSubscriber (new class ($ reader ) implements ErroredSubscriber {
56
+ public function __construct (private AttributeReader $ reader )
57
+ {
58
+ }
59
+
54
60
public function notify (Errored $ event ): void
55
61
{
56
- SymfonyExtension::disableClockMock ($ event ->test ());
57
- SymfonyExtension::disableDnsMock ($ event ->test ());
62
+ SymfonyExtension::disableClockMock ($ event ->test (), $ this -> reader );
63
+ SymfonyExtension::disableDnsMock ($ event ->test (), $ this -> reader );
58
64
}
59
65
});
60
- $ facade ->registerSubscriber (new class implements FinishedSubscriber {
66
+ $ facade ->registerSubscriber (new class ($ reader ) implements FinishedSubscriber {
67
+ public function __construct (private AttributeReader $ reader )
68
+ {
69
+ }
70
+
61
71
public function notify (Finished $ event ): void
62
72
{
63
- SymfonyExtension::disableClockMock ($ event ->test ());
64
- SymfonyExtension::disableDnsMock ($ event ->test ());
73
+ SymfonyExtension::disableClockMock ($ event ->test (), $ this -> reader );
74
+ SymfonyExtension::disableDnsMock ($ event ->test (), $ this -> reader );
65
75
}
66
76
});
67
- $ facade ->registerSubscriber (new class implements SkippedSubscriber {
77
+ $ facade ->registerSubscriber (new class ($ reader ) implements SkippedSubscriber {
78
+ public function __construct (private AttributeReader $ reader )
79
+ {
80
+ }
81
+
68
82
public function notify (Skipped $ event ): void
69
83
{
70
- SymfonyExtension::disableClockMock ($ event ->test ());
71
- SymfonyExtension::disableDnsMock ($ event ->test ());
84
+ SymfonyExtension::disableClockMock ($ event ->test (), $ this -> reader );
85
+ SymfonyExtension::disableDnsMock ($ event ->test (), $ this -> reader );
72
86
}
73
87
});
74
88
75
89
if (interface_exists (BeforeTestMethodErroredSubscriber::class)) {
76
- $ facade ->registerSubscriber (new class implements BeforeTestMethodErroredSubscriber {
90
+ $ facade ->registerSubscriber (new class ($ reader ) implements BeforeTestMethodErroredSubscriber {
91
+ public function __construct (private AttributeReader $ reader )
92
+ {
93
+ }
94
+
77
95
public function notify (BeforeTestMethodErrored $ event ): void
78
96
{
79
97
if (method_exists ($ event , 'test ' )) {
80
- SymfonyExtension::disableClockMock ($ event ->test ());
81
- SymfonyExtension::disableDnsMock ($ event ->test ());
98
+ SymfonyExtension::disableClockMock ($ event ->test (), $ this -> reader );
99
+ SymfonyExtension::disableDnsMock ($ event ->test (), $ this -> reader );
82
100
} else {
83
101
ClockMock::withClockMock (false );
84
102
DnsMock::withMockedHosts ([]);
@@ -99,27 +117,27 @@ public function notify(BeforeTestMethodErrored $event): void
99
117
/**
100
118
* @internal
101
119
*/
102
- public static function disableClockMock (Test $ test ): void
120
+ public static function disableClockMock (Test $ test, AttributeReader $ reader ): void
103
121
{
104
- if (self ::hasGroup ($ test , 'time-sensitive ' )) {
122
+ if (self ::hasGroup ($ test , 'time-sensitive ' , $ reader , TimeSensitive::class )) {
105
123
ClockMock::withClockMock (false );
106
124
}
107
125
}
108
126
109
127
/**
110
128
* @internal
111
129
*/
112
- public static function disableDnsMock (Test $ test ): void
130
+ public static function disableDnsMock (Test $ test, AttributeReader $ reader ): void
113
131
{
114
- if (self ::hasGroup ($ test , 'dns-sensitive ' )) {
132
+ if (self ::hasGroup ($ test , 'dns-sensitive ' , $ reader , DnsSensitive::class )) {
115
133
DnsMock::withMockedHosts ([]);
116
134
}
117
135
}
118
136
119
137
/**
120
138
* @internal
121
139
*/
122
- public static function hasGroup (Test $ test , string $ groupName ): bool
140
+ public static function hasGroup (Test $ test , string $ groupName, AttributeReader $ reader , string $ attribute ): bool
123
141
{
124
142
if (!$ test instanceof TestMethod) {
125
143
return false ;
@@ -131,6 +149,6 @@ public static function hasGroup(Test $test, string $groupName): bool
131
149
}
132
150
}
133
151
134
- return false ;
152
+ return [] !== $ reader -> forClassAndMethod ( $ test -> className (), $ test -> methodName (), $ attribute ) ;
135
153
}
136
154
}
0 commit comments