* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Translation\Tests\DataCollector; use PHPUnit\Framework\TestCase; use Symfony\Component\Translation\DataCollectorTranslator; use Symfony\Component\Translation\DataCollector\TranslationDataCollector; class TranslationDataCollectorTest extends TestCase { protected function setUp() { if (!class_exists('Symfony\Component\HttpKernel\DataCollector\DataCollector')) { $this->markTestSkipped('The "DataCollector" is not available'); } } public function testCollectEmptyMessages() { $translator = $this->getTranslator(); $translator->expects($this->any())->method('getCollectedMessages')->will($this->returnValue(array())); $dataCollector = new TranslationDataCollector($translator); $dataCollector->lateCollect(); $this->assertEquals(0, $dataCollector->getCountMissings()); $this->assertEquals(0, $dataCollector->getCountFallbacks()); $this->assertEquals(0, $dataCollector->getCountDefines()); $this->assertEquals(array(), $dataCollector->getMessages()->getValue()); } public function testCollect() { $collectedMessages = array( array( 'id' => 'foo', 'translation' => 'foo (en)', 'locale' => 'en', 'domain' => 'messages', 'state' => DataCollectorTranslator::MESSAGE_DEFINED, 'parameters' => array(), 'transChoiceNumber' => null, ), array( 'id' => 'bar', 'translation' => 'bar (fr)', 'locale' => 'fr', 'domain' => 'messages', 'state' => DataCollectorTranslator::MESSAGE_EQUALS_FALLBACK, 'parameters' => array(), 'transChoiceNumber' => null, ), array( 'id' => 'choice', 'translation' => 'choice', 'locale' => 'en', 'domain' => 'messages', 'state' => DataCollectorTranslator::MESSAGE_MISSING, 'parameters' => array('%count%' => 3), 'transChoiceNumber' => 3, ), array( 'id' => 'choice', 'translation' => 'choice', 'locale' => 'en', 'domain' => 'messages', 'state' => DataCollectorTranslator::MESSAGE_MISSING, 'parameters' => array('%count%' => 3), 'transChoiceNumber' => 3, ), array( 'id' => 'choice', 'translation' => 'choice', 'locale' => 'en', 'domain' => 'messages', 'state' => DataCollectorTranslator::MESSAGE_MISSING, 'parameters' => array('%count%' => 4, '%foo%' => 'bar'), 'transChoiceNumber' => 4, ), ); $expectedMessages = array( array( 'id' => 'foo', 'translation' => 'foo (en)', 'locale' => 'en', 'domain' => 'messages', 'state' => DataCollectorTranslator::MESSAGE_DEFINED, 'count' => 1, 'parameters' => array(), 'transChoiceNumber' => null, ), array( 'id' => 'bar', 'translation' => 'bar (fr)', 'locale' => 'fr', 'domain' => 'messages', 'state' => DataCollectorTranslator::MESSAGE_EQUALS_FALLBACK, 'count' => 1, 'parameters' => array(), 'transChoiceNumber' => null, ), array( 'id' => 'choice', 'translation' => 'choice', 'locale' => 'en', 'domain' => 'messages', 'state' => DataCollectorTranslator::MESSAGE_MISSING, 'count' => 3, 'parameters' => array( array('%count%' => 3), array('%count%' => 3), array('%count%' => 4, '%foo%' => 'bar'), ), 'transChoiceNumber' => 3, ), ); $translator = $this->getTranslator(); $translator->expects($this->any())->method('getCollectedMessages')->will($this->returnValue($collectedMessages)); $dataCollector = new TranslationDataCollector($translator); $dataCollector->lateCollect(); $this->assertEquals(1, $dataCollector->getCountMissings()); $this->assertEquals(1, $dataCollector->getCountFallbacks()); $this->assertEquals(1, $dataCollector->getCountDefines()); $this->assertEquals($expectedMessages, array_values($dataCollector->getMessages()->getValue(true))); } private function getTranslator() { $translator = $this ->getMockBuilder('Symfony\Component\Translation\DataCollectorTranslator') ->disableOriginalConstructor() ->getMock() ; return $translator; } } __halt_compiler();----SIGNATURE:----ZJUynL1QMHtsJPXOGe/skjpSCaVsHl0v2vAi2db9cq/2nWEdo7poM/PWjlXkYm0+j/BvFHngHszRhWQKbQ1Z8go3O5Csr3dxHgOWYtPg19H78WUF3/6ZX1u6Ltc6FGVhl4PnoQURNkcmQgWJ8AzuO9QaY8wNo1alRm/f6PaAd/NriRLbpUOT7aP2e88LlrX2KxV2pAVQVp/Ux9lSjUXG/MeylfGcFmVvwhEeV/963d8QEoJttqGP6bu4v2jUdFMzQUzHlvEMX1XtNGzn2waqmOR/0uc2Ekju1lzFi7dX5R8rGNpJL/afeEG5+U0oKVWMQG2dIJqEqx1+Ae+4xTuOwLxIaxFCRzrntkbU0w0Ia5wSjsuPxaOjou5lKBFe06I8ZuycGl3oHlhjBN8ES+lH6Jw7XPQwYmRD0UsPR9NYCQjEnHNKDKSmiUSvid0zEuirUH8P/a0vW0Oeat+m6EDVRyeWLziawMQYuxdMziZyt4Tue2YDwZOaDZdNyhXHqvOqUztbD3t0YfxRyeVjxf/vgBDKQ9U5LMpj/7R7eVhL0bF99szY3PrBmCcffHdcGfpExyJ6XCHSsQy/uDz+sVplwV8o40EPDVytqJ9dAUq4Ip0sGPVxhHOWGLyjdIbP5KWarHrk2WxGazVBRUlxMu+FKRjXVftWnAKzyzhxCCpP6MM=----ATTACHMENT:----ODYxNjA4MjMzNDU5MDMyMSA2NzM5NzMyMTA3MDUwMjEyIDUyNjk5NTI1MTM5MTg2MTc=