public function scan(FileIterator $fileIterator)
{
$this->dispatcher->dispatch(self::SCAN_START);
foreach ($fileIterator as $file) {
$this->dispatcher->dispatch(self::FILE_OPEN, new Event\FileEvent($file));
if ($file->isPathMatch('/\\.phps$/i')) {
$this->dispatcher->dispatch(self::FILE_ERROR, new Event\ErrorEvent('You have a .phps file - REMOVE NOW', $file));
}
try {
$this->visitor->setFile($file);
$this->traverser->traverse($this->parser->parse($file->getContents()));
} catch (\PhpParser\Error $e) {
$this->dispatcher->dispatch(self::FILE_ERROR, new Event\ErrorEvent($e->getMessage(), $file));
}
$this->dispatcher->dispatch(self::FILE_CLOSE);
}
$this->dispatcher->dispatch(self::SCAN_COMPLETE);
}
public function testErrorOnParseException() { $file = m::mock('\\Psecio\\Parse\\File'); $file->shouldReceive('isPathMatch')->once()->with('/\\.phps$/i')->andReturn(false); $file->shouldReceive('getContents')->once()->andReturn(''); $dispatcher = $this->createErrorDispatcherMock(); $scanner = new Scanner($dispatcher, m::mock('\\Psecio\\Parse\\CallbackVisitor')->shouldReceive('onNodeFailure', 'setFile')->mock(), m::mock('\\PhpParser\\Parser')->shouldReceive('parse')->andThrow(new \PhpParser\Error(''))->mock(), m::mock('\\PhpParser\\NodeTraverser')->shouldReceive('addVisitor')->mock()); $scanner->scan(m::mock('\\Psecio\\Parse\\FileIterator')->shouldReceive('getIterator')->andReturn(new \ArrayIterator([$file]))->mock()); }