diff --git a/src/main/php/PDepend/Input/Iterator.php b/src/main/php/PDepend/Input/Iterator.php index 8deac012c3..33ff65b7b9 100644 --- a/src/main/php/PDepend/Input/Iterator.php +++ b/src/main/php/PDepend/Input/Iterator.php @@ -87,6 +87,9 @@ public function __construct(\Iterator $iterator, Filter $filter, $rootPath = nul */ public function accept() { + if ($this->getInnerIterator()->current()->isDir()) { + return false; + } return $this->filter->accept($this->getLocalPath(), $this->getFullPath()); } diff --git a/src/test/php/PDepend/Input/IteratorTest.php b/src/test/php/PDepend/Input/IteratorTest.php index b986e2ac70..27d25e4de7 100644 --- a/src/test/php/PDepend/Input/IteratorTest.php +++ b/src/test/php/PDepend/Input/IteratorTest.php @@ -81,6 +81,32 @@ public function testIteratorWithMultipleFileExtensions() $this->assertEquals($expected, $actual); } + /** + * Tests that iterator returns only files. + * + * @return void + */ + public function testIteratorReturnsOnlyFiles() + { + $directory=$this->createCodeResourceUriForTest(); + $pattern = $directory . DIRECTORY_SEPARATOR . 'Ignored'; + + $files = new Iterator( + new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($directory)), + new ExcludePathFilter(array($pattern)) + ); + + $actual = array(); + foreach ($files as $file) { + $actual[] = $file->getFilename(); + } + sort($actual); + + $expected = array('file.php', 'file_process.php'); + + $this->assertEquals($expected,$actual); + } + /** * testIteratorPassesLocalPathToFilterWhenRootIsPresent * diff --git a/src/test/resources/files/Input/Iterator/testIteratorReturnsOnlyFiles/Ignored/file_ignore.php b/src/test/resources/files/Input/Iterator/testIteratorReturnsOnlyFiles/Ignored/file_ignore.php new file mode 100644 index 0000000000..ea4b119ad4 --- /dev/null +++ b/src/test/resources/files/Input/Iterator/testIteratorReturnsOnlyFiles/Ignored/file_ignore.php @@ -0,0 +1,3 @@ +