Skip to content

Commit baf076d

Browse files
committed
Merge branch '4.4' into 5.1
* 4.4: fix merge drop logger mock in favor of using the BufferingLogger catch ValueError thrown on PHP 8 [Yaml Parser] Fix edge cases when parsing multiple documents fix parsing comments not prefixed by a space [Translator] Make sure a null locale is handled properly deal with errors being thrown on PHP 8 [Cache] Allow cache tags to be objects implementing __toString() [HttpKernel] Do not override max_redirects option in HttpClientKernel remove superfluous cast [HttpClient] Support for CURLOPT_LOCALPORT. Upgrade PHPUnit to 8.5 (php 7.2) and 9.3 (php >= 7.3). Fixed exception message formatting [FrameworkBundle] Fix error in xsd which prevent to register more than one metadata [Console] work around disabled putenv() [PhpUnitBridge] Fix error with ReflectionClass [HttpClient][HttpClientTrait] don't calculate alternatives if option is auth_ntlm Change 'cache_key' to AbstractRendererEngine::CACHE_KEY_VAR Upgrade PHPUnit to 8.5 (php 7.2) and 9.3 (php >= 7.3).
2 parents 06aeefb + 5e67d95 commit baf076d

File tree

3 files changed

+48
-2
lines changed

3 files changed

+48
-2
lines changed

HttpClientKernel.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ final class HttpClientKernel implements HttpKernelInterface
3535

3636
public function __construct(HttpClientInterface $client = null)
3737
{
38-
if (!class_exists(HttpClient::class)) {
38+
if (null === $client && !class_exists(HttpClient::class)) {
3939
throw new \LogicException(sprintf('You cannot use "%s" as the HttpClient component is not installed. Try running "composer require symfony/http-client".', __CLASS__));
4040
}
4141

@@ -53,7 +53,6 @@ public function handle(Request $request, int $type = HttpKernelInterface::MASTER
5353
$response = $this->client->request($request->getMethod(), $request->getUri(), [
5454
'headers' => $headers,
5555
'body' => $body,
56-
'max_redirects' => 0,
5756
] + $request->attributes->get('http_client_options', []));
5857

5958
$response = new Response($response->getContent(!$catch), $response->getStatusCode(), $response->getHeaders(!$catch));

Tests/HttpClientKernelTest.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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+
}

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"symfony/deprecation-contracts": "^2.1",
2121
"symfony/error-handler": "^4.4|^5.0",
2222
"symfony/event-dispatcher": "^5.0",
23+
"symfony/http-client-contracts": "^1.1|^2",
2324
"symfony/http-foundation": "^4.4|^5.0",
2425
"symfony/polyfill-ctype": "^1.8",
2526
"symfony/polyfill-php73": "^1.9",

0 commit comments

Comments
 (0)