diff options
author | Valentin Popov <info@valentineus.link> | 2020-07-19 19:18:09 +0300 |
---|---|---|
committer | Valentin Popov <info@valentineus.link> | 2020-07-19 19:18:26 +0300 |
commit | 506e16bdfcae6996adacdcb5ba23fdf45c98bafe (patch) | |
tree | 0f3bb42f2143c782f5289dfb81c3f57ba712500c | |
parent | a5a69a7732eaf278200ff2af53ed875de43714af (diff) | |
download | php-epg-service-506e16bdfcae6996adacdcb5ba23fdf45c98bafe.tar.xz php-epg-service-506e16bdfcae6996adacdcb5ba23fdf45c98bafe.zip |
Updated category entity
Signed-off-by: Valentin Popov <info@valentineus.link>
-rw-r--r-- | src/Entities/CategoryEntity.php | 26 | ||||
-rw-r--r-- | tests/Entities/CategoryEntityTest.php | 8 |
2 files changed, 15 insertions, 19 deletions
diff --git a/src/Entities/CategoryEntity.php b/src/Entities/CategoryEntity.php index af44434..2d113a4 100644 --- a/src/Entities/CategoryEntity.php +++ b/src/Entities/CategoryEntity.php @@ -20,11 +20,10 @@ declare(strict_types = 1); namespace EPGService\Entities; use RuntimeException; -use function is_int; use function is_string; /** - * @property-read int $id + * @property-read string $id * @property-read string $lang * @property-read string $name * @property-read string $version @@ -35,9 +34,9 @@ use function is_string; */ final class CategoryEntity { /** - * @var int + * @var string */ - private int $id; + private string $id; /** * @var string @@ -55,16 +54,13 @@ final class CategoryEntity { private string $version; /** - * @param int $id - * @param string $lang - * @param string $name - * @param string $version + * @param array $payload */ - private function __construct(int $id, string $lang, string $name, string $version) { - $this->id = $id; - $this->lang = $lang; - $this->name = $name; - $this->version = $version; + private function __construct(array $payload) { + $this->id = $payload['id']; + $this->lang = $payload['lang']; + $this->name = $payload['name']; + $this->version = $payload['version']; } /** @@ -74,7 +70,7 @@ final class CategoryEntity { * @throws \RuntimeException */ public static function create(array $payload): CategoryEntity { - if (!is_int($payload['id'])) { + if (!is_string($payload['id'])) { throw new RuntimeException('blah-blah-blah'); } @@ -90,7 +86,7 @@ final class CategoryEntity { throw new RuntimeException('blah-blah-blah'); } - return new CategoryEntity($payload['id'], $payload['lang'], $payload['name'], $payload['version']); + return new CategoryEntity($payload); } /** diff --git a/tests/Entities/CategoryEntityTest.php b/tests/Entities/CategoryEntityTest.php index 6ad7bd3..35363fa 100644 --- a/tests/Entities/CategoryEntityTest.php +++ b/tests/Entities/CategoryEntityTest.php @@ -32,10 +32,10 @@ final class CategoryEntityTest extends TestCase { public function testCreateEntity(): void { $faker = Faker::create(); - $id = $faker->numberBetween(1, 999); - $lang = $faker->languageCode; - $name = $faker->word; - $version = $faker->sha256; + $id = $faker->unique()->sha256; + $lang = $faker->unique()->sha256; + $name = $faker->unique()->sha256; + $version = $faker->unique()->sha256; $entity = CategoryEntity::create(compact('id', 'lang', 'name', 'version')); |