Skip to content

Commit

Permalink
Fix: Uuid i- prefix (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
silasjoisten authored Jun 18, 2024
1 parent 24d19ec commit d33b1ab
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/Domain/Value/Uuid.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,21 @@

use OskarStark\Value\TrimmedNonEmptyString;
use Webmozart\Assert\Assert;
use function Symfony\Component\String\u;

readonly class Uuid implements \Stringable
{
final public function __construct(
public string $value,
) {
public string $value;

final public function __construct(string $value)
{
TrimmedNonEmptyString::fromString($value);
// In rich text editor the UUID is prefixed with 'i-'
$value = u($value)->trimStart('i-')->toString();
Assert::uuid($value);
Assert::true(strtolower($this->value) === $this->value, 'Uuid must be lowercase');
Assert::true(strtolower($value) === $value, 'Uuid must be lowercase');

$this->value = $value;
}

/**
Expand Down
10 changes: 10 additions & 0 deletions tests/Unit/Domain/Value/UuidTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ public function value(): void
self::assertSame($value, (new Uuid($value))->value);
}

/**
* @test
*/
public function valueCanStartWithI(): void
{
$value = self::faker()->uuid();

self::assertSame($value, (new Uuid('i-'.$value))->value);
}

/**
* @test
*
Expand Down

0 comments on commit d33b1ab

Please sign in to comment.