11
11
12
12
namespace Symfony \Component \Security \Core \Tests \Validator \Constraints ;
13
13
14
+ use Symfony \Component \PasswordHasher \Hasher \PasswordHasherFactoryInterface ;
15
+ use Symfony \Component \PasswordHasher \PasswordHasherInterface ;
14
16
use Symfony \Component \Security \Core \Authentication \Token \Storage \TokenStorageInterface ;
15
17
use Symfony \Component \Security \Core \Authentication \Token \TokenInterface ;
16
- use Symfony \Component \Security \Core \Encoder \EncoderFactoryInterface ;
17
- use Symfony \Component \Security \Core \Encoder \PasswordEncoderInterface ;
18
18
use Symfony \Component \Security \Core \User \UserInterface ;
19
19
use Symfony \Component \Security \Core \Validator \Constraints \UserPassword ;
20
20
use Symfony \Component \Security \Core \Validator \Constraints \UserPasswordValidator ;
24
24
/**
25
25
* @author Bernhard Schussek <bschussek@gmail.com>
26
26
*/
27
- class UserPasswordValidatorTest extends ConstraintValidatorTestCase
27
+ abstract class UserPasswordValidatorTest extends ConstraintValidatorTestCase
28
28
{
29
29
private const PASSWORD = 's3Cr3t ' ;
30
30
private const SALT = '^S4lt$ ' ;
@@ -35,26 +35,26 @@ class UserPasswordValidatorTest extends ConstraintValidatorTestCase
35
35
protected $ tokenStorage ;
36
36
37
37
/**
38
- * @var PasswordEncoderInterface
38
+ * @var PasswordHasherInterface
39
39
*/
40
- protected $ encoder ;
40
+ protected $ hasher ;
41
41
42
42
/**
43
- * @var EncoderFactoryInterface
43
+ * @var PasswordHasherFactoryInterface
44
44
*/
45
- protected $ encoderFactory ;
45
+ protected $ hasherFactory ;
46
46
47
47
protected function createValidator ()
48
48
{
49
- return new UserPasswordValidator ($ this ->tokenStorage , $ this ->encoderFactory );
49
+ return new UserPasswordValidator ($ this ->tokenStorage , $ this ->hasherFactory );
50
50
}
51
51
52
52
protected function setUp (): void
53
53
{
54
54
$ user = $ this ->createUser ();
55
55
$ this ->tokenStorage = $ this ->createTokenStorage ($ user );
56
- $ this ->encoder = $ this ->createMock (PasswordEncoderInterface ::class);
57
- $ this ->encoderFactory = $ this ->createEncoderFactory ($ this ->encoder );
56
+ $ this ->hasher = $ this ->createMock (PasswordHasherInterface ::class);
57
+ $ this ->hasherFactory = $ this ->createHasherFactory ($ this ->hasher );
58
58
59
59
parent ::setUp ();
60
60
}
@@ -64,7 +64,7 @@ protected function setUp(): void
64
64
*/
65
65
public function testPasswordIsValid (UserPassword $ constraint )
66
66
{
67
- $ this ->encoder ->expects ($ this ->once ())
67
+ $ this ->hasher ->expects ($ this ->once ())
68
68
->method ('isPasswordValid ' )
69
69
->with (static ::PASSWORD , 'secret ' , static ::SALT )
70
70
->willReturn (true );
@@ -79,7 +79,7 @@ public function testPasswordIsValid(UserPassword $constraint)
79
79
*/
80
80
public function testPasswordIsNotValid (UserPassword $ constraint )
81
81
{
82
- $ this ->encoder ->expects ($ this ->once ())
82
+ $ this ->hasher ->expects ($ this ->once ())
83
83
->method ('isPasswordValid ' )
84
84
->with (static ::PASSWORD , 'secret ' , static ::SALT )
85
85
->willReturn (false );
@@ -94,9 +94,7 @@ public function provideConstraints(): iterable
94
94
{
95
95
yield 'Doctrine style ' => [new UserPassword (['message ' => 'myMessage ' ])];
96
96
97
- if (\PHP_VERSION_ID >= 80000 ) {
98
- yield 'named arguments ' => [eval ('return new \Symfony\Component\Security\Core\Validator\Constraints\UserPassword(message: "myMessage"); ' )];
99
- }
97
+ yield 'named arguments ' => [new UserPassword (message: "myMessage " )];
100
98
}
101
99
102
100
/**
@@ -153,14 +151,14 @@ protected function createUser()
153
151
return $ mock ;
154
152
}
155
153
156
- protected function createEncoderFactory ( $ encoder = null )
154
+ protected function createHasherFactory ( $ hasher = null )
157
155
{
158
- $ mock = $ this ->createMock (EncoderFactoryInterface ::class);
156
+ $ mock = $ this ->createMock (PasswordHasherFactoryInterface ::class);
159
157
160
158
$ mock
161
159
->expects ($ this ->any ())
162
- ->method ('getEncoder ' )
163
- ->willReturn ($ encoder )
160
+ ->method ('getPasswordHasher ' )
161
+ ->willReturn ($ hasher )
164
162
;
165
163
166
164
return $ mock ;
0 commit comments