Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[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.
Loading
Diff view
Diff view
[Validator] Add the message option to the PasswordStrength constr…
…aint
  • Loading branch information
alexandre-daubois committed Jun 13, 2023
commit 2eed59db0d5297f9b29227b3929b516f4de0e11c
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,
];
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.