From 57f93f7d0ff22db8a43a571556d19629cb8517d1 Mon Sep 17 00:00:00 2001 From: jsimmer Date: Wed, 11 Apr 2018 23:21:50 +0000 Subject: [PATCH] Added FileType box --- src/Zynga/Framework/Type/V1/FileType/Box.hh | 23 +++++++++++++++ .../Framework/Type/V1/FileType/BoxFactory.hh | 29 +++++++++++++++++++ .../Type/V1/FileType/BoxFactoryTest.hh | 28 ++++++++++++++++++ .../Framework/Type/V1/FileType/BoxTest.hh | 18 ++++++++++++ .../Type/V1/FileType/Enum/FileType.hh | 10 +++++++ .../Exception/UnknownFileTypeException.hh | 10 +++++++ 6 files changed, 118 insertions(+) create mode 100644 src/Zynga/Framework/Type/V1/FileType/Box.hh create mode 100644 src/Zynga/Framework/Type/V1/FileType/BoxFactory.hh create mode 100644 src/Zynga/Framework/Type/V1/FileType/BoxFactoryTest.hh create mode 100644 src/Zynga/Framework/Type/V1/FileType/BoxTest.hh create mode 100644 src/Zynga/Framework/Type/V1/FileType/Enum/FileType.hh create mode 100644 src/Zynga/Framework/Type/V1/FileType/Exception/UnknownFileTypeException.hh diff --git a/src/Zynga/Framework/Type/V1/FileType/Box.hh b/src/Zynga/Framework/Type/V1/FileType/Box.hh new file mode 100644 index 0000000..88160bf --- /dev/null +++ b/src/Zynga/Framework/Type/V1/FileType/Box.hh @@ -0,0 +1,23 @@ +> + protected function importFromString(string $value): bool { + if (FileTypeBoxFactory::isValidValue($value)) { + return parent::importFromString($value); + } + + throw new UnknownFileTypeException('value='.$value); + } + +} diff --git a/src/Zynga/Framework/Type/V1/FileType/BoxFactory.hh b/src/Zynga/Framework/Type/V1/FileType/BoxFactory.hh new file mode 100644 index 0000000..d80ebe6 --- /dev/null +++ b/src/Zynga/Framework/Type/V1/FileType/BoxFactory.hh @@ -0,0 +1,29 @@ +set(FileTypeEnum::JSON); + return $value; + } + + public static function csv(): FileTypeBox { + $value = new FileTypeBox(); + $value->set(FileTypeEnum::CSV); + return $value; + } + + public static function isValidValue(string $value): bool { + return FileTypeEnum::coerce($value) !== null; + } + +} diff --git a/src/Zynga/Framework/Type/V1/FileType/BoxFactoryTest.hh b/src/Zynga/Framework/Type/V1/FileType/BoxFactoryTest.hh new file mode 100644 index 0000000..83a9444 --- /dev/null +++ b/src/Zynga/Framework/Type/V1/FileType/BoxFactoryTest.hh @@ -0,0 +1,28 @@ +assertEquals((string)FileTypeEnum::JSON, BoxFactory::json()->get()); + } + + public function testCsvReturnsValidType(): void { + $this->assertEquals((string)FileTypeEnum::CSV, BoxFactory::csv()->get()); + } + + public function testIsValidValueReturnsFalseCorrectly(): void { + $this->assertFalse(BoxFactory::isValidValue('pumpernickel')); + } + + public function testIsValidValueReturnsTrueCorrectly(): void { + $this->assertTrue(BoxFactory::isValidValue((string)FileTypeEnum::JSON)); + $this->assertTrue(BoxFactory::isValidValue((string)FileTypeEnum::CSV)); + } + +} diff --git a/src/Zynga/Framework/Type/V1/FileType/BoxTest.hh b/src/Zynga/Framework/Type/V1/FileType/BoxTest.hh new file mode 100644 index 0000000..51f1fae --- /dev/null +++ b/src/Zynga/Framework/Type/V1/FileType/BoxTest.hh @@ -0,0 +1,18 @@ +expectException(UnknownFileTypeException::class); + $fileType->set('pumpernickel'); + } + +} diff --git a/src/Zynga/Framework/Type/V1/FileType/Enum/FileType.hh b/src/Zynga/Framework/Type/V1/FileType/Enum/FileType.hh new file mode 100644 index 0000000..2ff75c6 --- /dev/null +++ b/src/Zynga/Framework/Type/V1/FileType/Enum/FileType.hh @@ -0,0 +1,10 @@ +