File tree Expand file tree Collapse file tree 2 files changed +62
-0
lines changed
Expand file tree Collapse file tree 2 files changed +62
-0
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace Gember \IdentityGeneratorSymfony \Ulid ;
6+
7+ use Gember \EventSourcing \Util \Generator \Identity \IdentityGenerator ;
8+ use Override ;
9+ use Symfony \Component \Uid \Factory \UlidFactory ;
10+
11+ final readonly class SymfonyUlidIdentityGenerator implements IdentityGenerator
12+ {
13+ public function __construct (
14+ private UlidFactory $ ulidFactory ,
15+ ) {}
16+
17+ #[Override]
18+ public function generate (): string
19+ {
20+ return (string ) $ this ->ulidFactory ->create ();
21+ }
22+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace Gember \IdentityGeneratorSymfony \Test \Ulid ;
6+
7+ use Gember \IdentityGeneratorSymfony \Ulid \SymfonyUlidIdentityGenerator ;
8+ use PHPUnit \Framework \Attributes \Test ;
9+ use PHPUnit \Framework \TestCase ;
10+ use Override ;
11+ use Symfony \Component \Uid \Factory \UlidFactory ;
12+
13+ /**
14+ * @internal
15+ */
16+ final class SymfonyUlidIdentityGeneratorTest extends TestCase
17+ {
18+ private SymfonyUlidIdentityGenerator $ identityGenerator ;
19+
20+ #[Override]
21+ protected function setUp (): void
22+ {
23+ parent ::setUp ();
24+
25+ $ this ->identityGenerator = new SymfonyUlidIdentityGenerator (
26+ new UlidFactory (),
27+ );
28+ }
29+
30+ #[Test]
31+ public function itShouldGenerateUlid (): void
32+ {
33+ $ ulid = $ this ->identityGenerator ->generate ();
34+
35+ self ::assertMatchesRegularExpression (
36+ '#[0-7][0-9A-HJKMNP-TV-Z]{25}# ' ,
37+ $ ulid ,
38+ );
39+ }
40+ }
You can’t perform that action at this time.
0 commit comments