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

UpstreamGherkinTest::goodFeatures()   A

Complexity

Conditions 5
Paths 5

Size

Total Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 22
rs 9.2568
c 0
b 0
f 0
cc 5
nc 5
nop 0
1
<?php
2
3
use Behat\Gherkin\Keywords\ArrayKeywords;
4
5
final class UpstreamGherkinTest extends PHPUnit_Framework_TestCase
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
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
    );
23
24
    /**
25
     * @dataProvider goodFeatures
26
     */
27
    public function testGoodFeatures($featureFile, $astFile)
28
    {
29
        $arrKeywords = include __DIR__ . '/../../i18n.php';
30
        $lexer  = new Behat\Gherkin\Lexer(new ArrayKeywords($arrKeywords));
31
        $parser = new Behat\Gherkin\Parser($lexer);
32
33
        $feature = $parser->parse(file_get_contents($featureFile));
0 ignored issues
show
Unused Code introduced by
$feature is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
34
    }
35
36
    public function goodFeatures() : iterable
37
    {
38
       foreach (new FilesystemIterator(__DIR__ . '/../../gherkin_testdata/good') as $file) {
0 ignored issues
show
Coding Style introduced by
Blank line found at start of control structure
Loading history...
39
40
           if (in_array(preg_replace('/^.*\//', '', $file), $this->notSupported['good'])) {
41
               continue;
42
           }
43
44
           if (!preg_match('/(?<stem>.*)[.]feature$/', $file, $matches)) {
45
               continue;
46
           }
47
48
           if (in_array(preg_replace('/^.*\//', '', $matches['stem']), $this->notSupported['good'])) {
49
               continue;
50
           }
51
52
           yield $matches['stem'] => [
53
               $matches['stem'] . '.feature',
54
               $matches['stem'] . '.ast.ndjson'
55
           ];
56
       }
57
    }
58
}
59