4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Translation\Tests;
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\Translation\Translator;
16 use Symfony\Component\Translation\LoggingTranslator;
17 use Symfony\Component\Translation\Loader\ArrayLoader;
19 class LoggingTranslatorTest extends TestCase
21 public function testTransWithNoTranslationIsLogged()
23 $logger = $this->getMockBuilder('Psr\Log\LoggerInterface')->getMock();
24 $logger->expects($this->exactly(2))
26 ->with('Translation not found.')
29 $translator = new Translator('ar');
30 $loggableTranslator = new LoggingTranslator($translator, $logger);
31 $loggableTranslator->transChoice('some_message2', 10, array('%count%' => 10));
32 $loggableTranslator->trans('bar');
35 public function testTransChoiceFallbackIsLogged()
37 $logger = $this->getMockBuilder('Psr\Log\LoggerInterface')->getMock();
38 $logger->expects($this->once())
40 ->with('Translation use fallback catalogue.')
43 $translator = new Translator('ar');
44 $translator->setFallbackLocales(array('en'));
45 $translator->addLoader('array', new ArrayLoader());
46 $translator->addResource('array', array('some_message2' => 'one thing|%count% things'), 'en');
47 $loggableTranslator = new LoggingTranslator($translator, $logger);
48 $loggableTranslator->transChoice('some_message2', 10, array('%count%' => 10));