mirror of
https://github.com/ramsey/uuid.git
synced 2026-06-14 15:56:48 +03:00
feat: add UUIDv7 documentation and customization
This commit is contained in:
+38
-1
@@ -4,7 +4,10 @@ declare(strict_types=1);
|
||||
|
||||
namespace Ramsey\Uuid\Test;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use DateTimeInterface;
|
||||
use Ramsey\Uuid\Rfc4122\FieldsInterface;
|
||||
use Ramsey\Uuid\Rfc4122\UuidV7;
|
||||
use Ramsey\Uuid\Type\Hexadecimal;
|
||||
use Ramsey\Uuid\Type\Integer as IntegerObject;
|
||||
use Ramsey\Uuid\Uuid;
|
||||
@@ -15,6 +18,7 @@ use function Ramsey\Uuid\v3;
|
||||
use function Ramsey\Uuid\v4;
|
||||
use function Ramsey\Uuid\v5;
|
||||
use function Ramsey\Uuid\v6;
|
||||
use function Ramsey\Uuid\v7;
|
||||
|
||||
class FunctionsTest extends TestCase
|
||||
{
|
||||
@@ -79,6 +83,39 @@ class FunctionsTest extends TestCase
|
||||
$fields = Uuid::fromString($v6)->getFields();
|
||||
|
||||
$this->assertIsString($v6);
|
||||
$this->assertSame(Uuid::UUID_TYPE_PEABODY, $fields->getVersion());
|
||||
$this->assertSame(Uuid::UUID_TYPE_REORDERED_TIME, $fields->getVersion());
|
||||
}
|
||||
|
||||
public function testV7ReturnsVersion7UuidString(): void
|
||||
{
|
||||
$v7 = v7();
|
||||
|
||||
/** @var UuidV7 $uuid */
|
||||
$uuid = Uuid::fromString($v7);
|
||||
|
||||
/** @var FieldsInterface $fields */
|
||||
$fields = $uuid->getFields();
|
||||
|
||||
$this->assertIsString($v7);
|
||||
$this->assertSame(Uuid::UUID_TYPE_UNIX_TIME, $fields->getVersion());
|
||||
$this->assertInstanceOf(DateTimeInterface::class, $uuid->getDateTime());
|
||||
}
|
||||
|
||||
public function testV7WithCustomDateTimeReturnsVersion7UuidString(): void
|
||||
{
|
||||
$dateTime = new DateTimeImmutable('2022-09-14T22:44:33+00:00');
|
||||
|
||||
$v7 = v7($dateTime);
|
||||
|
||||
/** @var UuidV7 $uuid */
|
||||
$uuid = Uuid::fromString($v7);
|
||||
|
||||
/** @var FieldsInterface $fields */
|
||||
$fields = $uuid->getFields();
|
||||
|
||||
$this->assertIsString($v7);
|
||||
$this->assertSame(Uuid::UUID_TYPE_UNIX_TIME, $fields->getVersion());
|
||||
$this->assertInstanceOf(DateTimeInterface::class, $uuid->getDateTime());
|
||||
$this->assertSame(1663195473, $uuid->getDateTime()->getTimestamp());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user