Skip to content

Commit

Permalink
Remove test suite's live HTTP request to example.com (laravel#38410)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
derekmd authored and victorvilella committed Oct 12, 2021
1 parent 22f1b92 commit 74ab371
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions tests/Http/HttpClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ protected function setUp(): void
$this->factory = new Factory;
}

protected function tearDown(): void
{
m::close();
}

public function testStubbedResponsesAreReturnedAfterFaking()
{
$this->factory->fake();
Expand Down Expand Up @@ -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()
Expand All @@ -957,8 +960,6 @@ public function testTheRequestSendingAndResponseReceivedEventsAreFiredWhenAReque
$pool->delete('https://example.com'),
];
});

m::close();
}

public function testTheTransferStatsAreCalledSafelyWhenFakingTheRequest()
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 74ab371

Please sign in to comment.