diff --git a/src/Exception/NotFoundRouteException.php b/src/Exception/NotFoundRouteException.php deleted file mode 100644 index 7be2eab..0000000 --- a/src/Exception/NotFoundRouteException.php +++ /dev/null @@ -1,12 +0,0 @@ -normalizePath($path); + } + + return $this->normalizePath($prefix . '/' . $path); + } +} diff --git a/tests/Unit/PathHelperTest.php b/tests/Unit/PathHelperTest.php new file mode 100644 index 0000000..5a0f70e --- /dev/null +++ b/tests/Unit/PathHelperTest.php @@ -0,0 +1,60 @@ +helper = new class { + use PathHelper; + + public function testNormalize(string $path): string + { + return $this->normalizePath($path); + } + + public function testJoin(string $prefix, string $path): string + { + return $this->joinPaths($prefix, $path); + } + }; + } + + public function testNormalizePathEnsuresLeadingSlash(): void + { + $this->assertSame('/test', $this->helper->testNormalize('test')); + $this->assertSame('/test', $this->helper->testNormalize('/test')); + } + + public function testNormalizePathRemovesTrailingSlash(): void + { + $this->assertSame('/test', $this->helper->testNormalize('test/')); + $this->assertSame('/test', $this->helper->testNormalize('/test/')); + } + + public function testNormalizePathHandlesEmptyOrSlash(): void + { + $this->assertSame('/', $this->helper->testNormalize('')); + $this->assertSame('/', $this->helper->testNormalize('/')); + $this->assertSame('/', $this->helper->testNormalize('///')); + } + + public function testJoinPathsCombinesCorrectly(): void + { + $this->assertSame('/api/users', $this->helper->testJoin('/api', 'users')); + $this->assertSame('/api/users', $this->helper->testJoin('/api/', '/users')); + $this->assertSame('/api/users', $this->helper->testJoin('api', 'users')); + } + + public function testJoinPathsHandlesRootPrefix(): void + { + $this->assertSame('/users', $this->helper->testJoin('/', 'users')); + $this->assertSame('/users', $this->helper->testJoin('', 'users')); + } +}