IgnoreEntrySearcherTest::setUp()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace IgnoreFiles\Tests\Service;
4
5
use IgnoreFiles\Service\IgnoreEntrySearcher;
6
use IgnoreFiles\Tests\BaseUnitTestCase;
7
8
class IgnoreEntrySearcherTest extends BaseUnitTestCase
9
{
10
    /**
11
     * @var IgnoreEntrySearcher
12
     */
13
    private $ignoreEntrySearcher;
14
15
    protected function setUp()
16
    {
17
        $this->ignoreEntrySearcher = new IgnoreEntrySearcher($this->getFileReader());
0 ignored issues
show
Bug introduced by
It seems like $this->getFileReader() targeting IgnoreFiles\Tests\BaseUn...stCase::getFileReader() can also be of type object<Mockery\MockInterface>; however, IgnoreFiles\Service\Igno...Searcher::__construct() does only seem to accept object<IgnoreFiles\Infra...ucture\Disk\FileReader>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
18
    }
19
20
    /**
21
     * @return array
22
     */
23
    public function ignoreDataProvide()
24
    {
25
        return [
26
            'file1.php',
27
            'dir1/file2.php',
28
            'dir2',
29
            'dir3/        ',
30
        ];
31
    }
32
33
    /**
34
     * @return array
35
     */
36
    public function fileExistsDataProvider()
37
    {
38
        return [
39
            [
40
                $this->ignoreDataProvide(),
41
                'file1.php',
42
            ],
43
            [
44
                $this->ignoreDataProvide(),
45
                'dir1/file2.php',
46
            ],
47
            [
48
                $this->ignoreDataProvide(),
49
                'dir2/file3.php',
50
            ],
51
            [
52
                $this->ignoreDataProvide(),
53
                'dir3/file4.php',
54
            ],
55
            [
56
                $this->ignoreDataProvide(),
57
                'dir3/subdir1/file4.php',
58
            ],
59
            [
60
                $this->ignoreDataProvide(),
61
                'dir3/subdir1/subdir2/file4.php',
62
            ],
63
        ];
64
    }
65
66
    /**
67
     * @return array
68
     */
69
    public function fileNotExistsDataProvider()
70
    {
71
        return [
72
            [
73
                [],
74
                'file_valid.php',
75
            ],[
76
                $this->ignoreDataProvide(),
77
                'file_valid.php',
78
            ],
79
            [
80
                $this->ignoreDataProvide(),
81
                'dir_valid/file_valid.php',
82
            ],
83
            [
84
                $this->ignoreDataProvide(),
85
                'dir_valid/subdir_valid/file_valid.php',
86
            ],
87
        ];
88
    }
89
90
    /**
91
     * @test
92
     *
93
     * @dataProvider fileExistsDataProvider
94
     */
95
    public function itShouldReturnTrue($ignoredFiles, $entry)
96
    {
97
        $this->shouldReadIgnoreData($ignoredFiles);
98
        $this->assertTrue($this->ignoreEntrySearcher->search($entry));
99
    }
100
101
    /**
102
     * @test
103
     *
104
     * @dataProvider fileNotExistsDataProvider
105
     */
106
    public function itShouldReturnFalse($ignoredFiles, $entry)
107
    {
108
        $this->shouldReadIgnoreData($ignoredFiles);
109
        $this->assertFalse($this->ignoreEntrySearcher->search($entry));
110
    }
111
}
112