Keine Beschreibung

LoggingTranslatorTest.php 1.7KB

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