Skip to content

Commit

Permalink
Merge pull request pdepend#329 from KacerCZ/iterator-directory-fix
Browse files Browse the repository at this point in the history
Fix Iterator so it will not return directories
  • Loading branch information
Emir Beganović authored Nov 20, 2017
2 parents 632512a + 8d22dee commit a479c52
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/main/php/PDepend/Input/Iterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down
26 changes: 26 additions & 0 deletions src/test/php/PDepend/Input/IteratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php

// Empty file
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php

// Empty file
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php

// Empty file

0 comments on commit a479c52

Please sign in to comment.