Skip to content

Commit

Permalink
test: fill-in missing test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
ramsey committed Oct 17, 2022
1 parent fb7a036 commit 78703b2
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Uuid/UntypedUuid.php
Expand Up @@ -47,7 +47,7 @@
*
* @psalm-external-mutation-free
*/
final class UntypedUuid implements JsonSerializable, NodeBasedUuidIdentifier, TimeBasedUuidIdentifier
final class UntypedUuid implements JsonSerializable, NodeBasedUuidIdentifier
{
use StandardUuid;

Expand Down
10 changes: 10 additions & 0 deletions tests/unit/Ulid/DefaultUlidFactoryTest.php
Expand Up @@ -267,4 +267,14 @@ public function testCreateFromStringThrowsExceptionForWrongFormat(): void

$this->factory->createFromString('ffffffff-ffff-7fff-8fff-fffffffffffff');
}

public function testMax(): void
{
$this->assertInstanceOf(MaxUlid::class, $this->factory->max());
}

public function testNil(): void
{
$this->assertInstanceOf(NilUlid::class, $this->factory->nil());
}
}
11 changes: 11 additions & 0 deletions tests/unit/Uuid/UuidV1FactoryTest.php
Expand Up @@ -107,6 +107,17 @@ public function testCreateFromBytesThrowsExceptionForNonVersion1Uuid(): void
$this->factory->createFromBytes("\xff\xff\xff\xff\xff\xff\x2f\xff\x8f\xff\xff\xff\xff\xff\xff\xff");
}

public function testCreateFromDateTime(): void
{
$dateTime = new DateTimeImmutable('2022-09-25 17:32:12');
$uuid = $this->factory->createFromDateTime($dateTime);

$this->assertInstanceOf(UuidV1::class, $uuid);
$this->assertNotSame($dateTime, $uuid->getDateTime());
$this->assertSame('2022-09-25T17:32:12+00:00', $uuid->getDateTime()->format('c'));
$this->assertSame('fd24f600-3cf7-11ed', substr($uuid->toString(), 0, 18));
}

public function testCreateFromHexadecimal(): void
{
$uuid = $this->factory->createFromHexadecimal('ffffffffffff1fff8fffffffffffffff');
Expand Down
13 changes: 13 additions & 0 deletions tests/unit/Uuid/UuidV2FactoryTest.php
Expand Up @@ -137,6 +137,19 @@ public function testCreateFromBytesThrowsExceptionForNonVersion2Uuid(): void
$this->factory->createFromBytes("\xff\xff\xff\xff\xff\xff\x2f\xff\x8f\xff\xff\xff\xff\xff\xff\xff");
}

public function testCreateFromDateTime(): void
{
$dateTime = new DateTimeImmutable('2022-09-25 17:32:12');
$uuid = $this->factory->createFromDateTime($dateTime);

$this->assertInstanceOf(UuidV2::class, $uuid);
$this->assertNotSame($dateTime, $uuid->getDateTime());

// We lose up to 7+ minutes of time with UUID version 2.
$this->assertSame('2022-09-25T17:25:07+00:00', $uuid->getDateTime()->format('c'));
$this->assertSame('3cf7-21ed', substr($uuid->toString(), 9, 9));
}

public function testCreateFromHexadecimal(): void
{
$uuid = $this->factory->createFromHexadecimal('ffffffffffff2fff8f00ffffffffffff');
Expand Down
11 changes: 11 additions & 0 deletions tests/unit/Uuid/UuidV6FactoryTest.php
Expand Up @@ -107,6 +107,17 @@ public function testCreateFromBytesThrowsExceptionForNonVersion6Uuid(): void
$this->factory->createFromBytes("\xff\xff\xff\xff\xff\xff\x1f\xff\x8f\xff\xff\xff\xff\xff\xff\xff");
}

public function testCreateFromDateTime(): void
{
$dateTime = new DateTimeImmutable('2022-09-25 17:32:12');
$uuid = $this->factory->createFromDateTime($dateTime);

$this->assertInstanceOf(UuidV6::class, $uuid);
$this->assertNotSame($dateTime, $uuid->getDateTime());
$this->assertSame('2022-09-25T17:32:12+00:00', $uuid->getDateTime()->format('c'));
$this->assertSame('1ed3cf7f-d24f-6600', substr($uuid->toString(), 0, 18));
}

public function testCreateFromHexadecimal(): void
{
$uuid = $this->factory->createFromHexadecimal('ffffffffffff6fff8fffffffffffffff');
Expand Down
11 changes: 11 additions & 0 deletions tests/unit/Uuid/UuidV7FactoryTest.php
Expand Up @@ -80,6 +80,17 @@ public function testCreateFromBytesThrowsExceptionForNonVersion7Uuid(): void
$this->factory->createFromBytes("\xff\xff\xff\xff\xff\xff\x2f\xff\x8f\xff\xff\xff\xff\xff\xff\xff");
}

public function testCreateFromDateTime(): void
{
$dateTime = new DateTimeImmutable('2022-09-25 17:32:12');
$uuid = $this->factory->createFromDateTime($dateTime);

$this->assertInstanceOf(UuidV7::class, $uuid);
$this->assertNotSame($dateTime, $uuid->getDateTime());
$this->assertSame('2022-09-25T17:32:12+00:00', $uuid->getDateTime()->format('c'));
$this->assertSame('018375b4-e160', substr($uuid->toString(), 0, 13));
}

public function testCreateFromHexadecimal(): void
{
$uuid = $this->factory->createFromHexadecimal('ffffffffffff7fff8fffffffffffffff');
Expand Down

0 comments on commit 78703b2

Please sign in to comment.