f7ea16dbfb0360436ee3b7b8c9f9fa496d12bc31
[yaffs-website] / vendor / symfony / http-kernel / Tests / DependencyInjection / ResettableServicePassTest.php
1 <?php
2
3 namespace Symfony\Component\HttpKernel\Tests\DependencyInjection;
4
5 use PHPUnit\Framework\TestCase;
6 use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
7 use Symfony\Component\DependencyInjection\ContainerBuilder;
8 use Symfony\Component\DependencyInjection\ContainerInterface;
9 use Symfony\Component\DependencyInjection\Reference;
10 use Symfony\Component\HttpKernel\DependencyInjection\ResettableServicePass;
11 use Symfony\Component\HttpKernel\DependencyInjection\ServicesResetter;
12 use Symfony\Component\HttpKernel\Tests\Fixtures\ClearableService;
13 use Symfony\Component\HttpKernel\Tests\Fixtures\ResettableService;
14
15 class ResettableServicePassTest extends TestCase
16 {
17     public function testCompilerPass()
18     {
19         $container = new ContainerBuilder();
20         $container->register('one', ResettableService::class)
21             ->setPublic(true)
22             ->addTag('kernel.reset', array('method' => 'reset'));
23         $container->register('two', ClearableService::class)
24             ->setPublic(true)
25             ->addTag('kernel.reset', array('method' => 'clear'));
26
27         $container->register('services_resetter', ServicesResetter::class)
28             ->setPublic(true)
29             ->setArguments(array(null, array()));
30         $container->addCompilerPass(new ResettableServicePass());
31
32         $container->compile();
33
34         $definition = $container->getDefinition('services_resetter');
35
36         $this->assertEquals(
37             array(
38                 new IteratorArgument(array(
39                     'one' => new Reference('one', ContainerInterface::IGNORE_ON_UNINITIALIZED_REFERENCE),
40                     'two' => new Reference('two', ContainerInterface::IGNORE_ON_UNINITIALIZED_REFERENCE),
41                 )),
42                 array(
43                     'one' => 'reset',
44                     'two' => 'clear',
45                 ),
46             ),
47             $definition->getArguments()
48         );
49     }
50
51     /**
52      * @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
53      * @expectedExceptionMessage Tag kernel.reset requires the "method" attribute to be set.
54      */
55     public function testMissingMethod()
56     {
57         $container = new ContainerBuilder();
58         $container->register(ResettableService::class)
59             ->addTag('kernel.reset');
60         $container->register('services_resetter', ServicesResetter::class)
61             ->setArguments(array(null, array()));
62         $container->addCompilerPass(new ResettableServicePass());
63
64         $container->compile();
65     }
66
67     public function testCompilerPassWithoutResetters()
68     {
69         $container = new ContainerBuilder();
70         $container->register('services_resetter', ServicesResetter::class)
71             ->setArguments(array(null, array()));
72         $container->addCompilerPass(new ResettableServicePass());
73
74         $container->compile();
75
76         $this->assertFalse($container->has('services_resetter'));
77     }
78 }