Updated to Drupal 8.5. Core Media not yet in use.
[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     }
62
63     public function testProcessWithExistingAlias()
64     {
65         $container = new ContainerBuilder();
66
67         $container->register('example', 'Symfony\Component\DependencyInjection\Tests\Compiler\ServiceClassDefault')
68             ->addTag('auto_alias', array('format' => '%existing%.example'));
69
70         $container->register('mysql.example', 'Symfony\Component\DependencyInjection\Tests\Compiler\ServiceClassMysql');
71         $container->setParameter('existing', 'mysql');
72
73         $pass = new AutoAliasServicePass();
74         $pass->process($container);
75
76         $this->assertTrue($container->hasAlias('example'));
77         $this->assertEquals('mysql.example', $container->getAlias('example'));
78         $this->assertSame('Symfony\Component\DependencyInjection\Tests\Compiler\ServiceClassMysql', $container->getDefinition('mysql.example')->getClass());
79     }
80
81     public function testProcessWithManualAlias()
82     {
83         $container = new ContainerBuilder();
84
85         $container->register('example', 'Symfony\Component\DependencyInjection\Tests\Compiler\ServiceClassDefault')
86             ->addTag('auto_alias', array('format' => '%existing%.example'));
87
88         $container->register('mysql.example', 'Symfony\Component\DependencyInjection\Tests\Compiler\ServiceClassMysql');
89         $container->register('mariadb.example', 'Symfony\Component\DependencyInjection\Tests\Compiler\ServiceClassMariaDb');
90         $container->setAlias('example', 'mariadb.example');
91         $container->setParameter('existing', 'mysql');
92
93         $pass = new AutoAliasServicePass();
94         $pass->process($container);
95
96         $this->assertTrue($container->hasAlias('example'));
97         $this->assertEquals('mariadb.example', $container->getAlias('example'));
98         $this->assertSame('Symfony\Component\DependencyInjection\Tests\Compiler\ServiceClassMariaDb', $container->getDefinition('mariadb.example')->getClass());
99     }
100 }
101
102 class ServiceClassDefault
103 {
104 }
105
106 class ServiceClassMysql extends ServiceClassDefault
107 {
108 }
109
110 class ServiceClassMariaDb extends ServiceClassMysql
111 {
112 }