Skip to content

Commit ca6af4e

Browse files
committed
Merge branch '7.4' into 8.0
* 7.4: (23 commits) fix merge fix merge do not use PHPUnit mock objects without configured expectations do not use PHPUnit mock objects without configured expectations do not use PHPUnit mock objects without configured expectations do not use PHPUnit mock objects without configured expectations do not use PHPUnit mock objects without configured expectations do not use PHPUnit mock objects without configured expectations do not use PHPUnit mock objects without configured expectations do not use PHPUnit mock objects without configured expectations Bump Symfony version to 7.4.4 Update VERSION for 7.4.3 Update CHANGELOG for 7.4.3 Bump Symfony version to 7.3.10 Update VERSION for 7.3.9 Update CHANGELOG for 7.3.9 Bump Symfony version to 6.4.32 Update VERSION for 6.4.31 Update CONTRIBUTORS for 6.4.31 Update CHANGELOG for 6.4.31 ...
2 parents 80e7c7e + ab8e0ef commit ca6af4e

4 files changed

Lines changed: 37 additions & 45 deletions

File tree

Tests/Command/UserPasswordHashCommandTest.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
use Symfony\Component\PasswordHasher\Command\UserPasswordHashCommand;
1919
use Symfony\Component\PasswordHasher\Hasher\NativePasswordHasher;
2020
use Symfony\Component\PasswordHasher\Hasher\PasswordHasherFactory;
21-
use Symfony\Component\PasswordHasher\Hasher\PasswordHasherFactoryInterface;
2221
use Symfony\Component\PasswordHasher\Hasher\Pbkdf2PasswordHasher;
2322
use Symfony\Component\PasswordHasher\Hasher\SodiumPasswordHasher;
2423
use Symfony\Component\Security\Core\User\InMemoryUser;
@@ -279,7 +278,7 @@ public function testNonInteractiveEncodePasswordUsesFirstUserClass()
279278

280279
public function testThrowsExceptionOnNoConfiguredHashers()
281280
{
282-
$tester = new CommandTester(new UserPasswordHashCommand($this->getMockBuilder(PasswordHasherFactoryInterface::class)->getMock(), []));
281+
$tester = new CommandTester(new UserPasswordHashCommand(new PasswordHasherFactory([]), []));
283282

284283
$this->expectException(\RuntimeException::class);
285284
$this->expectExceptionMessage('There are no configured password hashers for the "security" extension.');
@@ -292,7 +291,7 @@ public function testThrowsExceptionOnNoConfiguredHashers()
292291
#[DataProvider('provideCompletionSuggestions')]
293292
public function testCompletionSuggestions(array $input, array $expectedSuggestions)
294293
{
295-
$command = new UserPasswordHashCommand($this->createMock(PasswordHasherFactoryInterface::class), ['App\Entity\User']);
294+
$command = new UserPasswordHashCommand(new PasswordHasherFactory([]), ['App\Entity\User']);
296295
$tester = new CommandCompletionTester($command);
297296

298297
$this->assertSame($expectedSuggestions, $tester->complete($input));

Tests/Hasher/MigratingPasswordHasherTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ public function testFallback()
4242
{
4343
$bestHasher = new NativePasswordHasher(4, 12000, 4);
4444

45-
$extraHasher1 = $this->createMock(PasswordHasherInterface::class);
46-
$extraHasher1->expects($this->any())
45+
$extraHasher1 = $this->createStub(PasswordHasherInterface::class);
46+
$extraHasher1
4747
->method('verify')
4848
->with('abc', 'foo', 'salt')
4949
->willReturn(true);
@@ -52,8 +52,8 @@ public function testFallback()
5252

5353
$this->assertTrue($hasher->verify('abc', 'foo', 'salt'));
5454

55-
$extraHasher2 = $this->createMock(PasswordHasherInterface::class);
56-
$extraHasher2->expects($this->any())
55+
$extraHasher2 = $this->createStub(PasswordHasherInterface::class);
56+
$extraHasher2
5757
->method('verify')
5858
->willReturn(false);
5959

Tests/Hasher/PasswordHasherFactoryTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function testGetHasherWithMessageDigestHasher()
3131
'arguments' => ['sha512', true, 5],
3232
]]);
3333

34-
$hasher = $factory->getPasswordHasher($this->createMock(PasswordAuthenticatedUserInterface::class));
34+
$hasher = $factory->getPasswordHasher($this->createStub(PasswordAuthenticatedUserInterface::class));
3535
$expectedHasher = new MessageDigestPasswordHasher('sha512', true, 5);
3636

3737
$this->assertEquals($expectedHasher->hash('foo', 'moo'), $hasher->hash('foo', 'moo'));
@@ -43,7 +43,7 @@ public function testGetHasherWithService()
4343
PasswordAuthenticatedUserInterface::class => new MessageDigestPasswordHasher('sha1'),
4444
]);
4545

46-
$hasher = $factory->getPasswordHasher($this->createMock(PasswordAuthenticatedUserInterface::class));
46+
$hasher = $factory->getPasswordHasher($this->createStub(PasswordAuthenticatedUserInterface::class));
4747
$expectedHasher = new MessageDigestPasswordHasher('sha1');
4848
$this->assertEquals($expectedHasher->hash('foo', ''), $hasher->hash('foo', ''));
4949
}
@@ -54,7 +54,7 @@ public function testGetHasherWithInstance()
5454
PasswordAuthenticatedUserInterface::class => ['instance' => new MessageDigestPasswordHasher('sha1')],
5555
]);
5656

57-
$hasher = $factory->getPasswordHasher($this->createMock(PasswordAuthenticatedUserInterface::class));
57+
$hasher = $factory->getPasswordHasher($this->createStub(PasswordAuthenticatedUserInterface::class));
5858
$expectedHasher = new MessageDigestPasswordHasher('sha1');
5959
$this->assertEquals($expectedHasher->hash('foo', ''), $hasher->hash('foo', ''));
6060
}

Tests/Hasher/UserPasswordHasherTest.php

Lines changed: 28 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\PasswordHasher\Hasher\NativePasswordHasher;
16+
use Symfony\Component\PasswordHasher\Hasher\PasswordHasherFactory;
1617
use Symfony\Component\PasswordHasher\Hasher\PasswordHasherFactoryInterface;
1718
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasher;
1819
use Symfony\Component\PasswordHasher\PasswordHasherInterface;
@@ -26,19 +27,17 @@ public function testHashWithLegacyUser()
2627
{
2728
$user = new TestLegacyPasswordAuthenticatedUser('name', null, 'userSalt');
2829

29-
$mockHasher = $this->createMock(PasswordHasherInterface::class);
30-
$mockHasher->expects($this->any())
30+
$passwordHasher = $this->createStub(PasswordHasherInterface::class);
31+
$passwordHasher
3132
->method('hash')
3233
->with($this->equalTo('plainPassword'), $this->equalTo('userSalt'))
3334
->willReturn('hash');
3435

35-
$mockPasswordHasherFactory = $this->createMock(PasswordHasherFactoryInterface::class);
36-
$mockPasswordHasherFactory->expects($this->any())
37-
->method('getPasswordHasher')
38-
->with($user)
39-
->willReturn($mockHasher);
36+
$passwordHasherFactory = new PasswordHasherFactory([
37+
$user::class => $passwordHasher,
38+
]);
4039

41-
$passwordHasher = new UserPasswordHasher($mockPasswordHasherFactory);
40+
$passwordHasher = new UserPasswordHasher($passwordHasherFactory);
4241

4342
$encoded = $passwordHasher->hashPassword($user, 'plainPassword');
4443
$this->assertEquals('hash', $encoded);
@@ -48,19 +47,17 @@ public function testHashWithPasswordAuthenticatedUser()
4847
{
4948
$user = new TestPasswordAuthenticatedUser();
5049

51-
$mockHasher = $this->createMock(PasswordHasherInterface::class);
52-
$mockHasher->expects($this->any())
50+
$passwordHasher = $this->createStub(PasswordHasherInterface::class);
51+
$passwordHasher
5352
->method('hash')
5453
->with($this->equalTo('plainPassword'), $this->equalTo(null))
5554
->willReturn('hash');
5655

57-
$mockPasswordHasherFactory = $this->createMock(PasswordHasherFactoryInterface::class);
58-
$mockPasswordHasherFactory->expects($this->any())
59-
->method('getPasswordHasher')
60-
->with($user)
61-
->willReturn($mockHasher);
56+
$passwordHasherFactory = new PasswordHasherFactory([
57+
$user::class => $passwordHasher,
58+
]);
6259

63-
$passwordHasher = new UserPasswordHasher($mockPasswordHasherFactory);
60+
$passwordHasher = new UserPasswordHasher($passwordHasherFactory);
6461

6562
$hashedPassword = $passwordHasher->hashPassword($user, 'plainPassword');
6663

@@ -71,19 +68,17 @@ public function testVerifyWithLegacyUser()
7168
{
7269
$user = new TestLegacyPasswordAuthenticatedUser('user', 'hash', 'userSalt');
7370

74-
$mockHasher = $this->createMock(PasswordHasherInterface::class);
75-
$mockHasher->expects($this->any())
71+
$passwordHasher = $this->createStub(PasswordHasherInterface::class);
72+
$passwordHasher
7673
->method('verify')
7774
->with($this->equalTo('hash'), $this->equalTo('plainPassword'), $this->equalTo('userSalt'))
7875
->willReturn(true);
7976

80-
$mockPasswordHasherFactory = $this->createMock(PasswordHasherFactoryInterface::class);
81-
$mockPasswordHasherFactory->expects($this->any())
82-
->method('getPasswordHasher')
83-
->with($user)
84-
->willReturn($mockHasher);
77+
$passwordHasherFactory = new PasswordHasherFactory([
78+
$user::class => $passwordHasher,
79+
]);
8580

86-
$passwordHasher = new UserPasswordHasher($mockPasswordHasherFactory);
81+
$passwordHasher = new UserPasswordHasher($passwordHasherFactory);
8782

8883
$isValid = $passwordHasher->isPasswordValid($user, 'plainPassword');
8984
$this->assertTrue($isValid);
@@ -93,19 +88,17 @@ public function testVerify()
9388
{
9489
$user = new TestPasswordAuthenticatedUser('hash');
9590

96-
$mockHasher = $this->createMock(PasswordHasherInterface::class);
97-
$mockHasher->expects($this->any())
91+
$passwordHasher = $this->createStub(PasswordHasherInterface::class);
92+
$passwordHasher
9893
->method('verify')
9994
->with($this->equalTo('hash'), $this->equalTo('plainPassword'), $this->equalTo(null))
10095
->willReturn(true);
10196

102-
$mockPasswordHasherFactory = $this->createMock(PasswordHasherFactoryInterface::class);
103-
$mockPasswordHasherFactory->expects($this->any())
104-
->method('getPasswordHasher')
105-
->with($user)
106-
->willReturn($mockHasher);
97+
$passwordHasherFactory = new PasswordHasherFactory([
98+
$user::class => $passwordHasher,
99+
]);
107100

108-
$passwordHasher = new UserPasswordHasher($mockPasswordHasherFactory);
101+
$passwordHasher = new UserPasswordHasher($passwordHasherFactory);
109102

110103
$isValid = $passwordHasher->isPasswordValid($user, 'plainPassword');
111104
$this->assertTrue($isValid);
@@ -116,13 +109,13 @@ public function testNeedsRehash()
116109
$user = new InMemoryUser('username', null);
117110
$hasher = new NativePasswordHasher(4, 20000, 4);
118111

119-
$mockPasswordHasherFactory = $this->createMock(PasswordHasherFactoryInterface::class);
120-
$mockPasswordHasherFactory->expects($this->any())
112+
$passwordHasherFactory = $this->createStub(PasswordHasherFactoryInterface::class);
113+
$passwordHasherFactory
121114
->method('getPasswordHasher')
122115
->with($user)
123116
->willReturn($hasher, $hasher, new NativePasswordHasher(5, 20000, 5), $hasher);
124117

125-
$passwordHasher = new UserPasswordHasher($mockPasswordHasherFactory);
118+
$passwordHasher = new UserPasswordHasher($passwordHasherFactory);
126119

127120
\Closure::bind(function () use ($passwordHasher) { $this->password = $passwordHasher->hashPassword($this, 'foo', 'salt'); }, $user, InMemoryUser::class)();
128121
$this->assertFalse($passwordHasher->needsRehash($user));

0 commit comments

Comments
 (0)