Last active
August 29, 2015 14:06
-
-
Save kerdany/9b63eb726801c99a650f to your computer and use it in GitHub Desktop.
[symfony/routing] TestCase: Inconsistencies in matching lagging slash in routes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Symfony\Component\HttpFoundation\Request; | |
use Symfony\Component\Routing\Route; | |
use Symfony\Component\Routing\RouteCollection; | |
use Symfony\Component\Routing\RequestContext; | |
use Symfony\Component\Routing\Matcher\UrlMatcher; | |
class LaggingSlashInRouteTest extends \PHPUnit_Framework_TestCase | |
{ | |
public function laggingSlashDataProvider() | |
{ | |
// URL Route Path Matches? | |
return array( | |
// Lagging slash is optional in root paths. | |
// This is because Request::getPathInfo() always returns '/' for root paths. | |
array('http://example.com', '/', true), | |
array('http://example.com/', '/', true), | |
// Lagging slash follows the route pattern in non root paths that end with a mandatory variable, or with no variable. | |
array('http://example.com/foo', '/foo', true), | |
array('http://example.com/foo/', '/foo', false), | |
array('http://example.com/foo', '/foo/', false), | |
array('http://example.com/foo/', '/foo/', true), | |
array('http://example.com/foo', '/{mandatory}', true), | |
array('http://example.com/foo/', '/{mandatory}', false), | |
array('http://example.com/foo', '/{mandatory}/', false), | |
array('http://example.com/foo/', '/{mandatory}/', true), | |
// Lagging slash never matches in non-root paths that end with an optional variable. | |
array('http://example.com/foo', '/foo/{optional}', true), | |
array('http://example.com/foo/', '/foo/{optional}', false), | |
array('http://example.com/foo', '/foo/{optional}/', false), | |
array('http://example.com/foo/', '/foo/{optional}/', false), | |
); | |
} | |
/** | |
* @dataProvider laggingSlashDataProvider | |
*/ | |
public function testLaggingSlash($url, $path, $match) | |
{ | |
$request = Request::create($url); | |
$context = new RequestContext(); | |
$context->fromRequest($request); | |
$routes = new RouteCollection(); | |
$routes->add('test_route', new Route($path, array('optional' => 'bar'))); | |
$matcher = new UrlMatcher($routes, $context); | |
if(!$match) { | |
$this->setExpectedException('Symfony\Component\Routing\Exception\ResourceNotFoundException'); | |
} | |
$parameters = $matcher->match($request->getPathInfo()); | |
//$this->assertEquals(array('_route' => 'test_route', 'optional' => 'bar'), $parameters); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment