@@ -428,32 +428,47 @@ public function testFromStringBase58Padding()
428428 $ this ->assertInstanceOf (Uuid::class, Uuid::fromString ('111111111u9QRyVM94rdmZ ' ));
429429 }
430430
431- public function testV6FromV1 ()
431+ public function testV1ToV6 ()
432432 {
433433 $ uuidV1 = new UuidV1 ('8189d3de-9670-11ee-b9d1-0242ac120002 ' );
434- $ uuidV6 = UuidV6:: fromV1 ( $ uuidV1 );
434+ $ uuidV6 = $ uuidV1-> toV6 ( );
435435
436436 $ this ->assertEquals ($ uuidV1 ->getDateTime (), $ uuidV6 ->getDateTime ());
437437 $ this ->assertSame ($ uuidV1 ->getNode (), $ uuidV6 ->getNode ());
438- $ this ->assertEquals ($ uuidV6 , UuidV6:: fromV1 ( $ uuidV1 ));
438+ $ this ->assertEquals ($ uuidV6 , $ uuidV1-> toV6 ( ));
439439 }
440440
441- public function testV7FromV1BeforeUnixEpochThrows ()
441+ public function testV1ToV7BeforeUnixEpochThrows ()
442442 {
443443 $ this ->expectException (\InvalidArgumentException::class);
444- $ this ->expectExceptionMessage ('UUIDv1 with a timestamp before Unix epoch cannot be converted to UUIDv7 ' );
444+ $ this ->expectExceptionMessage ('Cannot convert UUID to v7: its timestamp is before the Unix epoch. ' );
445445
446- UuidV7:: fromV1 (new UuidV1 ('9aba8000-ff00-11b0-b3db-3b3fc83afdfc ' )); // Timestamp is 1969-01-01 00:00:00.0000000
446+ (new UuidV1 ('9aba8000-ff00-11b0-b3db-3b3fc83afdfc ' ))-> toV7 ( ); // Timestamp is 1969-01-01 00:00:00.0000000
447447 }
448448
449- public function testV7FromV1 ()
449+ public function testV1ToV7 ()
450450 {
451451 $ uuidV1 = new UuidV1 ('eb248d80-ea4f-11ec-9d2a-839425e6fb88 ' );
452452 $ sameUuidV1100NanosecondsLater = new UuidV1 ('eb248d81-ea4f-11ec-9d2a-839425e6fb88 ' );
453- $ uuidV7 = UuidV7::fromV1 ($ uuidV1 );
453+ $ uuidV7 = $ uuidV1 ->toV7 ();
454+ $ sameUuidV7100NanosecondsLater = $ sameUuidV1100NanosecondsLater ->toV7 ();
454455
455- $ this ->assertEquals ($ uuidV1 ->getDateTime (), $ uuidV7 ->getDateTime ());
456- $ this ->assertEquals ($ uuidV7 , UuidV7::fromV1 ($ uuidV1 ));
457- $ this ->assertNotEquals ($ uuidV7 , UuidV7::fromV1 ($ sameUuidV1100NanosecondsLater ));
456+ $ this ->assertSame ($ uuidV1 ->getDateTime ()->format ('Uv ' ), $ uuidV7 ->getDateTime ()->format ('Uv ' ));
457+ $ this ->assertEquals ($ uuidV7 , $ uuidV1 ->toV7 ());
458+ $ this ->assertNotEquals ($ uuidV7 , $ sameUuidV7100NanosecondsLater );
459+ $ this ->assertSame (hexdec ('0 ' .substr ($ uuidV7 , -2 )) + 1 , hexdec ('0 ' .substr ($ sameUuidV7100NanosecondsLater , -2 )));
460+ }
461+
462+ public function testV1ToV7WhenExtraTimeEntropyOverflows ()
463+ {
464+ $ uuidV1 = new UuidV1 ('10e7718f-2d4f-11be-bfed-cdd35907e584 ' );
465+ $ sameUuidV1100NanosecondsLater = new UuidV1 ('10e77190-2d4f-11be-bfed-cdd35907e584 ' );
466+ $ uuidV7 = $ uuidV1 ->toV7 ();
467+ $ sameUuidV7100NanosecondsLater = $ sameUuidV1100NanosecondsLater ->toV7 ();
468+
469+ $ this ->assertSame ($ uuidV1 ->getDateTime ()->format ('Uv ' ), $ uuidV7 ->getDateTime ()->format ('Uv ' ));
470+ $ this ->assertEquals ($ uuidV7 , $ uuidV1 ->toV7 ());
471+ $ this ->assertNotEquals ($ uuidV7 , $ sameUuidV7100NanosecondsLater );
472+ $ this ->assertSame (hexdec ('0 ' .substr ($ uuidV7 , -2 )) + 1 , hexdec ('0 ' .substr ($ sameUuidV7100NanosecondsLater , -2 )));
458473 }
459474}
0 commit comments