PasswordHasherTest.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. namespace PhpOffice\PhpSpreadsheetTests\Shared;
  3. use PhpOffice\PhpSpreadsheet\Exception as SpException;
  4. use PhpOffice\PhpSpreadsheet\Shared\PasswordHasher;
  5. use PHPUnit\Framework\TestCase;
  6. class PasswordHasherTest extends TestCase
  7. {
  8. /**
  9. * @dataProvider providerHashPassword
  10. */
  11. public function testHashPassword(
  12. string $expectedResult,
  13. string $password,
  14. ?string $algorithm = null,
  15. ?string $salt = null,
  16. ?int $spinCount = null
  17. ): void {
  18. if ($expectedResult === 'exception') {
  19. $this->expectException(SpException::class);
  20. }
  21. if ($algorithm === null) {
  22. $result = PasswordHasher::hashPassword($password);
  23. } elseif ($salt === null) {
  24. $result = PasswordHasher::hashPassword($password, $algorithm);
  25. } elseif ($spinCount === null) {
  26. $result = PasswordHasher::hashPassword($password, $algorithm, $salt);
  27. } else {
  28. $result = PasswordHasher::hashPassword($password, $algorithm, $salt, $spinCount);
  29. }
  30. self::assertSame($expectedResult, $result);
  31. }
  32. public function providerHashPassword(): array
  33. {
  34. return require 'tests/data/Shared/PasswordHashes.php';
  35. }
  36. }