Skip to content

Added seeFormErrorMessages function #67

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 20, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions src/Codeception/Module/Symfony.php
Original file line number Diff line number Diff line change
Expand Up @@ -1346,6 +1346,60 @@ public function seeCurrentActionIs(string $action): void
$this->fail("Action '$action' does not exist");
}

/**
* Verifies that multiple fields on a form have errors.
*
* If you only specify the name of the fields, this method will
* verify that the field contains at least one error of any type:
*
* ``` php
* <?php
* $I->seeFormErrorMessages(['telephone', 'address']);
* ```
*
* If you want to specify the error messages, you can do so
* by sending an associative array instead, with the key being
* the name of the field and the error message the value.
*
* This method will validate that the expected error message
* is contained in the actual error message, that is,
* you can specify either the entire error message or just a part of it:
*
* ``` php
* <?php
* $I->seeFormErrorMessages([
* 'address' => 'The address is too long'
* 'telephone' => 'too short', // the full error message is 'The telephone is too short'
* ]);
* ```
*
* If you don't want to specify the error message for some fields,
* you can pass `null` as value instead of the message string,
* or you can directly omit the value of that field. If that is the case,
* it will be validated that that field has at least one error of any type:
*
* ``` php
* <?php
* $I->seeFormErrorMessages([
* 'telephone' => 'too short',
* 'address' => null,
* 'postal code',
* ]);
* ```
*
* @param string[] $expectedErrors
*/
public function seeFormErrorMessages(array $expectedErrors): void
{
foreach ($expectedErrors as $field => $message) {
if (is_int($field)) {
$this->seeFormErrorMessage($message);
} else {
$this->seeFormErrorMessage($field, $message);
}
}
}

/**
* Verifies that a form field has an error.
* You can specify the expected error message as second parameter.
Expand Down