1313use Inertia \AlwaysProp ;
1414use Inertia \Inertia ;
1515use Inertia \Middleware ;
16+ use Inertia \Tests \Stubs \ArrayErrorsMiddleware ;
1617use Inertia \Tests \Stubs \CustomUrlResolverMiddleware ;
1718use Inertia \Tests \Stubs \ExampleMiddleware ;
1819use LogicException ;
@@ -168,11 +169,11 @@ public function test_validation_errors_can_be_empty(): void
168169 $ this ->withoutExceptionHandling ()->get ('/ ' );
169170 }
170171
171- public function test_validation_errors_are_returned_in_the_correct_format (): void
172+ public function test_validation_errors_are_mapped_to_strings_by_default (): void
172173 {
173174 Session::put ('errors ' , (new ViewErrorBag )->put ('default ' , new MessageBag ([
174- 'name ' => 'The name field is required. ' ,
175- 'email ' => 'Not a valid email address. ' ,
175+ 'name ' => [ 'The name field is required. ' ] ,
176+ 'email ' => [ 'Not a valid email address. ' , ' Another email error. ' ] ,
176177 ])));
177178
178179 Route::middleware ([StartSession::class, ExampleMiddleware::class])->get ('/ ' , function () {
@@ -186,6 +187,27 @@ public function test_validation_errors_are_returned_in_the_correct_format(): voi
186187 $ this ->withoutExceptionHandling ()->get ('/ ' );
187188 }
188189
190+ public function test_validation_errors_can_remain_multiple_per_field (): void
191+ {
192+ Session::put ('errors ' , (new ViewErrorBag )->put ('default ' , new MessageBag ([
193+ 'name ' => ['The name field is required. ' ],
194+ 'email ' => ['Not a valid email address. ' , 'Another email error. ' ],
195+ ])));
196+
197+ Route::middleware ([StartSession::class, ArrayErrorsMiddleware::class])->get ('/ ' , function () {
198+ $ errors = Inertia::getShared ('errors ' )();
199+
200+ $ this ->assertIsObject ($ errors );
201+ $ this ->assertSame (['The name field is required. ' ], $ errors ->name );
202+ $ this ->assertSame (
203+ ['Not a valid email address. ' , 'Another email error. ' ],
204+ $ errors ->email
205+ );
206+ });
207+
208+ $ this ->withoutExceptionHandling ()->get ('/ ' );
209+ }
210+
189211 public function test_validation_errors_with_named_error_bags_are_scoped (): void
190212 {
191213 Session::put ('errors ' , (new ViewErrorBag )->put ('example ' , new MessageBag ([
0 commit comments