Skip to content

Commit 2eed59d

Browse files
[Validator] Add the message option to the PasswordStrength constraint
1 parent 5b66f26 commit 2eed59d

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 6 additions & 0 deletions
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy