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 ;
@@ -41,7 +47,37 @@ public function bootstrap(Configuration $configuration, Facade $facade, Paramete
4147
4248 $ facade ->registerSubscriber (new RegisterClockMockSubscriber ($ reader ));
4349 $ 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+ }
4581
4682 if ($ parameters ->has ('dns-mock-namespaces ' )) {
4783 foreach (explode (', ' , $ parameters ->get ('dns-mock-namespaces ' )) as $ namespace ) {
@@ -50,6 +86,21 @@ public function bootstrap(Configuration $configuration, Facade $facade, Paramete
5086 }
5187
5288 $ 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 ([]);
54105 }
55106}
0 commit comments