From b597cccaea6b9d8250a6a07e6127fbe2d1ed488e Mon Sep 17 00:00:00 2001 From: Dwight Watson Date: Wed, 18 Aug 2021 11:23:41 +1000 Subject: [PATCH] Wrap errors, and allow no arguments --- src/Illuminate/Testing/TestResponse.php | 4 ++-- tests/Testing/TestResponseTest.php | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Illuminate/Testing/TestResponse.php b/src/Illuminate/Testing/TestResponse.php index 9e2db201ce20..bfd120036e23 100644 --- a/src/Illuminate/Testing/TestResponse.php +++ b/src/Illuminate/Testing/TestResponse.php @@ -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') { @@ -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, diff --git a/tests/Testing/TestResponseTest.php b/tests/Testing/TestResponseTest.php index fe5cac6699a2..3e0f82076901 100644 --- a/tests/Testing/TestResponseTest.php +++ b/tests/Testing/TestResponseTest.php @@ -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']);