@@ -164,6 +164,9 @@ public function __invoke(RequestInterface $request, array $config)
164164// ------------------- handler invokes -------------------
165165
166166it ('__invoke handler stack returns response with Laravel http events ' , function () {
167+
168+ Handler::shouldEvent (true );
169+
167170 $ mock = new MockHandler ([
168171 new Response (200 , [], 'PHP is ' ), // for sync
169172 new Response (200 , [], 'PHP is ' ), // for async
@@ -179,6 +182,8 @@ public function __invoke(RequestInterface $request, array $config)
179182
180183it ('__invoke handler stack failure with Laravel http event ConnectionFailed ' , function () {
181184
185+ Handler::shouldEvent (true );
186+
182187 // Mock handler: simulate connection failures for sync and async requests
183188 $ mock = new MockHandler ([
184189 new ConnectException ('Connection failed ' , new Request ('GET ' , 'test-sync ' )),
@@ -195,9 +200,7 @@ public function __invoke(RequestInterface $request, array $config)
195200 }
196201
197202 // Assert Laravel events
198- Event::assertDispatched (ConnectionFailed::class, function ($ event ) {
199- return $ event ->exception ->getMessage () === 'Connection failed ' ;
200- });
203+ Event::assertDispatched (ConnectionFailed::class);
201204 Event::assertDispatched (RequestSending::class);
202205 Event::assertNotDispatched (ResponseReceived::class);
203206});
0 commit comments