Accept Type\Hexadecimal for the first parameter to uuid1()

This commit is contained in:
Ben Ramsey
2020-02-24 14:30:48 -06:00
parent ab3c89fb8e
commit fec93008bc
7 changed files with 73 additions and 14 deletions
+45
View File
@@ -26,6 +26,7 @@ use Ramsey\Uuid\Generator\RandomGeneratorInterface;
use Ramsey\Uuid\Guid\Guid;
use Ramsey\Uuid\Nonstandard\Uuid as NonstandardUuid;
use Ramsey\Uuid\Nonstandard\UuidV6;
use Ramsey\Uuid\Provider\Node\RandomNodeProvider;
use Ramsey\Uuid\Provider\Time\FixedTimeProvider;
use Ramsey\Uuid\Rfc4122\FieldsInterface;
use Ramsey\Uuid\Rfc4122\NilUuid;
@@ -481,6 +482,19 @@ class UuidTest extends TestCase
$this->assertEquals('9669-0800200c9a66', substr($uuid->toString(), 19));
}
public function testUuid1WithHexadecimalObjectNodeAndClockSequence(): void
{
/** @var Uuid $uuid */
$uuid = Uuid::uuid1(new Hexadecimal('0800200c9a66'), 0x1669);
$this->assertInstanceOf(Uuid::class, $uuid);
$this->assertInstanceOf(DateTimeInterface::class, $uuid->getDateTime());
$this->assertEquals(2, $uuid->getVariant());
$this->assertEquals(1, $uuid->getVersion());
$this->assertEquals(5737, $uuid->getClockSequence());
$this->assertSame('8796630719078', $uuid->getNode());
$this->assertEquals('9669-0800200c9a66', substr($uuid->toString(), 19));
}
public function testUuid1WithHexadecimalNode(): void
{
/** @var Uuid $uuid */
@@ -494,6 +508,19 @@ class UuidTest extends TestCase
$this->assertSame('1902130526', $uuid->getNode());
}
public function testUuid1WithHexadecimalObjectNode(): void
{
/** @var Uuid $uuid */
$uuid = Uuid::uuid1(new Hexadecimal('7160355e'));
$this->assertInstanceOf(Uuid::class, $uuid);
$this->assertInstanceOf(DateTimeInterface::class, $uuid->getDateTime());
$this->assertEquals(2, $uuid->getVariant());
$this->assertEquals(1, $uuid->getVersion());
$this->assertEquals('00007160355e', $uuid->getNodeHex());
$this->assertSame('1902130526', $uuid->getNode());
}
public function testUuid1WithMixedCaseHexadecimalNode(): void
{
/** @var Uuid $uuid */
@@ -542,6 +569,15 @@ class UuidTest extends TestCase
$this->assertEquals(1, $uuid->getVersion());
}
public function testUuid1WithUserGeneratedRandomNode(): void
{
$uuid = Uuid::uuid1(new Hexadecimal((string) (new RandomNodeProvider())->getNode()));
$this->assertInstanceOf(Uuid::class, $uuid);
$this->assertInstanceOf(DateTimeInterface::class, $uuid->getDateTime());
$this->assertEquals(2, $uuid->getVariant());
$this->assertEquals(1, $uuid->getVersion());
}
public function testUuid6(): void
{
$uuid = Uuid::uuid6();
@@ -612,6 +648,15 @@ class UuidTest extends TestCase
$this->assertEquals(6, $uuid->getVersion());
}
public function testUuid6WithUserGeneratedRandomNode(): void
{
$uuid = Uuid::uuid6(new Hexadecimal((string) (new RandomNodeProvider())->getNode()));
$this->assertInstanceOf(UuidV6::class, $uuid);
$this->assertInstanceOf(DateTimeInterface::class, $uuid->getDateTime());
$this->assertEquals(2, $uuid->getVariant());
$this->assertEquals(6, $uuid->getVersion());
}
/**
* Tests known version-3 UUIDs
*