1212
1313use Behat \Gherkin \Exception \NodeException ;
1414use Behat \Gherkin \Loader \CucumberNDJsonAstLoader ;
15+ use Behat \Gherkin \Node \BackgroundNode ;
16+ use Behat \Gherkin \Node \ExampleTableNode ;
17+ use Behat \Gherkin \Node \FeatureNode ;
18+ use Behat \Gherkin \Node \OutlineNode ;
19+ use Behat \Gherkin \Node \ScenarioNode ;
1520use PHPUnit \Framework \TestCase ;
1621
1722final class CucumberNDJsonAstLoaderTest extends TestCase
@@ -28,6 +33,99 @@ public function testStringResourcesAreSupported(): void
2833 $ this ->assertTrue ($ this ->loader ->supports ('a string ' ));
2934 }
3035
36+ public function testValidLoading (): void
37+ {
38+ $ file = $ this ->serializeCucumberMessagesToFile ([
39+ 'gherkinDocument ' => [
40+ 'feature ' => [
41+ 'location ' => ['line ' => 111 ],
42+ 'description ' => 'Feature with a valid Scenario ' ,
43+ 'keyword ' => 'fea ' ,
44+ 'language ' => 'en ' ,
45+ 'children ' => [
46+ [
47+ 'background ' => [
48+ 'location ' => ['line ' => 222 ],
49+ 'keyword ' => 'bac ' ,
50+ 'name ' => 'Empty Background ' ,
51+ ],
52+ ],
53+ [
54+ 'scenario ' => [
55+ 'location ' => ['line ' => 333 ],
56+ 'keyword ' => 'sce ' ,
57+ 'name ' => 'Empty Scenario ' ,
58+ 'examples ' => [],
59+ ],
60+ ],
61+ [
62+ 'scenario ' => [
63+ 'location ' => ['line ' => 444 ],
64+ 'keyword ' => 'out ' ,
65+ 'examples ' => [
66+ [
67+ 'location ' => ['line ' => 555 ],
68+ 'keyword ' => 'exa ' ,
69+ 'tableHeader ' => [
70+ 'location ' => ['line ' => 666 ],
71+ 'cells ' => [
72+ ['value ' => 'A ' ],
73+ ['value ' => 'B ' ],
74+ ],
75+ ],
76+ 'tableBody ' => [
77+ [
78+ 'location ' => ['line ' => 777 ],
79+ 'cells ' => [
80+ ['value ' => 'A1 ' ],
81+ ['value ' => 'B1 ' ],
82+ ],
83+ ],
84+ [
85+ 'location ' => ['line ' => 888 ],
86+ 'cells ' => [
87+ ['value ' => 'A2 ' ],
88+ ['value ' => 'B2 ' ],
89+ ],
90+ ],
91+ ],
92+ ],
93+ ],
94+ ],
95+ ],
96+ ],
97+ ],
98+ ],
99+ ]);
100+ $ features = $ this ->loader ->load ($ file );
101+
102+ $ this ->assertEquals (
103+ [
104+ new FeatureNode (
105+ null ,
106+ 'Feature with a valid Scenario ' ,
107+ [],
108+ new BackgroundNode ('Empty Background ' , [], 'bac ' , 222 ),
109+ [
110+ new ScenarioNode ('Empty Scenario ' , [], [], 'sce ' , 333 ),
111+ new OutlineNode (null , [], [], [
112+ new ExampleTableNode ([
113+ 666 => ['A ' , 'B ' ],
114+ 777 => ['A1 ' , 'B1 ' ],
115+ 888 => ['A2 ' , 'B2 ' ],
116+ ], 'exa ' ),
117+ ], 'out ' , 444 ),
118+ ],
119+ 'fea ' ,
120+ 'en ' ,
121+ $ file ,
122+ 111 ,
123+ ),
124+ ],
125+ $ features ,
126+ );
127+ }
128+
31129 public function testOutlineTableHeaderIsRequired (): void
32130 {
33131 $ this ->expectException (NodeException::class);
0 commit comments