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 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