From 8a311caddca33c6743be47f3da75467d9908f533 Mon Sep 17 00:00:00 2001 From: Kevin Frantz Date: Fri, 23 Nov 2018 13:22:45 +0100 Subject: [PATCH] implemented sourcemeta and test --- application/src/DBAL/Types/TemplateType.php | 22 ++++ .../FormManagement/FormMetaInterface.php | 8 ++ .../Domain/SourceManagement/SourceMeta.php | 106 ++++++++++++++++++ .../SourceManagement/SourceMetaInterface.php | 35 ++++++ .../TemplateManagement/TemplateMeta.php | 41 +++++++ .../TemplateMetaInterface.php | 37 ++++++ .../src/Entity/Attribut/SourceAttribut.php | 3 - application/src/Security/SourceVoter.php | 1 + .../tests/Integration/UrlIntegrationTest.php | 2 +- .../SourceManagement/SourceMetaTest.php | 76 +++++++++++++ 10 files changed, 327 insertions(+), 4 deletions(-) create mode 100644 application/src/DBAL/Types/TemplateType.php create mode 100644 application/src/Domain/FormManagement/FormMetaInterface.php create mode 100644 application/src/Domain/SourceManagement/SourceMeta.php create mode 100644 application/src/Domain/SourceManagement/SourceMetaInterface.php create mode 100644 application/src/Domain/TemplateManagement/TemplateMeta.php create mode 100644 application/src/Domain/TemplateManagement/TemplateMetaInterface.php create mode 100644 application/tests/Unit/Domain/SourceManagement/SourceMetaTest.php diff --git a/application/src/DBAL/Types/TemplateType.php b/application/src/DBAL/Types/TemplateType.php new file mode 100644 index 0000000..d089b51 --- /dev/null +++ b/application/src/DBAL/Types/TemplateType.php @@ -0,0 +1,22 @@ + 'json', + self::HTML => 'html', + ]; +} diff --git a/application/src/Domain/FormManagement/FormMetaInterface.php b/application/src/Domain/FormManagement/FormMetaInterface.php new file mode 100644 index 0000000..f008d42 --- /dev/null +++ b/application/src/Domain/FormManagement/FormMetaInterface.php @@ -0,0 +1,8 @@ +source = $source; + $this->sourceReflection = new \ReflectionClass($source); + $this->setBasicPathArray(); + $this->setBasicName(); + $this->setInterfaceReflection(); + $this->templateMeta = new TemplateMeta($this); + } + + private function setBasicPathArray(): void + { + $namespace = $this->sourceReflection->getNamespaceName(); + $namespaceWithoutRoot = str_replace('App\\', '', $namespace); + $this->basicPathArray = []; + foreach (explode('\\', $namespaceWithoutRoot) as $element) { + $this->basicPathArray[] = strtolower($element); + } + } + + private function setInterfaceReflection(): void + { + $namespace = str_replace('\Abstract', '\\', $this->sourceReflection->getName()).'Interface'; + $this->interfaceReflection = new \ReflectionClass($namespace); + } + + private function setBasicName(): void + { + $withoutAbstract = str_replace('Abstract', '', $this->sourceReflection->getShortName()); + $withoutSource = str_replace('Source', '', $withoutAbstract); + $this->basicName = strtolower($withoutSource); + } + + public function getBasicPathArray(): array + { + return $this->basicPathArray; + } + + public function getInterfaceReflection(): \ReflectionClass + { + return $this->interfaceReflection; + } + + public function getSourceReflection(): \ReflectionClass + { + return $this->sourceReflection; + } + + public function getTemplateMeta(): TemplateMetaInterface + { + return $this->templateMeta; + } + + public function getBasicName(): string + { + return $this->basicName; + } + + public function getSource(): SourceInterface + { + return $this->source; + } +} diff --git a/application/src/Domain/SourceManagement/SourceMetaInterface.php b/application/src/Domain/SourceManagement/SourceMetaInterface.php new file mode 100644 index 0000000..88a8706 --- /dev/null +++ b/application/src/Domain/SourceManagement/SourceMetaInterface.php @@ -0,0 +1,35 @@ +sourceMeta = $sourceMeta; + } + + public function getFramedTemplatePath(): string + { + } + + public function getFramelessTemplatePath(): string + { + } + + public function getFormMeta(): FormMetaInterface + { + } + + public function setTemplateType(string $type): void + { + } +} diff --git a/application/src/Domain/TemplateManagement/TemplateMetaInterface.php b/application/src/Domain/TemplateManagement/TemplateMetaInterface.php new file mode 100644 index 0000000..7950757 --- /dev/null +++ b/application/src/Domain/TemplateManagement/TemplateMetaInterface.php @@ -0,0 +1,37 @@ + 200, 'register' => 301, 'logout' => 302, - 'profile/edit'=>302, + 'profile/edit' => 302, ]; public function setUp(): void diff --git a/application/tests/Unit/Domain/SourceManagement/SourceMetaTest.php b/application/tests/Unit/Domain/SourceManagement/SourceMetaTest.php new file mode 100644 index 0000000..f2767b6 --- /dev/null +++ b/application/tests/Unit/Domain/SourceManagement/SourceMetaTest.php @@ -0,0 +1,76 @@ +source = new UserSource(); + $this->sourceMeta = new SourceMeta($this->source); + } + + public function testBasicName(): void + { + $this->assertEquals('user', $this->sourceMeta->getBasicName()); + $this->assertNotEquals('user2', $this->sourceMeta->getBasicName()); + } + + public function testBasicPath(): void + { + $subset = ['entity', 'source', 'complex']; + $amount = count($subset); + $basicPathArray = $this->sourceMeta->getBasicPathArray(); + for ($index = 0; $index < $amount; ++$index) { + $this->assertEquals($subset[$index], $basicPathArray[$index]); + } + $this->assertArraySubset($subset, $basicPathArray); + $this->assertEquals($amount, count($basicPathArray)); + } + + public function testInterfaceReflection(): void + { + /** + * @var \ReflectionClass + */ + $interfaceReflection = $this->sourceMeta->getInterfaceReflection(); + $this->assertEquals(UserSourceInterface::class, $interfaceReflection->getName()); + } + + public function testSourceReflection(): void + { + /** + * @var \ReflectionClass + */ + $sourceReflection = $this->sourceMeta->getSourceReflection(); + $this->assertEquals(UserSource::class, $sourceReflection->getName()); + } + + public function testTemplateMeta(): void + { + $this->assertInstanceOf(TemplateMetaInterface::class, $this->sourceMeta->getTemplateMeta()); + } + + public function testSource(): void + { + $this->assertEquals($this->source, $this->sourceMeta->getSource()); + } +}