@@ -298,6 +298,31 @@ public function theResponseContainsTheFollowingValue(TableNode $table)
298298 $ this ->compareValues ($ item , $ data );
299299 }
300300
301+ /**
302+ * Check response contains specified values from JSON
303+ *
304+ * Example: The the response contains the following values from JSON:
305+ * """
306+ * """
307+ * Example: And the response contains the following value from JSON:
308+ * """
309+ * """
310+ *
311+ * @param PyStringNode $string Values specified in feature as JSON
312+ *
313+ * @Then the response contains the following value(s) from JSON:
314+ */
315+ public function theResponseContainsTheFollowingValueFromJSON (
316+ PyStringNode $ string
317+ ) {
318+ $ data = json_decode ($ string , true );
319+ $ item = $ this ->getGuzzleResult ();
320+
321+ $ data = $ this ->addStoredValuesToArray ($ data );
322+
323+ $ this ->compareValues ($ item , $ data );
324+ }
325+
301326 /**
302327 *
303328 * Example: Then the response contains 2 resources with the following data:
@@ -317,7 +342,7 @@ public function theResponseContainsResourceWithTheFollowingData(
317342 $ count ,
318343 TableNode $ table
319344 ) {
320- $ list = $ this ->getGuzzleResult ();
345+ $ list = $ this ->getGuzzleResult ();
321346 $ length = count ($ list );
322347
323348 if ($ length != $ count ) {
@@ -402,4 +427,27 @@ protected function addStoredValues($string)
402427
403428 return $ string ;
404429 }
430+
431+ /**
432+ * Adds stored values to array
433+ *
434+ * @param array $array Array containing stored field markers
435+ *
436+ * @access protected
437+ * @return array
438+ */
439+ protected function addStoredValuesToArray ($ array )
440+ {
441+ foreach ($ array as $ field => $ value ) {
442+ if (is_array ($ value )) {
443+ $ value = $ this ->addStoredValuesToArray ($ value );
444+ } else {
445+ $ value = $ this ->addStoredValues ($ value );
446+ }
447+
448+ $ array [$ field ] = $ value ;
449+ }
450+
451+ return $ array ;
452+ }
405453}
0 commit comments