namespace Symfony\Component\DependencyInjection\Tests\Loader;
use PHPUnit\Framework\TestCase;
-use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
);
$this->assertEquals(array_keys($expected), array_keys($actual), '->load() imports and merges imported files');
+ $this->assertTrue($actual['imported_from_ini']);
// Bad import throws no exception due to ignore_errors value.
$loader->load('services4_bad_import.xml');
$this->assertSame($fooArgs[0], $barArgs[0]);
}
- /**
- * @group legacy
- */
- public function testLegacyLoadServices()
- {
- $container = new ContainerBuilder();
- $loader = new XmlFileLoader($container, new FileLocator(self::$fixturesPath.'/xml'));
- $loader->load('legacy-services6.xml');
- $services = $container->getDefinitions();
- $this->assertEquals('FooClass', $services['constructor']->getClass());
- $this->assertEquals('getInstance', $services['constructor']->getFactoryMethod());
- $this->assertNull($services['factory_service']->getClass());
- $this->assertEquals('baz_factory', $services['factory_service']->getFactoryService());
- $this->assertEquals('getInstance', $services['factory_service']->getFactoryMethod());
- $this->assertEquals('container', $services['scope.container']->getScope());
- $this->assertEquals('custom', $services['scope.custom']->getScope());
- $this->assertEquals('prototype', $services['scope.prototype']->getScope());
- $this->assertTrue($services['request']->isSynthetic(), '->load() parses the synthetic flag');
- $this->assertTrue($services['request']->isSynchronized(), '->load() parses the synchronized flag');
- $this->assertTrue($services['request']->isLazy(), '->load() parses the lazy flag');
- $this->assertNull($services['request']->getDecoratedService());
- }
-
public function testLoadServices()
{
$container = new ContainerBuilder();
$this->assertEquals('%path%/foo.php', $services['file']->getFile(), '->load() parses the file tag');
$this->assertEquals(array('foo', new Reference('foo'), array(true, false)), $services['arguments']->getArguments(), '->load() parses the argument tags');
$this->assertEquals('sc_configure', $services['configurator1']->getConfigurator(), '->load() parses the configurator tag');
- $this->assertEquals(array(new Reference('baz', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, false), 'configure'), $services['configurator2']->getConfigurator(), '->load() parses the configurator tag');
+ $this->assertEquals(array(new Reference('baz'), 'configure'), $services['configurator2']->getConfigurator(), '->load() parses the configurator tag');
$this->assertEquals(array('BazClass', 'configureStatic'), $services['configurator3']->getConfigurator(), '->load() parses the configurator tag');
$this->assertEquals(array(array('setBar', array()), array('setBar', array(new Expression('service("foo").foo() ~ (container.hasParameter("foo") ? parameter("foo") : "default")')))), $services['method_call1']->getMethodCalls(), '->load() parses the method_call tag');
$this->assertEquals(array(array('setBar', array('foo', new Reference('foo'), array(true, false)))), $services['method_call2']->getMethodCalls(), '->load() parses the method_call tag');
$this->assertEquals('factory', $services['new_factory1']->getFactory(), '->load() parses the factory tag');
- $this->assertEquals(array(new Reference('baz', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, false), 'getClass'), $services['new_factory2']->getFactory(), '->load() parses the factory tag');
+ $this->assertEquals(array(new Reference('baz'), 'getClass'), $services['new_factory2']->getFactory(), '->load() parses the factory tag');
$this->assertEquals(array('BazClass', 'getInstance'), $services['new_factory3']->getFactory(), '->load() parses the factory tag');
$aliases = $container->getAliases();
$this->assertTrue($container->getDefinition('bar')->isAutowired());
}
+ /**
+ * @group legacy
+ * @expectedDeprecation Using the attribute "class" is deprecated for the service "bar" which is defined as an alias %s.
+ * @expectedDeprecation Using the element "tag" is deprecated for the service "bar" which is defined as an alias %s.
+ * @expectedDeprecation Using the element "factory" is deprecated for the service "bar" which is defined as an alias %s.
+ */
+ public function testAliasDefinitionContainsUnsupportedElements()
+ {
+ $container = new ContainerBuilder();
+ $loader = new XmlFileLoader($container, new FileLocator(self::$fixturesPath.'/xml'));
+
+ $loader->load('legacy_invalid_alias_definition.xml');
+
+ $this->assertTrue($container->has('bar'));
+ }
+
public function testArgumentWithKeyOutsideCollection()
{
$container = new ContainerBuilder();