router = new AltoRouter(); } /** * @throws Exception */ public function testAddRoutesThrowsExceptionForInvalidInput() { $this->expectException(RuntimeException::class); $this->router->addRoutes('invalid input'); } public function testGetRoutesReturnsArrayOfRoutes() { $this->assertIsArray($this->router->getRoutes()); } public function testSetBasePathSetsBasePath() { $this->router->setBasePath('/test'); $this->assertEquals('/test', $this->router->getBasePath()); } public function testAddMatchTypesAddsMatchTypes() { $this->router->addMatchTypes(['test' => 'regex']); $this->assertArrayHasKey('test', $this->router->getMatchTypes()); } /** * @throws Exception */ public function testMapAddsRouteToRoutesArray() { $this->router->map('GET', '/test', 'handler'); $this->assertEquals([['GET', '/test', 'handler', null]], $this->router->getRoutes()); } /** * @throws Exception */ public function testMapAddsNamedRouteToNamedRoutesArray() { $this->router->map('GET', '/test', 'handler', 'test'); $this->assertEquals('/test', $this->router->getNamedRoutes()['test']); } /** * @throws Exception */ public function testMapThrowsExceptionForDuplicateNamedRoutes() { $this->expectException(RuntimeException::class); $this->router->map('GET', '/test', 'handler', 'test'); $this->router->map('GET', '/test2', 'handler', 'test'); } }