No Description

LoggingTranslatorTest.php 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. protected function setUp()
  17. {
  18. if (!interface_exists('Psr\Log\LoggerInterface')) {
  19. $this->markTestSkipped('The "LoggerInterface" is not available');
  20. }
  21. }
  22. public function testTransWithNoTranslationIsLogged()
  23. {
  24. $logger = $this->getMock('Psr\Log\LoggerInterface');
  25. $logger->expects($this->exactly(2))
  26. ->method('warning')
  27. ->with('Translation not found.')
  28. ;
  29. $translator = new Translator('ar');
  30. $loggableTranslator = new LoggingTranslator($translator, $logger);
  31. $loggableTranslator->transChoice('some_message2', 10, array('%count%' => 10));
  32. $loggableTranslator->trans('bar');
  33. }
  34. public function testTransChoiceFallbackIsLogged()
  35. {
  36. $logger = $this->getMock('Psr\Log\LoggerInterface');
  37. $logger->expects($this->once())
  38. ->method('debug')
  39. ->with('Translation use fallback catalogue.')
  40. ;
  41. $translator = new Translator('ar');
  42. $translator->setFallbackLocales(array('en'));
  43. $translator->addLoader('array', new ArrayLoader());
  44. $translator->addResource('array', array('some_message2' => 'one thing|%count% things'), 'en');
  45. $loggableTranslator = new LoggingTranslator($translator, $logger);
  46. $loggableTranslator->transChoice('some_message2', 10, array('%count%' => 10));
  47. }
  48. }