|
4 | 4 |
|
5 | 5 | use Exception;
|
6 | 6 | use GuzzleHttp\Exception\RequestException as GuzzleRequestException;
|
| 7 | +use GuzzleHttp\Exception\TooManyRedirectsException; |
7 | 8 | use GuzzleHttp\Middleware;
|
8 | 9 | use GuzzleHttp\Promise\PromiseInterface;
|
9 | 10 | use GuzzleHttp\Promise\RejectedPromise;
|
@@ -2609,6 +2610,38 @@ public function testSslCertificateErrorsConvertedToConnectionException()
|
2609 | 2610 | $this->factory->head('https://ssl-error.laravel.example');
|
2610 | 2611 | }
|
2611 | 2612 |
|
| 2613 | + public function testTooManyRedirectsExceptionConvertedToConnectionException() |
| 2614 | + { |
| 2615 | + $this->factory->fake(function () { |
| 2616 | + $request = new GuzzleRequest('GET', 'https://redirect.laravel.example'); |
| 2617 | + $response = new Psr7Response(301, ['Location' => 'https://redirect2.laravel.example']); |
| 2618 | + |
| 2619 | + throw new TooManyRedirectsException( |
| 2620 | + 'Maximum number of redirects (5) exceeded', |
| 2621 | + $request, |
| 2622 | + $response |
| 2623 | + ); |
| 2624 | + }); |
| 2625 | + |
| 2626 | + $this->expectException(ConnectionException::class); |
| 2627 | + $this->expectExceptionMessage('Maximum number of redirects (5) exceeded'); |
| 2628 | + |
| 2629 | + $this->factory->maxRedirects(5)->get('https://redirect.laravel.example'); |
| 2630 | + } |
| 2631 | + |
| 2632 | + public function testTooManyRedirectsWithFakedRedirectChain() |
| 2633 | + { |
| 2634 | + $this->factory->fake([ |
| 2635 | + '1.example.com' => $this->factory->response(null, 301, ['Location' => 'https://2.example.com']), |
| 2636 | + '2.example.com' => $this->factory->response(null, 301, ['Location' => 'https://3.example.com']), |
| 2637 | + '3.example.com' => $this->factory->response('', 200), |
| 2638 | + ]); |
| 2639 | + |
| 2640 | + $this->expectException(ConnectionException::class); |
| 2641 | + |
| 2642 | + $this->factory->maxRedirects(1)->get('https://1.example.com'); |
| 2643 | + } |
| 2644 | + |
2612 | 2645 | public function testRequestExceptionIsNotThrownIfThePendingRequestIsSetToThrowOnFailureButTheResponseIsSuccessful()
|
2613 | 2646 | {
|
2614 | 2647 | $this->factory->fake([
|
|
0 commit comments