Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8e96a98

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

File tree

4 files changed

+15
-2
lines changed

4 files changed

+15
-2
lines changed

src/Symfony/Component/Validator/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
6.4
5+
---
6+
7+
* Add the `message` option to the `PasswordStrength` constraint
8+
49
6.3
510
---
611

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)