From b8e466b4610f3a95337bac3a549ae31b34e7c7ed Mon Sep 17 00:00:00 2001 From: Mehmet Korkmaz Date: Tue, 27 Nov 2018 22:52:39 +0300 Subject: [PATCH] id revert to string to use anyting --- src/Entity.php | 10 ++++------ tests/resources/test-schema.json | 4 +--- tests/unit/EntityTest.php | 10 +++++----- 3 files changed, 10 insertions(+), 14 deletions(-) diff --git a/src/Entity.php b/src/Entity.php index 5310d82..3d4e0ba 100644 --- a/src/Entity.php +++ b/src/Entity.php @@ -4,8 +4,6 @@ namespace Selami\Entity; use stdClass; -use Ramsey\Uuid\Uuid; -use Ramsey\Uuid\UuidInterface; use JsonSerializable; use Selami\Entity\Exception\UnexpectedValueException; @@ -13,17 +11,17 @@ final class Entity implements JsonSerializable { use ObjectTrait; - public function __construct(Model $model, UuidInterface $id, ?stdClass $data = null) + public function __construct(Model $model, string $id, ?stdClass $data = null) { $this->model = $model; $this->data = $data; if ($data === null) { $this->data = new stdClass(); } - $this->data->id = $id->toString(); + $this->data->id = $id; } - public static function createFromJsonFile($filePath, UuidInterface $id) : Entity + public static function createFromJsonFile($filePath, string $id) : Entity { if (!file_exists($filePath)) { throw new UnexpectedValueException(sprintf('Model definition file (%s) does not exist!', $filePath)); @@ -32,7 +30,7 @@ public static function createFromJsonFile($filePath, UuidInterface $id) : Entity return static::createFromJson($json, $id); } - public static function createFromJson($json, UuidInterface $id) : Entity + public static function createFromJson($json, string $id) : Entity { return new static(new Model($json), $id); } diff --git a/tests/resources/test-schema.json b/tests/resources/test-schema.json index 1a274c3..bccef97 100644 --- a/tests/resources/test-schema.json +++ b/tests/resources/test-schema.json @@ -5,9 +5,7 @@ "properties": { "id": { "type": "string", - "minLength": 36, - "maxLength": 36, - "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}$" + "format": "uuid" }, "name": { "type": "string", diff --git a/tests/unit/EntityTest.php b/tests/unit/EntityTest.php index 32ca520..d513625 100644 --- a/tests/unit/EntityTest.php +++ b/tests/unit/EntityTest.php @@ -24,7 +24,7 @@ protected function _after() */ public function shouldReturnEntityObjectSuccessfully() : void { - $id = Uuid::uuid4(); + $id = Uuid::uuid4()->toString(); $entity = Entity::createFromJsonFile(__DIR__.'/../resources/test-schema.json', $id); $entity->name = 'John Doe'; $entity->age = 31; @@ -52,7 +52,7 @@ public function shouldReturnEntityObjectSuccessfully() : void */ public function shouldValidatePartiallySuccessfully() : void { - $id = Uuid::uuid4(); + $id = Uuid::uuid4()->toString(); $entity = Entity::createFromJsonFile(__DIR__.'/../resources/test-schema.json', $id); $entity->name = 'John Doe'; $entity->age = 31; @@ -67,7 +67,7 @@ public function shouldValidatePartiallySuccessfully() : void */ public function shouldCompareTwoEntityObjectSuccessfully() : void { - $id = Uuid::uuid4(); + $id = Uuid::uuid4()->toString(); $entity1 = Entity::createFromJsonFile(__DIR__.'/../resources/test-schema.json', $id); $entity2 = Entity::createFromJsonFile(__DIR__.'/../resources/test-schema.json', $id); $entity3 = Entity::createFromJsonFile(__DIR__.'/../resources/test-schema.json', $id); @@ -100,7 +100,7 @@ public function shouldCompareTwoEntityObjectSuccessfully() : void */ public function shouldFailForRequiredInput() : void { - $id = Uuid::uuid4(); + $id = Uuid::uuid4()->toString(); $model = Model::createFromJsonFile(__DIR__.'/../resources/test-schema.json'); $entity = new Entity($model, $id); $entity->name = 'John Doe'; @@ -116,7 +116,7 @@ public function shouldFailForRequiredInput() : void */ public function shouldFailForAModelFileDoesNotExist() : void { - $id = Uuid::uuid4(); + $id = Uuid::uuid4()->toString(); Entity::createFromJsonFile(__DIR__.'/../resources/test-schema-no-file.json', $id); } }