Skip to content

Commit

Permalink
Wrap errors, and allow no arguments (laravel#38422)
Browse files Browse the repository at this point in the history
  • Loading branch information
dwightwatson authored and victorvilella committed Oct 12, 2021
1 parent d4e2e12 commit 84761da
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Illuminate/Testing/TestResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -1073,7 +1073,7 @@ public function assertValid($keys = null, $errorBag = 'default', $responseKey =
* @param string $responseKey
* @return $this
*/
public function assertInvalid($errors,
public function assertInvalid($errors = null,
$errorBag = 'default',
$responseKey = 'errors')
{
Expand All @@ -1092,7 +1092,7 @@ public function assertInvalid($errors,
PHP_EOL.PHP_EOL.json_encode($sessionErrors, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE).PHP_EOL
: 'Response does not have validation errors in the session.';

foreach ($errors as $key => $value) {
foreach (Arr::wrap($errors) as $key => $value) {
PHPUnit::assertArrayHasKey(
(is_int($key)) ? $value : $key,
$sessionErrors,
Expand Down
4 changes: 4 additions & 0 deletions tests/Testing/TestResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -947,7 +947,11 @@ public function testAssertSessionValidationErrorsUsingAssertInvalid()

$testResponse = TestResponse::fromBaseResponse(new Response);

$testResponse->assertValid('last_name');
$testResponse->assertValid(['last_name']);

$testResponse->assertInvalid();
$testResponse->assertInvalid('first_name');
$testResponse->assertInvalid(['first_name']);
$testResponse->assertInvalid(['first_name' => 'required']);
$testResponse->assertInvalid(['first_name' => 'character']);
Expand Down

0 comments on commit 84761da

Please sign in to comment.