11
11
12
12
namespace Symfony \Bridge \PhpUnit ;
13
13
14
+ use PHPUnit \Event \Code \Test ;
15
+ use PHPUnit \Event \Code \TestMethod ;
14
16
use PHPUnit \Event \Test \BeforeTestMethodErrored ;
15
17
use PHPUnit \Event \Test \BeforeTestMethodErroredSubscriber ;
16
18
use PHPUnit \Event \Test \Errored ;
19
21
use PHPUnit \Event \Test \FinishedSubscriber ;
20
22
use PHPUnit \Event \Test \Skipped ;
21
23
use PHPUnit \Event \Test \SkippedSubscriber ;
24
+ use PHPUnit \Metadata \Group ;
22
25
use PHPUnit \Runner \Extension \Extension ;
23
26
use PHPUnit \Runner \Extension \Facade ;
24
27
use PHPUnit \Runner \Extension \ParameterCollection ;
@@ -50,31 +53,36 @@ public function bootstrap(Configuration $configuration, Facade $facade, Paramete
50
53
$ facade ->registerSubscriber (new class implements ErroredSubscriber {
51
54
public function notify (Errored $ event ): void
52
55
{
53
- SymfonyExtension::disableClockMock ();
54
- SymfonyExtension::disableDnsMock ();
56
+ SymfonyExtension::disableClockMock ($ event -> test () );
57
+ SymfonyExtension::disableDnsMock ($ event -> test () );
55
58
}
56
59
});
57
60
$ facade ->registerSubscriber (new class implements FinishedSubscriber {
58
61
public function notify (Finished $ event ): void
59
62
{
60
- SymfonyExtension::disableClockMock ();
61
- SymfonyExtension::disableDnsMock ();
63
+ SymfonyExtension::disableClockMock ($ event -> test () );
64
+ SymfonyExtension::disableDnsMock ($ event -> test () );
62
65
}
63
66
});
64
67
$ facade ->registerSubscriber (new class implements SkippedSubscriber {
65
68
public function notify (Skipped $ event ): void
66
69
{
67
- SymfonyExtension::disableClockMock ();
68
- SymfonyExtension::disableDnsMock ();
70
+ SymfonyExtension::disableClockMock ($ event -> test () );
71
+ SymfonyExtension::disableDnsMock ($ event -> test () );
69
72
}
70
73
});
71
74
72
75
if (interface_exists (BeforeTestMethodErroredSubscriber::class)) {
73
76
$ facade ->registerSubscriber (new class implements BeforeTestMethodErroredSubscriber {
74
77
public function notify (BeforeTestMethodErrored $ event ): void
75
78
{
76
- SymfonyExtension::disableClockMock ();
77
- SymfonyExtension::disableDnsMock ();
79
+ if (method_exists ($ event , 'test ' )) {
80
+ SymfonyExtension::disableClockMock ($ event ->test ());
81
+ SymfonyExtension::disableDnsMock ($ event ->test ());
82
+ } else {
83
+ ClockMock::withClockMock (false );
84
+ DnsMock::withMockedHosts ([]);
85
+ }
78
86
}
79
87
});
80
88
}
@@ -91,16 +99,38 @@ public function notify(BeforeTestMethodErrored $event): void
91
99
/**
92
100
* @internal
93
101
*/
94
- public static function disableClockMock (): void
102
+ public static function disableClockMock (Test $ test ): void
95
103
{
96
- ClockMock::withClockMock (false );
104
+ if (self ::hasGroup ($ test , 'time-sensitive ' )) {
105
+ ClockMock::withClockMock (false );
106
+ }
97
107
}
98
108
99
109
/**
100
110
* @internal
101
111
*/
102
- public static function disableDnsMock (): void
112
+ public static function disableDnsMock (Test $ test ): void
103
113
{
104
- DnsMock::withMockedHosts ([]);
114
+ if (self ::hasGroup ($ test , 'dns-sensitive ' )) {
115
+ DnsMock::withMockedHosts ([]);
116
+ }
117
+ }
118
+
119
+ /**
120
+ * @internal
121
+ */
122
+ public static function hasGroup (Test $ test , string $ groupName ): bool
123
+ {
124
+ if (!$ test instanceof TestMethod) {
125
+ return false ;
126
+ }
127
+
128
+ foreach ($ test ->metadata () as $ metadata ) {
129
+ if ($ metadata instanceof Group && $ groupName === $ metadata ->groupName ()) {
130
+ return true ;
131
+ }
132
+ }
133
+
134
+ return false ;
105
135
}
106
136
}
0 commit comments