From 76e8ed954e2a1c70437fb34a927d1bb1d921d3ce Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Wed, 15 Jul 2020 13:54:01 +0400 Subject: Added category entity Signed-off-by: Valentin Popov --- tests/Entities/CategoryEntityTest.php | 47 +++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 tests/Entities/CategoryEntityTest.php (limited to 'tests/Entities') diff --git a/tests/Entities/CategoryEntityTest.php b/tests/Entities/CategoryEntityTest.php new file mode 100644 index 0000000..6ad7bd3 --- /dev/null +++ b/tests/Entities/CategoryEntityTest.php @@ -0,0 +1,47 @@ + + * @license http://www.apache.org/licenses/LICENSE-2.0 + * @package Tests\Entities + */ +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; + + $entity = CategoryEntity::create(compact('id', 'lang', 'name', 'version')); + + self::assertEquals($id, $entity->id); + self::assertEquals($lang, $entity->lang); + self::assertEquals($name, $entity->name); + self::assertEquals($version, $entity->version); + } +} -- cgit v1.2.3 From 6c52322a3cc5fe4036cc7689d60bd47eca402452 Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Wed, 15 Jul 2020 19:20:43 +0400 Subject: Added genre entity Signed-off-by: Valentin Popov --- src/Entities/GenreEntity.php | 108 +++++++++++++++++++++++++++++++++++++ tests/Entities/GenreEntityTest.php | 47 ++++++++++++++++ 2 files changed, 155 insertions(+) create mode 100644 src/Entities/GenreEntity.php create mode 100644 tests/Entities/GenreEntityTest.php (limited to 'tests/Entities') diff --git a/src/Entities/GenreEntity.php b/src/Entities/GenreEntity.php new file mode 100644 index 0000000..78a9ac0 --- /dev/null +++ b/src/Entities/GenreEntity.php @@ -0,0 +1,108 @@ + + * @license http://www.apache.org/licenses/LICENSE-2.0 + * @package EPGService\Entities + */ +class GenreEntity { + /** + * @var int + */ + protected int $id; + + /** + * @var string + */ + protected string $lang; + + /** + * @var string + */ + protected string $name; + + /** + * @var string + */ + protected string $version; + + /** + * @param int $id + * @param string $lang + * @param string $name + * @param string $version + */ + protected function __construct(int $id, string $lang, string $name, string $version) { + $this->id = $id; + $this->lang = $lang; + $this->name = $name; + $this->version = $version; + } + + public static function create(array $payload): GenreEntity { + if (!is_int($payload['id'])) { + throw new RuntimeException('blah-blah-blah'); + } + + if (!is_string($payload['lang'])) { + throw new RuntimeException('blah-blah-blah'); + } + + if (!is_string($payload['name'])) { + throw new RuntimeException('blah-blah-blah'); + } + + if (!is_string($payload['version'])) { + throw new RuntimeException('blah-blah-blah'); + } + + return new GenreEntity($payload['id'], $payload['lang'], $payload['name'], $payload['version']); + } + + /** + * @param string $name + * + * @return mixed + */ + public function __get(string $name) { + return $this->$name; + } + + /** + * @param string $name + * @param mixed $value + * + * @throws \RuntimeException + */ + public function __set(string $name, $value) { + throw new RuntimeException('blah-blah-blah'); + } +} diff --git a/tests/Entities/GenreEntityTest.php b/tests/Entities/GenreEntityTest.php new file mode 100644 index 0000000..0b1b12c --- /dev/null +++ b/tests/Entities/GenreEntityTest.php @@ -0,0 +1,47 @@ + + * @license http://www.apache.org/licenses/LICENSE-2.0 + * @package Tests\Entities + */ +final class GenreEntityTest extends TestCase { + public function testCreateEntity(): void { + $faker = Faker::create(); + + $id = $faker->numberBetween(1, 999); + $lang = $faker->languageCode; + $name = $faker->word; + $version = $faker->sha256; + + $entity = GenreEntity::create(compact('id', 'lang', 'name', 'version')); + + self::assertEquals($id, $entity->id); + self::assertEquals($lang, $entity->lang); + self::assertEquals($name, $entity->name); + self::assertEquals($version, $entity->version); + } +} -- cgit v1.2.3 From 964ba206127de4eb904f271fd80db7941653adaa Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Fri, 17 Jul 2020 12:14:42 +0400 Subject: Added channel entity Signed-off-by: Valentin Popov --- src/Entities/ChannelEntity.php | 177 +++++++++++++++++++++++++++++++++++ tests/Entities/ChannelEntityTest.php | 70 ++++++++++++++ 2 files changed, 247 insertions(+) create mode 100644 src/Entities/ChannelEntity.php create mode 100644 tests/Entities/ChannelEntityTest.php (limited to 'tests/Entities') diff --git a/src/Entities/ChannelEntity.php b/src/Entities/ChannelEntity.php new file mode 100644 index 0000000..59fc8ce --- /dev/null +++ b/src/Entities/ChannelEntity.php @@ -0,0 +1,177 @@ + + * @license http://www.apache.org/licenses/LICENSE-2.0 + * @package EPGService\Entities + */ +final class ChannelEntity { + /** + * @var string + */ + private string $base_id; + + /** + * @var string + */ + private string $epg_id; + + /** + * @var string + */ + private string $geo_data; + + /** + * @var string + */ + private string $href; + + /** + * @var string + */ + private string $icon; + + /** + * @var string + */ + private string $id; + + /** + * @var string + */ + private string $lang; + + /** + * @var string + */ + private string $name; + + /** + * @var string + */ + private string $update_at; + + /** + * @var string + */ + private string $week; + + /** + * @param array $payload + */ + private function __construct(array $payload) { + $this->base_id = $payload['base_id']; + $this->epg_id = $payload['epg_id']; + $this->geo_data = $payload['geo_data']; + $this->href = $payload['href']; + $this->icon = $payload['icon']; + $this->id = $payload['id']; + $this->lang = $payload['lang']; + $this->name = $payload['name']; + $this->update_at = $payload['update_at']; + $this->week = $payload['week']; + } + + /** + * @param array $payload + * + * @return \EPGService\Entities\ChannelEntity + * + * @throws \RuntimeException + */ + public static function create(array $payload): ChannelEntity { + if (!is_string($payload['base_id'])) { + throw new RuntimeException('blah-blah-blah'); + } + + if (!is_string($payload['epg_id'])) { + throw new RuntimeException('blah-blah-blah'); + } + + if (!is_string($payload['geo_data'])) { + throw new RuntimeException('blah-blah-blah'); + } + + if (!is_string($payload['href'])) { + throw new RuntimeException('blah-blah-blah'); + } + + if (!is_string($payload['icon'])) { + throw new RuntimeException('blah-blah-blah'); + } + + if (!is_string($payload['id'])) { + throw new RuntimeException('blah-blah-blah'); + } + + if (!is_string($payload['lang'])) { + throw new RuntimeException('blah-blah-blah'); + } + + if (!is_string($payload['name'])) { + throw new RuntimeException('blah-blah-blah'); + } + + if (!is_string($payload['update_at'])) { + throw new RuntimeException('blah-blah-blah'); + } + + if (!is_string($payload['week'])) { + throw new RuntimeException('blah-blah-blah'); + } + + return new ChannelEntity($payload); + } + + /** + * @param string $name + * + * @return mixed + */ + public function __get(string $name) { + return $this->$name; + } + + /** + * @param string $name + * @param mixed $value + * + * @throws \RuntimeException + */ + public function __set(string $name, $value) { + throw new RuntimeException('blah-blah-blah'); + } +} diff --git a/tests/Entities/ChannelEntityTest.php b/tests/Entities/ChannelEntityTest.php new file mode 100644 index 0000000..e4f2456 --- /dev/null +++ b/tests/Entities/ChannelEntityTest.php @@ -0,0 +1,70 @@ + + * @license http://www.apache.org/licenses/LICENSE-2.0 + * @package Tests\Entities + */ +final class ChannelEntityTest extends TestCase { + public function testCreateEntity(): void { + $faker = Factory::create(); + + $base_id = $faker->unique()->sha256; + $epg_id = $faker->unique()->sha256; + $geo_data = $faker->unique()->sha256; + $href = $faker->unique()->sha256; + $icon = $faker->unique()->sha256; + $id = $faker->unique()->sha256; + $lang = $faker->unique()->sha256; + $name = $faker->unique()->sha256; + $update_at = $faker->unique()->sha256; + $week = $faker->unique()->sha256; + + $entity = ChannelEntity::create(compact( + 'base_id', + 'epg_id', + 'geo_data', + 'href', + 'icon', + 'id', + 'lang', + 'name', + 'update_at', + 'week', + )); + + self::assertEquals($base_id, $entity->base_id); + self::assertEquals($epg_id, $entity->epg_id); + self::assertEquals($geo_data, $entity->geo_data); + self::assertEquals($href, $entity->href); + self::assertEquals($icon, $entity->icon); + self::assertEquals($id, $entity->id); + self::assertEquals($lang, $entity->lang); + self::assertEquals($name, $entity->name); + self::assertEquals($update_at, $entity->update_at); + self::assertEquals($week, $entity->week); + } +} -- cgit v1.2.3 From 46f834c9bf7ff890700cef3b05fd2d7ebefb21a0 Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Fri, 17 Jul 2020 13:42:45 +0400 Subject: Updated channel entity Signed-off-by: Valentin Popov --- src/Entities/ChannelEntity.php | 11 +++++++++++ tests/Entities/ChannelEntityTest.php | 3 +++ 2 files changed, 14 insertions(+) (limited to 'tests/Entities') diff --git a/src/Entities/ChannelEntity.php b/src/Entities/ChannelEntity.php index 59fc8ce..0d8d3fc 100644 --- a/src/Entities/ChannelEntity.php +++ b/src/Entities/ChannelEntity.php @@ -24,6 +24,7 @@ use function is_string; /** * @property-read string $base_id + * @property-read string $base_name * @property-read string $epg_id * @property-read string $geo_data * @property-read string $href @@ -44,6 +45,11 @@ final class ChannelEntity { */ private string $base_id; + /** + * @var string + */ + private string $base_name; + /** * @var string */ @@ -94,6 +100,7 @@ final class ChannelEntity { */ private function __construct(array $payload) { $this->base_id = $payload['base_id']; + $this->base_name = $payload['base_name']; $this->epg_id = $payload['epg_id']; $this->geo_data = $payload['geo_data']; $this->href = $payload['href']; @@ -117,6 +124,10 @@ final class ChannelEntity { throw new RuntimeException('blah-blah-blah'); } + if (!is_string($payload['base_name'])) { + throw new RuntimeException('blah-blah-blah'); + } + if (!is_string($payload['epg_id'])) { throw new RuntimeException('blah-blah-blah'); } diff --git a/tests/Entities/ChannelEntityTest.php b/tests/Entities/ChannelEntityTest.php index e4f2456..e3c2733 100644 --- a/tests/Entities/ChannelEntityTest.php +++ b/tests/Entities/ChannelEntityTest.php @@ -33,6 +33,7 @@ final class ChannelEntityTest extends TestCase { $faker = Factory::create(); $base_id = $faker->unique()->sha256; + $base_name = $faker->unique()->sha256; $epg_id = $faker->unique()->sha256; $geo_data = $faker->unique()->sha256; $href = $faker->unique()->sha256; @@ -45,6 +46,7 @@ final class ChannelEntityTest extends TestCase { $entity = ChannelEntity::create(compact( 'base_id', + 'base_name', 'epg_id', 'geo_data', 'href', @@ -57,6 +59,7 @@ final class ChannelEntityTest extends TestCase { )); self::assertEquals($base_id, $entity->base_id); + self::assertEquals($base_name, $entity->base_name); self::assertEquals($epg_id, $entity->epg_id); self::assertEquals($geo_data, $entity->geo_data); self::assertEquals($href, $entity->href); -- cgit v1.2.3 From 6d354e6a7791026b4a45e5e20963b10ed1a8bfbe Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Fri, 17 Jul 2020 15:32:14 +0400 Subject: Added credit entity Signed-off-by: Valentin Popov --- src/Entities/Program/CreditEntity.php | 89 +++++++++++++++++++++++++++++ tests/Entities/Program/CreditEntityTest.php | 43 ++++++++++++++ 2 files changed, 132 insertions(+) create mode 100644 src/Entities/Program/CreditEntity.php create mode 100644 tests/Entities/Program/CreditEntityTest.php (limited to 'tests/Entities') diff --git a/src/Entities/Program/CreditEntity.php b/src/Entities/Program/CreditEntity.php new file mode 100644 index 0000000..f7088ea --- /dev/null +++ b/src/Entities/Program/CreditEntity.php @@ -0,0 +1,89 @@ + + * @license http://www.apache.org/licenses/LICENSE-2.0 + * @package EPGService\Entities\Program + */ +final class CreditEntity { + /** + * @var string + */ + private string $name; + + /** + * @var string + */ + private string $type; + + /** + * @param array $payload + */ + private function __construct(array $payload) { + $this->name = $payload['name']; + $this->type = $payload['type']; + } + + /** + * @param array $payload + * + * @return \EPGService\Entities\Program\CreditEntity + * + * @throws \RuntimeException + */ + public static function create(array $payload): CreditEntity { + if (!is_string($payload['name'])) { + throw new RuntimeException('blah-blah-blah'); + } + + if (!is_string($payload['type'])) { + throw new RuntimeException('blah-blah-blah'); + } + + return new CreditEntity($payload); + } + + /** + * @param string $name + * + * @return mixed + */ + public function __get(string $name) { + return $this->$name; + } + + /** + * @param string $name + * @param mixed $value + * + * @throws \RuntimeException + */ + public function __set(string $name, $value) { + throw new RuntimeException('blah-blah-blah'); + } +} diff --git a/tests/Entities/Program/CreditEntityTest.php b/tests/Entities/Program/CreditEntityTest.php new file mode 100644 index 0000000..3c80300 --- /dev/null +++ b/tests/Entities/Program/CreditEntityTest.php @@ -0,0 +1,43 @@ + + * @license http://www.apache.org/licenses/LICENSE-2.0 + * @package Tests\Entities\Program + */ +final class CreditEntityTest extends TestCase { + public function testCreateEntity(): void { + $faker = Faker::create(); + + $name = $faker->unique()->sha256; + $type = $faker->unique()->sha256; + + $entity = CreditEntity::create(compact('name', 'type')); + + self::assertEquals($name, $entity->name); + self::assertEquals($type, $entity->type); + } +} -- cgit v1.2.3 From 74cde415cfa48d318105b301df9c516da0857e9e Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Fri, 17 Jul 2020 15:54:59 +0400 Subject: Added program entity Signed-off-by: Valentin Popov --- src/Entities/ProgramEntity.php | 223 +++++++++++++++++++++++++++++++++++ tests/Entities/ProgramEntityTest.php | 83 +++++++++++++ 2 files changed, 306 insertions(+) create mode 100644 src/Entities/ProgramEntity.php create mode 100644 tests/Entities/ProgramEntityTest.php (limited to 'tests/Entities') diff --git a/src/Entities/ProgramEntity.php b/src/Entities/ProgramEntity.php new file mode 100644 index 0000000..a789de9 --- /dev/null +++ b/src/Entities/ProgramEntity.php @@ -0,0 +1,223 @@ + + * @license http://www.apache.org/licenses/LICENSE-2.0 + * @package EPGService\Entities + */ +final class ProgramEntity { + /** + * @var string[] + */ + private array $categories; + + /** + * @var string + */ + private string $channel_id; + + /** + * @var string[] + */ + private array $countries; + + /** + * @var \EPGService\Entities\Program\CreditEntity[] + */ + private array $credits; + + /** + * @var \DateTime + */ + private DateTime $date; + + /** + * @var string + */ + private string $description; + + /** + * @var string[] + */ + private array $icons; + + /** + * @var string + */ + private string $parents_guide; + + /** + * @var string[] + */ + private array $productions; + + /** + * @var \DateTime + */ + private DateTime $start; + + /** + * @var \DateTime + */ + private DateTime $stop; + + /** + * @var string + */ + private string $sub_title; + + /** + * @var string + */ + private string $title; + + /** + * @var string + */ + private string $year; + + /** + * @param array $payload + */ + private function __construct(array $payload) { + $this->categories = $payload['categories']; + $this->channel_id = $payload['channel_id']; + $this->countries = $payload['countries']; + $this->credits = $payload['credits']; + $this->date = $payload['date']; + $this->description = $payload['description']; + $this->icons = $payload['icons']; + $this->parents_guide = $payload['parents_guide']; + $this->productions = $payload['productions']; + $this->start = $payload['start']; + $this->stop = $payload['stop']; + $this->sub_title = $payload['sub_title']; + $this->title = $payload['title']; + $this->year = $payload['year']; + } + + /** + * @param array $payload + * + * @return \EPGService\Entities\ProgramEntity + * + * @throws \RuntimeException + */ + public static function create(array $payload): ProgramEntity { + if (!is_array($payload['categories'])) { + throw new RuntimeException('blah-blah-blah'); + } + + if (!is_string($payload['channel_id'])) { + throw new RuntimeException('blah-blah-blah'); + } + + if (!is_array($payload['countries'])) { + throw new RuntimeException('blah-blah-blah'); + } + + if (!is_array($payload['credits'])) { + throw new RuntimeException('blah-blah-blah'); + } + + if (!$payload['date'] instanceof DateTime) { + throw new RuntimeException('blah-blah-blah'); + } + + if (!is_string($payload['description'])) { + throw new RuntimeException('blah-blah-blah'); + } + + if (!is_array($payload['icons'])) { + throw new RuntimeException('blah-blah-blah'); + } + + if (!is_string($payload['parents_guide'])) { + throw new RuntimeException('blah-blah-blah'); + } + + if (!is_array($payload['productions'])) { + throw new RuntimeException('blah-blah-blah'); + } + + if (!$payload['start'] instanceof DateTime) { + throw new RuntimeException('blah-blah-blah'); + } + + if (!$payload['stop'] instanceof DateTime) { + throw new RuntimeException('blah-blah-blah'); + } + + if (!is_string($payload['sub_title'])) { + throw new RuntimeException('blah-blah-blah'); + } + + if (!is_string($payload['title'])) { + throw new RuntimeException('blah-blah-blah'); + } + + if (!is_string($payload['year'])) { + throw new RuntimeException('blah-blah-blah'); + } + + return new ProgramEntity($payload); + } + + /** + * @param string $name + * + * @return mixed + */ + public function __get(string $name) { + return $this->$name; + } + + /** + * @param string $name + * @param mixed $value + * + * @throws \RuntimeException + */ + public function __set(string $name, $value) { + throw new RuntimeException('blah-blah-blah'); + } +} diff --git a/tests/Entities/ProgramEntityTest.php b/tests/Entities/ProgramEntityTest.php new file mode 100644 index 0000000..c36e283 --- /dev/null +++ b/tests/Entities/ProgramEntityTest.php @@ -0,0 +1,83 @@ + + * @license http://www.apache.org/licenses/LICENSE-2.0 + * @package Tests\Entities + */ +final class ProgramEntityTest extends TestCase { + public function testCreateEntity(): void { + $faker = Faker::create(); + + $categories = [$faker->unique()->sha256]; + $channel_id = $faker->unique()->sha256; + $countries = [$faker->unique()->sha256]; + $credits = [GetCreditEntityUtility::get()]; + $date = $faker->unique()->dateTime; + $description = $faker->unique()->sha256; + $icons = [$faker->unique()->sha256]; + $parents_guide = $faker->unique()->sha256; + $productions = [$faker->unique()->sha256]; + $start = $faker->unique()->dateTime; + $stop = $faker->unique()->dateTime; + $sub_title = $faker->unique()->sha256; + $title = $faker->unique()->sha256; + $year = $faker->unique()->sha256; + + $entity = ProgramEntity::create(compact( + 'categories', + 'channel_id', + 'countries', + 'credits', + 'date', + 'description', + 'icons', + 'parents_guide', + 'productions', + 'start', + 'stop', + 'sub_title', + 'title', + 'year' + )); + + self::assertEquals($categories, $entity->categories); + self::assertEquals($channel_id, $entity->channel_id); + self::assertEquals($countries[0], $entity->countries[0]); + self::assertEquals($credits[0]->name, $entity->credits[0]->name); + self::assertEquals($date->getTimestamp(), $entity->date->getTimestamp()); + self::assertEquals($description, $entity->description); + self::assertEquals($icons[0], $entity->icons[0]); + self::assertEquals($parents_guide, $entity->parents_guide); + self::assertEquals($productions[0], $entity->productions[0]); + self::assertEquals($start->getTimestamp(), $entity->start->getTimestamp()); + self::assertEquals($stop->getTimestamp(), $entity->stop->getTimestamp()); + self::assertEquals($sub_title, $entity->sub_title); + self::assertEquals($title, $entity->title); + self::assertEquals($year, $entity->year); + } +} -- cgit v1.2.3 From 5ba704abceb11f6e0bb3646492809a323a8fa19d Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Sun, 19 Jul 2020 19:16:47 +0400 Subject: Added country entity Signed-off-by: Valentin Popov --- src/Entities/CountryEntity.php | 123 +++++++++++++++++++++++++++++++++++ tests/Entities/CountryEntityTest.php | 49 ++++++++++++++ 2 files changed, 172 insertions(+) create mode 100644 src/Entities/CountryEntity.php create mode 100644 tests/Entities/CountryEntityTest.php (limited to 'tests/Entities') diff --git a/src/Entities/CountryEntity.php b/src/Entities/CountryEntity.php new file mode 100644 index 0000000..fb559d8 --- /dev/null +++ b/src/Entities/CountryEntity.php @@ -0,0 +1,123 @@ + + * @license http://www.apache.org/licenses/LICENSE-2.0 + * @package EPGService\Entities + */ +final class CountryEntity { + /** + * @var int + */ + private int $id; + + /** + * @var string + */ + private string $iso; + + /** + * @var string + */ + private string $lang; + + /** + * @var string + */ + private string $name; + + /** + * @var string + */ + private string $version; + + /** + * @param array $payload + */ + private function __construct(array $payload) { + $this->id = $payload['id']; + $this->iso = $payload['iso']; + $this->lang = $payload['lang']; + $this->name = $payload['name']; + $this->version = $payload['version']; + } + + /** + * @param array $payload + * + * @return \EPGService\Entities\CountryEntity + * + * @throws \RuntimeException + */ + public static function create(array $payload): CountryEntity { + if (!is_int($payload['id'])) { + throw new RuntimeException('blah-blah-blah'); + } + + if (!is_string($payload['iso'])) { + throw new RuntimeException('blah-blah-blah'); + } + + if (!is_string($payload['lang'])) { + throw new RuntimeException('blah-blah-blah'); + } + + if (!is_string($payload['name'])) { + throw new RuntimeException('blah-blah-blah'); + } + + if (!is_string($payload['version'])) { + throw new RuntimeException('blah-blah-blah'); + } + + return new CountryEntity($payload); + } + + /** + * @param string $name + * + * @return mixed + */ + public function __get(string $name) { + return $this->$name; + } + + /** + * @param string $name + * @param mixed $value + * + * @throws \RuntimeException + */ + public function __set(string $name, $value) { + throw new RuntimeException('blah-blah-blah'); + } +} diff --git a/tests/Entities/CountryEntityTest.php b/tests/Entities/CountryEntityTest.php new file mode 100644 index 0000000..dd44075 --- /dev/null +++ b/tests/Entities/CountryEntityTest.php @@ -0,0 +1,49 @@ + + * @license http://www.apache.org/licenses/LICENSE-2.0 + * @package Tests\Entities + */ +final class CountryEntityTest extends TestCase { + public function testCreateEntity(): void { + $faker = Faker::create(); + + $id = $faker->numberBetween(1, 100); + $iso = $faker->countryCode; + $lang = $faker->languageCode; + $name = $faker->unique()->sha256; + $version = $faker->unique()->sha256; + + $entity = CountryEntity::create(compact('id', 'iso', 'lang', 'name', 'version')); + + self::assertEquals($id, $entity->id); + self::assertEquals($iso, $entity->iso); + self::assertEquals($lang, $entity->lang); + self::assertEquals($name, $entity->name); + self::assertEquals($version, $entity->version); + } +} -- cgit v1.2.3 From 400862f5eea453730b556b34faf1bb45b03a6751 Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Sun, 19 Jul 2020 19:48:41 +0400 Subject: Updated country entity Signed-off-by: Valentin Popov --- src/Entities/CountryEntity.php | 7 +++---- tests/Entities/CountryEntityTest.php | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) (limited to 'tests/Entities') diff --git a/src/Entities/CountryEntity.php b/src/Entities/CountryEntity.php index fb559d8..37d4d6e 100644 --- a/src/Entities/CountryEntity.php +++ b/src/Entities/CountryEntity.php @@ -20,7 +20,6 @@ declare(strict_types = 1); namespace EPGService\Entities; use RuntimeException; -use function is_int; use function is_string; /** @@ -36,9 +35,9 @@ use function is_string; */ final class CountryEntity { /** - * @var int + * @var string */ - private int $id; + private string $id; /** * @var string @@ -79,7 +78,7 @@ final class CountryEntity { * @throws \RuntimeException */ public static function create(array $payload): CountryEntity { - if (!is_int($payload['id'])) { + if (!is_string($payload['id'])) { throw new RuntimeException('blah-blah-blah'); } diff --git a/tests/Entities/CountryEntityTest.php b/tests/Entities/CountryEntityTest.php index dd44075..ffff4fd 100644 --- a/tests/Entities/CountryEntityTest.php +++ b/tests/Entities/CountryEntityTest.php @@ -32,7 +32,7 @@ final class CountryEntityTest extends TestCase { public function testCreateEntity(): void { $faker = Faker::create(); - $id = $faker->numberBetween(1, 100); + $id = $faker->unique()->sha256; $iso = $faker->countryCode; $lang = $faker->languageCode; $name = $faker->unique()->sha256; -- cgit v1.2.3 From 7d078315d6f592de968fbaf9959a2dbc2f59ddfe Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Sun, 19 Jul 2020 20:14:20 +0400 Subject: Updated genre entity Signed-off-by: Valentin Popov --- src/Entities/GenreEntity.php | 26 +++++++++++--------------- tests/Entities/GenreEntityTest.php | 8 ++++---- 2 files changed, 15 insertions(+), 19 deletions(-) (limited to 'tests/Entities') diff --git a/src/Entities/GenreEntity.php b/src/Entities/GenreEntity.php index 61e11ba..ee81041 100644 --- a/src/Entities/GenreEntity.php +++ b/src/Entities/GenreEntity.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 GenreEntity { /** - * @var int + * @var string */ - private int $id; + private string $id; /** * @var string @@ -55,20 +54,17 @@ final class GenreEntity { 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']; } public static function create(array $payload): GenreEntity { - if (!is_int($payload['id'])) { + if (!is_string($payload['id'])) { throw new RuntimeException('blah-blah-blah'); } @@ -84,7 +80,7 @@ final class GenreEntity { throw new RuntimeException('blah-blah-blah'); } - return new GenreEntity($payload['id'], $payload['lang'], $payload['name'], $payload['version']); + return new GenreEntity($payload); } /** diff --git a/tests/Entities/GenreEntityTest.php b/tests/Entities/GenreEntityTest.php index 0b1b12c..278fb68 100644 --- a/tests/Entities/GenreEntityTest.php +++ b/tests/Entities/GenreEntityTest.php @@ -32,10 +32,10 @@ final class GenreEntityTest 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 = GenreEntity::create(compact('id', 'lang', 'name', 'version')); -- cgit v1.2.3 From 506e16bdfcae6996adacdcb5ba23fdf45c98bafe Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Sun, 19 Jul 2020 20:18:09 +0400 Subject: Updated category entity Signed-off-by: Valentin Popov --- src/Entities/CategoryEntity.php | 26 +++++++++++--------------- tests/Entities/CategoryEntityTest.php | 8 ++++---- 2 files changed, 15 insertions(+), 19 deletions(-) (limited to 'tests/Entities') 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')); -- cgit v1.2.3