示例#1
0
 public function testExtraction()
 {
     // Arrange
     $extractor = new PhpExtractor();
     $extractor->setPrefix('prefix');
     $catalogue = new MessageCatalogue('en');
     // Act
     $extractor->extract(__DIR__ . '/../Fixtures/Resources/views/', $catalogue);
     // Assert
     $this->assertEquals(1, count($catalogue->all('messages')), '->extract() should find 1 translation');
     $this->assertTrue($catalogue->has('new key'), '->extract() should find at leat "new key" message');
     $this->assertEquals('prefixnew key', $catalogue->get('new key'), '->extract() should apply "prefix" as prefix');
 }
示例#2
0
    public function testExtraction()
    {
        // Arrange
        $extractor = new PhpExtractor();
        $extractor->setPrefix('prefix');
        $catalogue = new MessageCatalogue('en');
        // Act
        $extractor->extract(__DIR__ . '/../Fixtures/Resources/views/', $catalogue);
        $expectedHeredoc = <<<EOF
heredoc key with whitespace and escaped \$
 sequences
EOF;
        $expectedNowdoc = <<<'EOF'
nowdoc key with whitespace and nonescaped \$\n sequences
EOF;
        // Assert
        $expectedCatalogue = array('messages' => array('single-quoted key' => 'prefixsingle-quoted key', 'double-quoted key' => 'prefixdouble-quoted key', 'heredoc key' => 'prefixheredoc key', 'nowdoc key' => 'prefixnowdoc key', "double-quoted key with whitespace and escaped \$\n\" sequences" => "prefixdouble-quoted key with whitespace and escaped \$\n\" sequences", 'single-quoted key with whitespace and nonescaped \\$\\n\' sequences' => 'prefixsingle-quoted key with whitespace and nonescaped \\$\\n\' sequences', 'single-quoted key with "quote mark at the end"' => 'prefixsingle-quoted key with "quote mark at the end"', $expectedHeredoc => "prefix" . $expectedHeredoc, $expectedNowdoc => "prefix" . $expectedNowdoc, '{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'));
        $actualCatalogue = $catalogue->all();
        $this->assertEquals($expectedCatalogue, $actualCatalogue);
    }