File tree Expand file tree Collapse file tree 2 files changed +34
-1
lines changed
src/Illuminate/Validation Expand file tree Collapse file tree 2 files changed +34
-1
lines changed Original file line number Diff line number Diff line change @@ -577,7 +577,11 @@ public function safe(array $keys = null)
577
577
*/
578
578
public function validated ()
579
579
{
580
- throw_if ($ this ->invalid (), $ this ->exception , $ this );
580
+ if (! $ this ->messages ) {
581
+ $ this ->passes ();
582
+ }
583
+
584
+ throw_if ($ this ->messages ->isNotEmpty (), $ this ->exception , $ this );
581
585
582
586
$ results = [];
583
587
Original file line number Diff line number Diff line change @@ -167,6 +167,35 @@ public function testValidateDoesntThrowOnPass()
167
167
$ this ->assertSame (['foo ' => 'bar ' ], $ v ->validate ());
168
168
}
169
169
170
+ public function testValidatedThrowsOnFail ()
171
+ {
172
+ $ this ->expectException (ValidationException::class);
173
+
174
+ $ trans = $ this ->getIlluminateArrayTranslator ();
175
+ $ v = new Validator ($ trans , ['foo ' => 'bar ' ], ['baz ' => 'required ' ]);
176
+
177
+ $ v ->validated ();
178
+ }
179
+
180
+ public function testValidatedThrowsOnFailEvenAfterPassesCall ()
181
+ {
182
+ $ this ->expectException (ValidationException::class);
183
+
184
+ $ trans = $ this ->getIlluminateArrayTranslator ();
185
+ $ v = new Validator ($ trans , ['foo ' => 'bar ' ], ['baz ' => 'required ' ]);
186
+
187
+ $ v ->passes ();
188
+ $ v ->validated ();
189
+ }
190
+
191
+ public function testValidatedDoesntThrowOnPass ()
192
+ {
193
+ $ trans = $ this ->getIlluminateArrayTranslator ();
194
+ $ v = new Validator ($ trans , ['foo ' => 'bar ' ], ['foo ' => 'required ' ]);
195
+
196
+ $ this ->assertSame (['foo ' => 'bar ' ], $ v ->validated ());
197
+ }
198
+
170
199
public function testHasFailedValidationRules ()
171
200
{
172
201
$ trans = $ this ->getIlluminateArrayTranslator ();
You can’t perform that action at this time.
0 commit comments