Skip to content

Commit 786b782

Browse files
committed
adjust test response
1 parent 406185e commit 786b782

File tree

1 file changed

+25
-22
lines changed

1 file changed

+25
-22
lines changed

src/Illuminate/Foundation/Testing/TestResponse.php

+25-22
Original file line numberDiff line numberDiff line change
@@ -289,11 +289,10 @@ public function assertExactJson(array $data)
289289
/**
290290
* Assert that the response contains the given JSON fragment.
291291
*
292-
* @param array $data
293-
* @param bool $negate
292+
* @param array $data
294293
* @return $this
295294
*/
296-
public function assertJsonFragment(array $data, $negate = false)
295+
public function assertJsonFragment(array $data)
297296
{
298297
$actual = json_encode(Arr::sortRecursive(
299298
(array) $this->decodeResponseJson()
@@ -302,23 +301,13 @@ public function assertJsonFragment(array $data, $negate = false)
302301
foreach (Arr::sortRecursive($data) as $key => $value) {
303302
$expected = substr(json_encode([$key => $value]), 1, -1);
304303

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+
);
322311
}
323312

324313
return $this;
@@ -330,9 +319,23 @@ public function assertJsonFragment(array $data, $negate = false)
330319
* @param array $data
331320
* @return $this
332321
*/
333-
public function assertJsonFragmentMissing(array $data)
322+
public function assertJsonMissing(array $data)
334323
{
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+
}
336339

337340
return $this;
338341
}

0 commit comments

Comments
 (0)