11
11
12
12
namespace Symfony \Bridge \PhpUnit ;
13
13
14
+ use PHPUnit \Event \Test \BeforeTestMethodErrored ;
15
+ use PHPUnit \Event \Test \BeforeTestMethodErroredSubscriber ;
16
+ use PHPUnit \Event \Test \Errored ;
17
+ use PHPUnit \Event \Test \ErroredSubscriber ;
18
+ use PHPUnit \Event \Test \Finished ;
19
+ use PHPUnit \Event \Test \FinishedSubscriber ;
20
+ use PHPUnit \Event \Test \Skipped ;
21
+ use PHPUnit \Event \Test \SkippedSubscriber ;
14
22
use PHPUnit \Runner \Extension \Extension ;
15
23
use PHPUnit \Runner \Extension \Facade ;
16
24
use PHPUnit \Runner \Extension \ParameterCollection ;
17
25
use PHPUnit \TextUI \Configuration \Configuration ;
18
- use Symfony \Bridge \PhpUnit \Extension \DisableClockMockSubscriber ;
19
- use Symfony \Bridge \PhpUnit \Extension \DisableDnsMockSubscriber ;
20
26
use Symfony \Bridge \PhpUnit \Extension \EnableClockMockSubscriber ;
21
27
use Symfony \Bridge \PhpUnit \Extension \RegisterClockMockSubscriber ;
22
28
use Symfony \Bridge \PhpUnit \Extension \RegisterDnsMockSubscriber ;
@@ -38,7 +44,37 @@ public function bootstrap(Configuration $configuration, Facade $facade, Paramete
38
44
39
45
$ facade ->registerSubscriber (new RegisterClockMockSubscriber ());
40
46
$ facade ->registerSubscriber (new EnableClockMockSubscriber ());
41
- $ facade ->registerSubscriber (new DisableClockMockSubscriber ());
47
+ $ facade ->registerSubscriber (new class implements ErroredSubscriber {
48
+ public function notify (Errored $ event ): void
49
+ {
50
+ SymfonyExtension::disableClockMock ();
51
+ SymfonyExtension::disableDnsMock ();
52
+ }
53
+ });
54
+ $ facade ->registerSubscriber (new class implements FinishedSubscriber {
55
+ public function notify (Finished $ event ): void
56
+ {
57
+ SymfonyExtension::disableClockMock ();
58
+ SymfonyExtension::disableDnsMock ();
59
+ }
60
+ });
61
+ $ facade ->registerSubscriber (new class implements SkippedSubscriber {
62
+ public function notify (Skipped $ event ): void
63
+ {
64
+ SymfonyExtension::disableClockMock ();
65
+ SymfonyExtension::disableDnsMock ();
66
+ }
67
+ });
68
+
69
+ if (interface_exists (BeforeTestMethodErroredSubscriber::class)) {
70
+ $ facade ->registerSubscriber (new class implements BeforeTestMethodErroredSubscriber {
71
+ public function notify (BeforeTestMethodErrored $ event ): void
72
+ {
73
+ SymfonyExtension::disableClockMock ();
74
+ SymfonyExtension::disableDnsMock ();
75
+ }
76
+ });
77
+ }
42
78
43
79
if ($ parameters ->has ('dns-mock-namespaces ' )) {
44
80
foreach (explode (', ' , $ parameters ->get ('dns-mock-namespaces ' )) as $ namespace ) {
@@ -47,6 +83,21 @@ public function bootstrap(Configuration $configuration, Facade $facade, Paramete
47
83
}
48
84
49
85
$ facade ->registerSubscriber (new RegisterDnsMockSubscriber ());
50
- $ facade ->registerSubscriber (new DisableDnsMockSubscriber ());
86
+ }
87
+
88
+ /**
89
+ * @internal
90
+ */
91
+ public static function disableClockMock (): void
92
+ {
93
+ ClockMock::withClockMock (false );
94
+ }
95
+
96
+ /**
97
+ * @internal
98
+ */
99
+ public static function disableDnsMock (): void
100
+ {
101
+ DnsMock::withMockedHosts ([]);
51
102
}
52
103
}
0 commit comments