Skip to content

Commit b79c787

Browse files
Merge branch '5.4' into 6.0
* 5.4: expand uninitialized session tests [Lock] Release PostgreSqlStore connection lock on failure [DomCrawler] Fix HTML5 parser charset option cs fix [HttpKernel] Do not attempt to register enum arguments in controller service locator [Mime] Fix missing sprintf in DkimSigner [Translation] [LocoProvider] Use rawurlencode and separate tag setting [Security] fix unserializing session payloads from v4 [Cache] Don't lock when doing nested computations [Messenger] fix Redis support on 32b arch [HttpFoundation] Fix notice when HTTP_PHP_AUTH_USER passed without pass [Security] Add getting started example to README
2 parents 2df8538 + a0d8297 commit b79c787

File tree

4 files changed

+57
-4
lines changed

4 files changed

+57
-4
lines changed

DependencyInjection/RegisterControllerArgumentLocatorsPass.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,11 @@ public function process(ContainerBuilder $container)
123123
$type = ltrim($target = (string) ProxyHelper::getTypeHint($r, $p), '\\');
124124
$invalidBehavior = ContainerInterface::IGNORE_ON_INVALID_REFERENCE;
125125

126+
if (is_subclass_of($type, \UnitEnum::class)) {
127+
// do not attempt to register enum typed arguments
128+
continue;
129+
}
130+
126131
if (isset($arguments[$r->name][$p->name])) {
127132
$target = $arguments[$r->name][$p->name];
128133
if ('?' !== $target[0]) {

Tests/DependencyInjection/RegisterControllerArgumentLocatorsPassTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
use Symfony\Component\DependencyInjection\ServiceLocator;
2525
use Symfony\Component\DependencyInjection\TypedReference;
2626
use Symfony\Component\HttpKernel\DependencyInjection\RegisterControllerArgumentLocatorsPass;
27+
use Symfony\Component\HttpKernel\Tests\Fixtures\Suit;
2728

2829
class RegisterControllerArgumentLocatorsPassTest extends TestCase
2930
{
@@ -400,6 +401,25 @@ public function testAlias()
400401
$this->assertEqualsCanonicalizing([RegisterTestController::class.'::fooAction', 'foo::fooAction'], array_keys($locator));
401402
}
402403

404+
/**
405+
* @requires PHP 8.1
406+
*/
407+
public function testEnumArgumentIsIgnored()
408+
{
409+
$container = new ContainerBuilder();
410+
$resolver = $container->register('argument_resolver.service')->addArgument([]);
411+
412+
$container->register('foo', NonNullableEnumArgumentWithDefaultController::class)
413+
->addTag('controller.service_arguments')
414+
;
415+
416+
$pass = new RegisterControllerArgumentLocatorsPass();
417+
$pass->process($container);
418+
419+
$locator = $container->getDefinition((string) $resolver->getArgument(0))->getArgument(0);
420+
$this->assertEmpty(array_keys($locator), 'enum typed argument is ignored');
421+
}
422+
403423
public function testBindWithTarget()
404424
{
405425
$container = new ContainerBuilder();
@@ -479,6 +499,13 @@ public function fooAction(string $someArg)
479499
}
480500
}
481501

502+
class NonNullableEnumArgumentWithDefaultController
503+
{
504+
public function fooAction(Suit $suit = Suit::Spades)
505+
{
506+
}
507+
}
508+
482509
class WithTarget
483510
{
484511
public function fooAction(

Tests/EventListener/SessionListenerTest.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -308,17 +308,18 @@ public function testSessionSaveAndResponseHasSessionCookie()
308308
$this->assertSame('123456', $cookies[0]->getValue());
309309
}
310310

311-
public function testUninitializedSession()
311+
public function testUninitializedSessionUsingSessionFromRequest()
312312
{
313313
$kernel = $this->createMock(HttpKernelInterface::class);
314314
$response = new Response();
315315
$response->setSharedMaxAge(60);
316316
$response->headers->set(AbstractSessionListener::NO_AUTO_CACHE_CONTROL_HEADER, 'true');
317317

318-
$container = new Container();
318+
$request = new Request();
319+
$request->setSession(new Session());
319320

320-
$listener = new SessionListener($container);
321-
$listener->onKernelResponse(new ResponseEvent($kernel, new Request(), HttpKernelInterface::MAIN_REQUEST, $response));
321+
$listener = new SessionListener(new Container());
322+
$listener->onKernelResponse(new ResponseEvent($kernel, $request, HttpKernelInterface::MAIN_REQUEST, $response));
322323
$this->assertFalse($response->headers->has('Expires'));
323324
$this->assertTrue($response->headers->hasCacheControlDirective('public'));
324325
$this->assertFalse($response->headers->hasCacheControlDirective('private'));

Tests/Fixtures/Suit.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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\Fixtures;
13+
14+
enum Suit: string
15+
{
16+
case Hearts = 'H';
17+
case Diamonds = 'D';
18+
case Clubs = 'C';
19+
case Spades = 'S';
20+
}

0 commit comments

Comments
 (0)