File tree Expand file tree Collapse file tree 2 files changed +37
-1
lines changed
main/QafooLabs/Refactoring/Domain/Model
test/QafooLabs/Refactoring/Domain/Model Expand file tree Collapse file tree 2 files changed +37
-1
lines changed Original file line number Diff line number Diff line change 19
19
use RecursiveIteratorIterator ;
20
20
use SplFileInfo ;
21
21
use AppendIterator ;
22
+ use CallbackFilterIterator as StandardCallbackFilterIterator ;
22
23
23
24
/**
24
25
* A directory in a project.
@@ -73,7 +74,10 @@ function ($file) use ($workingDirectory) {
73
74
);
74
75
}
75
76
76
- return $ iterator ;
77
+ $ files = iterator_to_array ($ iterator );
78
+ return new StandardCallbackFilterIterator ($ iterator , function ($ file , $ filename ) use ($ files ) {
79
+ return !in_array ($ filename , $ files );
80
+ });
77
81
}
78
82
}
79
83
Original file line number Diff line number Diff line change 2
2
3
3
namespace QafooLabs \Refactoring \Domain \Model ;
4
4
5
+ use org \bovigo \vfs \vfsStream ;
6
+ use org \bovigo \vfs \vfsStreamWrapper ;
7
+
5
8
class DirectoryTest extends \PHPUnit_Framework_TestCase
6
9
{
7
10
public function testFindAllPhpFilesRecursivly ()
@@ -11,4 +14,33 @@ public function testFindAllPhpFilesRecursivly()
11
14
12
15
$ this ->assertContainsOnly ('QafooLabs\Refactoring\Domain\Model\File ' , $ files );
13
16
}
17
+
18
+ public function testRemovesDuplicates ()
19
+ {
20
+ vfsStreamWrapper::register ();
21
+
22
+ $ structure = array (
23
+ 'src ' => array (
24
+ 'src ' => array (),
25
+ 'Foo ' => array (
26
+ 'src ' => array (),
27
+ 'Foo ' => array (),
28
+ 'Bar.php ' => '<?php '
29
+ ),
30
+ )
31
+ );
32
+
33
+ vfsStream::create ($ structure , VfsStream::setup ('project ' ));
34
+ $ dir = VfsStream::url ('project/src ' );
35
+
36
+ $ directory = new Directory ($ dir , $ dir );
37
+ $ files = $ directory ->findAllPhpFilesRecursivly ();
38
+
39
+ $ foundFiles = array ();
40
+ foreach ($ files as $ f => $ file ) {
41
+ $ foundFiles [] = $ f ;
42
+ }
43
+
44
+ $ this ->assertEquals (array ('vfs://project/src/Foo/Bar.php ' ), $ foundFiles );
45
+ }
14
46
}
You can’t perform that action at this time.
0 commit comments