1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Tests\Behat\Gherkin\Node; |
4
|
|
|
|
5
|
|
|
use Behat\Gherkin\Node\ExampleTableNode; |
6
|
|
|
use Behat\Gherkin\Node\OutlineNode; |
7
|
|
|
use Behat\Gherkin\Node\StepNode; |
8
|
|
|
use PHPUnit\Framework\TestCase; |
9
|
|
|
|
10
|
|
|
class OutlineNodeTest extends TestCase |
11
|
|
|
{ |
12
|
|
|
public function testCreatesExamplesForExampleTable() |
13
|
|
|
{ |
14
|
|
|
$steps = array( |
15
|
|
|
new StepNode('Gangway!', 'I am <name>', array(), null, 'Given'), |
16
|
|
|
new StepNode('Aye!', 'my email is <email>', array(), null, 'And'), |
17
|
|
|
new StepNode('Blimey!', 'I open homepage', array(), null, 'When'), |
18
|
|
|
new StepNode('Let go and haul', 'website should recognise me', array(), null, 'Then'), |
19
|
|
|
); |
20
|
|
|
|
21
|
|
|
$table = new ExampleTableNode(array( |
22
|
|
|
2 => array('name', 'email'), |
23
|
|
|
22 => array('everzet', '[email protected]'), |
24
|
|
|
23 => array('example', '[email protected]') |
25
|
|
|
), 'Examples'); |
26
|
|
|
|
27
|
|
|
$outline = new OutlineNode(null, array(), $steps, $table, null, null); |
28
|
|
|
|
29
|
|
|
$this->assertCount(2, $examples = $outline->getExamples()); |
|
|
|
|
30
|
|
|
$this->assertEquals(22, $examples[0]->getLine()); |
31
|
|
|
$this->assertEquals(23, $examples[1]->getLine()); |
32
|
|
|
$this->assertEquals(array('name' => 'everzet', 'email' => '[email protected]'), $examples[0]->getTokens()); |
33
|
|
|
$this->assertEquals(array('name' => 'example', 'email' => '[email protected]'), $examples[1]->getTokens()); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function testCreatesExamplesForExampleTableWithSeveralExamplesAndTags() |
37
|
|
|
{ |
38
|
|
|
$steps = array( |
39
|
|
|
new StepNode('Gangway!', 'I am <name>', array(), null, 'Given'), |
40
|
|
|
new StepNode('Aye!', 'my email is <email>', array(), null, 'And'), |
41
|
|
|
new StepNode('Blimey!', 'I open homepage', array(), null, 'When'), |
42
|
|
|
new StepNode('Let go and haul', 'website should recognise me', array(), null, 'Then'), |
43
|
|
|
); |
44
|
|
|
|
45
|
|
|
$table = new ExampleTableNode(array( |
46
|
|
|
2 => array('name', 'email'), |
47
|
|
|
22 => array('everzet', '[email protected]'), |
48
|
|
|
23 => array('example', '[email protected]') |
49
|
|
|
), 'Examples', array()); |
50
|
|
|
|
51
|
|
|
$table2 = new ExampleTableNode(array( |
52
|
|
|
3 => array('name', 'email'), |
53
|
|
|
32 => array('everzet2', '[email protected]'), |
54
|
|
|
33 => array('example2', '[email protected]') |
55
|
|
|
), 'Examples', array('etag1', 'etag2')); |
56
|
|
|
|
57
|
|
|
$outline = new OutlineNode(null, array('otag1', 'otag2'), $steps, array($table, $table2), null, null); |
58
|
|
|
|
59
|
|
|
$this->assertCount(4, $examples = $outline->getExamples()); |
|
|
|
|
60
|
|
|
$this->assertEquals(22, $examples[0]->getLine()); |
61
|
|
|
$this->assertEquals(23, $examples[1]->getLine()); |
62
|
|
|
$this->assertEquals(32, $examples[2]->getLine()); |
63
|
|
|
$this->assertEquals(33, $examples[3]->getLine()); |
64
|
|
|
$this->assertEquals(array('name' => 'everzet', 'email' => '[email protected]'), $examples[0]->getTokens()); |
65
|
|
|
$this->assertEquals(array('name' => 'example', 'email' => '[email protected]'), $examples[1]->getTokens()); |
66
|
|
|
$this->assertEquals(array('name' => 'everzet2', 'email' => '[email protected]'), $examples[2]->getTokens()); |
67
|
|
|
$this->assertEquals(array('name' => 'example2', 'email' => '[email protected]'), $examples[3]->getTokens()); |
68
|
|
|
|
69
|
|
|
for ($i = 0; $i < 2; $i++) { |
70
|
|
|
foreach (array('otag1', 'otag2') as $tag) { |
71
|
|
|
$this->assertTrue($examples[$i]->hasTag($tag), "there is no tag " . $tag . " in example #" . $i); |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
for ($i = 2; $i < 4; $i++) { |
76
|
|
|
foreach (array('otag1', 'otag2', 'etag1', 'etag2') as $tag) { |
77
|
|
|
$this->assertTrue($examples[$i]->hasTag($tag), "there is no tag " . $tag . " in example #" . $i); |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function testCreatesEmptyExamplesForEmptyExampleTable() |
83
|
|
|
{ |
84
|
|
|
$steps = array( |
85
|
|
|
new StepNode('Gangway!', 'I am <name>', array(), null, 'Given'), |
86
|
|
|
new StepNode('Aye!', 'my email is <email>', array(), null, 'And'), |
87
|
|
|
new StepNode('Blimey!', 'I open homepage', array(), null, 'When'), |
88
|
|
|
new StepNode('Let go and haul', 'website should recognise me', array(), null, 'Then'), |
89
|
|
|
); |
90
|
|
|
|
91
|
|
|
$table = new ExampleTableNode(array( |
92
|
|
|
array('name', 'email') |
93
|
|
|
), 'Examples'); |
94
|
|
|
|
95
|
|
|
$outline = new OutlineNode(null, array(), $steps, $table, null, null); |
96
|
|
|
|
97
|
|
|
$this->assertCount(0, $examples = $outline->getExamples()); |
|
|
|
|
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
public function testCreatesEmptyExamplesForNoExampleTable() |
101
|
|
|
{ |
102
|
|
|
$steps = array( |
103
|
|
|
new StepNode('Gangway!', 'I am <name>', array(), null, 'Given'), |
104
|
|
|
new StepNode('Aye!', 'my email is <email>', array(), null, 'And'), |
105
|
|
|
new StepNode('Blimey!', 'I open homepage', array(), null, 'When'), |
106
|
|
|
new StepNode('Let go and haul', 'website should recognise me', array(), null, 'Then'), |
107
|
|
|
); |
108
|
|
|
|
109
|
|
|
$table = new ExampleTableNode(array(), 'Examples'); |
110
|
|
|
|
111
|
|
|
$outline = new OutlineNode(null, array(), $steps, array($table), null, null); |
112
|
|
|
|
113
|
|
|
$this->assertCount(0, $examples = $outline->getExamples()); |
|
|
|
|
114
|
|
|
} |
115
|
|
|
} |
116
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: