Completed
Pull Request — master (#152)
by Ciaran
02:52
created

UpstreamGherkinTest   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 90
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 4

Importance

Changes 0
Metric Value
wmc 10
lcom 2
cbo 4
dl 0
loc 90
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 6 1
A testGoodFeaturesCanParse() 0 4 1
A testBadFeaturesCanNotParse() 0 5 1
A goodFeatures() 0 4 1
A badFeatures() 0 4 1
A findFeatures() 0 24 5
1
<?php
2
3
namespace Behat\Gherkin;
4
5
final class UpstreamGherkinTest extends \PHPUnit_Framework_TestCase
6
{
7
8
    private $notSupported = array(
9
        'good' => array(
10
            'descriptions',
11
            'docstrings',
12
            'incomplete_feature_3',
13
            'incomplete_scenario_outline',
14
            'readme_example',
15
            'rule',
16
            'scenario_outline',
17
            'scenario_outlines_with_tags',
18
            'several_examples',
19
            'spaces_in_language',
20
            'tags'
21
        ),
22
        'bad' => array(
23
            'invalid_language'
24
        )
25
    );
26
27
    /**
28
     * @var Parser
29
     */
30
    private $parser;
31
32
    public function setUp()
33
    {
34
        $arrKeywords = include __DIR__ . '/../../../i18n.php';
35
        $lexer  = new Lexer(new Keywords\ArrayKeywords($arrKeywords));
36
        $this->parser = new Parser($lexer);
37
    }
38
39
    /**
40
     * @dataProvider goodFeatures
41
     */
42
    public function testGoodFeaturesCanParse($featureFile)
43
    {
44
        $this->parser->parse(file_get_contents($featureFile));
45
    }
46
47
    /**
48
     * @dataProvider badFeatures
49
     */
50
    public function testBadFeaturesCanNotParse($featureFile)
51
    {
52
        $this->expectException(\Exception::class);
53
        $this->parser->parse(file_get_contents($featureFile));
54
    }
55
56
    public function goodFeatures()
57
    {
58
        return $this->findFeatures('good');
59
    }
60
61
    public function badFeatures()
62
    {
63
        return $this->findFeatures('bad');
64
    }
65
66
    /**
67
     * @param $type
68
     * @return array
69
     */
70
    private function findFeatures($type)
71
    {
72
        $features = array();
73
74
        foreach (new \FilesystemIterator(__DIR__ . '/../../../gherkin_testdata/' . $type) as $file) {
75
            if (in_array(preg_replace('/^.*\//', '', $file), $this->notSupported[$type])) {
76
                continue;
77
            }
78
79
            if (!preg_match('/(?<stem>.*)[.]feature$/', $file, $matches)) {
80
                continue;
81
            }
82
83
            if (in_array(preg_replace('/^.*\//', '', $matches['stem']), $this->notSupported[$type])) {
84
                continue;
85
            }
86
87
            $features[$matches['stem']] = array(
88
                $matches['stem'] . '.feature'
89
            );
90
        }
91
92
        return $features;
93
    }
94
}
95