Skip to content

Commit a0d8297

Browse files
Merge branch '5.3' into 5.4
* 5.3: 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 13303cf + fa04d14 commit a0d8297

File tree

4 files changed

+73
-1
lines changed

4 files changed

+73
-1
lines changed

DependencyInjection/RegisterControllerArgumentLocatorsPass.php

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

143+
if (is_subclass_of($type, \UnitEnum::class)) {
144+
// do not attempt to register enum typed arguments
145+
continue;
146+
}
147+
143148
if (isset($arguments[$r->name][$p->name])) {
144149
$target = $arguments[$r->name][$p->name];
145150
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
/**
404424
* @requires PHP 8
405425
*/
@@ -482,6 +502,13 @@ public function fooAction(string $someArg)
482502
}
483503
}
484504

505+
class NonNullableEnumArgumentWithDefaultController
506+
{
507+
public function fooAction(Suit $suit = Suit::Spades)
508+
{
509+
}
510+
}
511+
485512
class WithTarget
486513
{
487514
public function fooAction(

Tests/EventListener/SessionListenerTest.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ public function testSessionSaveAndResponseHasSessionCookie()
262262
$this->assertSame('123456', $cookies[0]->getValue());
263263
}
264264

265-
public function testUninitializedSession()
265+
public function testUninitializedSessionUsingInitializedSessionService()
266266
{
267267
$kernel = $this->createMock(HttpKernelInterface::class);
268268
$response = new Response();
@@ -283,6 +283,26 @@ public function testUninitializedSession()
283283
$this->assertFalse($response->headers->has(AbstractSessionListener::NO_AUTO_CACHE_CONTROL_HEADER));
284284
}
285285

286+
public function testUninitializedSessionUsingSessionFromRequest()
287+
{
288+
$kernel = $this->createMock(HttpKernelInterface::class);
289+
$response = new Response();
290+
$response->setSharedMaxAge(60);
291+
$response->headers->set(AbstractSessionListener::NO_AUTO_CACHE_CONTROL_HEADER, 'true');
292+
293+
$request = new Request();
294+
$request->setSession(new Session());
295+
296+
$listener = new SessionListener(new Container());
297+
$listener->onKernelResponse(new ResponseEvent($kernel, $request, HttpKernelInterface::MAIN_REQUEST, $response));
298+
$this->assertFalse($response->headers->has('Expires'));
299+
$this->assertTrue($response->headers->hasCacheControlDirective('public'));
300+
$this->assertFalse($response->headers->hasCacheControlDirective('private'));
301+
$this->assertFalse($response->headers->hasCacheControlDirective('must-revalidate'));
302+
$this->assertSame('60', $response->headers->getCacheControlDirective('s-maxage'));
303+
$this->assertFalse($response->headers->has(AbstractSessionListener::NO_AUTO_CACHE_CONTROL_HEADER));
304+
}
305+
286306
public function testUninitializedSessionWithoutInitializedSession()
287307
{
288308
$kernel = $this->createMock(HttpKernelInterface::class);

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)