Skip to content

Commit

Permalink
id revert to string to use anyting
Browse files Browse the repository at this point in the history
  • Loading branch information
mkorkmaz committed Nov 27, 2018
1 parent cb58024 commit b8e466b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 14 deletions.
10 changes: 4 additions & 6 deletions src/Entity.php
Expand Up @@ -4,26 +4,24 @@
namespace Selami\Entity;

use stdClass;
use Ramsey\Uuid\Uuid;
use Ramsey\Uuid\UuidInterface;
use JsonSerializable;
use Selami\Entity\Exception\UnexpectedValueException;

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));
Expand All @@ -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);
}
Expand Down
4 changes: 1 addition & 3 deletions tests/resources/test-schema.json
Expand Up @@ -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",
Expand Down
10 changes: 5 additions & 5 deletions tests/unit/EntityTest.php
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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';
Expand All @@ -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);
}
}

0 comments on commit b8e466b

Please sign in to comment.