|
3 | 3 | namespace Illuminate\Tests\Http;
|
4 | 4 |
|
5 | 5 | use Exception;
|
| 6 | +use GuzzleHttp\Exception\ConnectException; |
6 | 7 | use GuzzleHttp\Exception\RequestException as GuzzleRequestException;
|
7 | 8 | use GuzzleHttp\Exception\TooManyRedirectsException;
|
8 | 9 | use GuzzleHttp\Middleware;
|
@@ -2379,7 +2380,7 @@ public function testRequestCanBeModifiedInRetryCallbackInPool()
|
2379 | 2380 |
|
2380 | 2381 | public function testHandleRequestExeptionWithNoResponseInPoolConsideredConnectionException()
|
2381 | 2382 | {
|
2382 |
| - $requestException = new \GuzzleHttp\Exception\RequestException('Error', new \GuzzleHttp\Psr7\Request('GET', '/')); |
| 2383 | + $requestException = new GuzzleRequestException('Error', new \GuzzleHttp\Psr7\Request('GET', '/')); |
2383 | 2384 | $this->factory->fake([
|
2384 | 2385 | 'noresponse.com' => new RejectedPromise($requestException),
|
2385 | 2386 | ]);
|
@@ -2610,6 +2611,76 @@ public function testSslCertificateErrorsConvertedToConnectionException()
|
2610 | 2611 | $this->factory->head('https://ssl-error.laravel.example');
|
2611 | 2612 | }
|
2612 | 2613 |
|
| 2614 | + public function testConnectExceptionIsConvertedToConnectionExceptionEvenWhenWithoutFactory() |
| 2615 | + { |
| 2616 | + $this->expectException(ConnectionException::class); |
| 2617 | + $this->expectExceptionMessage('cURL error 60: SSL certificate problem'); |
| 2618 | + |
| 2619 | + $pendingRequest = new PendingRequest(); |
| 2620 | + |
| 2621 | + $pendingRequest->setHandler(function () { |
| 2622 | + throw new ConnectException( |
| 2623 | + 'cURL error 60: SSL certificate problem: unable to get local issuer certificate', |
| 2624 | + new GuzzleRequest('HEAD', 'https://ssl-error.laravel.example') |
| 2625 | + ); |
| 2626 | + }); |
| 2627 | + |
| 2628 | + $pendingRequest->head('https://ssl-error.laravel.example'); |
| 2629 | + } |
| 2630 | + |
| 2631 | + public function testRequestExceptionWithoutResponseIsConvertedToConnectionExceptionEvenWhenWithoutFactory() |
| 2632 | + { |
| 2633 | + $this->expectException(ConnectionException::class); |
| 2634 | + $this->expectExceptionMessage('cURL error 28: Operation timed out'); |
| 2635 | + |
| 2636 | + $pendingRequest = new PendingRequest(); |
| 2637 | + |
| 2638 | + $pendingRequest->setHandler(function () { |
| 2639 | + throw new GuzzleRequestException( |
| 2640 | + 'cURL error 28: Operation timed out', |
| 2641 | + new GuzzleRequest('GET', 'https://timeout-laravel.example') |
| 2642 | + ); |
| 2643 | + }); |
| 2644 | + |
| 2645 | + $pendingRequest->get('https://timeout-laravel.example'); |
| 2646 | + } |
| 2647 | + |
| 2648 | + public function testRequestExceptionWithResponseIsConvertedToConnectionExceptionEvenWhenWithoutFactory() |
| 2649 | + { |
| 2650 | + $this->expectException(ConnectionException::class); |
| 2651 | + $this->expectExceptionMessage('cURL error 28: Operation timed out'); |
| 2652 | + |
| 2653 | + $pendingRequest = new PendingRequest(); |
| 2654 | + |
| 2655 | + $pendingRequest->setHandler(function () { |
| 2656 | + throw new GuzzleRequestException( |
| 2657 | + 'cURL error 28: Operation timed out', |
| 2658 | + new GuzzleRequest('GET', 'https://timeout-laravel.example'), |
| 2659 | + new Psr7Response(301) |
| 2660 | + ); |
| 2661 | + }); |
| 2662 | + |
| 2663 | + $pendingRequest->get('https://timeout-laravel.example'); |
| 2664 | + } |
| 2665 | + |
| 2666 | + public function testTooManyRedirectsExceptionIsConvertedToConnectionExceptionEvenWhenWithoutFactory() |
| 2667 | + { |
| 2668 | + $this->expectException(ConnectionException::class); |
| 2669 | + $this->expectExceptionMessage('Maximum number of redirects (5) exceeded'); |
| 2670 | + |
| 2671 | + $pendingRequest = new PendingRequest(); |
| 2672 | + |
| 2673 | + $pendingRequest->setHandler(function () { |
| 2674 | + throw new TooManyRedirectsException( |
| 2675 | + 'Maximum number of redirects (5) exceeded', |
| 2676 | + new GuzzleRequest('GET', 'https://redirect.laravel.example'), |
| 2677 | + new Psr7Response(301) |
| 2678 | + ); |
| 2679 | + }); |
| 2680 | + |
| 2681 | + $pendingRequest->maxRedirects(5)->get('https://redirect.laravel.example'); |
| 2682 | + } |
| 2683 | + |
2613 | 2684 | public function testTooManyRedirectsExceptionConvertedToConnectionException()
|
2614 | 2685 | {
|
2615 | 2686 | $this->factory->fake(function () {
|
|
0 commit comments