1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of phpDocumentor. |
4
|
|
|
* |
5
|
|
|
* For the full copyright and license information, please view the LICENSE |
6
|
|
|
* file that was distributed with this source code. |
7
|
|
|
* |
8
|
|
|
* @copyright 2010-2015 Mike van Riel<[email protected]> |
9
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php MIT |
10
|
|
|
* @link http://phpdoc.org |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace Flyfinder; |
14
|
|
|
|
15
|
|
|
use PHPUnit\Framework\TestCase; |
16
|
|
|
use Mockery as m; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Test case for Finder |
20
|
|
|
* @coversDefaultClass Flyfinder\Finder |
21
|
|
|
*/ |
22
|
|
|
class FinderTest extends TestCase |
23
|
|
|
{ |
24
|
|
|
/** @var Finder */ |
25
|
|
|
private $fixture; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Initializes the fixture for this test. |
29
|
|
|
*/ |
30
|
|
|
public function setUp() |
31
|
|
|
{ |
32
|
|
|
$this->fixture = new Finder(); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function tearDown() |
36
|
|
|
{ |
37
|
|
|
m::close(); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @covers ::getMethod |
42
|
|
|
*/ |
43
|
|
|
public function testGetMethod() |
44
|
|
|
{ |
45
|
|
|
$this->assertEquals('find', $this->fixture->getMethod()); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @covers ::handle |
50
|
|
|
* @covers ::setFilesystem |
51
|
|
|
* @covers ::<private> |
52
|
|
|
*/ |
53
|
|
|
public function testIfCorrectFilesAreBeingYielded() |
54
|
|
|
{ |
55
|
|
|
$isHidden = m::mock('Flyfinder\Specification\IsHidden'); |
56
|
|
|
$filesystem = m::mock('League\Flysystem\Filesystem'); |
57
|
|
|
|
58
|
|
|
$listContents1 = [ |
59
|
|
|
0 => [ |
60
|
|
|
"type" => "dir", |
61
|
|
|
"path" => ".hiddendir", |
62
|
|
|
"dirname" => "", |
63
|
|
|
"basename" => ".hiddendir", |
64
|
|
|
"filename" => ".hiddendir", |
65
|
|
|
], |
66
|
|
|
1 => [ |
67
|
|
|
"type" => "file", |
68
|
|
|
"path" => "test.txt", |
69
|
|
|
"basename" => "test.txt" |
70
|
|
|
], |
71
|
|
|
]; |
72
|
|
|
|
73
|
|
|
$listContents2 = [ |
74
|
|
|
0 => [ |
75
|
|
|
"type" => "file", |
76
|
|
|
"path" => ".hiddendir/.test.txt", |
77
|
|
|
"dirname" => ".hiddendir", |
78
|
|
|
"basename" => ".test.txt", |
79
|
|
|
"filename" => ".test", |
80
|
|
|
"extension" => "txt", |
81
|
|
|
], |
82
|
|
|
]; |
83
|
|
|
|
84
|
|
|
$filesystem->shouldReceive('listContents') |
85
|
|
|
->with('') |
86
|
|
|
->andReturn($listContents1); |
87
|
|
|
|
88
|
|
|
$filesystem->shouldReceive('listContents') |
89
|
|
|
->with('.hiddendir') |
90
|
|
|
->andReturn($listContents2); |
91
|
|
|
|
92
|
|
|
$isHidden->shouldReceive('isSatisfiedBy') |
93
|
|
|
->with($listContents1[0]) |
94
|
|
|
->andReturn(true); |
95
|
|
|
|
96
|
|
|
$isHidden->shouldReceive('isSatisfiedBy') |
97
|
|
|
->with($listContents1[1]) |
98
|
|
|
->andReturn(false); |
99
|
|
|
|
100
|
|
|
$isHidden->shouldReceive('isSatisfiedBy') |
101
|
|
|
->with($listContents2[0]) |
102
|
|
|
->andReturn(true); |
103
|
|
|
|
104
|
|
|
$this->fixture->setFilesystem($filesystem); |
105
|
|
|
$generator = $this->fixture->handle($isHidden); |
106
|
|
|
|
107
|
|
|
$result = []; |
108
|
|
|
|
109
|
|
|
foreach ($generator as $value) { |
110
|
|
|
$result[] = $value; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
$expected = [ |
114
|
|
|
0 => [ |
115
|
|
|
"type" => "file", |
116
|
|
|
"path" => ".hiddendir/.test.txt", |
117
|
|
|
"dirname" => ".hiddendir", |
118
|
|
|
"basename" => ".test.txt", |
119
|
|
|
"filename" => ".test", |
120
|
|
|
"extension" => "txt", |
121
|
|
|
] |
122
|
|
|
]; |
123
|
|
|
|
124
|
|
|
$this->assertEquals($expected, $result); |
125
|
|
|
} |
126
|
|
|
} |
127
|
|
|
|