LoggingTranslatorTest.php 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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\Translation\Tests;
  11. use PHPUnit\Framework\TestCase;
  12. use Symfony\Component\Translation\Translator;
  13. use Symfony\Component\Translation\LoggingTranslator;
  14. use Symfony\Component\Translation\Loader\ArrayLoader;
  15. class LoggingTranslatorTest extends TestCase
  16. {
  17. public function testTransWithNoTranslationIsLogged()
  18. {
  19. $logger = $this->getMockBuilder('Psr\Log\LoggerInterface')->getMock();
  20. $logger->expects($this->exactly(2))
  21. ->method('warning')
  22. ->with('Translation not found.')
  23. ;
  24. $translator = new Translator('ar');
  25. $loggableTranslator = new LoggingTranslator($translator, $logger);
  26. $loggableTranslator->transChoice('some_message2', 10, array('%count%' => 10));
  27. $loggableTranslator->trans('bar');
  28. }
  29. public function testTransChoiceFallbackIsLogged()
  30. {
  31. $logger = $this->getMockBuilder('Psr\Log\LoggerInterface')->getMock();
  32. $logger->expects($this->once())
  33. ->method('debug')
  34. ->with('Translation use fallback catalogue.')
  35. ;
  36. $translator = new Translator('ar');
  37. $translator->setFallbackLocales(array('en'));
  38. $translator->addLoader('array', new ArrayLoader());
  39. $translator->addResource('array', array('some_message2' => 'one thing|%count% things'), 'en');
  40. $loggableTranslator = new LoggingTranslator($translator, $logger);
  41. $loggableTranslator->transChoice('some_message2', 10, array('%count%' => 10));
  42. }
  43. }