8000 test : add specific closure in the PasswordStrengthValidatorWithClosu… · symfony/symfony@36f7f44 · GitHub
[go: up one dir, main page]

Skip to content

Commit 36f7f44

Browse files
committed
test : add specific closure in the PasswordStrengthValidatorWithClosureTest
1 parent 4b82938 commit 36f7f44

File tree

1 file changed

+23
-12
lines changed

1 file changed

+23
-12
lines changed

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

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,26 @@
1616
use Symfony\Component\Validator\Test\ConstraintValidatorTestCase;
1717
use Symfony\Component\Validator\Tests\Constraints\Fixtures\StringableValue;
1818

19-
/**
20-
* @group legacy
21-
*/
2219
class PasswordStrengthValidatorWithClosureTest extends ConstraintValidatorTestCase
2320
{
2421
protected function createValidator(): PasswordStrengthValidator
2522
{
26-
return new PasswordStrengthValidator(PasswordStrengthValidator::estimateStrength(...));
23+
return new PasswordStrengthValidator(function (string $value) {
24+
$length = strlen($value);
25+
if ($length < 6) {
26+
return PasswordStrength::STRENGTH_VERY_WEAK;
27+
}
28+
if ($length < 10) {
29+
return PasswordStrength::STRENGTH_WEAK;
30+
}
31+
if ($length < 15) {
32+
return PasswordStrength::STRENGTH_MEDIUM;
33+
}
34+
if ($length < 20) {
35+
return PasswordStrength::STRENGTH_STRONG;
36+
}
37+
return PasswordStrength::STRENGTH_VERY_STRONG;
38+
});
2739
}
2840

2941
/**
@@ -49,11 +61,10 @@ public function testValidValues(string|\Stringable $value, int $expectedStrength
4961

5062
public static function getValidValues(): iterable
5163
{
52-
yield ['How-is-this', PasswordStrength::STRENGTH_WEAK];
53-
yield ['Reasonable-pwd', PasswordStrength::STRENGTH_MEDIUM];
54-
yield ['This 1s a very g00d Pa55word! ;-)', PasswordStrength::STRENGTH_VERY_STRONG];
55-
yield ['pudding-smack-👌🏼-fox-😎', PasswordStrength::STRENGTH_VERY_STRONG];
56-
yield [new StringableValue('How-is-this'), PasswordStrength::STRENGTH_WEAK];
64+
yield ['az34tyu', PasswordStrength::STRENGTH_WEAK];
65+
yield ['A med1um one', PasswordStrength::STRENGTH_MEDIUM];
66+
yield ['a str0ng3r one doh', PasswordStrength::STRENGTH_STRONG];
67+
yield [new StringableValue('HeloW0rld'), PasswordStrength::STRENGTH_WEAK];
5768
}
5869

5970
/**
@@ -78,21 +89,21 @@ public static function provideInvalidConstraints(): iterable
7889
'password',
7990
'The password strength is too low. Please use a stronger password.',
8091
PasswordStrength::PASSWORD_STRENGTH_ERROR,
81-
'0',
92+
(string) PasswordStrength::STRENGTH_WEAK,
8293
];
8394
yield [
8495
new PasswordStrength(minScore: PasswordStrength::STRENGTH_VERY_STRONG),
8596
'Good password?',
8697
'The password strength is too low. Please use a stronger password.',
8798
PasswordStrength::PASSWORD_STRENGTH_ERROR,
88-
'1',
99+
(string) PasswordStrength::STRENGTH_MEDIUM,
89100
];
90101
yield [
91102
new PasswordStrength(message: 'This password should be strong.'),
92103
'password',
93104
'This password should be strong.',
94105
PasswordStrength::PASSWORD_STRENGTH_ERROR,
95-
'0',
106+
(string) PasswordStrength::STRENGTH_WEAK,
96107
];
97108
}
98109
}

0 commit comments

Comments
 (0)
0