/test/Unit/RandomLib/Source/UniqIDTest.php

https://github.com/ezimuel/RandomLib · PHP · 36 lines · 24 code · 7 blank · 5 comment · 1 complexity · b881982d0b327fec806a1bbb4f882ede MD5 · raw file

  1. <?php
  2. namespace RandomLib\Source;
  3. use SecurityLib\Strength;
  4. class UniqIDTest extends \PHPUnit_Framework_TestCase {
  5. public static function provideGenerate() {
  6. $data = array();
  7. for ($i = 0; $i < 100; $i += 5) {
  8. $not = $i > 0 ? str_repeat(chr(0), $i) : chr(0);
  9. $data[] = array($i, $not);
  10. }
  11. return $data;
  12. }
  13. /**
  14. */
  15. public function testGetStrength() {
  16. $strength = new Strength(Strength::LOW);
  17. $actual = UniqID::getStrength();
  18. $this->assertEquals($actual, $strength);
  19. }
  20. /**
  21. * @dataProvider provideGenerate
  22. */
  23. public function testGenerate($length, $not) {
  24. $rand = new UniqID;
  25. $stub = $rand->generate($length);
  26. $this->assertEquals($length, strlen($stub));
  27. $this->assertNotEquals($not, $stub);
  28. }
  29. }