/**
  * @test
  */
 public function itShouldAnalyseAllFiles()
 {
     $files = [fixture('MyClass.php')];
     $nodes = [$this->node];
     $parseRes = $this->parser->parse(Argument::type('string'));
     $this->parser->parse(Argument::type('string'))->shouldBeCalled()->willReturn($nodes);
     $this->nodeTraverser->traverse($nodes)->shouldBeCalled();
     $this->analyser->analyse($files);
 }
Exemple #2
0
 /**
  * @param array $args
  */
 public function handle(array $args)
 {
     $this->cli->out(sprintf('PHPAssumptions analyser v%s by @rskuipers', Cli::VERSION))->br();
     try {
         $this->cli->arguments->parse($args);
     } catch (\Exception $e) {
         $this->cli->usage($args);
         return;
     }
     switch ($this->cli->arguments->get('format')) {
         case 'xml':
             $output = new XmlOutput($this->cli, $this->cli->arguments->get('output'));
             break;
         default:
             $output = new PrettyOutput($this->cli);
             break;
     }
     $nodeTraverser = new NodeTraverser();
     $analyser = new Analyser($this->parser, $nodeTraverser);
     $nodeTraverser->addVisitor(new NodeVisitor($analyser, new Detector()));
     $target = $this->cli->arguments->get('path');
     $targets = [];
     if (is_file($target)) {
         $targets[] = $target;
     } else {
         $directory = new \RecursiveDirectoryIterator($target);
         $iterator = new \RecursiveIteratorIterator($directory);
         $regex = new \RegexIterator($iterator, '/^.+\\.php$/i', \RecursiveRegexIterator::GET_MATCH);
         foreach ($regex as $file) {
             $targets[] = $file[0];
         }
     }
     $result = $analyser->analyse($targets);
     $output->output($result);
 }