forked from symfony/symfony
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature symfony#14185 [Translation][Profiler]added the number of time…
…s a translation has been used. (aitboudad) This PR was merged into the 2.7 branch. Discussion ---------- [Translation][Profiler]added the number of times a translation has been used. | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Fixed tickets | symfony#14183 | Tests pass? | yes | License | MIT Commits ------- b470a5b [Translation][Profiler] added the number of times a translation has been used.
- Loading branch information
Showing
3 changed files
with
138 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
src/Symfony/Component/Translation/Tests/DataCollector/TranslationDataCollectorTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <[email protected]> | ||
* | ||
* 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 Symfony\Component\Translation\DataCollectorTranslator; | ||
use Symfony\Component\Translation\DataCollector\TranslationDataCollector; | ||
|
||
class TranslationDataCollectorTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
protected function setUp() | ||
{ | ||
if (!class_exists('Symfony\Component\HttpKernel\DataCollector\DataCollector')) { | ||
$this->markTestSkipped('The "DataCollector" is not available'); | ||
} | ||
} | ||
public function testCollect() | ||
{ | ||
$collectedMessages = array( | ||
array( | ||
'id' => 'foo', | ||
'translation' => 'foo (en)', | ||
'locale' => 'en', | ||
'domain' => 'messages', | ||
'state' => DataCollectorTranslator::MESSAGE_DEFINED, | ||
), | ||
array( | ||
'id' => 'bar', | ||
'translation' => 'bar (fr)', | ||
'locale' => 'fr', | ||
'domain' => 'messages', | ||
'state' => DataCollectorTranslator::MESSAGE_EQUALS_FALLBACK, | ||
), | ||
array( | ||
'id' => 'choice', | ||
'translation' => 'choice', | ||
'locale' => 'en', | ||
'domain' => 'messages', | ||
'state' => DataCollectorTranslator::MESSAGE_MISSING, | ||
), | ||
array( | ||
'id' => 'choice', | ||
'translation' => 'choice', | ||
'locale' => 'en', | ||
'domain' => 'messages', | ||
'state' => DataCollectorTranslator::MESSAGE_MISSING, | ||
), | ||
); | ||
$expectedMessages = array( | ||
array( | ||
'id' => 'foo', | ||
'translation' => 'foo (en)', | ||
'locale' => 'en', | ||
'domain' => 'messages', | ||
'state' => DataCollectorTranslator::MESSAGE_DEFINED, | ||
'count' => 1, | ||
), | ||
array( | ||
'id' => 'bar', | ||
'translation' => 'bar (fr)', | ||
'locale' => 'fr', | ||
'domain' => 'messages', | ||
'state' => DataCollectorTranslator::MESSAGE_EQUALS_FALLBACK, | ||
'count' => 1, | ||
), | ||
array( | ||
'id' => 'choice', | ||
'translation' => 'choice', | ||
'locale' => 'en', | ||
'domain' => 'messages', | ||
'state' => DataCollectorTranslator::MESSAGE_MISSING, | ||
'count' => 2, | ||
), | ||
); | ||
|
||
$translator = $this | ||
->getMockBuilder('Symfony\Component\Translation\DataCollectorTranslator') | ||
->disableOriginalConstructor() | ||
->getMock() | ||
; | ||
$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())); | ||
} | ||
} |