Skip to content

Commit

Permalink
entityId medhod added to Entity
Browse files Browse the repository at this point in the history
  • Loading branch information
mkorkmaz committed Nov 27, 2018
1 parent 8b4437f commit dc69cb5
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/EntityTrait.php
Expand Up @@ -45,6 +45,11 @@ public static function createFromJson(string $json, string $id) : EntityInterfac
return new static(new Model($json), $id);
}

public function entityId() : string
{
return $this->data->id;
}

public function validatePartially(array $requiredFields) : bool
{
$model = $this->model->getModel();
Expand Down
1 change: 1 addition & 0 deletions src/Interfaces/EntityInterface.php
Expand Up @@ -7,6 +7,7 @@

interface EntityInterface extends JsonSerializable
{
public function entityId() : string;
public function validate() : bool;
public function equals(object $object) : bool;
public static function createFromJsonFile(string $filePath, string $id) : EntityInterface;
Expand Down
1 change: 1 addition & 0 deletions tests/unit/EntityTest.php
Expand Up @@ -39,6 +39,7 @@ public function shouldReturnEntityObjectSuccessfully() : void
$item->name = 'PHP';
$item->value = 100;
$entity->skills = [$item];
$this->assertEquals($id, $entity->entityId());
$this->assertTrue($entity->validate());
$arrayFromJson = json_decode(json_encode($entity), true);
$this->assertEquals(31, $arrayFromJson['age']);
Expand Down

0 comments on commit dc69cb5

Please sign in to comment.