1111
1212namespace Symfony \Bridge \PhpUnit ;
1313
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 ;
1422use PHPUnit \Runner \Extension \Extension ;
1523use PHPUnit \Runner \Extension \Facade ;
1624use PHPUnit \Runner \Extension \ParameterCollection ;
1725use PHPUnit \TextUI \Configuration \Configuration ;
18- use Symfony \Bridge \PhpUnit \Extension \DisableClockMockSubscriber ;
19- use Symfony \Bridge \PhpUnit \Extension \DisableDnsMockSubscriber ;
2026use Symfony \Bridge \PhpUnit \Extension \EnableClockMockSubscriber ;
2127use Symfony \Bridge \PhpUnit \Extension \RegisterClockMockSubscriber ;
2228use Symfony \Bridge \PhpUnit \Extension \RegisterDnsMockSubscriber ;
@@ -38,7 +44,37 @@ public function bootstrap(Configuration $configuration, Facade $facade, Paramete
3844
3945 $ facade ->registerSubscriber (new RegisterClockMockSubscriber ());
4046 $ 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+ }
4278
4379 if ($ parameters ->has ('dns-mock-namespaces ' )) {
4480 foreach (explode (', ' , $ parameters ->get ('dns-mock-namespaces ' )) as $ namespace ) {
@@ -47,6 +83,21 @@ public function bootstrap(Configuration $configuration, Facade $facade, Paramete
4783 }
4884
4985 $ 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 ([]);
51102 }
52103}
0 commit comments