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

Commit

Permalink
Parameters as values of associative array.
Browse files Browse the repository at this point in the history
Parameters as values of associative array.
  • Loading branch information
edno authored Jun 21, 2019
2 parents 9361f99 + c57d6a7 commit dc3639c
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ script:
- ./vendor/bin/codecept run --coverage-xml

after_script:
- ./vendor/bin/coveralls
- ./vendor/bin/php-coveralls
6 changes: 6 additions & 0 deletions src/GherkinParam.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,12 @@ final public function beforeStep(\Codeception\Event\StepEvent $e)
}
}
$args[$index] = new TableNode($table);
} elseif (is_array($arg)) {
foreach ($arg as $k => $v) {
if (is_string($v)) {
$args[$index][$k] = $this->getValueFromParam($v);
}
}
}
}
// set new arguments value
Expand Down
23 changes: 23 additions & 0 deletions tests/_support/AcceptanceTester.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,27 @@ public function iSeeNull($arg1)
{
$this->assertNull($arg1);
}

/**
* @Given I have a parameter :param with values
* @param string $param
* @param TableNode $values
*/
public function iHaveParameterWithValues(string $param, TableNode $values)
{
Fixtures::add($param, $values->getHash());
}

/**
* @Then I should see :param with values
* @param string $param
* @param TableNode $table
*/
public function iSeeParamEquals(string $param, TableNode $table)
{
$hash = $table->getHash();
foreach (Fixtures::get($param) as $key => $values) {
$this->assertEquals($hash[$key], $values);
}
}
}
14 changes: 14 additions & 0 deletions tests/acceptance/GherkinParam.feature
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,17 @@ Feature: Parametrize Gherkin Feature
Scenario: Scenario using JSON string
Given I have a parameter "test" with value "{'value': 42}"
Then I should see "{{test}}" equals "{'value': 42}"

Scenario: Using parameter as value of associative array
Given I have a parameter "shape" with value "triangle"
And I have a parameter "color" with value "blue"
And I have a parameter "shapes" with values
| shape | color |
| circle | green |
| square | yellow |
| {{shape}} | {{color}} |
Then I should see "shapes" with values
| shape | color |
| circle | green |
| square | yellow |
| triangle | blue |
13 changes: 13 additions & 0 deletions tests/acceptance/GherkinParamArray.feature
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,16 @@ Feature: Parametrize Gherkin Feature (Array)
Scenario: Key not exist (exception)
Given I have an array "test" with values [1, two, 3.14, IV, 101]
Then I should see "{{test[9999]}}" is null

Scenario: Using array parameters as values of associative array
Given I have an array "shape" with values [triangle, blue]
And I have a parameter "shapes" with values
| shape | color |
| circle | green |
| square | yellow |
| {{shape[0]}} | {{shape[1]}} |
Then I should see "shapes" with values
| shape | color |
| circle | green |
| square | yellow |
| triangle | blue |

0 comments on commit dc3639c

Please sign in to comment.