HttpClientKernelTest.php 1.5 KB

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