Skip to content

Commit 6c60332

Browse files
committed
Fix test
1 parent 073ef99 commit 6c60332

File tree

1 file changed

+17
-19
lines changed

1 file changed

+17
-19
lines changed

Tests/Validator/Constraints/UserPasswordValidatorTest.php

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111

1212
namespace Symfony\Component\Security\Core\Tests\Validator\Constraints;
1313

14+
use Symfony\Component\PasswordHasher\Hasher\PasswordHasherFactoryInterface;
15+
use Symfony\Component\PasswordHasher\PasswordHasherInterface;
1416
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
1517
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
16-
use Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface;
17-
use Symfony\Component\Security\Core\Encoder\PasswordEncoderInterface;
1818
use Symfony\Component\Security\Core\User\UserInterface;
1919
use Symfony\Component\Security\Core\Validator\Constraints\UserPassword;
2020
use Symfony\Component\Security\Core\Validator\Constraints\UserPasswordValidator;
@@ -24,7 +24,7 @@
2424
/**
2525
* @author Bernhard Schussek <bschussek@gmail.com>
2626
*/
27-
class UserPasswordValidatorTest extends ConstraintValidatorTestCase
27+
abstract class UserPasswordValidatorTest extends ConstraintValidatorTestCase
2828
{
2929
private const PASSWORD = 's3Cr3t';
3030
private const SALT = '^S4lt$';
@@ -35,26 +35,26 @@ class UserPasswordValidatorTest extends ConstraintValidatorTestCase
3535
protected $tokenStorage;
3636

3737
/**
38-
* @var PasswordEncoderInterface
38+
* @var PasswordHasherInterface
3939
*/
40-
protected $encoder;
40+
protected $hasher;
4141

4242
/**
43-
* @var EncoderFactoryInterface
43+
* @var PasswordHasherFactoryInterface
4444
*/
45-
protected $encoderFactory;
45+
protected $hasherFactory;
4646

4747
protected function createValidator()
4848
{
49-
return new UserPasswordValidator($this->tokenStorage, $this->encoderFactory);
49+
return new UserPasswordValidator($this->tokenStorage, $this->hasherFactory);
5050
}
5151

5252
protected function setUp(): void
5353
{
5454
$user = $this->createUser();
5555
$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);
5858

5959
parent::setUp();
6060
}
@@ -64,7 +64,7 @@ protected function setUp(): void
6464
*/
6565
public function testPasswordIsValid(UserPassword $constraint)
6666
{
67-
$this->encoder->expects($this->once())
67+
$this->hasher->expects($this->once())
6868
->method('isPasswordValid')
6969
->with(static::PASSWORD, 'secret', static::SALT)
7070
->willReturn(true);
@@ -79,7 +79,7 @@ public function testPasswordIsValid(UserPassword $constraint)
7979
*/
8080
public function testPasswordIsNotValid(UserPassword $constraint)
8181
{
82-
$this->encoder->expects($this->once())
82+
$this->hasher->expects($this->once())
8383
->method('isPasswordValid')
8484
->with(static::PASSWORD, 'secret', static::SALT)
8585
->willReturn(false);
@@ -94,9 +94,7 @@ public function provideConstraints(): iterable
9494
{
9595
yield 'Doctrine style' => [new UserPassword(['message' => 'myMessage'])];
9696

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")];
10098
}
10199

102100
/**
@@ -153,14 +151,14 @@ protected function createUser()
153151
return $mock;
154152
}
155153

156-
protected function createEncoderFactory($encoder = null)
154+
protected function createHasherFactory($hasher = null)
157155
{
158-
$mock = $this->createMock(EncoderFactoryInterface::class);
156+
$mock = $this->createMock(PasswordHasherFactoryInterface::class);
159157

160158
$mock
161159
->expects($this->any())
162-
->method('getEncoder')
163-
->willReturn($encoder)
160+
->method('getPasswordHasher')
161+
->willReturn($hasher)
164162
;
165163

166164
return $mock;

0 commit comments

Comments
 (0)