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 ;
@@ -47,31 +50,36 @@ public function bootstrap(Configuration $configuration, Facade $facade, Paramete
47
50
$ facade ->registerSubscriber (new class implements ErroredSubscriber {
48
51
public function notify (Errored $ event ): void
49
52
{
50
- SymfonyExtension::disableClockMock ();
51
- SymfonyExtension::disableDnsMock ();
53
+ SymfonyExtension::disableClockMock ($ event -> test () );
54
+ SymfonyExtension::disableDnsMock ($ event -> test () );
52
55
}
53
56
});
54
57
$ facade ->registerSubscriber (new class implements FinishedSubscriber {
55
58
public function notify (Finished $ event ): void
56
59
{
57
- SymfonyExtension::disableClockMock ();
58
- SymfonyExtension::disableDnsMock ();
60
+ SymfonyExtension::disableClockMock ($ event -> test () );
61
+ SymfonyExtension::disableDnsMock ($ event -> test () );
59
62
}
60
63
});
61
64
$ facade ->registerSubscriber (new class implements SkippedSubscriber {
62
65
public function notify (Skipped $ event ): void
63
66
{
64
- SymfonyExtension::disableClockMock ();
65
- SymfonyExtension::disableDnsMock ();
67
+ SymfonyExtension::disableClockMock ($ event -> test () );
68
+ SymfonyExtension::disableDnsMock ($ event -> test () );
66
69
}
67
70
});
68
71
69
72
if (interface_exists (BeforeTestMethodErroredSubscriber::class)) {
70
73
$ facade ->registerSubscriber (new class implements BeforeTestMethodErroredSubscriber {
71
74
public function notify (BeforeTestMethodErrored $ event ): void
72
75
{
73
- SymfonyExtension::disableClockMock ();
74
- SymfonyExtension::disableDnsMock ();
76
+ if (method_exists ($ event , 'test ' )) {
77
+ SymfonyExtension::disableClockMock ($ event ->test ());
78
+ SymfonyExtension::disableDnsMock ($ event ->test ());
79
+ } else {
80
+ ClockMock::withClockMock (false );
81
+ DnsMock::withMockedHosts ([]);
82
+ }
75
83
}
76
84
});
77
85
}
@@ -88,16 +96,38 @@ public function notify(BeforeTestMethodErrored $event): void
88
96
/**
89
97
* @internal
90
98
*/
91
- public static function disableClockMock (): void
99
+ public static function disableClockMock (Test $ test ): void
92
100
{
93
- ClockMock::withClockMock (false );
101
+ if (self ::hasGroup ($ test , 'time-sensitive ' )) {
102
+ ClockMock::withClockMock (false );
103
+ }
94
104
}
95
105
96
106
/**
97
107
* @internal
98
108
*/
99
- public static function disableDnsMock (): void
109
+ public static function disableDnsMock (Test $ test ): void
100
110
{
101
- DnsMock::withMockedHosts ([]);
111
+ if (self ::hasGroup ($ test , 'dns-sensitive ' )) {
112
+ DnsMock::withMockedHosts ([]);
113
+ }
114
+ }
115
+
116
+ /**
117
+ * @internal
118
+ */
119
+ public static function hasGroup (Test $ test , string $ groupName ): bool
120
+ {
121
+ if (!$ test instanceof TestMethod) {
122
+ return false ;
123
+ }
124
+
125
+ foreach ($ test ->metadata () as $ metadata ) {
126
+ if ($ metadata instanceof Group && $ groupName === $ metadata ->groupName ()) {
127
+ return true ;
128
+ }
129
+ }
130
+
131
+ return false ;
102
132
}
103
133
}
0 commit comments