Exemplo n.º 1
0
 /**
  * @expectedException \UnexpectedValueException
  * @expectedExceptionMessage No phrases found in the specified dictionary file.
  */
 public function testGenerateWithNoPhrases()
 {
     $baseDir = 'no_phrases';
     $outputFilename = 'no_file.csv';
     $filesOptions = array('file1', 'file2');
     $optionResolver = $this->getMock('Magento\\Tools\\I18n\\Code\\Dictionary\\Options\\Resolver', [], [], '', false);
     $optionResolver->expects($this->once())->method('getOptions')->will($this->returnValue($filesOptions));
     $this->optionsResolverFactory->expects($this->once())->method('create')->with($this->equalTo($baseDir), $this->equalTo(true))->will($this->returnValue($optionResolver));
     $this->contextualParserMock->expects($this->once())->method('parse')->with($filesOptions);
     $this->contextualParserMock->expects($this->once())->method('getPhrases')->will($this->returnValue([]));
     $this->generator->generate($baseDir, $outputFilename, true);
 }
Exemplo n.º 2
0
 /**
  * Generate dictionary
  *
  * @param string $directory
  * @param string $outputFilename
  * @param bool $withContext
  * @throws \UnexpectedValueException
  * @return void
  */
 public function generate($directory, $outputFilename, $withContext = false)
 {
     $optionResolver = $this->optionResolverFactory->create($directory, $withContext);
     $parser = $this->getActualParser($withContext);
     $parser->parse($optionResolver->getOptions());
     $phraseList = $parser->getPhrases();
     if (!count($phraseList)) {
         throw new \UnexpectedValueException('No phrases found in the specified dictionary file.');
     }
     foreach ($phraseList as $phrase) {
         $this->getDictionaryWriter($outputFilename)->write($phrase);
     }
     $this->writer = null;
 }