Yaffs site version 1.1
[yaffs-website] / vendor / symfony / dependency-injection / Tests / Compiler / AutoAliasServicePassTest.php
1 <?php
2
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11
12 namespace Symfony\Component\DependencyInjection\Tests\Compiler;
13
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\DependencyInjection\Compiler\AutoAliasServicePass;
16 use Symfony\Component\DependencyInjection\ContainerBuilder;
17
18 class AutoAliasServicePassTest extends TestCase
19 {
20     /**
21      * @expectedException \Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException
22      */
23     public function testProcessWithMissingParameter()
24     {
25         $container = new ContainerBuilder();
26
27         $container->register('example')
28             ->addTag('auto_alias', array('format' => '%non_existing%.example'));
29
30         $pass = new AutoAliasServicePass();
31         $pass->process($container);
32     }
33
34     /**
35      * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
36      */
37     public function testProcessWithMissingFormat()
38     {
39         $container = new ContainerBuilder();
40
41         $container->register('example')
42             ->addTag('auto_alias', array());
43         $container->setParameter('existing', 'mysql');
44
45         $pass = new AutoAliasServicePass();
46         $pass->process($container);
47     }
48
49     public function testProcessWithNonExistingAlias()
50     {
51         $container = new ContainerBuilder();
52
53         $container->register('example', 'Symfony\Component\DependencyInjection\Tests\Compiler\ServiceClassDefault')
54             ->addTag('auto_alias', array('format' => '%existing%.example'));
55         $container->setParameter('existing', 'mysql');
56
57         $pass = new AutoAliasServicePass();
58         $pass->process($container);
59
60         $this->assertEquals('Symfony\Component\DependencyInjection\Tests\Compiler\ServiceClassDefault', $container->getDefinition('example')->getClass());
61         $this->assertInstanceOf('Symfony\Component\DependencyInjection\Tests\Compiler\ServiceClassDefault', $container->get('example'));
62     }
63
64     public function testProcessWithExistingAlias()
65     {
66         $container = new ContainerBuilder();
67
68         $container->register('example', 'Symfony\Component\DependencyInjection\Tests\Compiler\ServiceClassDefault')
69             ->addTag('auto_alias', array('format' => '%existing%.example'));
70
71         $container->register('mysql.example', 'Symfony\Component\DependencyInjection\Tests\Compiler\ServiceClassMysql');
72         $container->setParameter('existing', 'mysql');
73
74         $pass = new AutoAliasServicePass();
75         $pass->process($container);
76
77         $this->assertTrue($container->hasAlias('example'));
78         $this->assertEquals('mysql.example', $container->getAlias('example'));
79         $this->assertInstanceOf('Symfony\Component\DependencyInjection\Tests\Compiler\ServiceClassMysql', $container->get('example'));
80     }
81
82     public function testProcessWithManualAlias()
83     {
84         $container = new ContainerBuilder();
85
86         $container->register('example', 'Symfony\Component\DependencyInjection\Tests\Compiler\ServiceClassDefault')
87             ->addTag('auto_alias', array('format' => '%existing%.example'));
88
89         $container->register('mysql.example', 'Symfony\Component\DependencyInjection\Tests\Compiler\ServiceClassMysql');
90         $container->register('mariadb.example', 'Symfony\Component\DependencyInjection\Tests\Compiler\ServiceClassMariadb');
91         $container->setAlias('example', 'mariadb.example');
92         $container->setParameter('existing', 'mysql');
93
94         $pass = new AutoAliasServicePass();
95         $pass->process($container);
96
97         $this->assertTrue($container->hasAlias('example'));
98         $this->assertEquals('mariadb.example', $container->getAlias('example'));
99         $this->assertInstanceOf('Symfony\Component\DependencyInjection\Tests\Compiler\ServiceClassMariaDb', $container->get('example'));
100     }
101 }
102
103 class ServiceClassDefault
104 {
105 }
106
107 class ServiceClassMysql extends ServiceClassDefault
108 {
109 }
110
111 class ServiceClassMariaDb extends ServiceClassMysql
112 {
113 }