* * 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; use PHPUnit\Framework\TestCase; use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\DependencyInjection\Compiler\ResolveInvalidReferencesPass; use Symfony\Component\DependencyInjection\ContainerBuilder; class ResolveInvalidReferencesPassTest extends TestCase { public function testProcess() { $container = new ContainerBuilder(); $def = $container ->register('foo') ->setArguments(array( new Reference('bar', ContainerInterface::NULL_ON_INVALID_REFERENCE), new Reference('baz', ContainerInterface::IGNORE_ON_INVALID_REFERENCE), )) ->addMethodCall('foo', array(new Reference('moo', ContainerInterface::IGNORE_ON_INVALID_REFERENCE))) ; $this->process($container); $arguments = $def->getArguments(); $this->assertSame(array(null, null), $arguments); $this->assertCount(0, $def->getMethodCalls()); } public function testProcessIgnoreInvalidArgumentInCollectionArgument() { $container = new ContainerBuilder(); $container->register('baz'); $def = $container ->register('foo') ->setArguments(array( array( new Reference('bar', ContainerInterface::IGNORE_ON_INVALID_REFERENCE), $baz = new Reference('baz', ContainerInterface::IGNORE_ON_INVALID_REFERENCE), new Reference('moo', ContainerInterface::NULL_ON_INVALID_REFERENCE), ), )) ; $this->process($container); $arguments = $def->getArguments(); $this->assertSame(array($baz, null), $arguments[0]); } public function testProcessKeepMethodCallOnInvalidArgumentInCollectionArgument() { $container = new ContainerBuilder(); $container->register('baz'); $def = $container ->register('foo') ->addMethodCall('foo', array( array( new Reference('bar', ContainerInterface::IGNORE_ON_INVALID_REFERENCE), $baz = new Reference('baz', ContainerInterface::IGNORE_ON_INVALID_REFERENCE), new Reference('moo', ContainerInterface::NULL_ON_INVALID_REFERENCE), ), )) ; $this->process($container); $calls = $def->getMethodCalls(); $this->assertCount(1, $def->getMethodCalls()); $this->assertSame(array($baz, null), $calls[0][1][0]); } public function testProcessIgnoreNonExistentServices() { $container = new ContainerBuilder(); $def = $container ->register('foo') ->setArguments(array(new Reference('bar'))) ; $this->process($container); $arguments = $def->getArguments(); $this->assertEquals('bar', (string) $arguments[0]); } public function testProcessRemovesPropertiesOnInvalid() { $container = new ContainerBuilder(); $def = $container ->register('foo') ->setProperty('foo', new Reference('bar', ContainerInterface::IGNORE_ON_INVALID_REFERENCE)) ; $this->process($container); $this->assertEquals(array(), $def->getProperties()); } public function testProcessRemovesArgumentsOnInvalid() { $container = new ContainerBuilder(); $def = $container ->register('foo') ->addArgument(array( array( new Reference('bar', ContainerInterface::IGNORE_ON_INVALID_REFERENCE), new ServiceClosureArgument(new Reference('baz', ContainerInterface::IGNORE_ON_INVALID_REFERENCE)), ), )) ; $this->process($container); $this->assertSame(array(array(array())), $def->getArguments()); } protected function process(ContainerBuilder $container) { $pass = new ResolveInvalidReferencesPass(); $pass->process($container); } } __halt_compiler();----SIGNATURE:----l7V7YKMzMzsp9UwwqwgNz7DlIPGXjy7Ua81TOY1LK0Qf8IRnhm/pFN0vCmmGhRZfePu1hWXjy6rgOPxAyPChTdtGp771jcByionlEJMsJx7igUA26hRIjhTeud5izJSVWZETr27qTEyOuAKAQwJ20+XMiGBLmpig6nqDm33uJ0l9yPdEczZRjxSV2f4onJ6UC7Rg4fjKmdP2wAo5NWJ826bpmo6Bj5/DXQ+cYyJx8eIgKDr+gb0QoPlN4Wq2mKux2k1TUNhvnaoQO7+lTex3CQmh4kJ18gTfnuLqI3aD6Dqayrbus5B2CGdQYXssqQt/UbzS9kwhpzGoTuNK7+gSMCFq4EK0OyXawLvAGWNQ52snJ7j2h2a/4SDJeZahZYJmV0BINy/AeIqfGfy9PpfVG+JyFirDB5EDRoaIeBb43zzjxLjq+NPrXkTh2QQzGt15SRmMmUXOvHR7gLq+7UFIUk07kCoNvHtVNJhbId+qrX3FJAJr7XxIW4rjtztz6/clbJfY2xdFkNzPT17gXyowETabGLWFRZfJ+R+z1fh9+vpTt4gb79WOctY3kBeYN/4yW4czstmb/hiFIlKSqTOrNvLOX/Swlk5BX9SwpaLf9x5TQ2s6DiRR0g2pY/Qf3+boEILfTYaIqCpABoVBYRTwH0taSxF06A/Wp7yjjjdFP80=----ATTACHMENT:----OTA4MTMwNzY4ODU0NTA0NiA0NDg2MzUyNDc0ODg3MTkyIDg5MjM3NjY4MzM5NDY2MTA=