Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
mambax7 committed Oct 30, 2023
1 parent 5f62cf8 commit fcb56e9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
1 change: 0 additions & 1 deletion src/Ulid.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ class Ulid
* @return string The generated ULID.
* @throws \Exception
*/

public static function generate(bool $upperCase = true): string
{
$time = (int)(microtime(true) * 1000000);
Expand Down
28 changes: 27 additions & 1 deletion tests/unit/UlidTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ protected function tearDown()
}

/**
* Tests that the `generate()` method generates a unique ULID.
*
* @covers Xmf\Ulid::generate
* @throws \Exception
*/
public function testGenerate()
Expand All @@ -33,6 +36,12 @@ public function testGenerate()
$this->assertNotEquals($ulid1, $ulid2, 'ULIDs should be unique');
$this->assertTrue(strcasecmp($ulid1, $ulid2) < 0, 'ULIDs should collate correctly');
}

/**
* Tests that the `generate()` method generates a lowercase ULID when configured to do so.
*
* @covers Xmf\Ulid::generate
*/
public function testGeneratesLowercaseIdentifierWhenConfigured()
{
$ulid = Ulid::generate(false); //generate lower case
Expand All @@ -44,11 +53,23 @@ public function testGeneratesLowercaseIdentifierWhenConfigured()
}
}

/**
* Tests that the `generate()` method generates a 26-character ULID.
*
* @covers Xmf\Ulid::generate
*/
public function testGeneratesTwentySixChars()
{
$this->assertSame(26, strlen(Ulid::generate()));
$ulid = Ulid::generate();

$this->assertSame(26, strlen($ulid));
}

/**
* Tests that the `generate()` method generates ULIDs with different random characters when generated multiple times.
*
* @covers Xmf\Ulid::generate
*/
public function testRandomnessWhenGeneratedMultipleTimes()
{
$a = Ulid::generate();
Expand All @@ -67,6 +88,11 @@ public function testRandomnessWhenGeneratedMultipleTimes()
$this->assertNotEquals(substr($a, 10), substr($b, 10));
}

/**
* Tests that the `generate()` method generates lexicographically sortable ULIDs.
*
* @covers Xmf\Ulid::generate
*/
public function testGeneratesLexographicallySortableUlids()
{
$a = Ulid::generate();
Expand Down

0 comments on commit fcb56e9

Please sign in to comment.