Esempio n. 1
0
 /**
  * @Then /^match them with files from "([^"]*)"$/
  */
 public function matchThemWithFilesFrom($dir)
 {
     $this->testFilesDir = realpath(dirname(__FILE__) . DIRECTORY_SEPARATOR . '..') . DIRECTORY_SEPARATOR . $dir;
     foreach ($this->testFiles as $row) {
         $expected = json_decode(file_get_contents($this->testFilesDir . DIRECTORY_SEPARATOR . $row['expected-json-result']), true);
         $result = $this->parser->processFile($this->testFilesDir . DIRECTORY_SEPARATOR . $row['source-filename'], Parser::INCLUDE_EXAMPLES);
         $funcName = $result->getFuncNames()[0];
         $actual = array_merge($result->getResult($funcName), ['examples' => $result->getExamples($funcName)]);
         //            echo json_encode($actual, JSON_PRETTY_PRINT);
         assertEquals($expected, $actual);
     }
 }
Esempio n. 2
0
 private function parse(Package $package, $outDir, $includeExamples)
 {
     $parser = new Parser();
     $bar = $this->createProgressBar(count($parser->getFilesToProcess($package->getUnpackedDir())));
     $bar->setRedrawFrequency(100);
     $bar->start();
     $results = $parser->processDir($package->getUnpackedDir(), $includeExamples, function ($filename, $total, $processed) use($bar) {
         $bar->setMessage('Processing: ' . $filename);
         $bar->advance();
     });
     $bar->finish();
     $functions = [];
     $examples = [];
     foreach ($results->getFuncNames() as $funcName) {
         $arrayRes = $results->getResult($funcName);
         $examplesRes = $results->getExamples($funcName);
         if ($examplesRes && is_array($arrayRes)) {
             if ($includeExamples == Parser::INCLUDE_EXAMPLES) {
                 $arrayRes = array_merge($arrayRes, ['examples' => $examplesRes]);
             } elseif ($includeExamples == Parser::EXPORT_EXAMPLES) {
                 $examples[$funcName] = $examplesRes;
             }
         }
         $functions[$funcName] = $arrayRes;
     }
     $this->output->writeln('');
     $this->output->writeln("Warnings: <comment>" . $results->countAllWarnings() . "</comment> (malformed UTF8 in examples)");
     $this->output->writeln("Skipped files: <comment>" . count($results->getSkipped()) . "</comment> (no function definition found)");
     $basePath = $outDir . DIRECTORY_SEPARATOR . $package->getLang() . '_' . str_replace('.', '_', $package->getMirror());
     $this->saveOutput($basePath, $functions);
     $this->output->writeln("Total functions: <info>" . count($functions) . "</info>");
     $this->saveFunctionsList($basePath, $functions);
     if ($includeExamples == Parser::EXPORT_EXAMPLES) {
         $this->saveExamples($basePath, $examples);
         $this->output->writeln("Total examples: <info>" . $results->countAllExamples() . "</info>");
     }
     if ($this->output->isVerbose()) {
         foreach ($results->getWarnings() as $funcName => $warnings) {
             $this->output->writeln("<comment>Warning in {$funcName}</comment>");
             foreach ($warnings as $warning) {
                 $this->output->writeln($warning);
             }
         }
     }
     if ($this->output->isVeryVerbose()) {
         foreach (array_keys($results->getSkipped()) as $filename) {
             $this->output->writeln("<comment>Skipped {$filename}</comment>");
         }
     }
     //        $this->output->writeln("Total: <comment>${count}</comment> examples");
 }