Skip to content

Commit 2ecc809

Browse files
OskarStarknicolas-grekas
authored andcommitted
[Tests] Streamline
1 parent 17cb6b1 commit 2ecc809

File tree

5 files changed

+17
-8
lines changed

5 files changed

+17
-8
lines changed

Tests/Command/UserPasswordHashCommandTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,10 +277,11 @@ public function testNonInteractiveEncodePasswordUsesFirstUserClass()
277277

278278
public function testThrowsExceptionOnNoConfiguredHashers()
279279
{
280+
$tester = new CommandTester(new UserPasswordHashCommand($this->getMockBuilder(PasswordHasherFactoryInterface::class)->getMock(), []));
281+
280282
$this->expectException(\RuntimeException::class);
281283
$this->expectExceptionMessage('There are no configured password hashers for the "security" extension.');
282284

283-
$tester = new CommandTester(new UserPasswordHashCommand($this->getMockBuilder(PasswordHasherFactoryInterface::class)->getMock(), []));
284285
$tester->execute([
285286
'password' => 'password',
286287
], ['interactive' => false]);

Tests/Hasher/MessageDigestPasswordHasherTest.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,19 @@ public function testHash()
3838

3939
public function testHashAlgorithmDoesNotExist()
4040
{
41-
$this->expectException(\LogicException::class);
4241
$hasher = new MessageDigestPasswordHasher('foobar');
42+
43+
$this->expectException(\LogicException::class);
44+
4345
$hasher->hash('password', '');
4446
}
4547

4648
public function testHashLength()
4749
{
48-
$this->expectException(InvalidPasswordException::class);
4950
$hasher = new MessageDigestPasswordHasher();
5051

52+
$this->expectException(InvalidPasswordException::class);
53+
5154
$hasher->hash(str_repeat('a', 5000), 'salt');
5255
}
5356

Tests/Hasher/PasswordHasherFactoryTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,14 +130,16 @@ public function testGetNullNamedHasherForHasherAware()
130130

131131
public function testGetInvalidNamedHasherForHasherAware()
132132
{
133-
$this->expectException(\RuntimeException::class);
134133
$factory = new PasswordHasherFactory([
135134
HasherAwareUser::class => new MessageDigestPasswordHasher('sha1'),
136135
'hasher_name' => new MessageDigestPasswordHasher('sha256'),
137136
]);
138137

139138
$user = new HasherAwareUser();
140139
$user->hasherName = 'invalid_hasher_name';
140+
141+
$this->expectException(\RuntimeException::class);
142+
141143
$factory->getPasswordHasher($user);
142144
}
143145

Tests/Hasher/Pbkdf2PasswordHasherTest.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,19 @@ public function testHash()
3838

3939
public function testHashAlgorithmDoesNotExist()
4040
{
41-
$this->expectException(\LogicException::class);
4241
$hasher = new Pbkdf2PasswordHasher('foobar');
42+
43+
$this->expectException(\LogicException::class);
44+
4345
$hasher->hash('password', '');
4446
}
4547

4648
public function testHashLength()
4749
{
48-
$this->expectException(InvalidPasswordException::class);
4950
$hasher = new Pbkdf2PasswordHasher('foobar');
5051

52+
$this->expectException(InvalidPasswordException::class);
53+
5154
$hasher->hash(str_repeat('a', 5000), 'salt');
5255
}
5356

Tests/Hasher/SodiumPasswordHasherTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ public function testNonArgonValidation()
5252
public function testHashLength()
5353
{
5454
$this->expectException(InvalidPasswordException::class);
55-
$hasher = new SodiumPasswordHasher();
56-
$hasher->hash(str_repeat('a', 4097));
55+
56+
(new SodiumPasswordHasher())->hash(str_repeat('a', 4097));
5757
}
5858

5959
public function testCheckPasswordLength()

0 commit comments

Comments
 (0)