8000 bug #21794 [DI] Fix ServiceLocatorArgument::setValues() for non-refer… · symfony/symfony@7f012b6 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7f012b6

Browse files
bug #21794 [DI] Fix ServiceLocatorArgument::setValues() for non-reference values (chalasr)
This PR was merged into the 3.3-dev branch. Discussion ---------- [DI] Fix ServiceLocatorArgument::setValues() for non-reference values | Q | A | ------------- | --- | Branch? | master | Fixed tickets | #21625 (comment) | Tests pass? | yes | License | MIT `ResolveInvalidReferencesPass` [calls `setValues()`](https://github.com/symfony/symfony/blob/master/src/Symfony/Component/DependencyInjection/Compiler/ResolveInvalidReferencesPass.php#L91) with resolved invalid reference (null), the `Reference` type check should occurs at construction only. Commits ------- 256b836 [DI] Fix ServiceLocatorArgument::setValues() for non-reference values
2 parents e0568d8 + 256b836 commit 7f012b6

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

src/Symfony/Component/DependencyInjection/Argument/ServiceLocatorArgument.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function getValues()
3939
public function setValues(array $values)
4040
{
4141
foreach ($values as $v) {
42-
if (!$v instanceof Reference) {
42+
if (!$v instanceof Reference && null !== $v) {
4343
throw new InvalidArgumentException('Values of a ServiceLocatorArgument must be Reference objects.');
4444
}
4545
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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\DependencyInjection\Tests\Argument;
13+
14+
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\DependencyInjection\Argument\ServiceLocatorArgument;
16+
use Symfony\Component\DependencyInjection\Reference;
17+
18+
class ServiceLocatorArgumentTest extends TestCase
19+
{
20+
/**
21+
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
22+
* @expectedExceptionMessage Values of a ServiceLocatorArgument must be Reference objects.
23+
*/
24+
public function testThrowsOnNonReferenceValues()
25+
{
26+
new ServiceLocatorArgument(array('foo' => 'bar'));
27+
}
28+
29+
public function testAcceptsReferencesOrNulls()
30+
{
31+
$locator = new ServiceLocatorArgument($values = array('foo' => new Reference('bar'), 'bar' => null));
32+
33+
$this->assertSame($values, $locator->getValues());
34+
}
35+
}

0 commit comments

Comments
 (0)
0