@@ -159,12 +159,33 @@ protected function seeJsonContains($expected)
159159 $ response = $ this ->response ();
160160 $ json = json_decode ($ response , true );
161161
162- $ this ->assertEquals (
163- @array_intersect ($ json , $ expected ),
164- $ expected ,
165- sprintf ("Dang! Expected %s to exist in %s, but no dice. Any ideas? " , json_encode ($ expected ), $ response )
166- );
162+ // If we have a collection of results, we'll sift through each array
163+ // in the collection, and check to see if there's a match.
164+ if ( ! isset ($ json [0 ])) $ json = [$ json ];
165+
166+ $ containsFragment = array_reduce ($ json , function ($ carry , $ array ) use ($ expected ) {
167+ if ($ carry ) return $ carry ;
168+
169+ return $ this ->jsonHasFragment ($ expected , $ array );
170+ });
171+
172+ $ this ->assertTrue ($ containsFragment , sprintf (
173+ "Dang! Expected %s to exist in %s, but nope. Ideas? " ,
174+ json_encode ($ expected ), $ response
175+ ));
167176
168177 return $ this ;
169178 }
179+
180+ /**
181+ * Determine if the given fragment is contained with a decoded set of JSON.
182+ *
183+ * @param array $fragment
184+ * @param array $json
185+ * @return boolean
186+ */
187+ protected function jsonHasFragment (array $ fragment , $ json )
188+ {
189+ return @array_intersect ($ json , $ fragment ) == $ fragment ;
190+ }
170191}
0 commit comments