|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the Symfony package. |
| 5 | + * |
| 6 | + * (c) Fabien Potencier <fabien@symfony.com> |
| 7 | + * |
| 8 | + * For the full copyright and license information, please view the LICENSE |
| 9 | + * file that was distributed with this source code. |
| 10 | + */ |
| 11 | + |
| 12 | +namespace Symfony\Component\HttpKernel\Tests; |
| 13 | + |
| 14 | +use PHPUnit\Framework\TestCase; |
| 15 | +use Symfony\Component\HttpFoundation\Request; |
| 16 | +use Symfony\Component\HttpKernel\HttpClientKernel; |
| 17 | +use Symfony\Contracts\HttpClient\HttpClientInterface; |
| 18 | +use Symfony\Contracts\HttpClient\ResponseInterface; |
| 19 | + |
| 20 | +class HttpClientKernelTest extends TestCase |
| 21 | +{ |
| 22 | + public function testHandlePassesMaxRedirectsHttpClientOption() |
| 23 | + { |
| 24 | + $request = new Request(); |
| 25 | + $request->attributes->set('http_client_options', ['max_redirects' => 50]); |
| 26 | + |
| 27 | + $response = $this->getMockBuilder(ResponseInterface::class)->getMock(); |
| 28 | + $response->expects($this->once())->method('getStatusCode')->willReturn(200); |
| 29 | + |
| 30 | + $client = $this->getMockBuilder(HttpClientInterface::class)->getMock(); |
| 31 | + $client |
| 32 | + ->expects($this->once()) |
| 33 | + ->method('request') |
| 34 | + ->willReturnCallback(function (string $method, string $uri, array $options) use ($request, $response) { |
| 35 | + $this->assertSame($request->getMethod(), $method); |
| 36 | + $this->assertSame($request->getUri(), $uri); |
| 37 | + $this->assertArrayHasKey('max_redirects', $options); |
| 38 | + $this->assertSame(50, $options['max_redirects']); |
| 39 | + |
| 40 | + return $response; |
| 41 | + }); |
| 42 | + |
| 43 | + $kernel = new HttpClientKernel($client); |
| 44 | + $kernel->handle($request); |
| 45 | + } |
| 46 | +} |
0 commit comments