diff --git a/src/UuidFactoryInterface.php b/src/UuidFactoryInterface.php index 18c364c..b3d6f2f 100644 --- a/src/UuidFactoryInterface.php +++ b/src/UuidFactoryInterface.php @@ -154,4 +154,34 @@ interface UuidFactoryInterface * @return UuidInterface A UuidInterface instance that represents a version 6 UUID */ public function uuid6(?Hexadecimal $node = null, ?int $clockSeq = null): UuidInterface; + + /** + * Returns a version 7 (Unix Epoch time) UUID + * + * @param DateTimeInterface|null $dateTime An optional date/time from which + * to create the version 7 UUID. If not provided, the UUID is generated + * using the current date/time. + * + * @return UuidInterface A UuidInterface instance that represents a + * version 7 UUID + */ + public function uuid7(?DateTimeInterface $dateTime = null): UuidInterface; + + /** + * Returns a version 8 (Custom) UUID + * + * The bytes provided may contain any value according to your application's + * needs. Be aware, however, that other applications may not understand the + * semantics of the value. + * + * @param string $bytes A 16-byte octet string. This is an open blob + * of data that you may fill with 128 bits of information. Be aware, + * however, bits 48 through 51 will be replaced with the UUID version + * field, and bits 64 and 65 will be replaced with the UUID variant. You + * MUST NOT rely on these bits for your application needs. + * + * @return UuidInterface A UuidInterface instance that represents a + * version 8 UUID + */ + public function uuid8(string $bytes): UuidInterface; } diff --git a/tests/ExpectedBehaviorTest.php b/tests/ExpectedBehaviorTest.php index a9cf02e..9a181c5 100644 --- a/tests/ExpectedBehaviorTest.php +++ b/tests/ExpectedBehaviorTest.php @@ -363,6 +363,9 @@ class ExpectedBehaviorTest extends TestCase 'uuid3' => $uuid, 'uuid4' => $uuid, 'uuid5' => $uuid, + 'uuid6' => $uuid, + 'uuid7' => $uuid, + 'uuid8' => $uuid, 'fromBytes' => $uuid, 'fromString' => $uuid, 'fromInteger' => $uuid, @@ -377,6 +380,9 @@ class ExpectedBehaviorTest extends TestCase $this->assertSame($uuid, Uuid::uuid3(Uuid::NAMESPACE_URL, 'https://example.com/foo')); $this->assertSame($uuid, Uuid::uuid4()); $this->assertSame($uuid, Uuid::uuid5(Uuid::NAMESPACE_URL, 'https://example.com/foo')); + $this->assertSame($uuid, Uuid::uuid6()); + $this->assertSame($uuid, Uuid::uuid7()); + $this->assertSame($uuid, Uuid::uuid8(hex2bin('ffffffffffffffffffffffffffffffff'))); $this->assertSame($uuid, Uuid::fromBytes($bytes)); $this->assertSame($uuid, Uuid::fromString('ffffffff-ffff-ffff-ffff-ffffffffffff')); $this->assertSame($uuid, Uuid::fromInteger('340282366920938463463374607431768211455')); diff --git a/tests/UuidTest.php b/tests/UuidTest.php index ba60f32..4cf166d 100644 --- a/tests/UuidTest.php +++ b/tests/UuidTest.php @@ -673,19 +673,6 @@ class UuidTest extends TestCase $this->assertSame(Version::UnixTime, $uuid->getFields()->getVersion()); } - public function testUuid7ThrowsExceptionForUnsupportedFactory(): void - { - /** @var UuidFactoryInterface&MockInterface $factory */ - $factory = Mockery::mock(UuidFactoryInterface::class); - - Uuid::setFactory($factory); - - $this->expectException(UnsupportedOperationException::class); - $this->expectExceptionMessage('The provided factory does not support the uuid7() method'); - - Uuid::uuid7(); - } - public function testUuid7WithDateTime(): void { $dateTime = new DateTimeImmutable('@281474976710.655');