HashTest.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. /*
  3. * The RandomLib library for securely generating random numbers and strings in PHP
  4. *
  5. * @author Anthony Ferrara <ircmaxell@ircmaxell.com>
  6. * @copyright 2011 The Authors
  7. * @license http://www.opensource.org/licenses/mit-license.html MIT License
  8. * @version Build @@version@@
  9. */
  10. namespace RandomLib\Mixer;
  11. use SecurityLib\Strength;
  12. class HashTest extends \PHPUnit_Framework_TestCase
  13. {
  14. public static function provideMix()
  15. {
  16. $data = array(
  17. array(array(), ''),
  18. array(array('1', '1'), '0d'),
  19. array(array('a'), '61'),
  20. // This expects 'b' because of how the mock hmac function works
  21. array(array('a', 'b'), '9a'),
  22. array(array('aa', 'ba'), '6e84'),
  23. array(array('ab', 'bb'), 'b0cb'),
  24. array(array('aa', 'bb'), 'ae8d'),
  25. array(array('aa', 'bb', 'cc'), 'a14c'),
  26. array(array('aabbcc', 'bbccdd', 'ccddee'), 'a8aff3939934'),
  27. );
  28. return $data;
  29. }
  30. public function testConstructWithoutArgument()
  31. {
  32. $hash = new Hash();
  33. $this->assertTrue($hash instanceof \RandomLib\Mixer);
  34. }
  35. public function testGetStrength()
  36. {
  37. $strength = new Strength(Strength::MEDIUM);
  38. $actual = Hash::getStrength();
  39. $this->assertEquals($actual, $strength);
  40. }
  41. public function testTest()
  42. {
  43. $actual = Hash::test();
  44. $this->assertTrue($actual);
  45. }
  46. /**
  47. * @dataProvider provideMix
  48. */
  49. public function testMix($parts, $result)
  50. {
  51. $mixer = new Hash('md5');
  52. $actual = $mixer->mix($parts);
  53. $this->assertEquals($result, bin2hex($actual));
  54. }
  55. }