LoggingTranslatorTest.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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\Loader\ArrayLoader;
  13. use Symfony\Component\Translation\LoggingTranslator;
  14. use Symfony\Component\Translation\Translator;
  15. class LoggingTranslatorTest extends TestCase
  16. {
  17. public function testTransWithNoTranslationIsLogged()
  18. {
  19. $logger = $this->getMockBuilder('Psr\Log\LoggerInterface')->getMock();
  20. $logger->expects($this->exactly(1))
  21. ->method('warning')
  22. ->with('Translation not found.')
  23. ;
  24. $translator = new Translator('ar');
  25. $loggableTranslator = new LoggingTranslator($translator, $logger);
  26. $loggableTranslator->trans('bar');
  27. }
  28. /**
  29. * @group legacy
  30. */
  31. public function testTransChoiceFallbackIsLogged()
  32. {
  33. $logger = $this->getMockBuilder('Psr\Log\LoggerInterface')->getMock();
  34. $logger->expects($this->once())
  35. ->method('debug')
  36. ->with('Translation use fallback catalogue.')
  37. ;
  38. $translator = new Translator('ar');
  39. $translator->setFallbackLocales(['en']);
  40. $translator->addLoader('array', new ArrayLoader());
  41. $translator->addResource('array', ['some_message2' => 'one thing|%count% things'], 'en');
  42. $loggableTranslator = new LoggingTranslator($translator, $logger);
  43. $loggableTranslator->transChoice('some_message2', 10, ['%count%' => 10]);
  44. }
  45. /**
  46. * @group legacy
  47. */
  48. public function testTransChoiceWithNoTranslationIsLogged()
  49. {
  50. $logger = $this->getMockBuilder('Psr\Log\LoggerInterface')->getMock();
  51. $logger->expects($this->exactly(1))
  52. ->method('warning')
  53. ->with('Translation not found.')
  54. ;
  55. $translator = new Translator('ar');
  56. $loggableTranslator = new LoggingTranslator($translator, $logger);
  57. $loggableTranslator->transChoice('some_message2', 10, ['%count%' => 10]);
  58. }
  59. }