@@ -289,11 +289,10 @@ public function assertExactJson(array $data)
289
289
/**
290
290
* Assert that the response contains the given JSON fragment.
291
291
*
292
- * @param array $data
293
- * @param bool $negate
292
+ * @param array $data
294
293
* @return $this
295
294
*/
296
- public function assertJsonFragment (array $ data, $ negate = false )
295
+ public function assertJsonFragment (array $ data )
297
296
{
298
297
$ actual = json_encode (Arr::sortRecursive (
299
298
(array ) $ this ->decodeResponseJson ()
@@ -302,23 +301,13 @@ public function assertJsonFragment(array $data, $negate = false)
302
301
foreach (Arr::sortRecursive ($ data ) as $ key => $ value ) {
303
302
$ expected = substr (json_encode ([$ key => $ value ]), 1 , -1 );
304
303
305
- if ($ negate ) {
306
- PHPUnit::assertFalse (
307
- Str::contains ($ actual , $ expected ),
308
- 'Found unexpected JSON fragment: ' .PHP_EOL .PHP_EOL .
309
- "[ {$ expected }] " .PHP_EOL .PHP_EOL .
310
- 'within ' .PHP_EOL .PHP_EOL .
311
- "[ {$ actual }]. "
312
- );
313
- } else {
314
- PHPUnit::assertTrue (
315
- Str::contains ($ actual , $ expected ),
316
- 'Unable to find JSON fragment: ' .PHP_EOL .PHP_EOL .
317
- "[ {$ expected }] " .PHP_EOL .PHP_EOL .
318
- 'within ' .PHP_EOL .PHP_EOL .
319
- "[ {$ actual }]. "
320
- );
321
- }
304
+ PHPUnit::assertTrue (
305
+ Str::contains ($ actual , $ expected ),
306
+ 'Unable to find JSON fragment: ' .PHP_EOL .PHP_EOL .
307
+ "[ {$ expected }] " .PHP_EOL .PHP_EOL .
308
+ 'within ' .PHP_EOL .PHP_EOL .
309
+ "[ {$ actual }]. "
310
+ );
322
311
}
323
312
324
313
return $ this ;
@@ -330,9 +319,23 @@ public function assertJsonFragment(array $data, $negate = false)
330
319
* @param array $data
331
320
* @return $this
332
321
*/
333
- public function assertJsonFragmentMissing (array $ data )
322
+ public function assertJsonMissing (array $ data )
334
323
{
335
- $ this ->assertJsonFragment ($ data , true );
324
+ $ actual = json_encode (Arr::sortRecursive (
325
+ (array ) $ this ->decodeResponseJson ()
326
+ ));
327
+
328
+ foreach (Arr::sortRecursive ($ data ) as $ key => $ value ) {
329
+ $ expected = substr (json_encode ([$ key => $ value ]), 1 , -1 );
330
+
331
+ PHPUnit::assertFalse (
332
+ Str::contains ($ actual , $ expected ),
333
+ 'Found unexpected JSON fragment: ' .PHP_EOL .PHP_EOL .
334
+ "[ {$ expected }] " .PHP_EOL .PHP_EOL .
335
+ 'within ' .PHP_EOL .PHP_EOL .
336
+ "[ {$ actual }]. "
337
+ );
338
+ }
336
339
337
340
return $ this ;
338
341
}
0 commit comments