2017-01-31 09:49:36 +00:00
|
|
|
<?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\Compiler;
|
|
|
|
|
2017-02-20 13:56:45 +00:00
|
|
|
use PHPUnit\Framework\TestCase;
|
2017-01-31 09:49:36 +00:00
|
|
|
use Symfony\Component\DependencyInjection\Compiler\CheckArgumentsValidityPass;
|
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @author Kévin Dunglas <dunglas@gmail.com>
|
|
|
|
*/
|
2017-02-20 13:56:45 +00:00
|
|
|
class CheckArgumentsValidityPassTest extends TestCase
|
2017-01-31 09:49:36 +00:00
|
|
|
{
|
|
|
|
public function testProcess()
|
|
|
|
{
|
|
|
|
$container = new ContainerBuilder();
|
|
|
|
$definition = $container->register('foo');
|
2019-01-16 09:39:14 +00:00
|
|
|
$definition->setArguments([null, 1, 'a']);
|
|
|
|
$definition->setMethodCalls([
|
|
|
|
['bar', ['a', 'b']],
|
|
|
|
['baz', ['c', 'd']],
|
|
|
|
]);
|
2017-01-31 09:49:36 +00:00
|
|
|
|
|
|
|
$pass = new CheckArgumentsValidityPass();
|
|
|
|
$pass->process($container);
|
|
|
|
|
2019-01-16 09:39:14 +00:00
|
|
|
$this->assertEquals([null, 1, 'a'], $container->getDefinition('foo')->getArguments());
|
|
|
|
$this->assertEquals([
|
|
|
|
['bar', ['a', 'b']],
|
|
|
|
['baz', ['c', 'd']],
|
|
|
|
], $container->getDefinition('foo')->getMethodCalls());
|
2017-01-31 09:49:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
|
|
|
|
* @dataProvider definitionProvider
|
|
|
|
*/
|
|
|
|
public function testException(array $arguments, array $methodCalls)
|
|
|
|
{
|
|
|
|
$container = new ContainerBuilder();
|
|
|
|
$definition = $container->register('foo');
|
|
|
|
$definition->setArguments($arguments);
|
|
|
|
$definition->setMethodCalls($methodCalls);
|
|
|
|
|
|
|
|
$pass = new CheckArgumentsValidityPass();
|
|
|
|
$pass->process($container);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function definitionProvider()
|
|
|
|
{
|
2019-01-16 09:39:14 +00:00
|
|
|
return [
|
|
|
|
[[null, 'a' => 'a'], []],
|
|
|
|
[[1 => 1], []],
|
|
|
|
[[], [['baz', [null, 'a' => 'a']]]],
|
|
|
|
[[], [['baz', [1 => 1]]]],
|
|
|
|
];
|
2017-01-31 09:49:36 +00:00
|
|
|
}
|
2017-09-22 18:54:05 +01:00
|
|
|
|
|
|
|
public function testNoException()
|
|
|
|
{
|
|
|
|
$container = new ContainerBuilder();
|
|
|
|
$definition = $container->register('foo');
|
2019-01-16 09:39:14 +00:00
|
|
|
$definition->setArguments([null, 'a' => 'a']);
|
2017-09-22 18:54:05 +01:00
|
|
|
|
|
|
|
$pass = new CheckArgumentsValidityPass(false);
|
|
|
|
$pass->process($container);
|
|
|
|
$this->assertCount(1, $definition->getErrors());
|
|
|
|
}
|
2017-01-31 09:49:36 +00:00
|
|
|
}
|