Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b71b4db

Browse files
committed
[DI] Fix ServiceLocatorArgument::setValues() for non-reference values
1 parent 924c1f0 commit b71b4db

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-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: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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\Argument;
13+
14+
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\DependencyInjection\Argument\ServiceLocatorArgument;
16+
17+
class ServiceLocatorArgumentTest extends TestCase
18+
{
19+
20+
/**
21+
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
22+
* @expectedExceptionMessage Values of a ServiceLocatorArgument must be Reference objects.
23+
*/
24+
public function testAcceptsOnlyReferenceOrNulls()
25+
{
26+
(new ServiceLocatorArgument(array('foo' => 'bar')));
27+
}
28+
}

0 commit comments

Comments
 (0)