@@ -75,26 +75,40 @@ public function test_validation_errors_are_not_registered_when_already_registere
75
75
$ this ->assertSame ('This is a validation error ' , Inertia::getShared ('errors ' ));
76
76
}
77
77
78
- public function test_validation_errors_can_be_an_array ()
78
+ public function basicValidationErrorsProvider ()
79
79
{
80
- Session::put ('errors ' , [
80
+ $ array = [
81
+ 'name ' => 'The name field is required. ' ,
82
+ 'email ' => [
83
+ 'The email must be a valid email address. ' ,
84
+ ],
85
+ ];
86
+
87
+ $ messageBag = new MessageBag ([
81
88
'name ' => 'The name field is required. ' ,
82
89
'email ' => 'The email must be a valid email address. ' ,
83
90
]);
84
91
85
- $ errors = Inertia::getShared ('errors ' )();
92
+ $ viewErrorBag = (new ViewErrorBag ())->put ('default ' , new MessageBag ([
93
+ 'name ' => [
94
+ 'The name field is required. ' ,
95
+ ],
96
+ 'email ' => 'The email must be a valid email address. ' ,
97
+ ]));
86
98
87
- $ this ->assertIsObject ($ errors );
88
- $ this ->assertSame ('The name field is required. ' , $ errors ->name );
89
- $ this ->assertSame ('The email must be a valid email address. ' , $ errors ->email );
99
+ return [
100
+ [$ array ],
101
+ [$ messageBag ],
102
+ [$ viewErrorBag ],
103
+ ];
90
104
}
91
105
92
- public function test_validation_exceptions_can_be_a_message_bag ()
106
+ /**
107
+ * @dataProvider basicValidationErrorsProvider
108
+ */
109
+ public function test_validation_errors_are_returned_in_the_correct_format ($ errors )
93
110
{
94
- Session::put ('errors ' , new MessageBag ([
95
- 'name ' => 'The name field is required. ' ,
96
- 'email ' => 'The email must be a valid email address. ' ,
97
- ]));
111
+ Session::put ('errors ' , $ errors );
98
112
99
113
$ errors = Inertia::getShared ('errors ' )();
100
114
@@ -103,26 +117,44 @@ public function test_validation_exceptions_can_be_a_message_bag()
103
117
$ this ->assertSame ('The email must be a valid email address. ' , $ errors ->email );
104
118
}
105
119
106
- public function test_validation_exceptions_can_be_an_error_bag ()
120
+ public function multipleErrorBagsValidationErrorsProvider ()
107
121
{
108
- Session::put ('errors ' , (new ViewErrorBag ())->put ('default ' , new MessageBag ([
109
- 'name ' => 'The name field is required. ' ,
110
- 'email ' => 'The email must be a valid email address. ' ,
111
- ])));
112
-
113
- $ errors = Inertia::getShared ('errors ' )();
114
-
115
- $ this ->assertIsObject ($ errors );
116
- $ this ->assertSame ('The name field is required. ' , $ errors ->name );
117
- $ this ->assertSame ('The email must be a valid email address. ' , $ errors ->email );
122
+ $ array = [
123
+ 'default ' => [
124
+ 'name ' => [
125
+ 'The name field is required. ' ,
126
+ ],
127
+ 'email ' => 'The email must be a valid email address. ' ,
128
+ ],
129
+ 'example ' => [
130
+ 'name ' => 'The name field is required. ' ,
131
+ 'email ' => 'The email must be a valid email address. ' ,
132
+ ],
133
+ ];
134
+
135
+ $ viewErrorBag = tap (new ViewErrorBag (), function ($ errorBag ) {
136
+ $ errorBag ->put ('default ' , new MessageBag ([
137
+ 'name ' => 'The name field is required. ' ,
138
+ 'email ' => 'The email must be a valid email address. ' ,
139
+ ]));
140
+ $ errorBag ->put ('example ' , new MessageBag ([
141
+ 'name ' => 'The name field is required. ' ,
142
+ 'email ' => [
143
+ 'The email must be a valid email address. ' ,
144
+ ],
145
+ ]));
146
+ });
147
+
148
+ return [
149
+ [$ array ],
150
+ [$ viewErrorBag ],
151
+ ];
118
152
}
119
153
120
- public function test_validation_exceptions_can_be_multiple_error_bags ()
154
+ /** @dataProvider multipleErrorBagsValidationErrorsProvider */
155
+ public function test_validation_exceptions_can_have_multiple_error_bags ($ errors )
121
156
{
122
- Session::put ('errors ' , tap (new ViewErrorBag (), function ($ errorBags ) {
123
- $ errorBags ->put ('default ' , new MessageBag (['name ' => 'The name field is required. ' ]));
124
- $ errorBags ->put ('example ' , new MessageBag (['email ' => 'The email must be a valid email address. ' ]));
125
- }));
157
+ Session::put ('errors ' , $ errors );
126
158
127
159
$ errors = Inertia::getShared ('errors ' )();
128
160
0 commit comments