From 2461845559cd472cbf813f69d5dd27a095fd8571 Mon Sep 17 00:00:00 2001 From: Derek Date: Mon, 16 Aug 2021 17:52:31 -0400 Subject: [PATCH] Remove test suite's live HTTP request to example.com Event Illuminate\Http\Client\Events\ConnectionFailed can randomly be dispatched by testClonedClientsWorkSuccessfullyWithTheRequestObject() on some test suite runs which causes this test case to fail. This HTTP client test is making an actual HTTP request to example.com that can intermittently fail. Remove this unreliable external dependency. Mock the response so the Guzzle handler middleware stack still runs to dispatch events RequestSending & ResponseReceived. Also move Mockery `m::close()` into PHPUnit's `tearDown()` lifecycle since failed test cases will cause registered mocks to leak into subsequent test cases. --- tests/Http/HttpClientTest.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/Http/HttpClientTest.php b/tests/Http/HttpClientTest.php index a8bb5e0e5825..55bc72814353 100644 --- a/tests/Http/HttpClientTest.php +++ b/tests/Http/HttpClientTest.php @@ -36,6 +36,11 @@ protected function setUp(): void $this->factory = new Factory; } + protected function tearDown(): void + { + m::close(); + } + public function testStubbedResponsesAreReturnedAfterFaking() { $this->factory->fake(); @@ -936,8 +941,6 @@ public function testTheRequestSendingAndResponseReceivedEventsAreFiredWhenAReque $factory->post('https://example.com'); $factory->patch('https://example.com'); $factory->delete('https://example.com'); - - m::close(); } public function testTheRequestSendingAndResponseReceivedEventsAreFiredWhenARequestIsSentAsync() @@ -957,8 +960,6 @@ public function testTheRequestSendingAndResponseReceivedEventsAreFiredWhenAReque $pool->delete('https://example.com'), ]; }); - - m::close(); } public function testTheTransferStatsAreCalledSafelyWhenFakingTheRequest() @@ -988,13 +989,12 @@ public function testClonedClientsWorkSuccessfullyWithTheRequestObject() $events->shouldReceive('dispatch')->once()->with(m::type(ResponseReceived::class)); $factory = new Factory($events); + $factory->fake(['example.com' => $factory->response('foo', 200)]); $client = $factory->timeout(10); $clonedClient = clone $client; $clonedClient->get('https://example.com'); - - m::close(); } public function testRequestIsMacroable()