* * 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\Config\FileLocator; use Symfony\Component\DependencyInjection\Alias; use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\DependencyInjection\ContainerBuilder; /** * This class tests the integration of the different compiler passes. */ class IntegrationTest extends TestCase { /** * This tests that dependencies are correctly processed. * * We're checking that: * * * A is public, B/C are private * * A -> C * * B -> C */ public function testProcessRemovesAndInlinesRecursively() { $container = new ContainerBuilder(); $container->setResourceTracking(false); $a = $container ->register('a', '\stdClass') ->addArgument(new Reference('c')) ; $b = $container ->register('b', '\stdClass') ->addArgument(new Reference('c')) ->setPublic(false) ; $c = $container ->register('c', '\stdClass') ->setPublic(false) ; $container->compile(); $this->assertTrue($container->hasDefinition('a')); $arguments = $a->getArguments(); $this->assertSame($c, $arguments[0]); $this->assertFalse($container->hasDefinition('b')); $this->assertFalse($container->hasDefinition('c')); } public function testProcessInlinesReferencesToAliases() { $container = new ContainerBuilder(); $container->setResourceTracking(false); $a = $container ->register('a', '\stdClass') ->addArgument(new Reference('b')) ; $container->setAlias('b', new Alias('c', false)); $c = $container ->register('c', '\stdClass') ->setPublic(false) ; $container->compile(); $this->assertTrue($container->hasDefinition('a')); $arguments = $a->getArguments(); $this->assertSame($c, $arguments[0]); $this->assertFalse($container->hasAlias('b')); $this->assertFalse($container->hasDefinition('c')); } public function testProcessInlinesWhenThereAreMultipleReferencesButFromTheSameDefinition() { $container = new ContainerBuilder(); $container->setResourceTracking(false); $container ->register('a', '\stdClass') ->addArgument(new Reference('b')) ->addMethodCall('setC', array(new Reference('c'))) ; $container ->register('b', '\stdClass') ->addArgument(new Reference('c')) ->setPublic(false) ; $container ->register('c', '\stdClass') ->setPublic(false) ; $container->compile(); $this->assertTrue($container->hasDefinition('a')); $this->assertFalse($container->hasDefinition('b')); $this->assertFalse($container->hasDefinition('c'), 'Service C was not inlined.'); } /** * @dataProvider getYamlCompileTests */ public function testYamlContainerCompiles($directory, $actualServiceId, $expectedServiceId, ContainerBuilder $mainContainer = null) { // allow a container to be passed in, which might have autoconfigure settings $container = $mainContainer ? $mainContainer : new ContainerBuilder(); $container->setResourceTracking(false); $loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Fixtures/yaml/integration/'.$directory)); $loader->load('main.yml'); $container->compile(); $actualService = $container->getDefinition($actualServiceId); // create a fresh ContainerBuilder, to avoid autoconfigure stuff $container = new ContainerBuilder(); $container->setResourceTracking(false); $loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Fixtures/yaml/integration/'.$directory)); $loader->load('expected.yml'); $container->compile(); $expectedService = $container->getDefinition($expectedServiceId); // reset changes, we don't care if these differ $actualService->setChanges(array()); $expectedService->setChanges(array()); $this->assertEquals($expectedService, $actualService); } public function getYamlCompileTests() { $container = new ContainerBuilder(); $container->registerForAutoconfiguration(IntegrationTestStub::class); yield array( 'autoconfigure_child_not_applied', 'child_service', 'child_service_expected', $container, ); $container = new ContainerBuilder(); $container->registerForAutoconfiguration(IntegrationTestStub::class); yield array( 'autoconfigure_parent_child', 'child_service', 'child_service_expected', $container, ); $container = new ContainerBuilder(); $container->registerForAutoconfiguration(IntegrationTestStub::class) ->addTag('from_autoconfigure'); yield array( 'autoconfigure_parent_child_tags', 'child_service', 'child_service_expected', $container, ); yield array( 'child_parent', 'child_service', 'child_service_expected', ); yield array( 'defaults_child_tags', 'child_service', 'child_service_expected', ); yield array( 'defaults_instanceof_importance', 'main_service', 'main_service_expected', ); yield array( 'defaults_parent_child', 'child_service', 'child_service_expected', ); yield array( 'instanceof_parent_child', 'child_service', 'child_service_expected', ); } } class IntegrationTestStub extends IntegrationTestStubParent { } class IntegrationTestStubParent { public function enableSummer($enable) { // methods used in calls - added here to prevent errors for not existing } public function setSunshine($type) { } } __halt_compiler();----SIGNATURE:----OAAEIy4d4oPXfoXYPfvf6TPVh3grCALlnClt1vahXQ/lNGBFJfatygwVZMAwvwjvaud/bG8r7GSnCd301Ras+Et8wm15Zo86x1W0GvPBynZVTn4Dr2sflfqGXywbqD4TeICBS6PbxsEThic+mxEJ5w+TJcfy70J+4FWtN/JySuY6UHxQQsQrS0SSVScU+cEb6jskl3IvuztqAOymwiZY5K0EwZDlfW83DorShbu0VqnZT1rhWrHbCa0HGGkU+yXG6WupbICGKBeM6VRIYj+/XGMAD4x/3HIz8qaZkeDZnwB02voZsY/uMgRGmCK5oCBFTWSTo6QQRcvJRzcKBA/h4hr99IKZJhuIjc+yBPN51bHBdbPjyQA78JX81++aAcEEc9Hc7uC9EHXKsX1viNJh6llDY7MR72L9usH4fth/08np0PZW45mMqOBU5lqQH2QBWfytDLHGJ10AaFJ0PcdJV/QBash199cYHzo1KOzM9+fh21p36Fxe6utZaTk42zVAKXLB/GAuD1iw+krJ+/k59gvch2TrsodgQ5VfnZsU2aaoP+7/UQX07BmziCoPxz2vQyldBCssqiDRumbq2va/Ubr7vrYlM2n3AiPrQZqOs6dWNIlL2oO0vCKm97SEf+Fy7IJsaSeMwuAL+Ot1xplYfAkOYf5PYUBXiBnBt4iKJgo=----ATTACHMENT:----NDEzNzk3NDE5NjA1MzU2IDcxMDAwMDU2NDM2NDM3IDM2MzcxNjQzMDgzNzkxNw==