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