Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
31 / 31 |
n/a |
0 / 0 |
CRAP | n/a |
0 / 0 |
||
| 1 | <?php |
| 2 | |
| 3 | // ╔════════════════════════════════════════════════════════════╗ |
| 4 | // ║ MIT Licence (#Expat) - https://opensource.org/licenses/MIT ║ |
| 5 | // ║ Copyright 2026 Frederic Poeydomenge <dyno@phexium.com> ║ |
| 6 | // ╚════════════════════════════════════════════════════════════╝ |
| 7 | |
| 8 | declare(strict_types=1); |
| 9 | |
| 10 | use Phexium\Plugin\PasswordHasher\Adapter\PlaintextPasswordHasher; |
| 11 | |
| 12 | beforeEach(function (): void { |
| 13 | $this->hasher = new PlaintextPasswordHasher(); |
| 14 | }); |
| 15 | |
| 16 | test('Can hash a plain password using plain text', function (): void { |
| 17 | $plainPassword = 'SecurePassword123'; |
| 18 | |
| 19 | $hash = $this->hasher->hash($plainPassword); |
| 20 | |
| 21 | expect($hash)->toBe('$plain$SecurePassword123'); |
| 22 | }); |
| 23 | |
| 24 | test('Verify returns true for correct password', function (): void { |
| 25 | $plainPassword = 'SecurePassword123'; |
| 26 | $hash = $this->hasher->hash($plainPassword); |
| 27 | |
| 28 | expect($this->hasher->verify($plainPassword, $hash))->toBeTrue(); |
| 29 | }); |
| 30 | |
| 31 | test('Verify returns false for incorrect password', function (): void { |
| 32 | $wrongPassword = 'WrongPassword456'; |
| 33 | $plainPassword = 'SecurePassword123'; |
| 34 | $hash = $this->hasher->hash($plainPassword); |
| 35 | |
| 36 | expect($this->hasher->verify($wrongPassword, $hash))->toBeFalse(); |
| 37 | }); |
| 38 | |
| 39 | test('Verify is case sensitive', function (): void { |
| 40 | $wrongPassword = 'securepassword123'; |
| 41 | $plainPassword = 'SecurePassword123'; |
| 42 | $hash = $this->hasher->hash($plainPassword); |
| 43 | |
| 44 | expect($this->hasher->verify($wrongPassword, $hash))->toBeFalse(); |
| 45 | }); |
| 46 | |
| 47 | test('Hash is deterministic - same password produces same hash', function (): void { |
| 48 | $plainPassword = 'SecurePassword123'; |
| 49 | |
| 50 | $hash1 = $this->hasher->hash($plainPassword); |
| 51 | $hash2 = $this->hasher->hash($plainPassword); |
| 52 | |
| 53 | expect($hash1)->toBe($hash2); |
| 54 | }); |