Skip to content

Commit

Permalink
Add test for TooManyRedirectsException response
Browse files Browse the repository at this point in the history
  • Loading branch information
davidgrayston committed Jun 12, 2020
1 parent bc50123 commit 4d05992
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions tests/RedirectMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,26 @@ public function testLimitsToMaxRedirects()
$promise->wait();
}

public function testTooManyRedirectsExceptionHasResponse()
{
$mock = new MockHandler([
new Response(301, ['Location' => 'http://test.com']),
new Response(302, ['Location' => 'http://test.com'])
]);
$stack = new HandlerStack($mock);
$stack->push(Middleware::redirect());
$handler = $stack->resolve();
$request = new Request('GET', 'http://example.com');
$promise = $handler($request, ['allow_redirects' => ['max' => 1]]);

try {
$promise->wait();
self::fail();
} catch (\GuzzleHttp\Exception\TooManyRedirectsException $e) {
self::assertSame(302, $e->getResponse()->getStatusCode());
}
}

public function testEnsuresProtocolIsValid()
{
$mock = new MockHandler([
Expand Down

0 comments on commit 4d05992

Please sign in to comment.