This repository was archived by the owner on Jul 12, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +38
-1
lines changed
main/QafooLabs/Refactoring/Domain/Model
test/QafooLabs/Refactoring/Domain/Model Expand file tree Collapse file tree 2 files changed +38
-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,14 @@ function ($file) use ($workingDirectory) {
73
74
);
74
75
}
75
76
76
- return $ iterator ;
77
+ $ files = array ();
78
+ foreach ($ iterator as $ filename => $ file ) {
79
+ $ files [] = $ file ;
80
+ }
81
+
82
+ return new StandardCallbackFilterIterator ($ iterator , function ($ file , $ filename ) use ($ files ) {
83
+ return !in_array ($ filename , $ files );
84
+ });
77
85
}
78
86
}
79
87
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,30 @@ 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
+ foreach ($ files as $ f => $ file ) {
40
+ $ this ->assertEquals ('vfs://project/src/Foo/Bar.php ' , $ f );
41
+ }
42
+ }
14
43
}
You can’t perform that action at this time.
0 commit comments