aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Entities/ProgramEntity.php223
-rw-r--r--tests/Entities/ProgramEntityTest.php83
2 files changed, 306 insertions, 0 deletions
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 @@
+<?php
+/**
+ * Copyright 2020 “EPGService”
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an “AS IS” BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+declare(strict_types = 1);
+
+namespace EPGService\Entities;
+
+use DateTime;
+use RuntimeException;
+use function is_array;
+use function is_string;
+
+/**
+ * @property-read \EPGService\Entities\Program\CreditEntity[] $credits
+ * @property-read \DateTime $date
+ * @property-read \DateTime $start
+ * @property-read \DateTime $stop
+ * @property-read string $channel_id
+ * @property-read string $description
+ * @property-read string $parents_guide
+ * @property-read string $sub_title
+ * @property-read string $title
+ * @property-read string $year
+ * @property-read string[] $categories
+ * @property-read string[] $countries
+ * @property-read string[] $icons
+ * @property-read string[] $productions
+ *
+ * @copyright Copyright © 2020 “Valentin Popov” <info@valentineus.link>
+ * @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 @@
+<?php
+/**
+ * Copyright 2020 “EPGService”
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an “AS IS” BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+declare(strict_types = 1);
+
+namespace Tests\Entities;
+
+use EPGService\Entities\ProgramEntity;
+use Faker\Factory as Faker;
+use PHPUnit\Framework\TestCase;
+use Tests\Utilities\GetCreditEntityUtility;
+
+/**
+ * @copyright Copyright © 2020 “Valentin Popov” <info@valentineus.link>
+ * @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);
+ }
+}