Skip to content
This repository has been archived by the owner on Jul 29, 2022. It is now read-only.

Commit

Permalink
Fix #27: fix bug on Scenario Outline
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentchalamon committed Jul 24, 2017
1 parent 5970a00 commit 7316a89
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 13 deletions.
7 changes: 7 additions & 0 deletions features/scenario_state.feature
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,10 @@ Feature: Scenario shared state
"""
[Behat\Testwork\Argument\Exception\UnknownParameterValueException]
"""

Scenario: Scenario Outline should work properly
When I run "behat --no-colors features/bandar-log.feature"
Then it should pass with:
"""
2 scenarios (2 passed)
"""
3 changes: 2 additions & 1 deletion src/Resolver/ArgumentsResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ public function resolve(\ReflectionMethod $function, array $arguments)
// Reorder arguments
$params = [];
foreach ($function->getParameters() as $parameter) {
$params[$parameter->getName()] = $arguments[$parameter->getName()];
$name = $parameter->getName();
$params[$name] = isset($arguments[$name]) ? $arguments[$name] : $arguments[$parameter->getPosition()];
}

return $params;
Expand Down
11 changes: 11 additions & 0 deletions testapp/features/bandar-log.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Feature: Monkey gathering bananas

Scenario Outline: Monkey gives a banana to another monkey
When the bonobo takes a banana
And gives this banana to <gorilla>
Then the gorilla is named <gorilla>

Examples:
| gorilla |
| Harambe |
| Max |
13 changes: 13 additions & 0 deletions testapp/features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,4 +179,17 @@ public function gorillaHasBanana($scenarioBanana, Gorilla $gorilla)
\PHPUnit_Framework_Assert::assertEquals('Yammy Banana', $scenarioBanana);
\PHPUnit_Framework_Assert::assertEquals('Yammy Banana', $gorilla->getBanana());
}

/**
* @Then the gorilla is named :name
*
* @ScenarioStateArgument(name="scenarioGorilla", argument="gorilla")
*
* @param string $name
* @param Gorilla $gorilla
*/
public function gorillaIsCorrectlyNamed($name, Gorilla $gorilla)
{
\PHPUnit_Framework_Assert::assertEquals($name, $gorilla->getName());
}
}
13 changes: 6 additions & 7 deletions testapp/features/donkeys.feature
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
Feature: Donkeys sharing carots

Scenario: Monkey gives a banana to another monkey
When the bonobo takes a banana
And gives this banana to Harambe
Then the gorilla has the banana

Scenario: Monkey gives a banana to another monkey
Then the gorilla has the banana
Scenario: Monkey gives a banana to another monkey
When the bonobo takes a banana
And gives this banana to Harambe
Then the gorilla has the banana

Scenario: Monkey gives a banana to another monkey
Then the gorilla has the banana
8 changes: 4 additions & 4 deletions testapp/features/monkey.feature
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Feature: Monkey gathering bananas

Scenario: Monkey gives a banana to another monkey
When the bonobo takes a banana
And gives this banana to Harambe
Then the gorilla has the banana
Scenario: Monkey gives a banana to another monkey
When the bonobo takes a banana
And gives this banana to Harambe
Then the gorilla has the banana
2 changes: 1 addition & 1 deletion tests/Resolver/ArgumentsResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function testResolve()
$annotationMock = $this->prophesize(ScenarioStateArgument::class);

$functionMock->getParameters()->willReturn([$parameterMock, $parameterMock])->shouldBeCalledTimes(2);
$parameterMock->getName()->willReturn('lorem', 'foo', 'lorem', 'lorem', 'foo', 'foo')->shouldBeCalledTimes(6);
$parameterMock->getName()->willReturn('lorem', 'foo', 'lorem', 'foo')->shouldBeCalledTimes(4);
$initializerMock->getStore()->willReturn($storeMock)->shouldBeCalledTimes(1);
$readerMock->getMethodAnnotation($functionMock, ScenarioStateArgument::class)->willReturn($annotationMock)->shouldBeCalledTimes(1);
$readerMock->getMethodAnnotations($functionMock)->willReturn([$this->prophesize(\stdClass::class), $annotationMock])->shouldBeCalledTimes(1);
Expand Down

0 comments on commit 7316a89

Please sign in to comment.