File tree Expand file tree Collapse file tree 3 files changed +65
-1
lines changed
src/PhpValueObject/Identifier Expand file tree Collapse file tree 3 files changed +65
-1
lines changed Original file line number Diff line number Diff line change 2020 }
2121 },
2222 "require" : {
23- "php" : " >=7"
23+ "php" : " >=7" ,
24+ "ramsey/uuid" : " ^3.7"
2425 },
2526 "require-dev" : {
2627 "phpunit/phpunit" : " ^6.2" ,
Original file line number Diff line number Diff line change 1+ <?php
2+ /**
3+ * This software was built by:
4+ * Daniel Tomé Fernández <[email protected] > 5+ * GitHub: danitome24
6+ */
7+
8+ namespace PhpValueObject \Identifier ;
9+
10+ final class Uuid
11+ {
12+ /**
13+ * @var string
14+ */
15+ private $ id ;
16+
17+ /**
18+ * Uuid constructor.
19+ */
20+ private function __construct ()
21+ {
22+ $ this ->id = \Ramsey \Uuid \Uuid::uuid4 ()->toString ();
23+ }
24+
25+ /**
26+ * Generate Uuid identifier
27+ *
28+ * @return static
29+ */
30+ public static function generate ()
31+ {
32+ return new static ();
33+ }
34+
35+ /**
36+ * @return string
37+ */
38+ public function id (): string
39+ {
40+ return $ this ->id ;
41+ }
42+ }
Original file line number Diff line number Diff line change 1+ <?php
2+ /**
3+ * This software was built by:
4+ * Daniel Tomé Fernández <[email protected] > 5+ * GitHub: danitome24
6+ */
7+
8+ namespace Test \Identifier ;
9+
10+ use PHPUnit \Framework \TestCase ;
11+ use PhpValueObject \Identifier \Uuid ;
12+
13+ class UuidTest extends TestCase
14+ {
15+ public function testUuidIsDifferentEachTime ()
16+ {
17+ $ this ->assertNotEquals (Uuid::generate (), Uuid::generate ());
18+ $ this ->assertNotEquals (Uuid::generate ()->id (), Uuid::generate ()->id ());
19+ }
20+
21+ }
You can’t perform that action at this time.
0 commit comments