Completed
Pull Request — master (#6)
by Chuck
02:31
created

FinderTest::tearDown()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
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
use Flyfinder\Specification\IsHidden;
18
use League\Flysystem\Filesystem;
19
20
/**
21
 * Test case for Finder
22
 * @coversDefaultClass Flyfinder\Finder
23
 */
24
class FinderTest extends TestCase
25
{
26
   /** @var Finder */
27
    private $fixture;
28
29
    /**
30
     * Initializes the fixture for this test.
31
     */
32
    public function setUp()
33
    {
34
        $this->fixture = new Finder();
35
    }
36
37
    public function tearDown()
38
    {
39
        m::close();
40
    }
41
42
    /**
43
     * @covers ::getMethod
44
     */
45
    public function testGetMethod()
46
    {
47
        $this->assertEquals('find', $this->fixture->getMethod());
48
    }
49
50
    /**
51
     * @covers ::handle
52
     * @covers ::setFilesystem
53
     * @covers ::<private>
54
     */
55
    public function testIfCorrectFilesAreBeingYielded()
56
    {
57
        $isHidden = m::mock('Flyfinder\Specification\IsHidden');
58
        $filesystem = m::mock('League\Flysystem\Filesystem');
59
60
        $listContents1 = [
61
            0 => [
62
                "type" => "dir",
63
                "path" => ".hiddendir",
64
                "dirname" => "",
65
                "basename" => ".hiddendir",
66
                "filename" => ".hiddendir",
67
            ],
68
            1 => [
69
                "type" => "file",
70
                "path" => "test.txt",
71
                "basename" => "test.txt"
72
            ],
73
        ];
74
75
        $listContents2 = [
76
            0 => [
77
                "type" => "file",
78
                "path" => ".hiddendir/.test.txt",
79
                "dirname" => ".hiddendir",
80
                "basename" => ".test.txt",
81
                "filename" => ".test",
82
                "extension" => "txt",
83
            ],
84
        ];
85
86
        $filesystem->shouldReceive('listContents')
87
            ->with('')
88
            ->andReturn($listContents1);
89
90
        $filesystem->shouldReceive('listContents')
91
            ->with('.hiddendir')
92
            ->andReturn($listContents2);
93
94
        $isHidden->shouldReceive('isSatisfiedBy')
95
            ->with($listContents1[0])
96
            ->andReturn(true);
97
98
        $isHidden->shouldReceive('isSatisfiedBy')
99
            ->with($listContents1[1])
100
            ->andReturn(false);
101
102
        $isHidden->shouldReceive('isSatisfiedBy')
103
            ->with($listContents2[0])
104
            ->andReturn(true);
105
106
        $this->fixture->setFilesystem($filesystem);
107
        $generator = $this->fixture->handle($isHidden);
108
109
        $result = [];
110
111
        foreach ($generator as $value) {
112
            $result[] = $value;
113
        }
114
115
        $expected = [
116
            0 => [
117
                "type" => "file",
118
                "path" => ".hiddendir/.test.txt",
119
                "dirname" => ".hiddendir",
120
                "basename" => ".test.txt",
121
                "filename" => ".test",
122
                "extension" => "txt",
123
            ]
124
        ];
125
126
        $this->assertEquals($expected, $result);
127
    }
128
}
129