Skip to content

Commit

Permalink
detect wrong e-mail validation modes
Browse files Browse the repository at this point in the history
  • Loading branch information
xabbuh committed Apr 27, 2024
1 parent f241871 commit 8a2f9f7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Constraints/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ public function __construct(
throw new InvalidArgumentException('The "mode" parameter value is not valid.');
}

if (null !== $mode && !\in_array($mode, self::$validationModes, true)) {
throw new InvalidArgumentException('The "mode" parameter value is not valid.');
}

parent::__construct($options, $groups, $payload);

$this->message = $message ?? $this->message;
Expand Down
7 changes: 7 additions & 0 deletions Tests/Constraints/EmailTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ public function testUnknownModesTriggerException()
new Email(['mode' => 'Unknown Mode']);
}

public function testUnknownModeArgumentsTriggerException()
{
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('The "mode" parameter value is not valid.');
new Email(null, null, 'Unknown Mode');
}

public function testNormalizerCanBeSet()
{
$email = new Email(['normalizer' => 'trim']);
Expand Down

0 comments on commit 8a2f9f7

Please sign in to comment.