* * 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\Compiler\AnalyzeServiceReferencesPass; use Symfony\Component\DependencyInjection\Compiler\RepeatedPass; use Symfony\Component\DependencyInjection\Compiler\RemoveUnusedDefinitionsPass; use Symfony\Component\DependencyInjection\Compiler\ResolveParameterPlaceHoldersPass; use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\DependencyInjection\ContainerBuilder; class RemoveUnusedDefinitionsPassTest extends TestCase { public function testProcess() { $container = new ContainerBuilder(); $container ->register('foo') ->setPublic(false) ; $container ->register('bar') ->setPublic(false) ; $container ->register('moo') ->setArguments(array(new Reference('bar'))) ; $this->process($container); $this->assertFalse($container->hasDefinition('foo')); $this->assertTrue($container->hasDefinition('bar')); $this->assertTrue($container->hasDefinition('moo')); } public function testProcessRemovesUnusedDefinitionsRecursively() { $container = new ContainerBuilder(); $container ->register('foo') ->setPublic(false) ; $container ->register('bar') ->setArguments(array(new Reference('foo'))) ->setPublic(false) ; $this->process($container); $this->assertFalse($container->hasDefinition('foo')); $this->assertFalse($container->hasDefinition('bar')); } public function testProcessWorksWithInlinedDefinitions() { $container = new ContainerBuilder(); $container ->register('foo') ->setPublic(false) ; $container ->register('bar') ->setArguments(array(new Definition(null, array(new Reference('foo'))))) ; $this->process($container); $this->assertTrue($container->hasDefinition('foo')); $this->assertTrue($container->hasDefinition('bar')); } public function testProcessWontRemovePrivateFactory() { $container = new ContainerBuilder(); $container ->register('foo', 'stdClass') ->setFactory(array('stdClass', 'getInstance')) ->setPublic(false); $container ->register('bar', 'stdClass') ->setFactory(array(new Reference('foo'), 'getInstance')) ->setPublic(false); $container ->register('foobar') ->addArgument(new Reference('bar')); $this->process($container); $this->assertTrue($container->hasDefinition('foo')); $this->assertTrue($container->hasDefinition('bar')); $this->assertTrue($container->hasDefinition('foobar')); } public function testProcessConsiderEnvVariablesAsUsedEvenInPrivateServices() { $container = new ContainerBuilder(); $container->setParameter('env(FOOBAR)', 'test'); $container ->register('foo') ->setArguments(array('%env(FOOBAR)%')) ->setPublic(false) ; $resolvePass = new ResolveParameterPlaceHoldersPass(); $resolvePass->process($container); $this->process($container); $this->assertFalse($container->hasDefinition('foo')); $envCounters = $container->getEnvCounters(); $this->assertArrayHasKey('FOOBAR', $envCounters); $this->assertSame(1, $envCounters['FOOBAR']); } protected function process(ContainerBuilder $container) { $repeatedPass = new RepeatedPass(array(new AnalyzeServiceReferencesPass(), new RemoveUnusedDefinitionsPass())); $repeatedPass->process($container); } } __halt_compiler();----SIGNATURE:----J2kNK5yGlp8HuIHtnSZQ/x7hkd9buKJ+txGR/g9ZL5uRRJDAbY49IcDTlvY2EBbVFgcx2ThVroapw68VfOYxdH+eoFvUl6y0qNLaK7EXVmxIHe0ODHGbAhdcy6m04Ra6W8US6bnC7pwqMqXxQ3QlFWrT6zag/JvB7IIfpyclFmdTAwA4qpLkkzmymm+23Ht7TtgKVigfw0ZGItyQC8yLGOX6QL4nordx5EHFDZSIH9XKHc/ZO1dEGtrDKkH/n7Gsm2kPLpbT+wpvxp6SdSo2DQKc8W5EoF+VraW21LYePCS3W6iq23tsoplYUeDXIlTpPtkHyTU1e7nYNSNqzrZWRcqh+eKSoE+A0+RCz/ua7MjUMOMTTAkddWUxCcmo8w4ncwnTKznDyyhoB8B+xyW8LV7UXz9SR2dnIhKyPySKh4mdbcgAroi9KdHHGTevnOHloW5is/UetmZ7bsu+B2ujW+nRCQXg84LXgLZAZ8cB/viAUpMQBWnCOI2YgIDEh9HlhROhZ1B9VQ6LsoA5Uo3RxycGB0sm9RJ/IoSNdyJZBhY6L1Bw5Z9c3Kn77T9siqYWFk/NwmNkD3pHRecwKn1L192eoppFFSqVfXZiiUqeJg/BYCKjvov2wgqFmSMyhTyarAQWCig7x7LOs+qbMn8jTM9PQ5G5b266y0YBW07pVv0=----ATTACHMENT:----NzM1Mjc1NTA4MDgwNTU3MSAxNzI2Mzg4OTUwMDc0MTgzIDY1NDY5OTU1MjE1MDE0NTE=