Skip to content

Commit f3be71b

Browse files
authored
Remove test suite's live HTTP request to example.com (#38410)
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.
1 parent fc2cd95 commit f3be71b

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

tests/Http/HttpClientTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ protected function setUp(): void
3636
$this->factory = new Factory;
3737
}
3838

39+
protected function tearDown(): void
40+
{
41+
m::close();
42+
}
43+
3944
public function testStubbedResponsesAreReturnedAfterFaking()
4045
{
4146
$this->factory->fake();
@@ -936,8 +941,6 @@ public function testTheRequestSendingAndResponseReceivedEventsAreFiredWhenAReque
936941
$factory->post('https://example.com');
937942
$factory->patch('https://example.com');
938943
$factory->delete('https://example.com');
939-
940-
m::close();
941944
}
942945

943946
public function testTheRequestSendingAndResponseReceivedEventsAreFiredWhenARequestIsSentAsync()
@@ -957,8 +960,6 @@ public function testTheRequestSendingAndResponseReceivedEventsAreFiredWhenAReque
957960
$pool->delete('https://example.com'),
958961
];
959962
});
960-
961-
m::close();
962963
}
963964

964965
public function testTheTransferStatsAreCalledSafelyWhenFakingTheRequest()
@@ -988,13 +989,12 @@ public function testClonedClientsWorkSuccessfullyWithTheRequestObject()
988989
$events->shouldReceive('dispatch')->once()->with(m::type(ResponseReceived::class));
989990

990991
$factory = new Factory($events);
992+
$factory->fake(['example.com' => $factory->response('foo', 200)]);
991993

992994
$client = $factory->timeout(10);
993995
$clonedClient = clone $client;
994996

995997
$clonedClient->get('https://example.com');
996-
997-
m::close();
998998
}
999999

10001000
public function testRequestIsMacroable()

0 commit comments

Comments
 (0)