From 72d0a6ba9504c645481d160f5116804ba5e3d7cd Mon Sep 17 00:00:00 2001 From: Kevin Frantz Date: Sun, 6 Jan 2019 13:13:24 +0100 Subject: [PATCH] In between commit solving tests for meta and template management --- .../EntityMetaInformation.php | 31 +++++++- .../EntityMetaInformationInterface.php | 5 ++ .../PathManagement/NamespacePathMap.php | 75 +++++++++++++++++++ .../NamespacePathMapInterface.php | 41 ++++++++++ .../SourceMetaInformation.php | 20 ++++- .../TemplatePathInformation.php | 8 +- .../FormMetaInformationTest.php | 36 +++++++++ .../tests/Unit/Domain/FormMetaTest.php | 34 --------- ...Test.php => SourceMetaInformationTest.php} | 32 ++++---- .../TemplateManagement/TemplateMetaTest.php | 53 ------------- .../TemplatePathInformationTest.php | 62 +++++++++++++++ 11 files changed, 289 insertions(+), 108 deletions(-) create mode 100644 application/symfony/src/Domain/PathManagement/NamespacePathMap.php create mode 100644 application/symfony/src/Domain/PathManagement/NamespacePathMapInterface.php create mode 100644 application/symfony/tests/Unit/Domain/FormManagement/FormMetaInformationTest.php delete mode 100644 application/symfony/tests/Unit/Domain/FormMetaTest.php rename application/symfony/tests/Unit/Domain/SourceManagement/{SourceMetaTest.php => SourceMetaInformationTest.php} (53%) delete mode 100644 application/symfony/tests/Unit/Domain/TemplateManagement/TemplateMetaTest.php create mode 100644 application/symfony/tests/Unit/Domain/TemplateManagement/TemplatePathInformationTest.php diff --git a/application/symfony/src/Domain/EntityManagement/EntityMetaInformation.php b/application/symfony/src/Domain/EntityManagement/EntityMetaInformation.php index d10a6cb..0a5b456 100644 --- a/application/symfony/src/Domain/EntityManagement/EntityMetaInformation.php +++ b/application/symfony/src/Domain/EntityManagement/EntityMetaInformation.php @@ -4,9 +4,10 @@ namespace App\Domain\EntityManagement; use App\Domain\TemplateManagement\TemplatePathFormAndViewInterface; use App\Entity\EntityInterface; -use src\Domain\TemplateManagement\TemplatePathFormAndView; +use App\Domain\TemplateManagement\TemplatePathFormAndView; use App\Domain\FormManagement\FormMetaInformationInterface; use App\Domain\FormManagement\FormMetaInformation; +use App\Domain\PathManagement\NamespacePathMapInterface; /** * @author kevinfrantz @@ -36,7 +37,7 @@ class EntityMetaInformation implements EntityMetaInformationInterface /** * @var string */ - private $pureName; + protected $pureName; /** * @var EntityInterface @@ -48,6 +49,16 @@ class EntityMetaInformation implements EntityMetaInformationInterface */ private $formMetaInformation; + /** + * @var string + */ + private $basicPathString; + + /** + * @var NamespacePathMapInterface + */ + private $namespacePathMap; + /** * @param EntityInterface $entity */ @@ -56,12 +67,18 @@ class EntityMetaInformation implements EntityMetaInformationInterface $this->entity = $entity; $this->entityReflection = new \ReflectionClass($entity); $this->setBasicPathArray(); + $this->setBasicPathString(); $this->setPureName(); $this->setInterfaceReflection(); $this->setTemplatePathFormAndView(); $this->formMetaInformation = new FormMetaInformation($this); } + private function setBasicPathString(): void + { + $this->basicPathString = implode('/', $this->basicPathArray); + } + private function setTemplatePathFormAndView(): void { $this->templatePathFormAndView = new TemplatePathFormAndView(implode('/', $this->basicPathArray), $this->pureName); @@ -158,4 +175,14 @@ class EntityMetaInformation implements EntityMetaInformationInterface { return $this->formMetaInformation; } + + /** + * {@inheritdoc} + * + * @see \App\Domain\EntityManagement\EntityMetaInformationInterface::getBasicPathString() + */ + public function getBasicPathString(): string + { + return $this->basicPathString; + } } diff --git a/application/symfony/src/Domain/EntityManagement/EntityMetaInformationInterface.php b/application/symfony/src/Domain/EntityManagement/EntityMetaInformationInterface.php index 352e4c0..7e703f2 100644 --- a/application/symfony/src/Domain/EntityManagement/EntityMetaInformationInterface.php +++ b/application/symfony/src/Domain/EntityManagement/EntityMetaInformationInterface.php @@ -47,4 +47,9 @@ interface EntityMetaInformationInterface * @return FormMetaInformationInterface The meta informations about the form */ public function getFormMetaInformation(): FormMetaInformationInterface; + + /** + * @return string + */ + public function getBasicPathString(): string; } diff --git a/application/symfony/src/Domain/PathManagement/NamespacePathMap.php b/application/symfony/src/Domain/PathManagement/NamespacePathMap.php new file mode 100644 index 0000000..059652d --- /dev/null +++ b/application/symfony/src/Domain/PathManagement/NamespacePathMap.php @@ -0,0 +1,75 @@ +namespace; + } + + /** + * {@inheritdoc} + * + * @see \App\Domain\PathManagement\NamespacePathMapInterface::getPath() + */ + public function getPath(): string + { + return $this->path; + } + + /** + * {@inheritdoc} + * + * @see \App\Domain\PathManagement\NamespacePathMapInterface::setPath() + */ + public function setPath(string $path): void + { + } + + /** + * {@inheritdoc} + * + * @see \App\Domain\PathManagement\NamespacePathMapInterface::setNamespace() + */ + public function setNamespace(string $namespace): void + { + } + + /** + * {@inheritdoc} + * + * @see \App\Domain\PathManagement\NamespacePathMapInterface::setFolderArray() + */ + public function setFolderArray(array $folders): void + { + } + + public function getFolderArray(): array + { + } +} diff --git a/application/symfony/src/Domain/PathManagement/NamespacePathMapInterface.php b/application/symfony/src/Domain/PathManagement/NamespacePathMapInterface.php new file mode 100644 index 0000000..2a30b2e --- /dev/null +++ b/application/symfony/src/Domain/PathManagement/NamespacePathMapInterface.php @@ -0,0 +1,41 @@ +pureName = str_replace('Source', '', $this->pureName); + $this->pureName = substr($this->pureName, 0, -strlen(self::UNPURE)); } } diff --git a/application/symfony/src/Domain/TemplateManagement/TemplatePathInformation.php b/application/symfony/src/Domain/TemplateManagement/TemplatePathInformation.php index 1a1d33b..2d3e407 100644 --- a/application/symfony/src/Domain/TemplateManagement/TemplatePathInformation.php +++ b/application/symfony/src/Domain/TemplateManagement/TemplatePathInformation.php @@ -9,6 +9,10 @@ use App\DBAL\Types\RESTResponseType; */ final class TemplatePathInformation implements TemplatePathInformationInterface { + const MOLECULE_FOLDER = 'molecule'; + + const ATOM_FOLDER = 'atom'; + /** * @var string */ @@ -73,12 +77,12 @@ final class TemplatePathInformation implements TemplatePathInformationInterface private function setMoleculeTemplatePath(): void { - $this->moleculeTemplatePath = 'molecule/'.$this->suffix; + $this->moleculeTemplatePath = self::MOLECULE_FOLDER.'/'.$this->prefix.'/'.$this->suffix; } private function setAtomTemplatePath(): void { - $this->atomTemplatePath = 'atom/'.$this->suffix; + $this->atomTemplatePath = self::ATOM_FOLDER.'/'.$this->prefix.'/'.$this->suffix; } /** diff --git a/application/symfony/tests/Unit/Domain/FormManagement/FormMetaInformationTest.php b/application/symfony/tests/Unit/Domain/FormManagement/FormMetaInformationTest.php new file mode 100644 index 0000000..cf5fa3e --- /dev/null +++ b/application/symfony/tests/Unit/Domain/FormManagement/FormMetaInformationTest.php @@ -0,0 +1,36 @@ +formMeta = new FormMetaInformation($sourceMeta); + } + + public function testGetFormClass(): void + { + $this->assertEquals('App\Form\Source\Primitive\Name\SurnameType', $this->formMeta->getFormClass()); + } + + public function testTemplateMeta(): void + { + $templatePathInformation = $this->formMeta->getTemplatePathInformation(); + $this->assertInstanceOf(TemplatePathInformationInterface::class, $templatePathInformation); + $this->assertEquals('atom/form/source/primitive/name/surname.html.twig', $templatePathInformation->getAtomTemplatePath()); + } +} diff --git a/application/symfony/tests/Unit/Domain/FormMetaTest.php b/application/symfony/tests/Unit/Domain/FormMetaTest.php deleted file mode 100644 index 5336312..0000000 --- a/application/symfony/tests/Unit/Domain/FormMetaTest.php +++ /dev/null @@ -1,34 +0,0 @@ -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/symfony/tests/Unit/Domain/SourceManagement/SourceMetaTest.php b/application/symfony/tests/Unit/Domain/SourceManagement/SourceMetaInformationTest.php similarity index 53% rename from application/symfony/tests/Unit/Domain/SourceManagement/SourceMetaTest.php rename to application/symfony/tests/Unit/Domain/SourceManagement/SourceMetaInformationTest.php index 530dad2..01329aa 100644 --- a/application/symfony/tests/Unit/Domain/SourceManagement/SourceMetaTest.php +++ b/application/symfony/tests/Unit/Domain/SourceManagement/SourceMetaInformationTest.php @@ -3,20 +3,20 @@ namespace Tests\Unit\Domain\SourceManagement; use PHPUnit\Framework\TestCase; -use App\Domain\SourceManagement\SourceMetaInterface; use App\Entity\Source\Complex\UserSource; -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; +use App\Domain\SourceManagement\SourceMetaInformation; +use App\Domain\SourceManagement\SourceMetaInformationInterface; +use App\Domain\TemplateManagement\TemplatePathFormAndViewInterface; +use App\Domain\FormManagement\FormMetaInformationInterface; -class SourceMetaTest extends TestCase +class SourceMetaInformationTest extends TestCase { /** - * @var SourceMetaInterface + * @var SourceMetaInformationInterface */ - protected $sourceMeta; + protected $sourceMetaInformation; /** * @var SourceInterface @@ -26,20 +26,20 @@ class SourceMetaTest extends TestCase public function setUp(): void { $this->source = new UserSource(); - $this->sourceMeta = new SourceMeta($this->source); + $this->sourceMetaInformation = new SourceMetaInformation($this->source); } public function testBasicName(): void { - $this->assertEquals('user', $this->sourceMeta->getBasicName()); - $this->assertNotEquals('user2', $this->sourceMeta->getBasicName()); + $this->assertEquals('user', $this->sourceMetaInformation->getPureName()); + $this->assertNotEquals('user2', $this->sourceMetaInformation->getPureName()); } public function testBasicPath(): void { $subset = ['source', 'complex']; $amount = count($subset); - $basicPathArray = $this->sourceMeta->getBasicPathArray(); + $basicPathArray = $this->sourceMetaInformation->getBasicPathArray(); for ($index = 0; $index < $amount; ++$index) { $this->assertEquals($subset[$index], $basicPathArray[$index]); } @@ -52,7 +52,7 @@ class SourceMetaTest extends TestCase /** * @var \ReflectionClass */ - $interfaceReflection = $this->sourceMeta->getInterfaceReflection(); + $interfaceReflection = $this->sourceMetaInformation->getInterfaceReflection(); $this->assertEquals(UserSourceInterface::class, $interfaceReflection->getName()); } @@ -61,22 +61,22 @@ class SourceMetaTest extends TestCase /** * @var \ReflectionClass */ - $sourceReflection = $this->sourceMeta->getSourceReflection(); + $sourceReflection = $this->sourceMetaInformation->getEntityReflection(); $this->assertEquals(UserSource::class, $sourceReflection->getName()); } public function testTemplateMeta(): void { - $this->assertInstanceOf(TemplateMetaInterface::class, $this->sourceMeta->getTemplateMeta()); + $this->assertInstanceOf(TemplatePathFormAndViewInterface::class, $this->sourceMetaInformation->getTemplatePathFormAndView()); } public function testSource(): void { - $this->assertEquals($this->source, $this->sourceMeta->getSource()); + $this->assertEquals($this->source, $this->sourceMetaInformation->getEntity()); } public function testFormMeta(): void { - $this->assertInstanceOf(FormMetaInterface::class, $this->sourceMeta->getFormMeta()); + $this->assertInstanceOf(FormMetaInformationInterface::class, $this->sourceMetaInformation->getFormMetaInformation()); } } diff --git a/application/symfony/tests/Unit/Domain/TemplateManagement/TemplateMetaTest.php b/application/symfony/tests/Unit/Domain/TemplateManagement/TemplateMetaTest.php deleted file mode 100644 index 3fde8df..0000000 --- a/application/symfony/tests/Unit/Domain/TemplateManagement/TemplateMetaTest.php +++ /dev/null @@ -1,53 +0,0 @@ -source = new FirstNameSource(); - $sourceMeta = new SourceMeta($this->source); - $this->templateMeta = new TemplateMeta($sourceMeta->getBasicPathArray(), $sourceMeta->getBasicName(), 'entity'); - } - - public function testFrameTemplatePath(): void - { - $this->assertEquals($this->getExpectedPath('html', 'frame'), $this->templateMeta->getFrameTemplatePath()); - } - - public function testContentTemplatePath(): void - { - $this->assertEquals($this->getExpectedPath('html', 'content'), $this->templateMeta->getContentTemplatePath()); - } - - public function testSetType(): void - { - $this->templateMeta->setTemplateType('json'); - $this->assertEquals($this->getExpectedPath('json', 'content'), $this->templateMeta->getContentTemplatePath()); - $this->assertEquals($this->getExpectedPath('json', 'frame'), $this->templateMeta->getFrameTemplatePath()); - $this->assertEquals('json', $this->templateMeta->getTemplateType()); - } -} diff --git a/application/symfony/tests/Unit/Domain/TemplateManagement/TemplatePathInformationTest.php b/application/symfony/tests/Unit/Domain/TemplateManagement/TemplatePathInformationTest.php new file mode 100644 index 0000000..67bccda --- /dev/null +++ b/application/symfony/tests/Unit/Domain/TemplateManagement/TemplatePathInformationTest.php @@ -0,0 +1,62 @@ +source = new FirstNameSource(); + $sourceMeta = new SourceMetaInformation($this->source); + $folder = implode('/', $sourceMeta->getBasicPathArray()); + $this->templateMeta = new TemplatePathInformation($sourceMeta->getPureName(), $folder, 'entity'); + } + + public function testFrameTemplatePath(): void + { + $this->assertEquals($this->getExpectedPath('html', 'molecule'), $this->templateMeta->getMoleculeTemplatePath()); + } + + public function testContentTemplatePath(): void + { + $this->assertEquals($this->getExpectedPath('html', 'atom'), $this->templateMeta->getAtomTemplatePath()); + } + + public function testSetType(): void + { + foreach (RESTResponseType::getChoices() as $type) { + $this->templateMeta->reloadType($type); + $this->assertEquals($this->getExpectedPath($type, 'atom'), $this->templateMeta->getAtomTemplatePath()); + $this->assertEquals($this->getExpectedPath($type, 'molecule'), $this->templateMeta->getMoleculeTemplatePath()); + $this->assertEquals($type, $this->templateMeta->getTemplateType()); + } + } +}