From 926eb0c3fbde7370cdfaec5a198d828409c1d32f Mon Sep 17 00:00:00 2001 From: Kevin Frantz Date: Fri, 23 Nov 2018 16:50:37 +0100 Subject: [PATCH] Optimized FormMeta and Tests --- .../src/Domain/FormManagement/FormMeta.php | 10 ++++-- .../FormManagement/FormMetaInterface.php | 4 ++- .../Domain/SourceManagement/SourceMeta.php | 9 ++++- .../TemplateManagement/TemplateMeta.php | 5 --- .../tests/Unit/Domain/FormMetaTest.php | 34 +++++++++++++++++++ .../SourceManagement/SourceMetaTest.php | 6 ++++ 6 files changed, 59 insertions(+), 9 deletions(-) create mode 100644 application/tests/Unit/Domain/FormMetaTest.php diff --git a/application/src/Domain/FormManagement/FormMeta.php b/application/src/Domain/FormManagement/FormMeta.php index d0630aa..0709e25 100644 --- a/application/src/Domain/FormManagement/FormMeta.php +++ b/application/src/Domain/FormManagement/FormMeta.php @@ -8,6 +8,8 @@ use App\Domain\TemplateManagement\TemplateMeta; /** * @author kevinfrantz + * + * @todo Optimize contructor parameter! */ class FormMeta implements FormMetaInterface { @@ -37,7 +39,11 @@ class FormMeta implements FormMetaInterface private function setFormClass(): void { - $this->formClass = 'App\\Form\\'.implode('\\', $this->sourceMeta->getBasicPathArray()).'\\'.$this->sourceMeta->getBasicName().'Type'; + $this->formClass = 'App\\Form'; + foreach ($this->sourceMeta->getBasicPathArray() as $element) { + $this->formClass .= '\\'.ucfirst($element); + } + $this->formClass .= '\\'.ucfirst($this->sourceMeta->getBasicName()).'Type'; } private function setMeta(): void @@ -50,7 +56,7 @@ class FormMeta implements FormMetaInterface return $this->formClass; } - public function getTemplateMeta(): string + public function getTemplateMeta(): TemplateMetaInterface { return $this->templateMeta; } diff --git a/application/src/Domain/FormManagement/FormMetaInterface.php b/application/src/Domain/FormManagement/FormMetaInterface.php index 7f3352e..7325300 100644 --- a/application/src/Domain/FormManagement/FormMetaInterface.php +++ b/application/src/Domain/FormManagement/FormMetaInterface.php @@ -2,9 +2,11 @@ namespace App\Domain\FormManagement; +use App\Domain\TemplateManagement\TemplateMetaInterface; + interface FormMetaInterface { public function getFormClass(): string; - public function getTemplateMeta(): string; + public function getTemplateMeta(): TemplateMetaInterface; } diff --git a/application/src/Domain/SourceManagement/SourceMeta.php b/application/src/Domain/SourceManagement/SourceMeta.php index 8ad35c3..905ec0f 100644 --- a/application/src/Domain/SourceManagement/SourceMeta.php +++ b/application/src/Domain/SourceManagement/SourceMeta.php @@ -13,6 +13,8 @@ use App\Domain\FormManagement\FormMeta; */ class SourceMeta implements SourceMetaInterface { + const FOLDER = 'entity'; + /** * @var \ReflectionClass */ @@ -55,10 +57,15 @@ class SourceMeta implements SourceMetaInterface $this->setBasicPathArray(); $this->setBasicName(); $this->setInterfaceReflection(); - $this->templateMeta = new TemplateMeta($this->basicPathArray, $this->basicName, 'entity'); + $this->setTemplateMeta(); $this->formMeta = new FormMeta($this); } + private function setTemplateMeta(): void + { + $this->templateMeta = new TemplateMeta($this->basicPathArray, $this->basicName, self::FOLDER); + } + private function setBasicPathArray(): void { $namespace = $this->sourceReflection->getNamespaceName(); diff --git a/application/src/Domain/TemplateManagement/TemplateMeta.php b/application/src/Domain/TemplateManagement/TemplateMeta.php index 6f038a5..0104fc8 100644 --- a/application/src/Domain/TemplateManagement/TemplateMeta.php +++ b/application/src/Domain/TemplateManagement/TemplateMeta.php @@ -94,9 +94,4 @@ class TemplateMeta implements TemplateMetaInterface { return $this->type; } - - public function getPathSuffix(): string - { - return $this->pathSuffix; - } } diff --git a/application/tests/Unit/Domain/FormMetaTest.php b/application/tests/Unit/Domain/FormMetaTest.php new file mode 100644 index 0000000..5336312 --- /dev/null +++ b/application/tests/Unit/Domain/FormMetaTest.php @@ -0,0 +1,34 @@ +formMeta = new FormMeta($sourceMeta); + } + + public function testGetFormClass(): void + { + $this->assertEquals('App\Form\Source\Primitive\Name\SurnameType', $this->formMeta->getFormClass()); + } + + public function testTemplateMeta(): void + { + $this->assertInstanceOf(TemplateMetaInterface::class, $this->formMeta->getTemplateMeta()); + } +} diff --git a/application/tests/Unit/Domain/SourceManagement/SourceMetaTest.php b/application/tests/Unit/Domain/SourceManagement/SourceMetaTest.php index 1af9256..530dad2 100644 --- a/application/tests/Unit/Domain/SourceManagement/SourceMetaTest.php +++ b/application/tests/Unit/Domain/SourceManagement/SourceMetaTest.php @@ -9,6 +9,7 @@ use App\Domain\SourceManagement\SourceMeta; use App\Entity\Source\Complex\UserSourceInterface; use App\Domain\TemplateManagement\TemplateMetaInterface; use App\Entity\Source\SourceInterface; +use App\Domain\FormManagement\FormMetaInterface; class SourceMetaTest extends TestCase { @@ -73,4 +74,9 @@ class SourceMetaTest extends TestCase { $this->assertEquals($this->source, $this->sourceMeta->getSource()); } + + public function testFormMeta(): void + { + $this->assertInstanceOf(FormMetaInterface::class, $this->sourceMeta->getFormMeta()); + } }