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\PyStringNode; |
8
|
|
|
use Behat\Gherkin\Node\StepNode; |
9
|
|
|
use Behat\Gherkin\Node\TableNode; |
10
|
|
|
use PHPUnit\Framework\TestCase; |
11
|
|
|
|
12
|
|
|
class ExampleNodeTest extends TestCase |
13
|
|
|
{ |
14
|
|
|
public function testCreateExampleSteps() |
15
|
|
|
{ |
16
|
|
|
$steps = array( |
17
|
|
|
$step1 = new StepNode('Gangway!', 'I am <name>', array(), null, 'Given'), |
18
|
|
|
$step2 = new StepNode('Aye!', 'my email is <email>', array(), null, 'And'), |
19
|
|
|
$step3 = new StepNode('Blimey!', 'I open homepage', array(), null, 'When'), |
20
|
|
|
$step4 = new StepNode('Let go and haul', 'website should recognise me', array(), null, 'Then'), |
21
|
|
|
); |
22
|
|
|
|
23
|
|
|
$table = new ExampleTableNode(array( |
24
|
|
|
array('name', 'email'), |
25
|
|
|
array('everzet', '[email protected]'), |
26
|
|
|
array('example', '[email protected]') |
27
|
|
|
), 'Examples'); |
28
|
|
|
|
29
|
|
|
$outline = new OutlineNode(null, array(), $steps, $table, null, null); |
30
|
|
|
$examples = $outline->getExamples(); |
31
|
|
|
|
32
|
|
|
$this->assertCount(4, $steps = $examples[0]->getSteps()); |
|
|
|
|
33
|
|
|
|
34
|
|
|
$this->assertEquals('Gangway!', $steps[0]->getType()); |
|
|
|
|
35
|
|
|
$this->assertEquals('Gangway!', $steps[0]->getKeyword()); |
36
|
|
|
$this->assertEquals('Given', $steps[0]->getKeywordType()); |
37
|
|
|
$this->assertEquals('I am everzet', $steps[0]->getText()); |
38
|
|
|
$this->assertEquals('Aye!', $steps[1]->getType()); |
|
|
|
|
39
|
|
|
$this->assertEquals('Aye!', $steps[1]->getKeyword()); |
40
|
|
|
$this->assertEquals('And', $steps[1]->getKeywordType()); |
41
|
|
|
$this->assertEquals('my email is [email protected]', $steps[1]->getText()); |
42
|
|
|
$this->assertEquals('Blimey!', $steps[2]->getType()); |
|
|
|
|
43
|
|
|
$this->assertEquals('Blimey!', $steps[2]->getKeyword()); |
44
|
|
|
$this->assertEquals('When', $steps[2]->getKeywordType()); |
45
|
|
|
$this->assertEquals('I open homepage', $steps[2]->getText()); |
46
|
|
|
|
47
|
|
|
$this->assertCount(4, $steps = $examples[1]->getSteps()); |
|
|
|
|
48
|
|
|
|
49
|
|
|
$this->assertEquals('Gangway!', $steps[0]->getType()); |
|
|
|
|
50
|
|
|
$this->assertEquals('Gangway!', $steps[0]->getKeyword()); |
51
|
|
|
$this->assertEquals('Given', $steps[0]->getKeywordType()); |
52
|
|
|
$this->assertEquals('I am example', $steps[0]->getText()); |
53
|
|
|
$this->assertEquals('Aye!', $steps[1]->getType()); |
|
|
|
|
54
|
|
|
$this->assertEquals('Aye!', $steps[1]->getKeyword()); |
55
|
|
|
$this->assertEquals('And', $steps[1]->getKeywordType()); |
56
|
|
|
$this->assertEquals('my email is [email protected]', $steps[1]->getText()); |
57
|
|
|
$this->assertEquals('Blimey!', $steps[2]->getType()); |
|
|
|
|
58
|
|
|
$this->assertEquals('Blimey!', $steps[2]->getKeyword()); |
59
|
|
|
$this->assertEquals('When', $steps[2]->getKeywordType()); |
60
|
|
|
$this->assertEquals('I open homepage', $steps[2]->getText()); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function testCreateExampleStepsWithArguments() |
64
|
|
|
{ |
65
|
|
|
$steps = array( |
66
|
|
|
$step1 = new StepNode('Gangway!', 'I am <name>', array(), null, 'Given'), |
67
|
|
|
$step2 = new StepNode('Aye!', 'my email is <email>', array(), null, 'And'), |
68
|
|
|
$step3 = new StepNode('Blimey!', 'I open:', array( |
69
|
|
|
new PyStringNode(array('page: <url>'), null) |
70
|
|
|
), null, 'When'), |
71
|
|
|
$step4 = new StepNode('Let go and haul', 'website should recognise me', array( |
72
|
|
|
new TableNode(array(array('page', '<url>'))) |
73
|
|
|
), null, 'Then'), |
74
|
|
|
); |
75
|
|
|
|
76
|
|
|
$table = new ExampleTableNode(array( |
77
|
|
|
array('name', 'email', 'url'), |
78
|
|
|
array('everzet', '[email protected]', 'homepage'), |
79
|
|
|
array('example', '[email protected]', 'other page') |
80
|
|
|
), 'Examples'); |
81
|
|
|
|
82
|
|
|
$outline = new OutlineNode(null, array(), $steps, $table, null, null); |
83
|
|
|
$examples = $outline->getExamples(); |
84
|
|
|
|
85
|
|
|
$steps = $examples[0]->getSteps(); |
86
|
|
|
|
87
|
|
|
$args = $steps[2]->getArguments(); |
88
|
|
|
$this->assertEquals('page: homepage', $args[0]->getRaw()); |
|
|
|
|
89
|
|
|
|
90
|
|
|
$args = $steps[3]->getArguments(); |
91
|
|
|
$this->assertEquals('| page | homepage |', $args[0]->getTableAsString()); |
|
|
|
|
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|
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: