4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\DependencyInjection\Tests\Compiler;
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\DependencyInjection\Compiler\PriorityTaggedServiceTrait;
16 use Symfony\Component\DependencyInjection\ContainerBuilder;
17 use Symfony\Component\DependencyInjection\Reference;
19 class PriorityTaggedServiceTraitTest extends TestCase
21 public function testThatCacheWarmersAreProcessedInPriorityOrder()
24 'my_service1' => array('my_custom_tag' => array('priority' => 100)),
25 'my_service2' => array('my_custom_tag' => array('priority' => 200)),
26 'my_service3' => array('my_custom_tag' => array('priority' => -501)),
27 'my_service4' => array('my_custom_tag' => array()),
28 'my_service5' => array('my_custom_tag' => array('priority' => -1)),
29 'my_service6' => array('my_custom_tag' => array('priority' => -500)),
30 'my_service7' => array('my_custom_tag' => array('priority' => -499)),
31 'my_service8' => array('my_custom_tag' => array('priority' => 1)),
32 'my_service9' => array('my_custom_tag' => array('priority' => -2)),
33 'my_service10' => array('my_custom_tag' => array('priority' => -1000)),
34 'my_service11' => array('my_custom_tag' => array('priority' => -1001)),
35 'my_service12' => array('my_custom_tag' => array('priority' => -1002)),
36 'my_service13' => array('my_custom_tag' => array('priority' => -1003)),
37 'my_service14' => array('my_custom_tag' => array('priority' => -1000)),
38 'my_service15' => array('my_custom_tag' => array('priority' => 1)),
39 'my_service16' => array('my_custom_tag' => array('priority' => -1)),
40 'my_service17' => array('my_custom_tag' => array('priority' => 200)),
41 'my_service18' => array('my_custom_tag' => array('priority' => 100)),
42 'my_service19' => array('my_custom_tag' => array()),
45 $container = new ContainerBuilder();
47 foreach ($services as $id => $tags) {
48 $definition = $container->register($id);
50 foreach ($tags as $name => $attributes) {
51 $definition->addTag($name, $attributes);
56 new Reference('my_service2'),
57 new Reference('my_service17'),
58 new Reference('my_service1'),
59 new Reference('my_service18'),
60 new Reference('my_service8'),
61 new Reference('my_service15'),
62 new Reference('my_service4'),
63 new Reference('my_service19'),
64 new Reference('my_service5'),
65 new Reference('my_service16'),
66 new Reference('my_service9'),
67 new Reference('my_service7'),
68 new Reference('my_service6'),
69 new Reference('my_service3'),
70 new Reference('my_service10'),
71 new Reference('my_service14'),
72 new Reference('my_service11'),
73 new Reference('my_service12'),
74 new Reference('my_service13'),
77 $priorityTaggedServiceTraitImplementation = new PriorityTaggedServiceTraitImplementation();
79 $this->assertEquals($expected, $priorityTaggedServiceTraitImplementation->test('my_custom_tag', $container));
83 class PriorityTaggedServiceTraitImplementation
85 use PriorityTaggedServiceTrait;
87 public function test($tagName, ContainerBuilder $container)
89 return $this->findAndSortTaggedServices($tagName, $container);