| Total Complexity | 4 |
| Total Lines | 44 |
| Duplicated Lines | 0 % |
| Changes | 4 | ||
| Bugs | 1 | Features | 0 |
| 1 | <?php |
||
| 8 | class PasswordHasherTest extends TestCase |
||
| 9 | { |
||
| 10 | public function testPasswordHashWithDefaults(): void |
||
| 11 | { |
||
| 12 | $password = new PasswordHasher(); |
||
| 13 | |||
| 14 | $secret = 'secret'; |
||
| 15 | $hash = $password->hash($secret); |
||
| 16 | |||
| 17 | $this->assertTrue($password->validate($secret, $hash)); |
||
| 18 | $this->assertFalse($password->validate('test', $hash)); |
||
| 19 | } |
||
| 20 | |||
| 21 | public function testPasswordHash(): void |
||
| 22 | { |
||
| 23 | $password = new PasswordHasher( |
||
| 24 | PASSWORD_BCRYPT, |
||
| 25 | [ |
||
| 26 | // minimum blowfish's value is enough for tests |
||
| 27 | 'cost' => 4, |
||
| 28 | ] |
||
| 29 | ); |
||
| 30 | |||
| 31 | $secret = 'secret'; |
||
| 32 | $hash = $password->hash($secret); |
||
| 33 | $this->assertTrue($password->validate($secret, $hash)); |
||
| 34 | $this->assertFalse($password->validate('test', $hash)); |
||
| 35 | } |
||
| 36 | |||
| 37 | public function testValidateEmptyPasswordException(): void |
||
| 38 | { |
||
| 39 | $this->expectException(\InvalidArgumentException::class); |
||
| 40 | |||
| 41 | $password = new PasswordHasher(); |
||
| 42 | $password->validate('', 'test'); |
||
| 43 | } |
||
| 44 | |||
| 45 | /** |
||
| 46 | * In PHP 7.4 password hashing algorithm identifiers are now nullable strings rather than integers. |
||
| 47 | */ |
||
| 48 | public function testAlgorithmString(): void |
||
| 49 | { |
||
| 50 | $password = new PasswordHasher('test'); |
||
| 51 | $this->assertTrue(true); |
||
| 52 | } |
||
| 54 |