Exemplo n.º 1
0
 public function testClassNamePriorityOverPhpDocSuggestions()
 {
     Phake::when($this->resolver)->isValid("\\foo\\Amount")->thenReturn(true);
     $src = "<?php namespace foo;\n            /**\n             * @param Amount \$a\n             */\n            function foo(\$a) {}\n        ";
     $result = $this->bugfree->parse('test', $src, $this->resolver);
     $this->assertEquals(0, count($result->getErrors()), print_r($result->getErrors(), true));
 }
Exemplo n.º 2
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $formatter = new JsonFormatter($output);
     $config = Config::load($input->getOption('config'));
     $this->bootstrap($config->getBoostrapPath());
     if ($input->getOption('autoFix')) {
         $config->autoFix = true;
     }
     $bugfree = new Bugfree(new AutoloaderResolver($config), $config);
     $status = self::SUCCESS;
     while ($file = fgets(STDIN)) {
         $formatter->begin(1);
         $file = trim($file);
         if (!$file) {
             continue;
         }
         if (!file_exists($file)) {
             $formatter->testFailed(1, $file, ["file '{$file}' does not exist"]);
             continue;
         }
         try {
             require_once $file;
             $rawFileContents = file_get_contents($file);
             $result = $bugfree->parse($file, $rawFileContents);
         } catch (\Exception $e) {
             $status = self::ERROR;
             $formatter->testFailed(1, $file, ["Exception while parsing {$file} " . get_class($e) . '("' . $e->getMessage() . "\")\n" . $e->getTraceAsString()], []);
             continue;
         }
         if (count($result->getErrors()) > 0) {
             $status = self::ERROR;
             $formatter->testFailed(1, $file, $result->getErrors());
         } else {
             $formatter->testPassed(1, $file);
         }
         if (count($result->getFixes()) > 0) {
             $fixes = $result->getFixes();
             $fileLines = preg_split('/\\r|\\r\\n|\\n/', $rawFileContents);
             foreach ($fixes as $fix) {
                 $fix->run($fileLines);
             }
             file_put_contents($file, trim(implode("\n", $fileLines)) . "\n");
         }
         $formatter->end($status);
     }
     return $status;
 }