PathsFilterTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 3
dl 0
loc 54
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testIsFeatureMatchFilter() 0 19 1
A testItDoesNotMatchPartialPaths() 0 21 1
A testItDoesNotMatchIfFileWithSameNameButNotPathExistsInFolder() 0 9 1
1
<?php
2
3
namespace Tests\Behat\Gherkin\Filter;
4
5
use Behat\Gherkin\Filter\PathsFilter;
6
use Behat\Gherkin\Node\FeatureNode;
7
8
class PathsFilterTest extends FilterTest
9
{
10
    public function testIsFeatureMatchFilter()
11
    {
12
        $feature = new FeatureNode(null, null, array(), null, array(), null, null, __FILE__, 1);
13
14
        $filter = new PathsFilter(array(__DIR__));
15
        $this->assertTrue($filter->isFeatureMatch($feature));
16
17
        $filter = new PathsFilter(array('/abc', '/def', dirname(__DIR__)));
18
        $this->assertTrue($filter->isFeatureMatch($feature));
19
20
        $filter = new PathsFilter(array('/abc', '/def', __DIR__));
21
        $this->assertTrue($filter->isFeatureMatch($feature));
22
23
        $filter = new PathsFilter(array('/abc', __DIR__, '/def'));
24
        $this->assertTrue($filter->isFeatureMatch($feature));
25
26
        $filter = new PathsFilter(array('/abc', '/def', '/wrong/path'));
27
        $this->assertFalse($filter->isFeatureMatch($feature));
28
    }
29
30
    public function testItDoesNotMatchPartialPaths()
31
    {
32
        $fixtures = __DIR__ . DIRECTORY_SEPARATOR . 'Fixtures' . DIRECTORY_SEPARATOR;
33
34
        $feature = new FeatureNode(null, null, array(), null, array(), null, null, $fixtures . 'full_path' . DIRECTORY_SEPARATOR . 'file1', 1);
35
36
        $filter = new PathsFilter(array($fixtures . 'full'));
37
        $this->assertFalse($filter->isFeatureMatch($feature));
38
39
        $filter = new PathsFilter(array($fixtures . 'full' . DIRECTORY_SEPARATOR));
40
        $this->assertFalse($filter->isFeatureMatch($feature));
41
42
        $filter = new PathsFilter(array($fixtures . 'full_path' . DIRECTORY_SEPARATOR));
43
        $this->assertTrue($filter->isFeatureMatch($feature));
44
45
        $filter = new PathsFilter(array($fixtures . 'full_path'));
46
        $this->assertTrue($filter->isFeatureMatch($feature));
47
        
48
        $filter = new PathsFilter(array($fixtures . 'ful._path')); // Don't accept regexp
49
        $this->assertFalse($filter->isFeatureMatch($feature));
50
    }
51
52
    public function testItDoesNotMatchIfFileWithSameNameButNotPathExistsInFolder()
53
    {
54
        $fixtures = __DIR__ . DIRECTORY_SEPARATOR . 'Fixtures' . DIRECTORY_SEPARATOR;
55
56
        $feature = new FeatureNode(null, null, array(), null, array(), null, null, $fixtures . 'full_path' . DIRECTORY_SEPARATOR . 'file1', 1);
57
58
        $filter = new PathsFilter(array($fixtures . 'full'));
59
        $this->assertFalse($filter->isFeatureMatch($feature));
60
    }
61
}
62