1
0
mirror of https://github.com/dannyvankooten/AltoRouter.git synced 2025-08-24 09:02:47 +02:00

simplify loop for non-param substring (#131)

optimize comparison using strcmp functions
This commit is contained in:
Koen Punt
2016-06-21 23:27:25 +02:00
committed by GitHub
parent a8ee8e875f
commit 693752b77a
2 changed files with 44 additions and 34 deletions

View File

@@ -306,6 +306,33 @@ class AltoRouterTest extends PHPUnit_Framework_TestCase
$this->assertFalse($this->router->match('/users/1/create', 'GET'));
}
public function testMatchWithPlainRoute()
{
$router = $this->getMockBuilder('AltoRouterDebug')
->setMethods(array('compileRoute'))
->getMock();
// this should prove that compileRoute is not called when the route doesn't
// have any params in it, but this doesn't work because compileRoute is private.
$router->expects($this->never())
->method('compileRoute');
$router->map('GET', '/contact', 'website#contact', 'contact');
// exact match, so no regex compilation necessary
$this->assertEquals(array(
'target' => 'website#contact',
'params' => array(),
'name' => 'contact'
), $router->match('/contact', 'GET'));
$router->map('GET', '/page/[:id]', 'pages#show', 'page');
// no prefix match, so no regex compilation necessary
$this->assertFalse($router->match('/page1', 'GET'));
}
public function testMatchWithServerVars()
{
$this->router->map('GET', '/foo/[:controller]/[:action]', 'foo_action', 'foo_route');