Skip to content

Commit 9dec914

Browse files
authored
test: Fix cucumber variant assertions to include inherited properties (#394)
Most of our nodes are standalone classes, but ExampleTableNode inherits from TableNode and the actual `table` content is a private property in the parent class. This meant that our dumped YAML data for assertions did not capture the example table content. I built this commit off the original (based on 4.14.0) and then patched it onto the current version - only one original feature was affected.
1 parent a269823 commit 9dec914

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

tests/Cucumber/ParserResultDumper.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,14 @@ private function recursiveDump(mixed $value): mixed
7070
// we know that the FeatureNode and the objects it contains do not contain any recursive references.
7171
$values = [];
7272
$reflection = new ReflectionClass($value);
73-
foreach ($reflection->getProperties() as $property) {
74-
$values[$property->getName()] = match ($property->isInitialized($value)) {
75-
true => $this->recursiveDump($property->getValue($value)),
76-
false => '**NOT INITIALIZED**',
77-
};
78-
}
73+
do {
74+
foreach ($reflection->getProperties() as $property) {
75+
$values[$property->getName()] = match ($property->isInitialized($value)) {
76+
true => $this->recursiveDump($property->getValue($value)),
77+
false => '**NOT INITIALIZED**',
78+
};
79+
}
80+
} while ($reflection = $reflection->getParentClass());
7981

8082
return [$value::class => $values];
8183
}

tests/Cucumber/expected_variants/gherkin-32/padded_example.feature.expected.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@ Behat\Gherkin\Node\FeatureNode:
1111
Behat\Gherkin\Node\ExampleTableNode:
1212
keyword: Examples
1313
tags: []
14+
maxLineLength:
15+
- 9
16+
table:
17+
17:
18+
- color
19+
18:
20+
- "\_ \tred\_ \t"
1421
examples: '**NOT INITIALIZED**'
1522
title: test
1623
tags: []

tests/Cucumber/expected_variants/legacy/padded_example.feature.expected.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@ Behat\Gherkin\Node\FeatureNode:
1111
Behat\Gherkin\Node\ExampleTableNode:
1212
keyword: Examples
1313
tags: []
14+
maxLineLength:
15+
- 7
16+
table:
17+
17:
18+
- color
19+
18:
20+
- "\_ \tred\_"
1421
examples: '**NOT INITIALIZED**'
1522
title: test
1623
tags: []

0 commit comments

Comments
 (0)