Skip to content

Commit ba94559

Browse files
Merge branch '5.3' into 5.4
* 5.3: [DependencyInjection][HttpKernel] Fix enum typed bindings make login link handler tests time sensitive [CI] Remove macOS jobs Suppress psalm error for UndefinedDocblockClass for PHP 8.1 classes
2 parents a7e4cff + 1f5c4d6 commit ba94559

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed

Compiler/ResolveBindingsPass.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,11 @@ protected function processValue($value, bool $isRoot = false)
134134
continue;
135135
}
136136

137+
if (is_subclass_of($m[1], \UnitEnum::class)) {
138+
$bindingNames[substr($key, \strlen($m[0]))] = $binding;
139+
continue;
140+
}
141+
137142
if (null !== $bindingValue && !$bindingValue instanceof Reference && !$bindingValue instanceof Definition && !$bindingValue instanceof TaggedIteratorArgument && !$bindingValue instanceof ServiceLocatorArgument) {
138143
throw new InvalidArgumentException(sprintf('Invalid value for binding key "%s" for service "%s": expected "%s", "%s", "%s", "%s" or null, "%s" given.', $key, $this->currentId, Reference::class, Definition::class, TaggedIteratorArgument::class, ServiceLocatorArgument::class, get_debug_type($bindingValue)));
139144
}

Tests/Compiler/ResolveBindingsPassTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@
2525
use Symfony\Component\DependencyInjection\Reference;
2626
use Symfony\Component\DependencyInjection\Tests\Fixtures\BarInterface;
2727
use Symfony\Component\DependencyInjection\Tests\Fixtures\CaseSensitiveClass;
28+
use Symfony\Component\DependencyInjection\Tests\Fixtures\FooUnitEnum;
2829
use Symfony\Component\DependencyInjection\Tests\Fixtures\NamedArgumentsDummy;
30+
use Symfony\Component\DependencyInjection\Tests\Fixtures\NamedEnumArgumentDummy;
2931
use Symfony\Component\DependencyInjection\Tests\Fixtures\ParentNotExists;
3032
use Symfony\Component\DependencyInjection\Tests\Fixtures\WithTarget;
3133
use Symfony\Component\DependencyInjection\TypedReference;
@@ -65,6 +67,27 @@ public function testProcess()
6567
$this->assertEquals([['setSensitiveClass', [new Reference('foo')]]], $definition->getMethodCalls());
6668
}
6769

70+
/**
71+
* @requires PHP 8.1
72+
*/
73+
public function testProcessEnum()
74+
{
75+
$container = new ContainerBuilder();
76+
77+
$bindings = [
78+
FooUnitEnum::class.' $bar' => new BoundArgument(FooUnitEnum::BAR),
79+
];
80+
81+
$definition = $container->register(NamedEnumArgumentDummy::class, NamedEnumArgumentDummy::class);
82+
$definition->setBindings($bindings);
83+
84+
$pass = new ResolveBindingsPass();
85+
$pass->process($container);
86+
87+
$expected = [FooUnitEnum::BAR];
88+
$this->assertEquals($expected, $definition->getArguments());
89+
}
90+
6891
public function testUnusedBinding()
6992
{
7093
$this->expectException(InvalidArgumentException::class);
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
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\DependencyInjection\Tests\Fixtures;
13+
14+
class NamedEnumArgumentDummy
15+
{
16+
public function __construct(FooUnitEnum $bar)
17+
{
18+
}
19+
}

0 commit comments

Comments
 (0)