|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Tests\Behat\Gherkin\Filter; |
|
4
|
|
|
|
|
5
|
|
|
use Behat\Gherkin\Filter\LineFilter; |
|
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 LineFilterTest extends FilterTest |
|
12
|
|
|
{ |
|
13
|
|
|
public function testIsFeatureMatchFilter() |
|
14
|
|
|
{ |
|
15
|
|
|
$feature = new FeatureNode(null, null, array(), null, array(), null, null, null, 1); |
|
16
|
|
|
|
|
17
|
|
|
$filter = new LineFilter(1); |
|
18
|
|
|
$this->assertTrue($filter->isFeatureMatch($feature)); |
|
19
|
|
|
|
|
20
|
|
|
$filter = new LineFilter(2); |
|
21
|
|
|
$this->assertFalse($filter->isFeatureMatch($feature)); |
|
22
|
|
|
|
|
23
|
|
|
$filter = new LineFilter(3); |
|
24
|
|
|
$this->assertFalse($filter->isFeatureMatch($feature)); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
public function testIsScenarioMatchFilter() |
|
28
|
|
|
{ |
|
29
|
|
|
$scenario = new ScenarioNode(null, array(), array(), null, 2); |
|
30
|
|
|
|
|
31
|
|
|
$filter = new LineFilter(2); |
|
32
|
|
|
$this->assertTrue($filter->isScenarioMatch($scenario)); |
|
33
|
|
|
|
|
34
|
|
|
$filter = new LineFilter(1); |
|
35
|
|
|
$this->assertFalse($filter->isScenarioMatch($scenario)); |
|
36
|
|
|
|
|
37
|
|
|
$filter = new LineFilter(5); |
|
38
|
|
|
$this->assertFalse($filter->isScenarioMatch($scenario)); |
|
39
|
|
|
|
|
40
|
|
|
$outline = new OutlineNode(null, array(), array(), new ExampleTableNode(array(), null), null, 20); |
|
41
|
|
|
|
|
42
|
|
|
$filter = new LineFilter(5); |
|
43
|
|
|
$this->assertFalse($filter->isScenarioMatch($outline)); |
|
44
|
|
|
|
|
45
|
|
|
$filter = new LineFilter(20); |
|
46
|
|
|
$this->assertTrue($filter->isScenarioMatch($outline)); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function testFilterFeatureScenario() |
|
50
|
|
|
{ |
|
51
|
|
|
$filter = new LineFilter(2); |
|
52
|
|
|
$feature = $filter->filterFeature($this->getParsedFeature()); |
|
|
|
|
|
|
53
|
|
|
$this->assertCount(1, $scenarios = $feature->getScenarios()); |
|
|
|
|
|
|
54
|
|
|
$this->assertSame('Scenario#1', $scenarios[0]->getTitle()); |
|
55
|
|
|
|
|
56
|
|
|
$filter = new LineFilter(7); |
|
57
|
|
|
$feature = $filter->filterFeature($this->getParsedFeature()); |
|
|
|
|
|
|
58
|
|
|
$this->assertCount(1, $scenarios = $feature->getScenarios()); |
|
|
|
|
|
|
59
|
|
|
$this->assertSame('Scenario#2', $scenarios[0]->getTitle()); |
|
60
|
|
|
|
|
61
|
|
|
$filter = new LineFilter(5); |
|
62
|
|
|
$feature = $filter->filterFeature($this->getParsedFeature()); |
|
|
|
|
|
|
63
|
|
|
$this->assertCount(0, $scenarios = $feature->getScenarios()); |
|
|
|
|
|
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
public function testFilterFeatureOutline() |
|
67
|
|
|
{ |
|
68
|
|
|
$filter = new LineFilter(13); |
|
69
|
|
|
$feature = $filter->filterFeature($this->getParsedFeature()); |
|
|
|
|
|
|
70
|
|
|
/** @var OutlineNode[] $scenarios */ |
|
71
|
|
|
$this->assertCount(1, $scenarios = $feature->getScenarios()); |
|
|
|
|
|
|
72
|
|
|
$this->assertSame('Scenario#3', $scenarios[0]->getTitle()); |
|
73
|
|
|
$this->assertCount(4, $scenarios[0]->getExampleTable()->getRows()); |
|
|
|
|
|
|
74
|
|
|
|
|
75
|
|
|
$filter = new LineFilter(20); |
|
76
|
|
|
$feature = $filter->filterFeature($this->getParsedFeature()); |
|
|
|
|
|
|
77
|
|
|
$this->assertCount(1, $scenarios = $feature->getScenarios()); |
|
|
|
|
|
|
78
|
|
|
$this->assertSame('Scenario#3', $scenarios[0]->getTitle()); |
|
79
|
|
|
$exampleTableNodes = $scenarios[0]->getExampleTables(); |
|
|
|
|
|
|
80
|
|
|
$this->assertEquals(1, count($exampleTableNodes)); |
|
81
|
|
|
$this->assertCount(2, $exampleTableNodes[0]->getRows()); |
|
82
|
|
|
$this->assertSame(array( |
|
83
|
|
|
array('action', 'outcome'), |
|
84
|
|
|
array('act#1', 'out#1'), |
|
85
|
|
|
), $exampleTableNodes[0]->getRows()); |
|
86
|
|
|
$this->assertEquals(array('etag1'), $exampleTableNodes[0]->getTags()); |
|
87
|
|
|
|
|
88
|
|
|
$filter = new LineFilter(26); |
|
89
|
|
|
$feature = $filter->filterFeature($this->getParsedFeature()); |
|
|
|
|
|
|
90
|
|
|
$this->assertCount(1, $scenarios = $feature->getScenarios()); |
|
|
|
|
|
|
91
|
|
|
$this->assertSame('Scenario#3', $scenarios[0]->getTitle()); |
|
92
|
|
|
$exampleTableNodes = $scenarios[0]->getExampleTables(); |
|
|
|
|
|
|
93
|
|
|
$this->assertEquals(1, count($exampleTableNodes)); |
|
94
|
|
|
$this->assertCount(2, $exampleTableNodes[0]->getRows()); |
|
95
|
|
|
$this->assertSame(array( |
|
96
|
|
|
array('action', 'outcome'), |
|
97
|
|
|
array('act#3', 'out#3'), |
|
98
|
|
|
), $exampleTableNodes[0]->getRows()); |
|
99
|
|
|
$this->assertEquals(array('etag2'), $exampleTableNodes[0]->getTags()); |
|
100
|
|
|
|
|
101
|
|
|
$filter = new LineFilter(19); |
|
102
|
|
|
$feature = $filter->filterFeature($this->getParsedFeature()); |
|
|
|
|
|
|
103
|
|
|
$this->assertCount(1, $scenarios = $feature->getScenarios()); |
|
|
|
|
|
|
104
|
|
|
$this->assertSame('Scenario#3', $scenarios[0]->getTitle()); |
|
105
|
|
|
$this->assertCount(1, $scenarios[0]->getExampleTable()->getRows()); |
|
|
|
|
|
|
106
|
|
|
$this->assertSame(array(array('action', 'outcome')), $scenarios[0]->getExampleTable()->getRows()); |
|
|
|
|
|
|
107
|
|
|
} |
|
108
|
|
|
} |
|
109
|
|
|
|
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: