@@ -1346,6 +1346,60 @@ public function seeCurrentActionIs(string $action): void
1346
1346
$ this ->fail ("Action ' $ action' does not exist " );
1347
1347
}
1348
1348
1349
+ /**
1350
+ * Verifies that multiple fields on a form have errors.
1351
+ *
1352
+ * If you only specify the name of the fields, this method will
1353
+ * verify that the field contains at least one error of any type:
1354
+ *
1355
+ * ``` php
1356
+ * <?php
1357
+ * $I->seeFormErrorMessages(['telephone', 'address']);
1358
+ * ```
1359
+ *
1360
+ * If you want to specify the error messages, you can do so
1361
+ * by sending an associative array instead, with the key being
1362
+ * the name of the field and the error message the value.
1363
+ *
1364
+ * This method will validate that the expected error message
1365
+ * is contained in the actual error message, that is,
1366
+ * you can specify either the entire error message or just a part of it:
1367
+ *
1368
+ * ``` php
1369
+ * <?php
1370
+ * $I->seeFormErrorMessages([
1371
+ * 'address' => 'The address is too long'
1372
+ * 'telephone' => 'too short', // the full error message is 'The telephone is too short'
1373
+ * ]);
1374
+ * ```
1375
+ *
1376
+ * If you don't want to specify the error message for some fields,
1377
+ * you can pass `null` as value instead of the message string,
1378
+ * or you can directly omit the value of that field. If that is the case,
1379
+ * it will be validated that that field has at least one error of any type:
1380
+ *
1381
+ * ``` php
1382
+ * <?php
1383
+ * $I->seeFormErrorMessages([
1384
+ * 'telephone' => 'too short',
1385
+ * 'address' => null,
1386
+ * 'postal code',
1387
+ * ]);
1388
+ * ```
1389
+ *
1390
+ * @param string[] $expectedErrors
1391
+ */
1392
+ public function seeFormErrorMessages (array $ expectedErrors ): void
1393
+ {
1394
+ foreach ($ expectedErrors as $ field => $ message ) {
1395
+ if (is_int ($ field )) {
1396
+ $ this ->seeFormErrorMessage ($ message );
1397
+ } else {
1398
+ $ this ->seeFormErrorMessage ($ field , $ message );
1399
+ }
1400
+ }
1401
+ }
1402
+
1349
1403
/**
1350
1404
* Verifies that a form field has an error.
1351
1405
* You can specify the expected error message as second parameter.
0 commit comments