* * 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:----iLwek45ISVmIFjWDr4WA6iNERN6gAEPfCA0V2+t3E+bYq4WrLPOUaY6exUX9nFI4lxdtWDzZQe/QctOH9/DlWrGg3O1qVQEe40nmjEq7yLBo+FnM599LwIw7oPa6ttG/qPCysnhzB93QwNjnXOJaDle1H+IbdgmkRwZnaDBHYBikHX236vP1PYY9C7r0ezgoRvCeyQTrSqLevNEdUP+6GpjGCKTXWivkluYr/FNZ8UxE6oA6YY3V+GQ7b6xhwlgy96BPkKvCTOUnB9oZhkpGsSPVoGyK46YwlOzYeTRfHIQrBxc1LIGJcK4Qf+2yHJ708dGgt10l41mIdR4qhdjFEtfHwihtPn+5aZT0DdxpR8De9mW+QP1KC2xu0xDUWMioi4LHW0JAyKbmRmu0uhgXQyut+iokCST/dp2/mvade424n0G7RzyB5nAXBHUbETIboJkmwvFQwDJfz5DQF/UHtt2RkINBLSGooiKPwxXqYX+D/emXmIY+3L5uYcQGh7KX0Nw6G70h/udUD9OIWK8Csj0UCJa2JE3hdTC9JNSRmweRfYXFQSeMsjwO2sUadCC2qylA+u8lq+D59fI1iejEIiN2kSEDnplxVzyiQN82VFCQ380nqDu/U6ikRYzFAFZCve5Er16FwGshtB9H5G07cvu3aIz/lPdyK8zFtI7bg/8=----ATTACHMENT:----Njk3NTU2NDczMjYxMDY4NyAyNjkyNTgwNDIyMzAxOTY1IDkyMjkyMjM5MDk1NTM0Mjk=