Files
iTop/lib/symfony/framework-bundle/Tests/DependencyInjection/Compiler/LoggingTranslatorPassTest.php
Pierre Goiffon ad821e7d9c N°2651 rollback gitignore for lib tests dirs
Too dangerous ! We'll work properly on this but for 2.8
2020-01-10 15:23:15 +01:00

82 lines
3.1 KiB
PHP

<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler;
use PHPUnit\Framework\TestCase;
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\LoggingTranslatorPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
class LoggingTranslatorPassTest extends TestCase
{
public function testProcess()
{
$container = new ContainerBuilder();
$container->setParameter('translator.logging', true);
$container->setParameter('translator.class', 'Symfony\Component\Translation\Translator');
$container->register('monolog.logger');
$container->setAlias('logger', 'monolog.logger');
$container->register('translator.default', '%translator.class%');
$container->register('translator.logging', '%translator.class%');
$container->setAlias('translator', 'translator.default');
$translationWarmerDefinition = $container->register('translation.warmer')
->addArgument(new Reference('translator'))
->addTag('container.service_subscriber', ['id' => 'translator'])
->addTag('container.service_subscriber', ['id' => 'foo']);
$pass = new LoggingTranslatorPass();
$pass->process($container);
$this->assertEquals(
['container.service_subscriber' => [
['id' => 'foo'],
['key' => 'translator', 'id' => 'translator.logging.inner'],
]],
$translationWarmerDefinition->getTags()
);
}
public function testThatCompilerPassIsIgnoredIfThereIsNotLoggerDefinition()
{
$container = new ContainerBuilder();
$container->register('identity_translator');
$container->setAlias('translator', 'identity_translator');
$definitionsBefore = \count($container->getDefinitions());
$aliasesBefore = \count($container->getAliases());
$pass = new LoggingTranslatorPass();
$pass->process($container);
// the container is untouched (i.e. no new definitions or aliases)
$this->assertCount($definitionsBefore, $container->getDefinitions());
$this->assertCount($aliasesBefore, $container->getAliases());
}
public function testThatCompilerPassIsIgnoredIfThereIsNotTranslatorDefinition()
{
$container = new ContainerBuilder();
$container->register('monolog.logger');
$container->setAlias('logger', 'monolog.logger');
$definitionsBefore = \count($container->getDefinitions());
$aliasesBefore = \count($container->getAliases());
$pass = new LoggingTranslatorPass();
$pass->process($container);
// the container is untouched (i.e. no new definitions or aliases)
$this->assertCount($definitionsBefore, $container->getDefinitions());
$this->assertCount($aliasesBefore, $container->getAliases());
}
}