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 ;
@@ -41,7 +47,37 @@ public function bootstrap(Configuration $configuration, Facade $facade, Paramete
41
47
42
48
$ facade ->registerSubscriber (new RegisterClockMockSubscriber ($ reader ));
43
49
$ facade ->registerSubscriber (new EnableClockMockSubscriber ($ reader ));
44
- $ facade ->registerSubscriber (new DisableClockMockSubscriber ($ reader ));
50
+ $ facade ->registerSubscriber (new class implements ErroredSubscriber {
51
+ public function notify (Errored $ event ): void
52
+ {
53
+ SymfonyExtension::disableClockMock ();
54
+ SymfonyExtension::disableDnsMock ();
55
+ }
56
+ });
57
+ $ facade ->registerSubscriber (new class implements FinishedSubscriber {
58
+ public function notify (Finished $ event ): void
59
+ {
60
+ SymfonyExtension::disableClockMock ();
61
+ SymfonyExtension::disableDnsMock ();
62
+ }
63
+ });
64
+ $ facade ->registerSubscriber (new class implements SkippedSubscriber {
65
+ public function notify (Skipped $ event ): void
66
+ {
67
+ SymfonyExtension::disableClockMock ();
68
+ SymfonyExtension::disableDnsMock ();
69
+ }
70
+ });
71
+
72
+ if (interface_exists (BeforeTestMethodErroredSubscriber::class)) {
73
+ $ facade ->registerSubscriber (new class implements BeforeTestMethodErroredSubscriber {
74
+ public function notify (BeforeTestMethodErrored $ event ): void
75
+ {
76
+ SymfonyExtension::disableClockMock ();
77
+ SymfonyExtension::disableDnsMock ();
78
+ }
79
+ });
80
+ }
45
81
46
82
if ($ parameters ->has ('dns-mock-namespaces ' )) {
47
83
foreach (explode (', ' , $ parameters ->get ('dns-mock-namespaces ' )) as $ namespace ) {
@@ -50,6 +86,21 @@ public function bootstrap(Configuration $configuration, Facade $facade, Paramete
50
86
}
51
87
52
88
$ facade ->registerSubscriber (new RegisterDnsMockSubscriber ($ reader ));
53
- $ facade ->registerSubscriber (new DisableDnsMockSubscriber ($ reader ));
89
+ }
90
+
91
+ /**
92
+ * @internal
93
+ */
94
+ public static function disableClockMock (): void
95
+ {
96
+ ClockMock::withClockMock (false );
97
+ }
98
+
99
+ /**
100
+ * @internal
101
+ */
102
+ public static function disableDnsMock (): void
103
+ {
104
+ DnsMock::withMockedHosts ([]);
54
105
}
55
106
}
0 commit comments