PasswordHasherFactoryTest.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. /**
  3. * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
  4. * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  5. *
  6. * Licensed under The MIT License
  7. * For full copyright and license information, please see the LICENSE.txt
  8. * Redistributions of files must retain the above copyright notice.
  9. *
  10. * @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  11. * @link https://cakephp.org CakePHP(tm) Project
  12. * @since 3.0.0
  13. * @license https://opensource.org/licenses/mit-license.php MIT License
  14. */
  15. namespace Cake\Test\TestCase\Auth;
  16. use Cake\Auth\PasswordHasherFactory;
  17. use Cake\Core\Plugin;
  18. use Cake\TestSuite\TestCase;
  19. /**
  20. * Test case for PasswordHasherFactory
  21. */
  22. class PasswordHasherFactoryTest extends TestCase
  23. {
  24. /**
  25. * test passwordhasher instance building
  26. *
  27. * @return void
  28. */
  29. public function testBuild()
  30. {
  31. $hasher = PasswordHasherFactory::build('Default');
  32. $this->assertInstanceof('Cake\Auth\DefaultPasswordHasher', $hasher);
  33. $hasher = PasswordHasherFactory::build([
  34. 'className' => 'Default',
  35. 'hashOptions' => ['foo' => 'bar'],
  36. ]);
  37. $this->assertInstanceof('Cake\Auth\DefaultPasswordHasher', $hasher);
  38. $this->assertEquals(['foo' => 'bar'], $hasher->getConfig('hashOptions'));
  39. $this->loadPlugins(['TestPlugin']);
  40. $hasher = PasswordHasherFactory::build('TestPlugin.Legacy');
  41. $this->assertInstanceof('TestPlugin\Auth\LegacyPasswordHasher', $hasher);
  42. $this->clearPlugins();
  43. }
  44. /**
  45. * test build() throws exception for non existent hasher
  46. *
  47. * @return void
  48. */
  49. public function testBuildException()
  50. {
  51. $this->expectException(\RuntimeException::class);
  52. $this->expectExceptionMessage('Password hasher class "FooBar" was not found.');
  53. $hasher = PasswordHasherFactory::build('FooBar');
  54. }
  55. }