* * 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:----X5WfwWzK0CDsYrHeJ2p+s5o7Kivm8R08JZhr+pFZP2XH5E+DP4IdFLnLiXER+WYQY41UsUn5K9bWbwb7XynTVWC6hrEvqtPJWGJNss8Pw4IiZ2+EXeSoywHWWpXGYyOEeqpZDV9bd04VJatvG+2T1W1CDydsHG0SiS9HU1FXyADgscqQbEo14iO/tO5QepFYuRSCJIJu+tn4ZcfhQWTq8YqZd9aLzgJTHs5yeYNAw64TbmwOpZkdXB0v5T+JCCVWJwtw37Dmd9yvcvBvvVDt6AuANXJNw4sK4dZw7+aiqT9e8La3ItAWZZT4Je5BR2K7lyPcLh5GJwjHeAyYuC+dl6SfACdwEUsB+YerAb8WEF5e/en+IlM3osTloMcgpDiv200UKvHTnuCSvDzPMsh7OwVCdaoSZRJUnB2kSPpeZK67kkbciX0DVGAXGf9Jrq0M25AfU0FQYD2Wtt1wXbYhtvFnG7jgfmgD4cUaH03Xcq3jRaXaq6DQnbbJ0zXXWPI9y4O1QVO/9pkOGmWgx5nh8P9JbWWcKeTYN5fwGeqN6fks6Y21lDD/ie69+sSAUXfj0Xgm9p38dzGdKQoH88ZDC8r94OcRSj9UBqWWo0cShXBT0UR2eGYTGVKm3YZer/qltliJkuni8q/N+GHKC7K4uw1JsG5N781Z9UHsFpkeCE8=----ATTACHMENT:----Mjc5OTE0OTE0NDAwODM4MSAxMzAyMzcyNzI3OTY3ODQwIDM3Nzc5MTQ1MjQ0ODA5NDY=