mirror of
https://github.com/ramsey/uuid.git
synced 2026-06-14 15:56:48 +03:00
Add behavior test for TimestampFirstCombCodec
This commit is contained in:
@@ -4,7 +4,9 @@ namespace Ramsey\Uuid\Test;
|
||||
|
||||
use Moontoast\Math\BigNumber;
|
||||
use Ramsey\Uuid\Builder\DegradedUuidBuilder;
|
||||
use Ramsey\Uuid\Codec\TimestampFirstCombCodec;
|
||||
use Ramsey\Uuid\Converter\Number\DegradedNumberConverter;
|
||||
use Ramsey\Uuid\Generator\CombGenerator;
|
||||
use Ramsey\Uuid\Generator\DefaultTimeGenerator;
|
||||
use Ramsey\Uuid\Uuid;
|
||||
use Ramsey\Uuid\UuidFactory;
|
||||
@@ -585,4 +587,39 @@ class ExpectedBehaviorTest extends TestCase
|
||||
$this->assertSame('aVersion4Uuid', \Ramsey\Uuid\v4());
|
||||
$this->assertSame('aVersion5Uuid', \Ramsey\Uuid\v5(Uuid::NAMESPACE_URL, 'https://example.com/foo'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @link https://git.io/JvJZo Use of TimestampFirstCombCodec in laravel/framework
|
||||
*/
|
||||
public function testUseOfTimestampFirstCombCodec()
|
||||
{
|
||||
$factory = new UuidFactory();
|
||||
|
||||
$factory->setRandomGenerator(new CombGenerator(
|
||||
$factory->getRandomGenerator(),
|
||||
$factory->getNumberConverter()
|
||||
));
|
||||
|
||||
$factory->setCodec(new TimestampFirstCombCodec(
|
||||
$factory->getUuidBuilder()
|
||||
));
|
||||
|
||||
$uuid = $factory->uuid4();
|
||||
|
||||
// Swap fields according to the rules for TimestampFirstCombCodec.
|
||||
$fields = array_values($uuid->getFieldsHex());
|
||||
$last48Bits = $fields[5];
|
||||
$fields[5] = $fields[0] . $fields[1];
|
||||
$fields[0] = substr($last48Bits, 0, 8);
|
||||
$fields[1] = substr($last48Bits, 8, 4);
|
||||
|
||||
$expectedHex = implode('', $fields);
|
||||
$expectedBytes = hex2bin($expectedHex);
|
||||
|
||||
$this->assertInstanceOf('Ramsey\Uuid\UuidInterface', $uuid);
|
||||
$this->assertSame(2, $uuid->getVariant());
|
||||
$this->assertSame(4, $uuid->getVersion());
|
||||
$this->assertSame($expectedBytes, $uuid->getBytes());
|
||||
$this->assertSame($expectedHex, $uuid->getHex());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user