[DI] Fix ServiceLocatorArgument::setValues() for non-reference values
This commit is contained in:
parent
924c1f06bf
commit
256b836482
@ -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.');
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* 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());
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user