- public function testGetModuleClass()
- {
- $router = new Router(['REQUEST_METHOD' => 'GET']);
-
- $routeCollector = $router->getRouteCollector();
- $routeCollector->addRoute(['GET'], '/', 'IndexModuleClassName');
- $routeCollector->addRoute(['GET'], '/test', 'TestModuleClassName');
- $routeCollector->addRoute(['GET'], '/test/sub', 'TestSubModuleClassName');
- $routeCollector->addRoute(['GET'], '/optional[/option]', 'OptionalModuleClassName');
- $routeCollector->addRoute(['GET'], '/variable/{var}', 'VariableModuleClassName');
- $routeCollector->addRoute(['GET'], '/optionalvariable[/{option}]', 'OptionalVariableModuleClassName');
- $routeCollector->addRoute(['POST', 'PUT', 'PATCH', 'DELETE', 'HEAD'], '/unsupported', 'UnsupportedMethodModuleClassName');
-
- $this->assertEquals('IndexModuleClassName', $router->getModuleClass('/'));
- $this->assertEquals('TestModuleClassName', $router->getModuleClass('/test'));
- $this->assertEquals('TestSubModuleClassName', $router->getModuleClass('/test/sub'));
- $this->assertEquals('OptionalModuleClassName', $router->getModuleClass('/optional'));
- $this->assertEquals('OptionalModuleClassName', $router->getModuleClass('/optional/option'));
- $this->assertEquals('VariableModuleClassName', $router->getModuleClass('/variable/123abc'));
- $this->assertEquals('OptionalVariableModuleClassName', $router->getModuleClass('/optionalvariable'));
- $this->assertEquals('OptionalVariableModuleClassName', $router->getModuleClass('/optionalvariable/123abc'));
- }
-
- public function testGetModuleClassNotFound()
- {
- $this->expectException(NotFoundException::class);
-
- $router = new Router(['REQUEST_METHOD' => 'GET']);
-
- $router->getModuleClass('/unsupported');
- }
-
- public function testGetModuleClassNotFoundTypo()
- {
- $this->expectException(NotFoundException::class);
-
- $router = new Router(['REQUEST_METHOD' => 'GET']);
-
- $routeCollector = $router->getRouteCollector();
- $routeCollector->addRoute(['GET'], '/test', 'TestModuleClassName');
-
- $router->getModuleClass('/tes');
- }
-
- public function testGetModuleClassNotFoundOptional()
- {
- $this->expectException(NotFoundException::class);
-
- $router = new Router(['REQUEST_METHOD' => 'GET']);
-
- $routeCollector = $router->getRouteCollector();
- $routeCollector->addRoute(['GET'], '/optional[/option]', 'OptionalModuleClassName');
-
- $router->getModuleClass('/optional/opt');
- }
-
- public function testGetModuleClassNotFoundVariable()
- {
- $this->expectException(NotFoundException::class);
-
- $router = new Router(['REQUEST_METHOD' => 'GET']);
-
- $routeCollector = $router->getRouteCollector();
- $routeCollector->addRoute(['GET'], '/variable/{var}', 'VariableModuleClassName');
-
- $router->getModuleClass('/variable');
- }