Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions src/Illuminate/Foundation/Testing/TestResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,26 @@ public function assertDontSeeText($value)
return $this;
}

/**
* Assert that the response has validation errors for the given keys.
*
* @param string|array $keys
* @return $this
*/
public function assertValidationErrors($keys)
{
$errors = $this->json()['errors'];

foreach (array_wrap($keys) as $key) {
PHPUnit::assertTrue(
isset($errors[$key]),
"Failed to find a validation error in the response for key: '{$key}'"
);
}

return $this;
}

/**
* Assert that the response is a superset of the given JSON.
*
Expand All @@ -293,6 +313,32 @@ public function assertJson(array $data, $strict = false)
return $this;
}

/**
* Assert that the response json has the expected count.
*
* @param int $count
* @param string|null $key
* @return $this
*/
public function assertJsonCount(int $count, $key = null)
{
if ($key) {
PHPUnit::assertCount($count,
$this->json()[$key],
"Failed to assert that the response count matched the expected {$count}"
);

return $this;
}

PHPUnit::assertCount($count,
$this->json(),
"Failed to assert that the response count matched the expected {$count}"
);

return $this;
}

/**
* Get the assertion message for assertJson.
*
Expand Down