diff --git a/src/Symfony/Component/DependencyInjection/Argument/ServiceLocatorArgument.php b/src/Symfony/Component/DependencyInjection/Argument/ServiceLocatorArgument.php index 613068c2a7..b53545e12b 100644 --- a/src/Symfony/Component/DependencyInjection/Argument/ServiceLocatorArgument.php +++ b/src/Symfony/Component/DependencyInjection/Argument/ServiceLocatorArgument.php @@ -39,7 +39,7 @@ class ServiceLocatorArgument implements ArgumentInterface public function setValues(array $values) { foreach ($values as $v) { - if (!$v instanceof Reference) { + if (!$v instanceof Reference && null !== $v) { throw new InvalidArgumentException('Values of a ServiceLocatorArgument must be Reference objects.'); } } diff --git a/src/Symfony/Component/DependencyInjection/Tests/Argument/ServiceLocatorArgumentTest.php b/src/Symfony/Component/DependencyInjection/Tests/Argument/ServiceLocatorArgumentTest.php new file mode 100644 index 0000000000..040ca7fe34 --- /dev/null +++ b/src/Symfony/Component/DependencyInjection/Tests/Argument/ServiceLocatorArgumentTest.php @@ -0,0 +1,35 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\DependencyInjection\Tests\Argument; + +use PHPUnit\Framework\TestCase; +use Symfony\Component\DependencyInjection\Argument\ServiceLocatorArgument; +use Symfony\Component\DependencyInjection\Reference; + +class ServiceLocatorArgumentTest extends TestCase +{ + /** + * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException + * @expectedExceptionMessage Values of a ServiceLocatorArgument must be Reference objects. + */ + public function testThrowsOnNonReferenceValues() + { + new ServiceLocatorArgument(array('foo' => 'bar')); + } + + public function testAcceptsReferencesOrNulls() + { + $locator = new ServiceLocatorArgument($values = array('foo' => new Reference('bar'), 'bar' => null)); + + $this->assertSame($values, $locator->getValues()); + } +}