/**
  * @covers \Magento\Setup\Module\I18n\Parser\Adapter\Php\Tokenizer\PhraseCollector::parse
  */
 public function testParse()
 {
     $file = __DIR__ . '/_files/objectsCode.php.txt';
     $this->phraseCollector->setIncludeObjects();
     $this->phraseCollector->parse($file);
     $expectation = [['phrase' => '\'Testing\'', 'arguments' => 0, 'file' => $file, 'line' => 3], ['phrase' => '\'More testing\'', 'arguments' => 0, 'file' => $file, 'line' => 4]];
     $this->assertEquals($expectation, $this->phraseCollector->getPhrases());
 }
Beispiel #2
0
 /**
  * {@inheritdoc}
  */
 protected function _parse()
 {
     $this->_phraseCollector->setIncludeObjects();
     $this->_phraseCollector->parse($this->_file);
     foreach ($this->_phraseCollector->getPhrases() as $phrase) {
         $this->_addPhrase($phrase['phrase'], $phrase['line']);
     }
 }
 /**
  * @covers \Magento\Setup\Module\I18n\Parser\Adapter\Php\Tokenizer\PhraseCollector::parse
  *
  * @param string $file
  * @param array $isEndOfLoopReturnValues
  * @param array $getNextRealTokenReturnValues
  * @param array $getFunctionArgumentsTokensReturnValues
  * @param array $isMatchingClassReturnValues
  * @param array $result
  * @dataProvider testParseDataProvider
  */
 public function testParse($file, array $isEndOfLoopReturnValues, array $getNextRealTokenReturnValues, array $getFunctionArgumentsTokensReturnValues, array $isMatchingClassReturnValues, array $result)
 {
     $matchingClass = 'Phrase';
     $this->tokenizerMock->expects($this->once())->method('parse')->with($file);
     $this->tokenizerMock->expects($this->atLeastOnce())->method('isEndOfLoop')->will(call_user_func_array([$this, 'onConsecutiveCalls'], $isEndOfLoopReturnValues));
     $this->tokenizerMock->expects($this->any())->method('getNextRealToken')->will(call_user_func_array([$this, 'onConsecutiveCalls'], $getNextRealTokenReturnValues));
     $this->tokenizerMock->expects($this->any())->method('getFunctionArgumentsTokens')->will(call_user_func_array([$this, 'onConsecutiveCalls'], $getFunctionArgumentsTokensReturnValues));
     $this->tokenizerMock->expects($this->any())->method('isMatchingClass')->with($matchingClass)->will(call_user_func_array([$this, 'onConsecutiveCalls'], $isMatchingClassReturnValues));
     $this->phraseCollector->setIncludeObjects();
     $this->phraseCollector->parse($file);
     $this->assertEquals($result, $this->phraseCollector->getPhrases());
 }
 public function testArguments()
 {
     $incorrectNumberOfArgumentsErrors = [];
     $missedPhraseErrors = [];
     foreach ($this->_getFiles() as $file) {
         if (in_array($file, $this->blackList)) {
             continue;
         }
         $this->_phraseCollector->parse($file);
         foreach ($this->_phraseCollector->getPhrases() as $phrase) {
             $this->checkEmptyPhrases($phrase, $missedPhraseErrors);
             $this->checkArgumentMismatch($phrase, $incorrectNumberOfArgumentsErrors);
         }
     }
     $this->assertEmpty($missedPhraseErrors, sprintf("\n%d missed phrases were discovered: \n%s", count($missedPhraseErrors), implode("\n\n", $missedPhraseErrors)));
     $this->assertEmpty($incorrectNumberOfArgumentsErrors, sprintf("\n%d usages of inconsistency the number of arguments and placeholders were discovered: \n%s", count($incorrectNumberOfArgumentsErrors), implode("\n\n", $incorrectNumberOfArgumentsErrors)));
 }
Beispiel #5
0
 public function testArguments()
 {
     $errors = [];
     foreach ($this->_getFiles() as $file) {
         if (in_array($file, $this->blackList)) {
             continue;
         }
         $this->_phraseCollector->parse($file);
         foreach ($this->_phraseCollector->getPhrases() as $phrase) {
             if (preg_match_all('/%(\\d+)/', $phrase['phrase'], $matches) || $phrase['arguments']) {
                 $placeholdersInPhrase = array_unique($matches[1]);
                 if (count($placeholdersInPhrase) != $phrase['arguments']) {
                     $errors[] = $this->_createPhraseError($phrase);
                 }
             }
         }
     }
     $this->assertEmpty($errors, sprintf("\n%d usages of inconsistency the number of arguments and placeholders were discovered: \n%s", count($errors), implode("\n\n", $errors)));
 }