Skip to content

Commit

Permalink
adjust test response
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Apr 8, 2017
1 parent 406185e commit 786b782
Showing 1 changed file with 25 additions and 22 deletions.
47 changes: 25 additions & 22 deletions src/Illuminate/Foundation/Testing/TestResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -289,11 +289,10 @@ public function assertExactJson(array $data)
/**
* Assert that the response contains the given JSON fragment.
*
* @param array $data
* @param bool $negate
* @param array $data
* @return $this
*/
public function assertJsonFragment(array $data, $negate = false)
public function assertJsonFragment(array $data)
{
$actual = json_encode(Arr::sortRecursive(
(array) $this->decodeResponseJson()
Expand All @@ -302,23 +301,13 @@ public function assertJsonFragment(array $data, $negate = false)
foreach (Arr::sortRecursive($data) as $key => $value) {
$expected = substr(json_encode([$key => $value]), 1, -1);

if ($negate) {
PHPUnit::assertFalse(
Str::contains($actual, $expected),
'Found unexpected JSON fragment: '.PHP_EOL.PHP_EOL.
"[{$expected}]".PHP_EOL.PHP_EOL.
'within'.PHP_EOL.PHP_EOL.
"[{$actual}]."
);
} else {
PHPUnit::assertTrue(
Str::contains($actual, $expected),
'Unable to find JSON fragment: '.PHP_EOL.PHP_EOL.
"[{$expected}]".PHP_EOL.PHP_EOL.
'within'.PHP_EOL.PHP_EOL.
"[{$actual}]."
);
}
PHPUnit::assertTrue(
Str::contains($actual, $expected),
'Unable to find JSON fragment: '.PHP_EOL.PHP_EOL.
"[{$expected}]".PHP_EOL.PHP_EOL.
'within'.PHP_EOL.PHP_EOL.
"[{$actual}]."
);
}

return $this;
Expand All @@ -330,9 +319,23 @@ public function assertJsonFragment(array $data, $negate = false)
* @param array $data
* @return $this
*/
public function assertJsonFragmentMissing(array $data)
public function assertJsonMissing(array $data)
{
$this->assertJsonFragment($data, true);
$actual = json_encode(Arr::sortRecursive(
(array) $this->decodeResponseJson()
));

foreach (Arr::sortRecursive($data) as $key => $value) {
$expected = substr(json_encode([$key => $value]), 1, -1);

PHPUnit::assertFalse(
Str::contains($actual, $expected),
'Found unexpected JSON fragment: '.PHP_EOL.PHP_EOL.
"[{$expected}]".PHP_EOL.PHP_EOL.
'within'.PHP_EOL.PHP_EOL.
"[{$actual}]."
);
}

return $this;
}
Expand Down

0 comments on commit 786b782

Please sign in to comment.