[DependencyInjection] Resolve aliases before removing abstract services + add tests
This commit is contained in:
parent
5fbfcb05d5
commit
9802a41b3c
@ -59,8 +59,8 @@ class PassConfig
|
|||||||
|
|
||||||
$this->removingPasses = array(
|
$this->removingPasses = array(
|
||||||
new RemovePrivateAliasesPass(),
|
new RemovePrivateAliasesPass(),
|
||||||
new RemoveAbstractDefinitionsPass(),
|
|
||||||
new ReplaceAliasByActualDefinitionPass(),
|
new ReplaceAliasByActualDefinitionPass(),
|
||||||
|
new RemoveAbstractDefinitionsPass(),
|
||||||
new RepeatedPass(array(
|
new RepeatedPass(array(
|
||||||
new AnalyzeServiceReferencesPass(),
|
new AnalyzeServiceReferencesPass(),
|
||||||
new InlineServiceDefinitionsPass(),
|
new InlineServiceDefinitionsPass(),
|
||||||
@ -103,8 +103,7 @@ class PassConfig
|
|||||||
throw new InvalidArgumentException(sprintf('Invalid type "%s".', $type));
|
throw new InvalidArgumentException(sprintf('Invalid type "%s".', $type));
|
||||||
}
|
}
|
||||||
|
|
||||||
$passes = &$this->$property;
|
$this->{$property}[] = $pass;
|
||||||
$passes[] = $pass;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -707,6 +707,21 @@ class ContainerBuilderTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals(array($second, $first), $configs);
|
$this->assertEquals(array($second, $first), $configs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testAbstractAlias()
|
||||||
|
{
|
||||||
|
$container = new ContainerBuilder();
|
||||||
|
|
||||||
|
$abstract = new Definition('AbstractClass');
|
||||||
|
$abstract->setAbstract(true);
|
||||||
|
|
||||||
|
$container->setDefinition('abstract_service', $abstract);
|
||||||
|
$container->setAlias('abstract_alias', 'abstract_service');
|
||||||
|
|
||||||
|
$container->compile();
|
||||||
|
|
||||||
|
$this->assertSame('abstract_service', (string) $container->getAlias('abstract_alias'));
|
||||||
|
}
|
||||||
|
|
||||||
public function testLazyLoadedService()
|
public function testLazyLoadedService()
|
||||||
{
|
{
|
||||||
$loader = new ClosureLoader($container = new ContainerBuilder());
|
$loader = new ClosureLoader($container = new ContainerBuilder());
|
||||||
|
@ -14,8 +14,12 @@
|
|||||||
</service>
|
</service>
|
||||||
</argument>
|
</argument>
|
||||||
<property name="p" type="service">
|
<property name="p" type="service">
|
||||||
<service class="BazClass" />
|
<service class="BuzClass" />
|
||||||
</property>
|
</property>
|
||||||
</service>
|
</service>
|
||||||
|
<service id="bar" parent="foo" />
|
||||||
|
<service class="BizClass">
|
||||||
|
<tag name="biz_tag" />
|
||||||
|
</service>
|
||||||
</services>
|
</services>
|
||||||
</container>
|
</container>
|
||||||
|
@ -121,7 +121,7 @@ class XmlFileLoaderTest extends \PHPUnit_Framework_TestCase
|
|||||||
$loader = new XmlFileLoader($container, new FileLocator(self::$fixturesPath.'/xml'));
|
$loader = new XmlFileLoader($container, new FileLocator(self::$fixturesPath.'/xml'));
|
||||||
$loader->load('services5.xml');
|
$loader->load('services5.xml');
|
||||||
$services = $container->getDefinitions();
|
$services = $container->getDefinitions();
|
||||||
$this->assertCount(4, $services, '->load() attributes unique ids to anonymous services');
|
$this->assertCount(6, $services, '->load() attributes unique ids to anonymous services');
|
||||||
|
|
||||||
// anonymous service as an argument
|
// anonymous service as an argument
|
||||||
$args = $services['foo']->getArguments();
|
$args = $services['foo']->getArguments();
|
||||||
@ -130,6 +130,7 @@ class XmlFileLoaderTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertTrue(isset($services[(string) $args[0]]), '->load() makes a reference to the created ones');
|
$this->assertTrue(isset($services[(string) $args[0]]), '->load() makes a reference to the created ones');
|
||||||
$inner = $services[(string) $args[0]];
|
$inner = $services[(string) $args[0]];
|
||||||
$this->assertEquals('BarClass', $inner->getClass(), '->load() uses the same configuration as for the anonymous ones');
|
$this->assertEquals('BarClass', $inner->getClass(), '->load() uses the same configuration as for the anonymous ones');
|
||||||
|
$this->assertFalse($inner->isPublic());
|
||||||
|
|
||||||
// inner anonymous services
|
// inner anonymous services
|
||||||
$args = $inner->getArguments();
|
$args = $inner->getArguments();
|
||||||
@ -138,6 +139,7 @@ class XmlFileLoaderTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertTrue(isset($services[(string) $args[0]]), '->load() makes a reference to the created ones');
|
$this->assertTrue(isset($services[(string) $args[0]]), '->load() makes a reference to the created ones');
|
||||||
$inner = $services[(string) $args[0]];
|
$inner = $services[(string) $args[0]];
|
||||||
$this->assertEquals('BazClass', $inner->getClass(), '->load() uses the same configuration as for the anonymous ones');
|
$this->assertEquals('BazClass', $inner->getClass(), '->load() uses the same configuration as for the anonymous ones');
|
||||||
|
$this->assertFalse($inner->isPublic());
|
||||||
|
|
||||||
// anonymous service as a property
|
// anonymous service as a property
|
||||||
$properties = $services['foo']->getProperties();
|
$properties = $services['foo']->getProperties();
|
||||||
@ -145,7 +147,25 @@ class XmlFileLoaderTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertInstanceOf('Symfony\\Component\\DependencyInjection\\Reference', $property, '->load() converts anonymous services to references to "normal" services');
|
$this->assertInstanceOf('Symfony\\Component\\DependencyInjection\\Reference', $property, '->load() converts anonymous services to references to "normal" services');
|
||||||
$this->assertTrue(isset($services[(string) $property]), '->load() makes a reference to the created ones');
|
$this->assertTrue(isset($services[(string) $property]), '->load() makes a reference to the created ones');
|
||||||
$inner = $services[(string) $property];
|
$inner = $services[(string) $property];
|
||||||
$this->assertEquals('BazClass', $inner->getClass(), '->load() uses the same configuration as for the anonymous ones');
|
$this->assertEquals('BuzClass', $inner->getClass(), '->load() uses the same configuration as for the anonymous ones');
|
||||||
|
$this->assertFalse($inner->isPublic());
|
||||||
|
|
||||||
|
// "wild" service
|
||||||
|
$service = $container->findTaggedServiceIds('biz_tag');
|
||||||
|
$this->assertCount(1, $service);
|
||||||
|
|
||||||
|
foreach ($service as $id => $tag) {
|
||||||
|
$service = $container->getDefinition($id);
|
||||||
|
}
|
||||||
|
$this->assertEquals('BizClass', $service->getClass(), '->load() uses the same configuration as for the anonymous ones');
|
||||||
|
$this->assertFalse($service->isPublic());
|
||||||
|
|
||||||
|
// anonymous services are shared when using decoration definitions
|
||||||
|
$container->compile();
|
||||||
|
$services = $container->getDefinitions();
|
||||||
|
$fooArgs = $services['foo']->getArguments();
|
||||||
|
$barArgs = $services['bar']->getArguments();
|
||||||
|
$this->assertSame($fooArgs[0], $barArgs[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testLoadServices()
|
public function testLoadServices()
|
||||||
|
Reference in New Issue
Block a user