8000 [Validator] Add the `message` option to the `PasswordStrength` constraint by alexandre-daubois · Pull Request #50654 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Validator] Add the message option to the PasswordStrength constraint #50654

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
Show file tree
Hide file tree
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.
10000 Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,14 @@ final class PasswordStrength extends Constraint

public int $minScore;

public function __construct(array $options = null, int $minScore = null, array $groups = null, mixed $payload = null)
public function __construct(array $options = null, int $minScore = null, array $groups = null, mixed $payload = null, string $message = null)
{
$options['minScore'] ??= self::STRENGTH_MEDIUM;

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

$this->minScore = $minScore ?? $this->minScore;
$this->message = $message ?? $this->message;

if ($this->minScore < 1 || 4 < $this->minScore) {
throw new ConstraintDefinitionException(sprintf('The parameter "minScore" of the "%s" constraint must be an integer between 1 and 4.', self::class));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ public function testConstructor()

public function testConstructorWithParameters()
{
$constraint = new PasswordStrength(minScore: PasswordStrength::STRENGTH_STRONG);
$constraint = new PasswordStrength(minScore: PasswordStrength::STRENGTH_STRONG, message: 'This password should be strong.');

$this->assertSame(PasswordStrength::STRENGTH_STRONG, $constraint->minScore);
$this->assertSame('This password should be strong.', $constraint->message);
}

public function testInvalidScoreOfZero()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,11 @@ public static function provideInvalidConstraints(): iterable
'The password strength is too low. Please use a stronger password.',
PasswordStrength::PASSWORD_STRENGTH_ERROR,
];
yield [
new PasswordStrength(message: 'This password should be strong.'),
'password',
'This password should be strong.',
PasswordStrength::PASSWORD_STRENGTH_ERROR,
];
}
}
0