|
15 | 15 | - [Available Assertions](#available-assertions)
|
16 | 16 | - [Response Assertions](#response-assertions)
|
17 | 17 | - [Authentication Assertions](#authentication-assertions)
|
| 18 | + - [Validation Assertions](#validation-assertions) |
18 | 19 |
|
19 | 20 | <a name="introduction"></a>
|
20 | 21 | ## Introduction
|
@@ -1287,3 +1288,33 @@ Assert that a user is not authenticated:
|
1287 | 1288 | Assert that a specific user is authenticated:
|
1288 | 1289 |
|
1289 | 1290 | $this->assertAuthenticatedAs($user, $guard = null);
|
| 1291 | + |
| 1292 | +<a name="validation-assertions"></a> |
| 1293 | +## Validation Assertions |
| 1294 | + |
| 1295 | +Laravel provides two primary validation related assertions that you may use to ensure the data provided in your request was either valid or invalid. |
| 1296 | + |
| 1297 | +<a name="validation-assert-valid"></a> |
| 1298 | +#### assertValid |
| 1299 | + |
| 1300 | +Assert that the response has no validation errors for the given keys. This method may be used for asserting against responses where the validation errors are returned as a JSON structure or where the validation errors have been flashed to the session: |
| 1301 | + |
| 1302 | + // Assert that no validation errors are present... |
| 1303 | + $response->assertValid(); |
| 1304 | + |
| 1305 | + // Assert that the given keys do not have validation errors... |
| 1306 | + $response->assertValid(['name', 'email']); |
| 1307 | + |
| 1308 | +<a name="validation-assert-invalid"></a> |
| 1309 | +#### assertInvalid |
| 1310 | + |
| 1311 | +Assert that the response has validation errors for the given keys. This method may be used for asserting against responses where the validation errors are returned as a JSON structure or where the validation errors have been flashed to the session: |
| 1312 | + |
| 1313 | + $response->assertInvalid(['name', 'email']); |
| 1314 | + |
| 1315 | +You may also assert that a given key has a particular validation error message. When doing so, you may provide the entire message or only a small portion of the message: |
| 1316 | + |
| 1317 | + $response->assertInvalid([ |
| 1318 | + 'name' => 'The name field is required.', |
| 1319 | + 'email' => 'valid email address', |
| 1320 | + ]); |
0 commit comments