Skip to content

Commit b8e466b

Browse files
committed
id revert to string to use anyting
1 parent cb58024 commit b8e466b

File tree

3 files changed

+10
-14
lines changed

3 files changed

+10
-14
lines changed

src/Entity.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,24 @@
44
namespace Selami\Entity;
55

66
use stdClass;
7-
use Ramsey\Uuid\Uuid;
8-
use Ramsey\Uuid\UuidInterface;
97
use JsonSerializable;
108
use Selami\Entity\Exception\UnexpectedValueException;
119

1210
final class Entity implements JsonSerializable
1311
{
1412
use ObjectTrait;
1513

16-
public function __construct(Model $model, UuidInterface $id, ?stdClass $data = null)
14+
public function __construct(Model $model, string $id, ?stdClass $data = null)
1715
{
1816
$this->model = $model;
1917
$this->data = $data;
2018
if ($data === null) {
2119
$this->data = new stdClass();
2220
}
23-
$this->data->id = $id->toString();
21+
$this->data->id = $id;
2422
}
2523

26-
public static function createFromJsonFile($filePath, UuidInterface $id) : Entity
24+
public static function createFromJsonFile($filePath, string $id) : Entity
2725
{
2826
if (!file_exists($filePath)) {
2927
throw new UnexpectedValueException(sprintf('Model definition file (%s) does not exist!', $filePath));
@@ -32,7 +30,7 @@ public static function createFromJsonFile($filePath, UuidInterface $id) : Entity
3230
return static::createFromJson($json, $id);
3331
}
3432

35-
public static function createFromJson($json, UuidInterface $id) : Entity
33+
public static function createFromJson($json, string $id) : Entity
3634
{
3735
return new static(new Model($json), $id);
3836
}

tests/resources/test-schema.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
"properties": {
66
"id": {
77
"type": "string",
8-
"minLength": 36,
9-
"maxLength": 36,
10-
"pattern": "^[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}$"
8+
"format": "uuid"
119
},
1210
"name": {
1311
"type": "string",

tests/unit/EntityTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ protected function _after()
2424
*/
2525
public function shouldReturnEntityObjectSuccessfully() : void
2626
{
27-
$id = Uuid::uuid4();
27+
$id = Uuid::uuid4()->toString();
2828
$entity = Entity::createFromJsonFile(__DIR__.'/../resources/test-schema.json', $id);
2929
$entity->name = 'John Doe';
3030
$entity->age = 31;
@@ -52,7 +52,7 @@ public function shouldReturnEntityObjectSuccessfully() : void
5252
*/
5353
public function shouldValidatePartiallySuccessfully() : void
5454
{
55-
$id = Uuid::uuid4();
55+
$id = Uuid::uuid4()->toString();
5656
$entity = Entity::createFromJsonFile(__DIR__.'/../resources/test-schema.json', $id);
5757
$entity->name = 'John Doe';
5858
$entity->age = 31;
@@ -67,7 +67,7 @@ public function shouldValidatePartiallySuccessfully() : void
6767
*/
6868
public function shouldCompareTwoEntityObjectSuccessfully() : void
6969
{
70-
$id = Uuid::uuid4();
70+
$id = Uuid::uuid4()->toString();
7171
$entity1 = Entity::createFromJsonFile(__DIR__.'/../resources/test-schema.json', $id);
7272
$entity2 = Entity::createFromJsonFile(__DIR__.'/../resources/test-schema.json', $id);
7373
$entity3 = Entity::createFromJsonFile(__DIR__.'/../resources/test-schema.json', $id);
@@ -100,7 +100,7 @@ public function shouldCompareTwoEntityObjectSuccessfully() : void
100100
*/
101101
public function shouldFailForRequiredInput() : void
102102
{
103-
$id = Uuid::uuid4();
103+
$id = Uuid::uuid4()->toString();
104104
$model = Model::createFromJsonFile(__DIR__.'/../resources/test-schema.json');
105105
$entity = new Entity($model, $id);
106106
$entity->name = 'John Doe';
@@ -116,7 +116,7 @@ public function shouldFailForRequiredInput() : void
116116
*/
117117
public function shouldFailForAModelFileDoesNotExist() : void
118118
{
119-
$id = Uuid::uuid4();
119+
$id = Uuid::uuid4()->toString();
120120
Entity::createFromJsonFile(__DIR__.'/../resources/test-schema-no-file.json', $id);
121121
}
122122
}

0 commit comments

Comments
 (0)