diff --git a/README.md b/README.md index cdf53e4..4f00b1e 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,8 @@ [![Code Coverage](https://scrutinizer-ci.com/g/teaandcode/behat-guzzle-extension/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/teaandcode/behat-guzzle-extension/?branch=master) [![Build Status](https://scrutinizer-ci.com/g/teaandcode/behat-guzzle-extension/badges/build.png?b=master)](https://scrutinizer-ci.com/g/teaandcode/behat-guzzle-extension/build-status/master) +[![Join the chat at https://gitter.im/teaandcode/behat-guzzle-extension](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/teaandcode/behat-guzzle-extension?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) + Guzzle extension for Behat is an integration layer between Behat 3.0+ and Guzzle 3.5+ and it provides: diff --git a/src/Behat/GuzzleExtension/Context/GuzzleContext.php b/src/Behat/GuzzleExtension/Context/GuzzleContext.php index b42b798..c926899 100644 --- a/src/Behat/GuzzleExtension/Context/GuzzleContext.php +++ b/src/Behat/GuzzleExtension/Context/GuzzleContext.php @@ -303,9 +303,23 @@ public function theResponseContainsTheFollowingValue(TableNode $table) * * Example: The the response contains the following values from JSON: * """ + * { + * "name": "Test Name", + * "users": [ + * { + * "id": 3 + * }, + * { + * "id": 6 + * } + * ] + * } * """ * Example: And the response contains the following value from JSON: * """ + * { + * "name": "Test Name" + * } * """ * * @param PyStringNode $string Values specified in feature as JSON @@ -315,12 +329,10 @@ public function theResponseContainsTheFollowingValue(TableNode $table) public function theResponseContainsTheFollowingValueFromJSON( PyStringNode $string ) { - $data = json_decode($string, true); - $item = $this->getGuzzleResult(); - - $data = $this->addStoredValuesToArray($data); - - $this->compareValues($item, $data); + $this->compareValues( + $this->getGuzzleResult(), + json_decode($this->addStoredValues($string->getRaw()), true) + ); } /** @@ -427,27 +439,4 @@ protected function addStoredValues($string) return $string; } - - /** - * Adds stored values to array - * - * @param array $array Array containing stored field markers - * - * @access protected - * @return array - */ - protected function addStoredValuesToArray($array) - { - foreach ($array as $field => $value) { - if (is_array($value)) { - $value = $this->addStoredValuesToArray($value); - } else { - $value = $this->addStoredValues($value); - } - - $array[$field] = $value; - } - - return $array; - } }