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

InPathTest::validDirnames()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 10
rs 9.4285
cc 1
eloc 7
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\Specification;
14
15
use PHPUnit\Framework\TestCase;
16
use Mockery as m;
17
use Flyfinder\Path;
18
19
/**
20
 * Test case for InPath
21
 * @coversDefaultClass Flyfinder\Specification\InPath
22
 * @covers ::<private>
23
 */
24
class InPathTest extends TestCase
25
{
26
    /** @var InPath */
27
    private $fixture;
28
29
    public function tearDown()
30
    {
31
        m::close();
32
    }
33
34
    /**
35
     * @covers ::__construct
36
     * @covers ::isSatisfiedBy
37
     * @dataProvider validDirnames
38
     * @uses Flyfinder\Path
39
     */
40
    public function testExactMatch()
41
    {
42
        $absolutePath = 'absolute/path/to/file.txt';
43
        $spec = new InPath(new Path($absolutePath));
44
        $this->assertTrue($spec->isSatisfiedBy([
45
            'type' => 'file',
46
            'path' => $absolutePath,
47
            'dirname' => $absolutePath,
48
            'filename' => 'file',
49
            'extension' => 'txt',
50
            'basename' => 'file.txt'
51
        ]));
52
    }
53
54
    private function useWildcardPath()
55
    {
56
        $this->fixture = new InPath(new Path('*dden?ir/n'));
57
    }
58
59
    /**
60
     * @covers ::__construct
61
     * @covers ::isSatisfiedBy
62
     * @dataProvider validDirnames
63
     * @uses Flyfinder\Path
64
     */
65
    public function testIfSpecificationIsSatisfied($dirname)
66
    {
67
        $this->useWildcardPath();
68
        $this->assertTrue($this->fixture->isSatisfiedBy(['dirname' => $dirname]));
69
    }
70
71
    /**
72
     * @covers ::__construct
73
     * @covers ::isSatisfiedBy
74
     * @dataProvider validDirnames
75
     * @uses Flyfinder\Path
76
     */
77
    public function testWithSingleDotSpec($dirname)
78
    {
79
        $spec = new InPath(new Path('.'));
80
        $this->assertTrue($spec->isSatisfiedBy(['dirname' => $dirname]));
81
    }
82
83
    /**
84
     * @covers ::__construct
85
     * @covers ::isSatisfiedBy
86
     * @dataProvider validDirnames
87
     * @uses Flyfinder\Path
88
     */
89
    public function testWithCurrentDirSpec($dirname)
90
    {
91
        $spec = new InPath(new Path('./'));
92
        $this->assertTrue($spec->isSatisfiedBy(['dirname' => $dirname]));
93
    }
94
95
    /**
96
     * Data provider for testIfSpecificationIsSatisfied. Contains a few valid directory names
97
     *
98
     * @return array
99
     */
100
    public function validDirnames()
101
    {
102
        return [
103
            ['.hiddendir/n'],
104
            ['.hiddendir/n/'],
105
            ['.hiddendir/n/somedir'],
106
            ['.hiddendir/n/somedir.txt'],
107
            ['ddenxir/n']
108
        ];
109
    }
110
111
    /**
112
     * @covers ::__construct
113
     * @covers ::isSatisfiedBy
114
     * @dataProvider invalidDirnames
115
     * @uses Flyfinder\Path
116
     */
117
    public function testIfSpecificationIsNotSatisfied($dirname)
118
    {
119
        $this->useWildcardPath();
120
        $this->assertFalse($this->fixture->isSatisfiedBy(['dirname' => $dirname]));
121
    }
122
123
    /**
124
     * Data provider for testIfSpecificationIsNotSatisfied. Contains a few invalid directory names
125
     *
126
     * @return array
127
     */
128
    public function invalidDirnames()
129
    {
130
        return [
131
            ['/hiddendir/n'],
132
            ['.hiddendir/normaldir'],
133
            ['.hiddendir.ext/n'],
134
            ['.hiddenxxir/n'],
135
            ['.hiddenir/n']
136
        ];
137
    }
138
}
139