Skip to content

Commit ddd38a0

Browse files
bug symfony#50654 [Validator] Add the message option to the PasswordStrength constraint (alexandre-daubois)
This PR was merged into the 6.3 branch. Discussion ---------- [Validator] Add the `message` option to the `PasswordStrength` constraint | Q | A | ------------- | --- | Branch? | 6.3 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix symfony#50651 | License | MIT | Doc PR | No need Commits ------- 2eed59d [Validator] Add the `message` option to the `PasswordStrength` constraint
2 parents ad04747 + 2eed59d commit ddd38a0

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

src/Symfony/Component/Validator/Constraints/PasswordStrength.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,14 @@ final class PasswordStrength extends Constraint
4040

4141
public int $minScore;
4242

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

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

4949
$this->minScore = $minScore ?? $this->minScore;
50+
$this->message = $message ?? $this->message;
5051

5152
if ($this->minScore < 1 || 4 < $this->minScore) {
5253
throw new ConstraintDefinitionException(sprintf('The parameter "minScore" of the "%s" constraint must be an integer between 1 and 4.', self::class));

src/Symfony/Component/Validator/Tests/Constraints/PasswordStrengthTest.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@ public function testConstructor()
2525

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

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

3334
public function testInvalidScoreOfZero()

src/Symfony/Component/Validator/Tests/Constraints/PasswordStrengthValidatorTest.php

+6
Original file line numberDiff line numberDiff line change
@@ -77,5 +77,11 @@ public static function provideInvalidConstraints(): iterable
7777
'The password strength is too low. Please use a stronger password.',
7878
PasswordStrength::PASSWORD_STRENGTH_ERROR,
7979
];
80+
yield [
81+
new PasswordStrength(message: 'This password should be strong.'),
82+
'password',
83+
'This password should be strong.',
84+
PasswordStrength::PASSWORD_STRENGTH_ERROR,
85+
];
8086
}
8187
}

0 commit comments

Comments
 (0)