1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Tests\Behat\Gherkin\Filter; |
4
|
|
|
|
5
|
|
|
use Behat\Gherkin\Filter\LineRangeFilter; |
6
|
|
|
use Behat\Gherkin\Node\ExampleTableNode; |
7
|
|
|
use Behat\Gherkin\Node\FeatureNode; |
8
|
|
|
use Behat\Gherkin\Node\OutlineNode; |
9
|
|
|
use Behat\Gherkin\Node\ScenarioNode; |
10
|
|
|
|
11
|
|
|
class LineRangeFilterTest extends FilterTest |
12
|
|
|
{ |
13
|
|
|
public function featureLineRangeProvider() |
14
|
|
|
{ |
15
|
|
|
return array( |
16
|
|
|
array('1', '1', true), |
17
|
|
|
array('1', '2', true), |
18
|
|
|
array('1', '*', true), |
19
|
|
|
array('2', '2', false), |
20
|
|
|
array('2', '*', false) |
21
|
|
|
); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @dataProvider featureLineRangeProvider |
26
|
|
|
*/ |
27
|
|
|
public function testIsFeatureMatchFilter($filterMinLine, $filterMaxLine, $expected) |
28
|
|
|
{ |
29
|
|
|
$feature = new FeatureNode(null, null, array(), null, array(), null, null, null, 1); |
30
|
|
|
|
31
|
|
|
$filter = new LineRangeFilter($filterMinLine, $filterMaxLine); |
32
|
|
|
$this->assertSame($expected, $filter->isFeatureMatch($feature)); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function scenarioLineRangeProvider() |
36
|
|
|
{ |
37
|
|
|
return array( |
38
|
|
|
array('1', '2', 1), |
39
|
|
|
array('1', '*', 2), |
40
|
|
|
array('2', '2', 1), |
41
|
|
|
array('2', '*', 2), |
42
|
|
|
array('3', '3', 1), |
43
|
|
|
array('3', '*', 1), |
44
|
|
|
array('1', '1', 0), |
45
|
|
|
array('4', '4', 0), |
46
|
|
|
array('4', '*', 0) |
47
|
|
|
); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @dataProvider scenarioLineRangeProvider |
52
|
|
|
*/ |
53
|
|
|
public function testIsScenarioMatchFilter($filterMinLine, $filterMaxLine, $expectedNumberOfMatches) |
54
|
|
|
{ |
55
|
|
|
$scenario = new ScenarioNode(null, array(), array(), null, 2); |
56
|
|
|
$outline = new OutlineNode(null, array(), array(), array(new ExampleTableNode(array(), null)), null, 3); |
57
|
|
|
|
58
|
|
|
$filter = new LineRangeFilter($filterMinLine, $filterMaxLine); |
59
|
|
|
$this->assertEquals( |
60
|
|
|
$expectedNumberOfMatches, |
61
|
|
|
intval($filter->isScenarioMatch($scenario)) + intval($filter->isScenarioMatch($outline)) |
62
|
|
|
); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function testFilterFeatureScenario() |
66
|
|
|
{ |
67
|
|
|
$filter = new LineRangeFilter(1, 3); |
68
|
|
|
$feature = $filter->filterFeature($this->getParsedFeature()); |
|
|
|
|
69
|
|
|
$this->assertCount(1, $scenarios = $feature->getScenarios()); |
|
|
|
|
70
|
|
|
$this->assertSame('Scenario#1', $scenarios[0]->getTitle()); |
71
|
|
|
|
72
|
|
|
$filter = new LineRangeFilter(5, 9); |
73
|
|
|
$feature = $filter->filterFeature($this->getParsedFeature()); |
|
|
|
|
74
|
|
|
$this->assertCount(1, $scenarios = $feature->getScenarios()); |
|
|
|
|
75
|
|
|
$this->assertSame('Scenario#2', $scenarios[0]->getTitle()); |
76
|
|
|
|
77
|
|
|
$filter = new LineRangeFilter(5, 6); |
78
|
|
|
$feature = $filter->filterFeature($this->getParsedFeature()); |
|
|
|
|
79
|
|
|
$this->assertCount(0, $scenarios = $feature->getScenarios()); |
|
|
|
|
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function testFilterFeatureOutline() |
83
|
|
|
{ |
84
|
|
|
$filter = new LineRangeFilter(12, 14); |
85
|
|
|
$feature = $filter->filterFeature($this->getParsedFeature()); |
|
|
|
|
86
|
|
|
/** @var OutlineNode[] $scenarios */ |
87
|
|
|
$this->assertCount(1, $scenarios = $feature->getScenarios()); |
|
|
|
|
88
|
|
|
$this->assertSame('Scenario#3', $scenarios[0]->getTitle()); |
89
|
|
|
$this->assertFalse($scenarios[0]->hasExamples()); |
|
|
|
|
90
|
|
|
|
91
|
|
|
$filter = new LineRangeFilter(16, 21); |
92
|
|
|
$feature = $filter->filterFeature($this->getParsedFeature()); |
|
|
|
|
93
|
|
|
$this->assertCount(1, $scenarios = $feature->getScenarios()); |
|
|
|
|
94
|
|
|
$this->assertSame('Scenario#3', $scenarios[0]->getTitle()); |
95
|
|
|
$exampleTableNodes = $scenarios[0]->getExampleTables(); |
|
|
|
|
96
|
|
|
$this->assertEquals(1, count($exampleTableNodes)); |
97
|
|
|
$this->assertCount(3, $exampleTableNodes[0]->getRows()); |
98
|
|
|
$this->assertSame(array( |
99
|
|
|
array('action', 'outcome'), |
100
|
|
|
array('act#1', 'out#1'), |
101
|
|
|
array('act#2', 'out#2'), |
102
|
|
|
), $exampleTableNodes[0]->getRows()); |
103
|
|
|
$this->assertEquals(array('etag1'), $exampleTableNodes[0]->getTags()); |
104
|
|
|
|
105
|
|
|
$filter = new LineRangeFilter(16, 26); |
106
|
|
|
$feature = $filter->filterFeature($this->getParsedFeature()); |
|
|
|
|
107
|
|
|
$this->assertCount(1, $scenarios = $feature->getScenarios()); |
|
|
|
|
108
|
|
|
$this->assertSame('Scenario#3', $scenarios[0]->getTitle()); |
109
|
|
|
$exampleTableNodes = $scenarios[0]->getExampleTables(); |
|
|
|
|
110
|
|
|
$this->assertEquals(2, count($exampleTableNodes)); |
111
|
|
|
|
112
|
|
|
$this->assertCount(3, $exampleTableNodes[0]->getRows()); |
113
|
|
|
$this->assertSame(array( |
114
|
|
|
array('action', 'outcome'), |
115
|
|
|
array('act#1', 'out#1'), |
116
|
|
|
array('act#2', 'out#2'), |
117
|
|
|
), $exampleTableNodes[0]->getRows()); |
118
|
|
|
$this->assertEquals(array('etag1'), $exampleTableNodes[0]->getTags()); |
119
|
|
|
|
120
|
|
|
$this->assertCount(2, $exampleTableNodes[1]->getRows()); |
121
|
|
|
$this->assertSame(array( |
122
|
|
|
array('action', 'outcome'), |
123
|
|
|
array('act#3', 'out#3') |
124
|
|
|
), $exampleTableNodes[1]->getRows()); |
125
|
|
|
|
126
|
|
|
$this->assertEquals(array('etag2'), $exampleTableNodes[1]->getTags()); |
127
|
|
|
|
128
|
|
|
$filter = new LineRangeFilter(25, 26); |
129
|
|
|
$feature = $filter->filterFeature($this->getParsedFeature()); |
|
|
|
|
130
|
|
|
$this->assertCount(1, $scenarios = $feature->getScenarios()); |
|
|
|
|
131
|
|
|
$this->assertSame('Scenario#3', $scenarios[0]->getTitle()); |
132
|
|
|
$exampleTableNodes = $scenarios[0]->getExampleTables(); |
|
|
|
|
133
|
|
|
$this->assertEquals(1, count($exampleTableNodes)); |
134
|
|
|
$this->assertCount(2, $exampleTableNodes[0]->getRows()); |
135
|
|
|
$this->assertSame(array( |
136
|
|
|
array('action', 'outcome'), |
137
|
|
|
array('act#3', 'out#3'), |
138
|
|
|
), $exampleTableNodes[0]->getRows()); |
139
|
|
|
$this->assertEquals(array('etag2'), $exampleTableNodes[0]->getTags()); |
140
|
|
|
} |
141
|
|
|
} |
142
|
|
|
|
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: