123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- <?php
- namespace Tests\Unit;
- if (!defined('INSTALLDIR')) {
- define('INSTALLDIR', dirname(dirname(__DIR__)));
- }
- if (!defined('PUBLICDIR')) {
- define('PUBLICDIR', INSTALLDIR . DIRECTORY_SEPARATOR . 'public');
- }
- if (!defined('GNUSOCIAL')) {
- define('GNUSOCIAL', true);
- }
- if (!defined('STATUSNET')) {
- define('STATUSNET', true);
- }
- use PHPUnit\Framework\TestCase;
- use UUID;
- require_once INSTALLDIR . '/lib/util/common.php';
- final class UUIDTest extends TestCase
- {
- public function testGenerate()
- {
- $result = UUID::gen();
- static::assertRegExp(
- '/^[0-9a-z]{8}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{12}$/',
- $result
- );
-
- static::assertSame(0x4000, hexdec(substr($result, 14, 4)) & 0xF000);
- static::assertSame(0x8000, hexdec(substr($result, 19, 4)) & 0xC000);
- }
- public function testUnique()
- {
- $reps = 100;
- $ids = [];
- for ($i = 0; $i < $reps; ++$i) {
- $ids[] = UUID::gen();
- }
- static::assertSame(count($ids), count(array_unique($ids)), 'UUIDs must be unique');
- }
- }
|