You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
74 lines
1.8 KiB
74 lines
1.8 KiB
<?php
|
|
|
|
namespace TestConfig;
|
|
|
|
|
|
use Config\AltoRouter;
|
|
use Exception;
|
|
use PHPUnit\Framework\TestCase;
|
|
use RuntimeException;
|
|
|
|
class AltoRouterTest extends TestCase
|
|
{
|
|
protected AltoRouter $router;
|
|
|
|
public function setUp(): void
|
|
{
|
|
$this->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');
|
|
}
|
|
}
|