Esempio n. 1
0
 public function testAlphabet()
 {
     $alphabet = '01';
     $su1 = new ShortUUID($alphabet);
     $su2 = new ShortUUID();
     $this->assertEquals($alphabet, $su1->getAlphabet());
     $su1->setAlphabet('01010101010101');
     $this->assertEquals($alphabet, $su1->getAlphabet());
     $d = array_values(array_unique(str_split($su1->uuid())));
     sort($d, SORT_NATURAL);
     $this->assertEquals($d, str_split('01'));
     $a = strlen($su1->uuid());
     $b = strlen($su2->uuid());
     $this->assertTrue($a > 116 && $a < 140);
     $this->assertTrue($b > 20 && $b < 24);
     $u = Uuid::uuid4();
     $this->assertEquals($u, $su1->decode($su1->encode($u)));
     $u = $su1->uuid();
     $this->assertEquals($u, $su1->encode($su1->decode($u)));
     try {
         $su1->setAlphabet('1');
     } catch (ValueError $e) {
         $this->assertTrue(true);
     }
     try {
         $su1->setAlphabet('1111111');
     } catch (ValueError $e) {
         $this->assertTrue(true);
     }
 }
 public function testDecoding()
 {
     $su = new ShortUUID();
     $randomUid = Uuid::uuid4();
     $smallestUid = Uuid::fromInteger(0);
     $encodedRandom = $su->encode($randomUid);
     $encodedSmall = $su->encode($smallestUid);
     $this->assertEquals($su->decode($encodedSmall), $smallestUid);
     $this->assertEquals($su->decode($encodedRandom), $randomUid);
 }