示例#1
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     Debugger::timer();
     $output->writeln('Running tests...');
     $runner = new Runner();
     $path = realpath($input->getArgument('path'));
     if ($path) {
         if (is_dir($path)) {
             $runner->setTestsRoot($path . '/');
             foreach (Finder::findFiles('*.php')->exclude('tester.php')->from($path) as $path => $fileInfo) {
                 $basePath = Helpers::stripExtension($path);
                 $runner->addTest($basePath);
             }
         } else {
             $basePath = Helpers::stripExtension($path);
             $runner->addTest($basePath);
         }
     } else {
         if ($path = realpath($input->getArgument('path') . '.php')) {
             $basePath = Helpers::stripExtension($path);
             $runner->addTest($basePath);
         } else {
             $output->writeln("<error>The given path isn't valid</error>");
             return 1;
         }
     }
     $runner->setOutput($output);
     $runner->runTests();
     $output->writeln('Completed in ' . round(Debugger::timer(), 2) . ' seconds');
     if ($runner->failed()) {
         return 1;
     } else {
         return 0;
     }
 }
示例#2
0
 public function runTests()
 {
     $this->setupColors();
     foreach ($this->tests as $basePath) {
         $transpiler = new Transpiler();
         $name = Helpers::stripPrefix($basePath, $this->testsRoot);
         $phpPath = $basePath . '.php';
         $jsPath = $basePath . '.js';
         $yamlPath = $basePath . '.yml';
         if (file_exists($yamlPath)) {
             $configuration = new Configuration();
             $yaml = Yaml::parse(file_get_contents($yamlPath));
             foreach ($yaml as $option => $value) {
                 if ($option === 'skip') {
                     $this->skipped[] = $name;
                     $this->writeSkip();
                     continue 2;
                 }
                 $configuration->{$option} = $value;
             }
             $transpiler->setConfiguration($configuration);
         }
         $generated = $transpiler->transpile(file_get_contents($phpPath));
         if (file_exists($jsPath)) {
             $expected = file_get_contents($jsPath);
             if ($expected === $generated) {
                 $this->writeSuccess();
             } else {
                 $this->writeFailure();
                 $this->addFailure($name, $this->generateFailureExplanation($expected, $generated));
             }
             file_put_contents($jsPath . "_expected", $generated);
         } else {
             $this->addFailure($name, "Not defined JS result file");
             file_put_contents($jsPath . "_expected", $generated);
         }
     }
     $this->output->writeln('');
     $this->output->writeln('');
     $this->writeSkippedList();
     if ($this->failures) {
         $this->writeFailuresExplanation();
         $this->output->writeln('');
     } else {
         $this->output->writeln('<success>All tests have passed �</success>');
     }
 }