Skip to content

Commit

Permalink
- improved tests for ULID
Browse files Browse the repository at this point in the history
  • Loading branch information
kodeart committed Apr 5, 2023
1 parent 7b3b0b8 commit 93c67f3
Showing 1 changed file with 27 additions and 12 deletions.
39 changes: 27 additions & 12 deletions tests/ULIDTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ public function test_invalid_generate_count()

public function test_toULID_from_ulid_string()
{
$ulid = ULID::fromULID('01GX5BDH020BV0XHGGJ0RE0H2D');
$ulid = ULID::fromULID('01GX86P1083Y9R4PYNYW8E4CDJ');

$this->assertStringContainsString(
'2023-04-04 05:21:44.450',
'2023-04-05 07:56:43.400',
$ulid->toDateTime()->format('Y-m-d H:i:s.u')
);
}
Expand Down Expand Up @@ -124,10 +124,10 @@ public function test_should_fail_from_invalid_uuid()

public function test_toUUID_from_ulid_string()
{
$ulid = ULID::fromUUID('01874ad1-12b6-328a-8cf8-97a3d48d8471');
$ulid = ULID::fromUUID('0187506b-0408-1be3-520f-ab0b9b510ccf');

$this->assertSame(
'2023-04-04 05:50:28.534',
'2023-04-05 07:56:43.400',
$ulid->toDateTime()->format('Y-m-d H:i:s.v')
);
}
Expand All @@ -142,16 +142,32 @@ public function test_toUUID_from_garbage_ulid_string()

public function test_from_timestamp()
{
$ulid = ULID::fromTimestamp(1680627803.321);
$ulid = ULID::fromTimestamp(1680681403.400);
$this->assertSame(
'2023-04-04 17:03:23.321',
$ulid->toDateTime()->format('Y-m-d H:i:s.v')
'2023-04-05 07:56:43.400',
$ulid->toDateTime()->format('Y-m-d H:i:s.v'),
'Timestamp in milliseconds'
);

$ulid = ULID::fromTimestamp(1680627803);
$ulid = ULID::fromTimestamp('1680681403.400');
$this->assertSame(
'2023-04-04 17:03:23.000',
$ulid->toDateTime()->format('Y-m-d H:i:s.v')
'2023-04-05 07:56:43.400',
$ulid->toDateTime()->format('Y-m-d H:i:s.v'),
'Timestamp in milliseconds as string'
);

$ulid = ULID::fromTimestamp(1680681403400);
$this->assertSame(
'2023-04-05 07:56:43.400',
$ulid->toDateTime()->format('Y-m-d H:i:s.v'),
'Timestamp in microseconds'
);

$ulid = ULID::fromTimestamp(1680681403);
$this->assertSame(
'2023-04-05 07:56:43.000',
$ulid->toDateTime()->format('Y-m-d H:i:s.v'),
'Timestamp in seconds'
);
}

Expand All @@ -164,7 +180,6 @@ public function test_from_invalid_timestamp()
ULID::fromTimestamp(-123);
}


public function test_from_invalid_datetime()
{
$this->expectException(\InvalidArgumentException::class);
Expand Down Expand Up @@ -195,7 +210,7 @@ public function test_should_transform_datetime()

public function test_transformations_should_return_same_datetime()
{
$actual = '2023-04-07 07:45:26';
$actual = '2023-04-05 07:56:43';
$instance = ULID::fromDateTime($actual);

$uuid = $instance->toUUID();
Expand Down

0 comments on commit 93c67f3

Please sign in to comment.