Skip to content

Commit fbade7c

Browse files
committed
Add Uuid
1 parent 925db03 commit fbade7c

File tree

3 files changed

+65
-1
lines changed

3 files changed

+65
-1
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
}
2121
},
2222
"require": {
23-
"php": ">=7"
23+
"php": ">=7",
24+
"ramsey/uuid": "^3.7"
2425
},
2526
"require-dev": {
2627
"phpunit/phpunit": "^6.2",
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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+
}

tests/Identifier/UuidTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
}

0 commit comments

Comments
 (0)