Skip to content

Commit ed4f354

Browse files
authored
Wrap errors, and allow no arguments (#38422)
1 parent 9e9bdaf commit ed4f354

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/Illuminate/Testing/TestResponse.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,7 +1073,7 @@ public function assertValid($keys = null, $errorBag = 'default', $responseKey =
10731073
* @param string $responseKey
10741074
* @return $this
10751075
*/
1076-
public function assertInvalid($errors,
1076+
public function assertInvalid($errors = null,
10771077
$errorBag = 'default',
10781078
$responseKey = 'errors')
10791079
{
@@ -1092,7 +1092,7 @@ public function assertInvalid($errors,
10921092
PHP_EOL.PHP_EOL.json_encode($sessionErrors, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE).PHP_EOL
10931093
: 'Response does not have validation errors in the session.';
10941094

1095-
foreach ($errors as $key => $value) {
1095+
foreach (Arr::wrap($errors) as $key => $value) {
10961096
PHPUnit::assertArrayHasKey(
10971097
(is_int($key)) ? $value : $key,
10981098
$sessionErrors,

tests/Testing/TestResponseTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -947,7 +947,11 @@ public function testAssertSessionValidationErrorsUsingAssertInvalid()
947947

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

950+
$testResponse->assertValid('last_name');
950951
$testResponse->assertValid(['last_name']);
952+
953+
$testResponse->assertInvalid();
954+
$testResponse->assertInvalid('first_name');
951955
$testResponse->assertInvalid(['first_name']);
952956
$testResponse->assertInvalid(['first_name' => 'required']);
953957
$testResponse->assertInvalid(['first_name' => 'character']);

0 commit comments

Comments
 (0)