PageRenderTime 20ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/src/Symfony/Bundle/FrameworkBundle/Tests/Translation/PhpExtractorTest.php

http://github.com/symfony/symfony
PHP | 82 lines | 57 code | 9 blank | 16 comment | 2 complexity | 91b6004e09ca6ef52986fdd5520e90ae MD5 | raw file
  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\Bundle\FrameworkBundle\Tests\Translation;
  11. use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
  12. use Symfony\Bundle\FrameworkBundle\Translation\PhpExtractor;
  13. use Symfony\Component\Translation\MessageCatalogue;
  14. class PhpExtractorTest extends TestCase
  15. {
  16. /**
  17. * @dataProvider resourcesProvider
  18. *
  19. * @param array|string $resource
  20. */
  21. public function testExtraction($resource)
  22. {
  23. // Arrange
  24. $extractor = new PhpExtractor();
  25. $extractor->setPrefix('prefix');
  26. $catalogue = new MessageCatalogue('en');
  27. // Act
  28. $extractor->extract($resource, $catalogue);
  29. $expectedHeredoc = <<<EOF
  30. heredoc key with whitespace and escaped \$\n sequences
  31. EOF;
  32. $expectedNowdoc = <<<'EOF'
  33. nowdoc key with whitespace and nonescaped \$\n sequences
  34. EOF;
  35. // Assert
  36. $expectedCatalogue = array('messages' => array(
  37. 'single-quoted key' => 'prefixsingle-quoted key',
  38. 'double-quoted key' => 'prefixdouble-quoted key',
  39. 'heredoc key' => 'prefixheredoc key',
  40. 'nowdoc key' => 'prefixnowdoc key',
  41. "double-quoted key with whitespace and escaped \$\n\" sequences" => "prefixdouble-quoted key with whitespace and escaped \$\n\" sequences",
  42. 'single-quoted key with whitespace and nonescaped \$\n\' sequences' => 'prefixsingle-quoted key with whitespace and nonescaped \$\n\' sequences',
  43. 'single-quoted key with "quote mark at the end"' => 'prefixsingle-quoted key with "quote mark at the end"',
  44. $expectedHeredoc => 'prefix'.$expectedHeredoc,
  45. $expectedNowdoc => 'prefix'.$expectedNowdoc,
  46. '{0} There is no apples|{1} There is one apple|]1,Inf[ There are %count% apples' => 'prefix{0} There is no apples|{1} There is one apple|]1,Inf[ There are %count% apples',
  47. ));
  48. $actualCatalogue = $catalogue->all();
  49. $this->assertEquals($expectedCatalogue, $actualCatalogue);
  50. }
  51. public function resourcesProvider()
  52. {
  53. $directory = __DIR__.'/../Fixtures/Resources/views/';
  54. $splFiles = array();
  55. foreach (new \DirectoryIterator($directory) as $fileInfo) {
  56. if ($fileInfo->isDot()) {
  57. continue;
  58. }
  59. if ('translation.html.php' === $fileInfo->getBasename()) {
  60. $phpFile = $fileInfo->getPathname();
  61. }
  62. $splFiles[] = $fileInfo->getFileInfo();
  63. }
  64. return array(
  65. array($directory),
  66. array($phpFile),
  67. array(glob($directory.'*')),
  68. array($splFiles),
  69. array(new \ArrayObject(glob($directory.'*'))),
  70. array(new \ArrayObject($splFiles)),
  71. );
  72. }
  73. }