LoggerPassTest.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\HttpKernel\Tests\DependencyInjection;
  11. use PHPUnit\Framework\TestCase;
  12. use Psr\Log\LoggerInterface;
  13. use Symfony\Component\DependencyInjection\ContainerBuilder;
  14. use Symfony\Component\HttpKernel\DependencyInjection\LoggerPass;
  15. use Symfony\Component\HttpKernel\Log\Logger;
  16. /**
  17. * @author Kévin Dunglas <dunglas@gmail.com>
  18. */
  19. class LoggerPassTest extends TestCase
  20. {
  21. public function testAlwaysSetAutowiringAlias()
  22. {
  23. $container = new ContainerBuilder();
  24. $container->register('logger', 'Foo');
  25. (new LoggerPass())->process($container);
  26. $this->assertFalse($container->getAlias(LoggerInterface::class)->isPublic());
  27. }
  28. public function testDoNotOverrideExistingLogger()
  29. {
  30. $container = new ContainerBuilder();
  31. $container->register('logger', 'Foo');
  32. (new LoggerPass())->process($container);
  33. $this->assertSame('Foo', $container->getDefinition('logger')->getClass());
  34. }
  35. public function testRegisterLogger()
  36. {
  37. $container = new ContainerBuilder();
  38. $container->setParameter('kernel.debug', false);
  39. (new LoggerPass())->process($container);
  40. $definition = $container->getDefinition('logger');
  41. $this->assertSame(Logger::class, $definition->getClass());
  42. $this->assertFalse($definition->isPublic());
  43. }
  44. }