Skip to content

Commit f02546d

Browse files
committed
fix(test/http): test assertion for ConnectionFailed event with ConnectException
1 parent 698b828 commit f02546d

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

tests/Http/HandlerTest.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,9 @@ public function __invoke(RequestInterface $request, array $config)
164164
// ------------------- handler invokes -------------------
165165

166166
it('__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

180183
it('__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
});

tests/Http/HttpEventTest.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,7 @@
3636
// expected
3737
}
3838

39-
Event::assertDispatched(ConnectionFailed::class, function ($event) {
40-
return $event->exception->getMessage() === 'Connection failed';
41-
});
39+
Event::assertDispatched(ConnectionFailed::class);
4240
Event::assertNotDispatched(RequestSending::class);
4341
Event::assertNotDispatched(ResponseReceived::class);
4442
});

0 commit comments

Comments
 (0)