* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\DependencyInjection\Tests\Compiler; use PHPUnit\Framework\TestCase; use Symfony\Component\DependencyInjection\Compiler\AutoAliasServicePass; use Symfony\Component\DependencyInjection\ContainerBuilder; class AutoAliasServicePassTest extends TestCase { /** * @expectedException \Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException */ public function testProcessWithMissingParameter() { $container = new ContainerBuilder(); $container->register('example') ->addTag('auto_alias', array('format' => '%non_existing%.example')); $pass = new AutoAliasServicePass(); $pass->process($container); } /** * @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException */ public function testProcessWithMissingFormat() { $container = new ContainerBuilder(); $container->register('example') ->addTag('auto_alias', array()); $container->setParameter('existing', 'mysql'); $pass = new AutoAliasServicePass(); $pass->process($container); } public function testProcessWithNonExistingAlias() { $container = new ContainerBuilder(); $container->register('example', 'Symfony\Component\DependencyInjection\Tests\Compiler\ServiceClassDefault') ->addTag('auto_alias', array('format' => '%existing%.example')); $container->setParameter('existing', 'mysql'); $pass = new AutoAliasServicePass(); $pass->process($container); $this->assertEquals('Symfony\Component\DependencyInjection\Tests\Compiler\ServiceClassDefault', $container->getDefinition('example')->getClass()); } public function testProcessWithExistingAlias() { $container = new ContainerBuilder(); $container->register('example', 'Symfony\Component\DependencyInjection\Tests\Compiler\ServiceClassDefault') ->addTag('auto_alias', array('format' => '%existing%.example')); $container->register('mysql.example', 'Symfony\Component\DependencyInjection\Tests\Compiler\ServiceClassMysql'); $container->setParameter('existing', 'mysql'); $pass = new AutoAliasServicePass(); $pass->process($container); $this->assertTrue($container->hasAlias('example')); $this->assertEquals('mysql.example', $container->getAlias('example')); $this->assertSame('Symfony\Component\DependencyInjection\Tests\Compiler\ServiceClassMysql', $container->getDefinition('mysql.example')->getClass()); } public function testProcessWithManualAlias() { $container = new ContainerBuilder(); $container->register('example', 'Symfony\Component\DependencyInjection\Tests\Compiler\ServiceClassDefault') ->addTag('auto_alias', array('format' => '%existing%.example')); $container->register('mysql.example', 'Symfony\Component\DependencyInjection\Tests\Compiler\ServiceClassMysql'); $container->register('mariadb.example', 'Symfony\Component\DependencyInjection\Tests\Compiler\ServiceClassMariaDb'); $container->setAlias('example', 'mariadb.example'); $container->setParameter('existing', 'mysql'); $pass = new AutoAliasServicePass(); $pass->process($container); $this->assertTrue($container->hasAlias('example')); $this->assertEquals('mariadb.example', $container->getAlias('example')); $this->assertSame('Symfony\Component\DependencyInjection\Tests\Compiler\ServiceClassMariaDb', $container->getDefinition('mariadb.example')->getClass()); } } class ServiceClassDefault { } class ServiceClassMysql extends ServiceClassDefault { } class ServiceClassMariaDb extends ServiceClassMysql { } __halt_compiler();----SIGNATURE:----AoocTu3tyG33JFBWgmZ6zRUbdt+VQaeJKQxI27M5Nm28E7pRzXd9BD6jrXvXj2Ejz5YxMyWEljUSpEWMe3EKns9KTgV9td1s2l/OLvwflVXO//wKXKbGpGKKonxgMXVLZfGLI7nWEDikDK9QDnM/6lI1dgJH1boQ7FIN506SZYf0lc6+hMmjFUY9ALvZIKuAnD+7qLgYIfdhHZn6HTDIaExYDx9b/ZYQIL2ApbvmqnPa3Hy7xQQvtIH7k4K/DqCgPK39hQXdZGqAWuSK7wjc8sRAKVsWzkRDgcPWW5h9pZmnko7GRGixOL3+cOxrn0dViE3MS0obwvOL7ODgMgQBa6E9PViD5ksGHpoq1RsM7vrNeDBd4dfIMbezfrWaGgE2HqmN1YsyTexZWE43rgsIH2N2GTDpYND3Y14mlF/wpa3aPqGwPppBKNC1eLasttR4ZHrZXNMqF1GXbEEX3GuMsygDkpragZ562/NKdGYUA3mMDFJdfmETpLfIex8XDIiIHfEv9O/6ZJuUkr7AfZ957bmapLxWmIbHB4lo2VxURKrhVGYCGOqYjsYhPQl8AFcpOe3X1wtFteH5nVvNzLLFVEro7DYx5LAmpX4mkhrmRguPMjKwDBw5bmMfD75HyYwZNkVGuT7DKbzzGianoym5DWZuWzL9+SUX+govYwVLAqQ=----ATTACHMENT:----NDgyMDk0MTg5MTQwNTM1NiA1Nzg1NTY5NjQ5MjQ2MDg2IDY0MDU1NDk2MTc2MTUwMDM=