diff --git a/application/symfony/src/Domain/PathManagement/NamespacePathMap.php b/application/symfony/src/Domain/PathManagement/NamespacePathMap.php index 059652d..8294a5e 100644 --- a/application/symfony/src/Domain/PathManagement/NamespacePathMap.php +++ b/application/symfony/src/Domain/PathManagement/NamespacePathMap.php @@ -3,6 +3,8 @@ namespace App\Domain\PathManagement; /** + * Be carefull with the case sensivity. + * * @author kevinfrantz */ final class NamespacePathMap implements NamespacePathMapInterface @@ -49,6 +51,7 @@ final class NamespacePathMap implements NamespacePathMapInterface */ public function setPath(string $path): void { + $this->setFolders(explode('/', $path)); } /** @@ -58,18 +61,32 @@ final class NamespacePathMap implements NamespacePathMapInterface */ public function setNamespace(string $namespace): void { + $this->setFolders(explode('\\', $namespace)); + } + + /** + * The strtolower function could lead to conflicts in other contextes + * {@inheritdoc} + * + * @see \App\Domain\PathManagement\NamespacePathMapInterface::setFolderArray() + */ + public function setFolders(array $folders): void + { + $this->folders = []; + foreach ($folders as $folder) { + $this->folders[] = strtolower($folder); + } + $this->namespace = implode('\\', $this->folders); + $this->path = implode('/', $this->folders); } /** * {@inheritdoc} * - * @see \App\Domain\PathManagement\NamespacePathMapInterface::setFolderArray() + * @see \App\Domain\PathManagement\NamespacePathMapInterface::getFolders() */ - public function setFolderArray(array $folders): void - { - } - - public function getFolderArray(): array + public function getFolders(): array { + return $this->folders; } } diff --git a/application/symfony/src/Domain/PathManagement/NamespacePathMapInterface.php b/application/symfony/src/Domain/PathManagement/NamespacePathMapInterface.php index 2a30b2e..cd87914 100644 --- a/application/symfony/src/Domain/PathManagement/NamespacePathMapInterface.php +++ b/application/symfony/src/Domain/PathManagement/NamespacePathMapInterface.php @@ -32,10 +32,10 @@ interface NamespacePathMapInterface /** * @param array|string[] $folders */ - public function setFolderArray(array $folders): void; + public function setFolders(array $folders): void; /** * @return array|string[] */ - public function getFolderArray(): array; + public function getFolders(): array; } diff --git a/application/symfony/tests/Unit/Domain/PathManagement/NamespacePathMapTest.php b/application/symfony/tests/Unit/Domain/PathManagement/NamespacePathMapTest.php new file mode 100644 index 0000000..b514b5d --- /dev/null +++ b/application/symfony/tests/Unit/Domain/PathManagement/NamespacePathMapTest.php @@ -0,0 +1,66 @@ +namespacePathMap = new NamespacePathMap(); + } + + private function validateArray(): void + { + $folders = $this->namespacePathMap->getFolders(); + foreach (self::FOLDERS as $key => $folder) { + $this->assertEquals(strtolower($folder), $folders[$key]); + } + } + + private function validateGet(): void + { + $this->assertEquals(strtolower(self::NAMESPACE), $this->namespacePathMap->getNamespace()); + $this->assertEquals(self::PATH, $this->namespacePathMap->getPath()); + $this->validateArray(); + } + + public function testSetNamespace(): void + { + $this->namespacePathMap->setNamespace(self::NAMESPACE); + $this->validateGet(); + } + + public function testSetPath(): void + { + $this->namespacePathMap->setPath(self::PATH); + $this->validateGet(); + } + + public function testSetFolders(): void + { + $this->namespacePathMap->setFolders(self::FOLDERS); + $this->validateGet(); + } +}