diff --git a/src/Symfony/Component/DependencyInjection/Tests/Compiler/IntegrationTest.php b/src/Symfony/Component/DependencyInjection/Tests/Compiler/IntegrationTest.php
index b9f9d7bf36204..1ba0a53eaa679 100644
--- a/src/Symfony/Component/DependencyInjection/Tests/Compiler/IntegrationTest.php
+++ b/src/Symfony/Component/DependencyInjection/Tests/Compiler/IntegrationTest.php
@@ -14,10 +14,14 @@
use PHPUnit\Framework\TestCase;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\Alias;
+use Symfony\Component\DependencyInjection\Argument\TaggedIteratorArgument;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\ServiceSubscriberInterface;
+use Symfony\Component\DependencyInjection\Tests\Fixtures\BarTagClass;
+use Symfony\Component\DependencyInjection\Tests\Fixtures\FooBarTaggedClass;
+use Symfony\Component\DependencyInjection\Tests\Fixtures\FooTagClass;
/**
* This class tests the integration of the different compiler passes.
@@ -234,6 +238,54 @@ public function getYamlCompileTests()
$container,
];
}
+
+ public function testTaggedServiceWithIndexAttribute()
+ {
+ $container = new ContainerBuilder();
+ $container->register(BarTagClass::class, BarTagClass::class)
+ ->setPublic(true)
+ ->addTag('foo_bar', ['foo' => 'bar'])
+ ;
+ $container->register(FooTagClass::class, FooTagClass::class)
+ ->setPublic(true)
+ ->addTag('foo_bar')
+ ;
+ $container->register(FooBarTaggedClass::class, FooBarTaggedClass::class)
+ ->addArgument(new TaggedIteratorArgument('foo_bar', 'foo'))
+ ->setPublic(true)
+ ;
+
+ $container->compile();
+
+ $s = $container->get(FooBarTaggedClass::class);
+
+ $param = iterator_to_array($s->getParam()->getIterator());
+ $this->assertSame(['bar' => $container->get(BarTagClass::class), 'foo_tag_class' => $container->get(FooTagClass::class)], $param);
+ }
+
+ public function testTaggedServiceWithIndexAttributeAndDefaultMethod()
+ {
+ $container = new ContainerBuilder();
+ $container->register(BarTagClass::class, BarTagClass::class)
+ ->setPublic(true)
+ ->addTag('foo_bar')
+ ;
+ $container->register(FooTagClass::class, FooTagClass::class)
+ ->setPublic(true)
+ ->addTag('foo_bar', ['foo' => 'foo'])
+ ;
+ $container->register(FooBarTaggedClass::class, FooBarTaggedClass::class)
+ ->addArgument(new TaggedIteratorArgument('foo_bar', 'foo', 'getFooBar'))
+ ->setPublic(true)
+ ;
+
+ $container->compile();
+
+ $s = $container->get(FooBarTaggedClass::class);
+
+ $param = iterator_to_array($s->getParam()->getIterator());
+ $this->assertSame(['bar_tab_class_with_defaultmethod' => $container->get(BarTagClass::class), 'foo' => $container->get(FooTagClass::class)], $param);
+ }
}
class ServiceSubscriberStub implements ServiceSubscriberInterface
diff --git a/src/Symfony/Component/DependencyInjection/Tests/Dumper/XmlDumperTest.php b/src/Symfony/Component/DependencyInjection/Tests/Dumper/XmlDumperTest.php
index ac274c6f26267..b110cdc5e880d 100644
--- a/src/Symfony/Component/DependencyInjection/Tests/Dumper/XmlDumperTest.php
+++ b/src/Symfony/Component/DependencyInjection/Tests/Dumper/XmlDumperTest.php
@@ -13,6 +13,7 @@
use PHPUnit\Framework\TestCase;
use Symfony\Component\Config\FileLocator;
+use Symfony\Component\DependencyInjection\Argument\TaggedIteratorArgument;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Dumper\XmlDumper;
@@ -200,6 +201,19 @@ public function testDumpLoad()
$this->assertStringEqualsFile(self::$fixturesPath.'/xml/services_dump_load.xml', $dumper->dump());
}
+ public function testTaggedArgument()
+ {
+ $container = new ContainerBuilder();
+ $container->register('foo', 'Foo')->addTag('foo_tag');
+ $container->register('foo_tagged_iterator', 'Bar')
+ ->setPublic(true)
+ ->addArgument(new TaggedIteratorArgument('foo_tag', 'barfoo', 'foobar'))
+ ;
+
+ $dumper = new XmlDumper($container);
+ $this->assertStringEqualsFile(self::$fixturesPath.'/xml/services_with_tagged_arguments.xml', $dumper->dump());
+ }
+
public function testDumpAbstractServices()
{
$container = include self::$fixturesPath.'/containers/container_abstract.php';
diff --git a/src/Symfony/Component/DependencyInjection/Tests/Dumper/YamlDumperTest.php b/src/Symfony/Component/DependencyInjection/Tests/Dumper/YamlDumperTest.php
index 49ee8e6f3002e..61a1aec5105dc 100644
--- a/src/Symfony/Component/DependencyInjection/Tests/Dumper/YamlDumperTest.php
+++ b/src/Symfony/Component/DependencyInjection/Tests/Dumper/YamlDumperTest.php
@@ -13,6 +13,7 @@
use PHPUnit\Framework\TestCase;
use Symfony\Component\Config\FileLocator;
+use Symfony\Component\DependencyInjection\Argument\TaggedIteratorArgument;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Definition;
@@ -95,6 +96,16 @@ public function testInlineServices()
$this->assertStringEqualsFile(self::$fixturesPath.'/yaml/services_inline.yml', $dumper->dump());
}
+ public function testTaggedArgument()
+ {
+ $container = new ContainerBuilder();
+ $container->register('foo_service', 'Foo')->addTag('foo');
+ $container->register('foo_service_tagged', 'Bar')->addArgument(new TaggedIteratorArgument('foo', 'barfoo', 'foobar'));
+
+ $dumper = new YamlDumper($container);
+ $this->assertStringEqualsFile(self::$fixturesPath.'/yaml/services_with_tagged_argument.yml', $dumper->dump());
+ }
+
private function assertEqualYamlStructure($expected, $yaml, $message = '')
{
$parser = new Parser();
diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/BarTagClass.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/BarTagClass.php
new file mode 100644
index 0000000000000..9e065f6b102a9
--- /dev/null
+++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/BarTagClass.php
@@ -0,0 +1,16 @@
+param = $param;
+ }
+
+ public function getParam()
+ {
+ return $this->param;
+ }
+}
diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/FooTagClass.php b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/FooTagClass.php
new file mode 100644
index 0000000000000..c1279b9a9feeb
--- /dev/null
+++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/FooTagClass.php
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/services_with_tagged_argument.yml b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/services_with_tagged_argument.yml
new file mode 100644
index 0000000000000..bf7cf06930d0c
--- /dev/null
+++ b/src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/services_with_tagged_argument.yml
@@ -0,0 +1,19 @@
+
+services:
+ service_container:
+ class: Symfony\Component\DependencyInjection\ContainerInterface
+ public: true
+ synthetic: true
+ foo_service:
+ class: Foo
+ tags:
+ - { name: foo }
+ foo_service_tagged:
+ class: Bar
+ arguments: [!tagged { tag: foo, index_by: barfoo, default_index_method: foobar }]
+ Psr\Container\ContainerInterface:
+ alias: service_container
+ public: false
+ Symfony\Component\DependencyInjection\ContainerInterface:
+ alias: service_container
+ public: false
diff --git a/src/Symfony/Component/DependencyInjection/Tests/Loader/XmlFileLoaderTest.php b/src/Symfony/Component/DependencyInjection/Tests/Loader/XmlFileLoaderTest.php
index 9cb64f39da17f..20c80258e2686 100644
--- a/src/Symfony/Component/DependencyInjection/Tests/Loader/XmlFileLoaderTest.php
+++ b/src/Symfony/Component/DependencyInjection/Tests/Loader/XmlFileLoaderTest.php
@@ -18,6 +18,7 @@
use Symfony\Component\Config\Resource\GlobResource;
use Symfony\Component\DependencyInjection\Argument\BoundArgument;
use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
+use Symfony\Component\DependencyInjection\Argument\TaggedIteratorArgument;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Dumper\PhpDumper;
use Symfony\Component\DependencyInjection\Loader\IniFileLoader;
@@ -315,6 +316,17 @@ public function testParsesTags()
}
}
+ public function testParseTaggedArgumentsWithIndexBy()
+ {
+ $container = new ContainerBuilder();
+ $loader = new XmlFileLoader($container, new FileLocator(self::$fixturesPath.'/xml'));
+ $loader->load('services_with_tagged_arguments.xml');
+
+ $this->assertCount(1, $container->getDefinition('foo')->getTag('foo_tag'));
+ $this->assertCount(1, $container->getDefinition('foo_tagged_iterator')->getArguments());
+ $this->assertEquals(new TaggedIteratorArgument('foo_tag', 'barfoo', 'foobar'), $container->getDefinition('foo_tagged_iterator')->getArgument(0));
+ }
+
/**
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
*/
diff --git a/src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php b/src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php
index 8c9ccaf06ff93..7870a521a9dbe 100644
--- a/src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php
+++ b/src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php
@@ -18,6 +18,7 @@
use Symfony\Component\Config\Resource\GlobResource;
use Symfony\Component\DependencyInjection\Argument\BoundArgument;
use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
+use Symfony\Component\DependencyInjection\Argument\TaggedIteratorArgument;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\IniFileLoader;
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
@@ -279,6 +280,17 @@ public function testTagWithoutNameThrowsException()
}
}
+ public function testTaggedArgumentsWithIndex()
+ {
+ $container = new ContainerBuilder();
+ $loader = new YamlFileLoader($container, new FileLocator(self::$fixturesPath.'/yaml'));
+ $loader->load('services_with_tagged_argument.yml');
+
+ $this->assertCount(1, $container->getDefinition('foo_service')->getTag('foo'));
+ $this->assertCount(1, $container->getDefinition('foo_service_tagged')->getArguments());
+ $this->assertEquals(new TaggedIteratorArgument('foo', 'barfoo', 'foobar'), $container->getDefinition('foo_service_tagged')->getArgument(0));
+ }
+
public function testNameOnlyTagsAreAllowedAsString()
{
$container = new ContainerBuilder();
pFad - Phonifier reborn
Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies:
Alternative Proxy
pFad Proxy
pFad v3 Proxy
pFad v4 Proxy