From 0c32101c5d43092daa528da279c77eb645c9ff56 Mon Sep 17 00:00:00 2001 From: user Date: Fri, 21 Jun 2019 12:39:55 +0900 Subject: [PATCH 1/2] Parameters as values of associative array. --- src/GherkinParam.php | 6 ++++++ tests/_support/AcceptanceTester.php | 23 ++++++++++++++++++++++ tests/acceptance/GherkinParam.feature | 14 +++++++++++++ tests/acceptance/GherkinParamArray.feature | 13 ++++++++++++ 4 files changed, 56 insertions(+) diff --git a/src/GherkinParam.php b/src/GherkinParam.php index c0feb37..090f3e8 100644 --- a/src/GherkinParam.php +++ b/src/GherkinParam.php @@ -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 diff --git a/tests/_support/AcceptanceTester.php b/tests/_support/AcceptanceTester.php index 73fee2f..0ede109 100644 --- a/tests/_support/AcceptanceTester.php +++ b/tests/_support/AcceptanceTester.php @@ -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); + } + } } diff --git a/tests/acceptance/GherkinParam.feature b/tests/acceptance/GherkinParam.feature index cf2fbb2..57b4aa0 100644 --- a/tests/acceptance/GherkinParam.feature +++ b/tests/acceptance/GherkinParam.feature @@ -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 | diff --git a/tests/acceptance/GherkinParamArray.feature b/tests/acceptance/GherkinParamArray.feature index 43ef4d5..a56e468 100644 --- a/tests/acceptance/GherkinParamArray.feature +++ b/tests/acceptance/GherkinParamArray.feature @@ -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 | From 638eb312a8c4638d736fb6d485c87f1115ddf444 Mon Sep 17 00:00:00 2001 From: user Date: Fri, 21 Jun 2019 13:01:15 +0900 Subject: [PATCH 2/2] Coverall script name fixed. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 3f68ee0..2e47d08 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,4 +17,4 @@ script: - ./vendor/bin/codecept run --coverage-xml after_script: - - ./vendor/bin/coveralls + - ./vendor/bin/php-coveralls