register('one', ResettableService::class) ->setPublic(true) ->addTag('kernel.reset', ['method' => 'reset']); $container->register('two', ClearableService::class) ->setPublic(true) ->addTag('kernel.reset', ['method' => 'clear']); $container->register('services_resetter', ServicesResetter::class) ->setPublic(true) ->setArguments([null, []]); $container->addCompilerPass(new ResettableServicePass()); $container->compile(); $definition = $container->getDefinition('services_resetter'); $this->assertEquals( [ new IteratorArgument([ 'one' => new Reference('one', ContainerInterface::IGNORE_ON_UNINITIALIZED_REFERENCE), 'two' => new Reference('two', ContainerInterface::IGNORE_ON_UNINITIALIZED_REFERENCE), ]), [ 'one' => 'reset', 'two' => 'clear', ], ], $definition->getArguments() ); } /** * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException * @expectedExceptionMessage Tag kernel.reset requires the "method" attribute to be set. */ public function testMissingMethod() { $container = new ContainerBuilder(); $container->register(ResettableService::class) ->addTag('kernel.reset'); $container->register('services_resetter', ServicesResetter::class) ->setArguments([null, []]); $container->addCompilerPass(new ResettableServicePass()); $container->compile(); } public function testCompilerPassWithoutResetters() { $container = new ContainerBuilder(); $container->register('services_resetter', ServicesResetter::class) ->setArguments([null, []]); $container->addCompilerPass(new ResettableServicePass()); $container->compile(); $this->assertFalse($container->has('services_resetter')); } }