From 4fbb54b3e43d1ed3302a671058f9c6f2b8beb86e Mon Sep 17 00:00:00 2001 From: Roberto Aguilar Date: Wed, 7 Feb 2018 15:14:53 -0600 Subject: [PATCH] Improve session errors assertions (#23055) In the previous implementation of `TestResponse::assertSessionHasErrors` i found that was not possible to find errors that had an integer key. This was happening because if the assertion detected that the key was an integer, it was sending the error value to the `MessageBag::has` method, which was incorrect because that method uses the key to determine if there is any messages for it. --- src/Illuminate/Foundation/Testing/TestResponse.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Illuminate/Foundation/Testing/TestResponse.php b/src/Illuminate/Foundation/Testing/TestResponse.php index 6c1f9fd67fab..9f2a98f0c7ff 100644 --- a/src/Illuminate/Foundation/Testing/TestResponse.php +++ b/src/Illuminate/Foundation/Testing/TestResponse.php @@ -746,8 +746,8 @@ public function assertSessionHasErrors($keys = [], $format = null, $errorBag = ' $errors = app('session.store')->get('errors')->getBag($errorBag); foreach ($keys as $key => $value) { - if (is_int($key)) { - PHPUnit::assertTrue($errors->has($value), "Session missing error: $value"); + if (is_array($value)) { + PHPUnit::assertArraySubset($value, $errors->get($key, $format)); } else { PHPUnit::assertContains($value, $errors->get($key, $format)); }