* * 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:----Y9DLoMJCh74EdaGXyg+iov1iQx0lEH86dTcNU4/OLa+Dg0TC4QK6dnkYFBI6wwDXZpk++8RVPou1m/yGPUHwvrs/PiJ6knRgByxHrtCJkh9cWW+Rj+n10BwTI8ywMI/dLZ4PmcO3/Xf4GVM8OCr5q1zklPRlYYDdTRrJ/IDM9mUeESf0jfpJ86JZJm6ZCqliBGauDEo1j6Hz4v164l9q4YS/uZY02HN5DhsEGgmw1fA6xvMHRnz31rHc2NJDfVyIFde7nPmYaL82knh5vj4T4rUwx0Abx/kQfvR25p6wjojNjb2yJ9e/Tvn5lGttjW65w4zii+4BSTclnI0VffwL8SE0wzxt1Z6bRS6iVs+HJGWBDKTqgd1kkAdqyaVzh7JvRhJPLZPZbA8yxZCahPzXH7aENLQFuPtzPUTPHZ8nk35qzhggE3+PjjRZm1oLXqfqB5zdtoe1YcrsYwbwaBpbbHYH2dtWlnvwml/+DMft5qOrvglfXih7VumUy+TO+lcb9rc7MaWFKg8qZtVRm2KafyNt87mnbOo5G7S2XMhdhKQOsy4eO2ZETEwHlu1mn1XWEFeMMVSCqNiiDyIeJcC5y58CYkbcYkKy1b+wM+Bn2jhwuotGkQExi2T1ueS1t6t52ou3GlIJI+ETgm9RctAxeGeDmg8qe+HEALIusW0MV0c=----ATTACHMENT:----MTkwODkxMjEwMDg1MjI4OSAxNjM3ODEyOTI0NDU3NzQ1IDQ0MjM4NDI5OTM4NDExMzE=