Laravel version update

Laravel version update
This commit is contained in:
Manish Verma
2018-08-06 18:48:58 +05:30
parent d143048413
commit 126fbb0255
13678 changed files with 1031482 additions and 778530 deletions

View File

@@ -11,9 +11,10 @@
namespace Symfony\Component\Routing\Tests\Annotation;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Routing\Annotation\Route;
class RouteTest extends \PHPUnit_Framework_TestCase
class RouteTest extends TestCase
{
/**
* @expectedException \BadMethodCallException

View File

@@ -11,13 +11,14 @@
namespace Symfony\Component\Routing\Tests;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Routing\CompiledRoute;
class CompiledRouteTest extends \PHPUnit_Framework_TestCase
class CompiledRouteTest extends TestCase
{
public function testAccessors()
{
$compiled = new CompiledRoute('prefix', 'regex', array('tokens'), array(), array(), array(), array(), array('variables'));
$compiled = new CompiledRoute('prefix', 'regex', array('tokens'), array(), null, array(), array(), array('variables'));
$this->assertEquals('prefix', $compiled->getStaticPrefix(), '__construct() takes a static prefix as its second argument');
$this->assertEquals('regex', $compiled->getRegex(), '__construct() takes a regexp as its third argument');
$this->assertEquals(array('tokens'), $compiled->getTokens(), '__construct() takes an array of tokens as its fourth argument');

View File

@@ -0,0 +1,36 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Routing\Tests\DependencyInjection;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Config\Loader\LoaderResolver;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\Routing\DependencyInjection\RoutingResolverPass;
class RoutingResolverPassTest extends TestCase
{
public function testProcess()
{
$container = new ContainerBuilder();
$container->register('routing.resolver', LoaderResolver::class);
$container->register('loader1')->addTag('routing.loader');
$container->register('loader2')->addTag('routing.loader');
(new RoutingResolverPass())->process($container);
$this->assertEquals(
array(array('addLoader', array(new Reference('loader1'))), array('addLoader', array(new Reference('loader2')))),
$container->getDefinition('routing.resolver')->getMethodCalls()
);
}
}

View File

@@ -0,0 +1,19 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Routing\Tests\Fixtures\AnnotatedClasses;
class BazClass
{
public function __invoke()
{
}
}

View File

@@ -0,0 +1,18 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Routing\Tests\Fixtures;
use Symfony\Component\Routing\CompiledRoute;
class CustomCompiledRoute extends CompiledRoute
{
}

View File

@@ -0,0 +1,26 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Routing\Tests\Fixtures;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouteCompiler;
class CustomRouteCompiler extends RouteCompiler
{
/**
* {@inheritdoc}
*/
public static function compile(Route $route)
{
return new CustomCompiledRoute('', '', array(), array());
}
}

View File

@@ -11,8 +11,8 @@
namespace Symfony\Component\Routing\Tests\Fixtures;
use Symfony\Component\Routing\Loader\XmlFileLoader;
use Symfony\Component\Config\Util\XmlUtils;
use Symfony\Component\Routing\Loader\XmlFileLoader;
/**
* XmlFileLoader with schema validation turned off.

View File

@@ -0,0 +1,24 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Routing\Tests\Fixtures\OtherAnnotatedClasses;
trait AnonymousClassInTrait
{
public function test()
{
return new class() {
public function foo()
{
}
};
}
}

View File

@@ -0,0 +1,3 @@
class NoStartTagClass
{
}

View File

@@ -11,8 +11,8 @@
namespace Symfony\Component\Routing\Tests\Fixtures;
use Symfony\Component\Routing\Matcher\UrlMatcher;
use Symfony\Component\Routing\Matcher\RedirectableUrlMatcherInterface;
use Symfony\Component\Routing\Matcher\UrlMatcher;
/**
* @author Fabien Potencier <fabien@symfony.com>

View File

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8" ?>
<routes xmlns="http://symfony.com/schema/routing"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/routing
http://symfony.com/schema/routing/routing-1.0.xsd">
<import resource="routing.xml">
<default key="_controller">FrameworkBundle:Template:template</default>
</import>
</routes>

View File

@@ -0,0 +1,4 @@
_static:
resource: routing.yml
defaults:
_controller: FrameworkBundle:Template:template

View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8" ?>
<routes xmlns="http://symfony.com/schema/routing"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/routing
http://symfony.com/schema/routing/routing-1.0.xsd">
<import resource="routing.xml" controller="FrameworkBundle:Template:template" />
</routes>

View File

@@ -0,0 +1,3 @@
_static:
resource: routing.yml
controller: FrameworkBundle:Template:template

View File

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8" ?>
<routes xmlns="http://symfony.com/schema/routing"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/routing
http://symfony.com/schema/routing/routing-1.0.xsd">
<import resource="routing.xml" controller="FrameworkBundle:Template:template">
<default key="_controller">AppBundle:Blog:index</default>
</import>
</routes>

View File

@@ -0,0 +1,5 @@
_static:
resource: routing.yml
controller: FrameworkBundle:Template:template
defaults:
_controller: AppBundle:Homepage:show

View File

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8" ?>
<routes xmlns="http://symfony.com/schema/routing"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/routing
http://symfony.com/schema/routing/routing-1.0.xsd">
<route id="app_blog" path="/blog" controller="AppBundle:Homepage:show">
<default key="_controller">AppBundle:Blog:index</default>
</route>
</routes>

View File

@@ -0,0 +1,5 @@
app_blog:
path: /blog
controller: AppBundle:Homepage:show
defaults:
_controller: AppBundle:Blog:index

View File

@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8" ?>
<routes xmlns="http://symfony.com/schema/routing"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/routing
http://symfony.com/schema/routing/routing-1.0.xsd">
<route id="app_homepage" path="/" controller="AppBundle:Homepage:show" />
<route id="app_blog" path="/blog">
<default key="_controller">AppBundle:Blog:list</default>
</route>
<route id="app_logout" path="/logout" />
</routes>

View File

@@ -0,0 +1,11 @@
app_homepage:
path: /
controller: AppBundle:Homepage:show
app_blog:
path: /blog
defaults:
_controller: AppBundle:Blog:list
app_logout:
path: /logout

View File

@@ -0,0 +1,37 @@
<?php
use Symfony\Component\Routing\Exception\MethodNotAllowedException;
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
use Symfony\Component\Routing\RequestContext;
/**
* This class has been auto-generated
* by the Symfony Routing Component.
*/
class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
{
public function __construct(RequestContext $context)
{
$this->context = $context;
}
public function match($rawPathinfo)
{
$allow = array();
$pathinfo = rawurldecode($rawPathinfo);
$trimmedPathinfo = rtrim($pathinfo, '/');
$context = $this->context;
$request = $this->request ?: $this->createRequest($pathinfo);
$requestMethod = $canonicalMethod = $context->getMethod();
if ('HEAD' === $requestMethod) {
$canonicalMethod = 'GET';
}
if ('/' === $pathinfo && !$allow) {
throw new Symfony\Component\Routing\Exception\NoConfigurationException();
}
throw 0 < count($allow) ? new MethodNotAllowedException(array_unique($allow)) : new ResourceNotFoundException();
}
}

View File

@@ -1,163 +0,0 @@
# skip "real" requests
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .* - [QSA,L]
# foo
RewriteCond %{REQUEST_URI} ^/foo/(baz|symfony)$
RewriteRule .* app.php [QSA,L,E=_ROUTING_route:foo,E=_ROUTING_param_bar:%1,E=_ROUTING_default_def:test]
# foobar
RewriteCond %{REQUEST_URI} ^/foo(?:/([^/]++))?$
RewriteRule .* app.php [QSA,L,E=_ROUTING_route:foobar,E=_ROUTING_param_bar:%1,E=_ROUTING_default_bar:toto]
# bar
RewriteCond %{REQUEST_URI} ^/bar/([^/]++)$
RewriteCond %{REQUEST_METHOD} !^(GET|HEAD)$ [NC]
RewriteRule .* - [S=1,E=_ROUTING_allow_GET:1,E=_ROUTING_allow_HEAD:1]
RewriteCond %{REQUEST_URI} ^/bar/([^/]++)$
RewriteRule .* app.php [QSA,L,E=_ROUTING_route:bar,E=_ROUTING_param_foo:%1]
# baragain
RewriteCond %{REQUEST_URI} ^/baragain/([^/]++)$
RewriteCond %{REQUEST_METHOD} !^(GET|POST|HEAD)$ [NC]
RewriteRule .* - [S=1,E=_ROUTING_allow_GET:1,E=_ROUTING_allow_POST:1,E=_ROUTING_allow_HEAD:1]
RewriteCond %{REQUEST_URI} ^/baragain/([^/]++)$
RewriteRule .* app.php [QSA,L,E=_ROUTING_route:baragain,E=_ROUTING_param_foo:%1]
# baz
RewriteCond %{REQUEST_URI} ^/test/baz$
RewriteRule .* app.php [QSA,L,E=_ROUTING_route:baz]
# baz2
RewriteCond %{REQUEST_URI} ^/test/baz\.html$
RewriteRule .* app.php [QSA,L,E=_ROUTING_route:baz2]
# baz3
RewriteCond %{REQUEST_URI} ^/test/baz3$
RewriteRule .* $0/ [QSA,L,R=301]
RewriteCond %{REQUEST_URI} ^/test/baz3/$
RewriteRule .* app.php [QSA,L,E=_ROUTING_route:baz3]
# baz4
RewriteCond %{REQUEST_URI} ^/test/([^/]++)$
RewriteRule .* $0/ [QSA,L,R=301]
RewriteCond %{REQUEST_URI} ^/test/([^/]++)/$
RewriteRule .* app.php [QSA,L,E=_ROUTING_route:baz4,E=_ROUTING_param_foo:%1]
# baz5
RewriteCond %{REQUEST_URI} ^/test/([^/]++)/$
RewriteCond %{REQUEST_METHOD} !^(GET|HEAD)$ [NC]
RewriteRule .* - [S=2,E=_ROUTING_allow_GET:1,E=_ROUTING_allow_HEAD:1]
RewriteCond %{REQUEST_URI} ^/test/([^/]++)$
RewriteRule .* $0/ [QSA,L,R=301]
RewriteCond %{REQUEST_URI} ^/test/([^/]++)/$
RewriteRule .* app.php [QSA,L,E=_ROUTING_route:baz5,E=_ROUTING_param_foo:%1]
# baz5unsafe
RewriteCond %{REQUEST_URI} ^/testunsafe/([^/]++)/$
RewriteCond %{REQUEST_METHOD} !^(POST)$ [NC]
RewriteRule .* - [S=1,E=_ROUTING_allow_POST:1]
RewriteCond %{REQUEST_URI} ^/testunsafe/([^/]++)/$
RewriteRule .* app.php [QSA,L,E=_ROUTING_route:baz5unsafe,E=_ROUTING_param_foo:%1]
# baz6
RewriteCond %{REQUEST_URI} ^/test/baz$
RewriteRule .* app.php [QSA,L,E=_ROUTING_route:baz6,E=_ROUTING_default_foo:bar\ baz]
# baz7
RewriteCond %{REQUEST_URI} ^/te\ st/baz$
RewriteRule .* app.php [QSA,L,E=_ROUTING_route:baz7]
# baz8
RewriteCond %{REQUEST_URI} ^/te\\\ st/baz$
RewriteRule .* app.php [QSA,L,E=_ROUTING_route:baz8]
# baz9
RewriteCond %{REQUEST_URI} ^/test/(te\\\ st)$
RewriteRule .* app.php [QSA,L,E=_ROUTING_route:baz9,E=_ROUTING_param_baz:%1]
RewriteCond %{HTTP:Host} ^a\.example\.com$
RewriteRule .? - [E=__ROUTING_host_1:1]
# route1
RewriteCond %{ENV:__ROUTING_host_1} =1
RewriteCond %{REQUEST_URI} ^/route1$
RewriteRule .* app.php [QSA,L,E=_ROUTING_route:route1]
# route2
RewriteCond %{ENV:__ROUTING_host_1} =1
RewriteCond %{REQUEST_URI} ^/c2/route2$
RewriteRule .* app.php [QSA,L,E=_ROUTING_route:route2]
RewriteCond %{HTTP:Host} ^b\.example\.com$
RewriteRule .? - [E=__ROUTING_host_2:1]
# route3
RewriteCond %{ENV:__ROUTING_host_2} =1
RewriteCond %{REQUEST_URI} ^/c2/route3$
RewriteRule .* app.php [QSA,L,E=_ROUTING_route:route3]
RewriteCond %{HTTP:Host} ^a\.example\.com$
RewriteRule .? - [E=__ROUTING_host_3:1]
# route4
RewriteCond %{ENV:__ROUTING_host_3} =1
RewriteCond %{REQUEST_URI} ^/route4$
RewriteRule .* app.php [QSA,L,E=_ROUTING_route:route4]
RewriteCond %{HTTP:Host} ^c\.example\.com$
RewriteRule .? - [E=__ROUTING_host_4:1]
# route5
RewriteCond %{ENV:__ROUTING_host_4} =1
RewriteCond %{REQUEST_URI} ^/route5$
RewriteRule .* app.php [QSA,L,E=_ROUTING_route:route5]
# route6
RewriteCond %{REQUEST_URI} ^/route6$
RewriteRule .* app.php [QSA,L,E=_ROUTING_route:route6]
RewriteCond %{HTTP:Host} ^([^\.]++)\.example\.com$
RewriteRule .? - [E=__ROUTING_host_5:1,E=__ROUTING_host_5_var1:%1]
# route11
RewriteCond %{ENV:__ROUTING_host_5} =1
RewriteCond %{REQUEST_URI} ^/route11$
RewriteRule .* app.php [QSA,L,E=_ROUTING_route:route11,E=_ROUTING_param_var1:%{ENV:__ROUTING_host_5_var1}]
# route12
RewriteCond %{ENV:__ROUTING_host_5} =1
RewriteCond %{REQUEST_URI} ^/route12$
RewriteRule .* app.php [QSA,L,E=_ROUTING_route:route12,E=_ROUTING_param_var1:%{ENV:__ROUTING_host_5_var1},E=_ROUTING_default_var1:val]
# route13
RewriteCond %{ENV:__ROUTING_host_5} =1
RewriteCond %{REQUEST_URI} ^/route13/([^/]++)$
RewriteRule .* app.php [QSA,L,E=_ROUTING_route:route13,E=_ROUTING_param_var1:%{ENV:__ROUTING_host_5_var1},E=_ROUTING_param_name:%1]
# route14
RewriteCond %{ENV:__ROUTING_host_5} =1
RewriteCond %{REQUEST_URI} ^/route14/([^/]++)$
RewriteRule .* app.php [QSA,L,E=_ROUTING_route:route14,E=_ROUTING_param_var1:%{ENV:__ROUTING_host_5_var1},E=_ROUTING_param_name:%1,E=_ROUTING_default_var1:val]
RewriteCond %{HTTP:Host} ^c\.example\.com$
RewriteRule .? - [E=__ROUTING_host_6:1]
# route15
RewriteCond %{ENV:__ROUTING_host_6} =1
RewriteCond %{REQUEST_URI} ^/route15/([^/]++)$
RewriteRule .* app.php [QSA,L,E=_ROUTING_route:route15,E=_ROUTING_param_name:%1]
# route16
RewriteCond %{REQUEST_URI} ^/route16/([^/]++)$
RewriteRule .* app.php [QSA,L,E=_ROUTING_route:route16,E=_ROUTING_param_name:%1,E=_ROUTING_default_var1:val]
# route17
RewriteCond %{REQUEST_URI} ^/route17$
RewriteRule .* app.php [QSA,L,E=_ROUTING_route:route17]
# 405 Method Not Allowed
RewriteCond %{ENV:_ROUTING__allow_GET} =1 [OR]
RewriteCond %{ENV:_ROUTING__allow_HEAD} =1 [OR]
RewriteCond %{ENV:_ROUTING__allow_POST} =1
RewriteRule .* app.php [QSA,L]

View File

@@ -5,148 +5,156 @@ use Symfony\Component\Routing\Exception\ResourceNotFoundException;
use Symfony\Component\Routing\RequestContext;
/**
* ProjectUrlMatcher.
*
* This class has been auto-generated
* by the Symfony Routing Component.
*/
class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
{
/**
* Constructor.
*/
public function __construct(RequestContext $context)
{
$this->context = $context;
}
public function match($pathinfo)
public function match($rawPathinfo)
{
$allow = array();
$pathinfo = rawurldecode($pathinfo);
$pathinfo = rawurldecode($rawPathinfo);
$trimmedPathinfo = rtrim($pathinfo, '/');
$context = $this->context;
$request = $this->request;
$request = $this->request ?: $this->createRequest($pathinfo);
$requestMethod = $canonicalMethod = $context->getMethod();
// foo
if (0 === strpos($pathinfo, '/foo') && preg_match('#^/foo/(?P<bar>baz|symfony)$#s', $pathinfo, $matches)) {
return $this->mergeDefaults(array_replace($matches, array('_route' => 'foo')), array ( 'def' => 'test',));
if ('HEAD' === $requestMethod) {
$canonicalMethod = 'GET';
}
if (0 === strpos($pathinfo, '/bar')) {
if (0 === strpos($pathinfo, '/foo')) {
// foo
if (preg_match('#^/foo/(?P<bar>baz|symfony)$#sD', $pathinfo, $matches)) {
return $this->mergeDefaults(array_replace($matches, array('_route' => 'foo')), array ( 'def' => 'test',));
}
// foofoo
if ('/foofoo' === $pathinfo) {
return array ( 'def' => 'test', '_route' => 'foofoo',);
}
}
elseif (0 === strpos($pathinfo, '/bar')) {
// bar
if (preg_match('#^/bar/(?P<foo>[^/]++)$#s', $pathinfo, $matches)) {
if (!in_array($this->context->getMethod(), array('GET', 'HEAD'))) {
if (preg_match('#^/bar/(?P<foo>[^/]++)$#sD', $pathinfo, $matches)) {
$ret = $this->mergeDefaults(array_replace($matches, array('_route' => 'bar')), array ());
if (!in_array($canonicalMethod, array('GET', 'HEAD'))) {
$allow = array_merge($allow, array('GET', 'HEAD'));
goto not_bar;
}
return $this->mergeDefaults(array_replace($matches, array('_route' => 'bar')), array ());
return $ret;
}
not_bar:
// barhead
if (0 === strpos($pathinfo, '/barhead') && preg_match('#^/barhead/(?P<foo>[^/]++)$#s', $pathinfo, $matches)) {
if (!in_array($this->context->getMethod(), array('GET', 'HEAD'))) {
$allow = array_merge($allow, array('GET', 'HEAD'));
if (0 === strpos($pathinfo, '/barhead') && preg_match('#^/barhead/(?P<foo>[^/]++)$#sD', $pathinfo, $matches)) {
$ret = $this->mergeDefaults(array_replace($matches, array('_route' => 'barhead')), array ());
if (!in_array($canonicalMethod, array('GET'))) {
$allow = array_merge($allow, array('GET'));
goto not_barhead;
}
return $this->mergeDefaults(array_replace($matches, array('_route' => 'barhead')), array ());
return $ret;
}
not_barhead:
}
if (0 === strpos($pathinfo, '/test')) {
elseif (0 === strpos($pathinfo, '/test')) {
if (0 === strpos($pathinfo, '/test/baz')) {
// baz
if ($pathinfo === '/test/baz') {
if ('/test/baz' === $pathinfo) {
return array('_route' => 'baz');
}
// baz2
if ($pathinfo === '/test/baz.html') {
if ('/test/baz.html' === $pathinfo) {
return array('_route' => 'baz2');
}
// baz3
if ($pathinfo === '/test/baz3/') {
if ('/test/baz3/' === $pathinfo) {
return array('_route' => 'baz3');
}
}
// baz4
if (preg_match('#^/test/(?P<foo>[^/]++)/$#s', $pathinfo, $matches)) {
if (preg_match('#^/test/(?P<foo>[^/]++)/$#sD', $pathinfo, $matches)) {
return $this->mergeDefaults(array_replace($matches, array('_route' => 'baz4')), array ());
}
// baz5
if (preg_match('#^/test/(?P<foo>[^/]++)/$#s', $pathinfo, $matches)) {
if ($this->context->getMethod() != 'POST') {
$allow[] = 'POST';
if (preg_match('#^/test/(?P<foo>[^/]++)/$#sD', $pathinfo, $matches)) {
$ret = $this->mergeDefaults(array_replace($matches, array('_route' => 'baz5')), array ());
if (!in_array($requestMethod, array('POST'))) {
$allow = array_merge($allow, array('POST'));
goto not_baz5;
}
return $this->mergeDefaults(array_replace($matches, array('_route' => 'baz5')), array ());
return $ret;
}
not_baz5:
// baz.baz6
if (preg_match('#^/test/(?P<foo>[^/]++)/$#s', $pathinfo, $matches)) {
if ($this->context->getMethod() != 'PUT') {
$allow[] = 'PUT';
if (preg_match('#^/test/(?P<foo>[^/]++)/$#sD', $pathinfo, $matches)) {
$ret = $this->mergeDefaults(array_replace($matches, array('_route' => 'baz.baz6')), array ());
if (!in_array($requestMethod, array('PUT'))) {
$allow = array_merge($allow, array('PUT'));
goto not_bazbaz6;
}
return $this->mergeDefaults(array_replace($matches, array('_route' => 'baz.baz6')), array ());
return $ret;
}
not_bazbaz6:
}
// foofoo
if ($pathinfo === '/foofoo') {
return array ( 'def' => 'test', '_route' => 'foofoo',);
}
// quoter
if (preg_match('#^/(?P<quoter>[\']+)$#s', $pathinfo, $matches)) {
if (preg_match('#^/(?P<quoter>[\']+)$#sD', $pathinfo, $matches)) {
return $this->mergeDefaults(array_replace($matches, array('_route' => 'quoter')), array ());
}
// space
if ($pathinfo === '/spa ce') {
if ('/spa ce' === $pathinfo) {
return array('_route' => 'space');
}
if (0 === strpos($pathinfo, '/a')) {
if (0 === strpos($pathinfo, '/a/b\'b')) {
// foo1
if (preg_match('#^/a/b\'b/(?P<foo>[^/]++)$#s', $pathinfo, $matches)) {
if (preg_match('#^/a/b\'b/(?P<foo>[^/]++)$#sD', $pathinfo, $matches)) {
return $this->mergeDefaults(array_replace($matches, array('_route' => 'foo1')), array ());
}
// bar1
if (preg_match('#^/a/b\'b/(?P<bar>[^/]++)$#s', $pathinfo, $matches)) {
if (preg_match('#^/a/b\'b/(?P<bar>[^/]++)$#sD', $pathinfo, $matches)) {
return $this->mergeDefaults(array_replace($matches, array('_route' => 'bar1')), array ());
}
}
// overridden
if (preg_match('#^/a/(?P<var>.*)$#s', $pathinfo, $matches)) {
if (preg_match('#^/a/(?P<var>.*)$#sD', $pathinfo, $matches)) {
return $this->mergeDefaults(array_replace($matches, array('_route' => 'overridden')), array ());
}
if (0 === strpos($pathinfo, '/a/b\'b')) {
// foo2
if (preg_match('#^/a/b\'b/(?P<foo1>[^/]++)$#s', $pathinfo, $matches)) {
if (preg_match('#^/a/b\'b/(?P<foo1>[^/]++)$#sD', $pathinfo, $matches)) {
return $this->mergeDefaults(array_replace($matches, array('_route' => 'foo2')), array ());
}
// bar2
if (preg_match('#^/a/b\'b/(?P<bar1>[^/]++)$#s', $pathinfo, $matches)) {
if (preg_match('#^/a/b\'b/(?P<bar1>[^/]++)$#sD', $pathinfo, $matches)) {
return $this->mergeDefaults(array_replace($matches, array('_route' => 'bar2')), array ());
}
@@ -154,110 +162,110 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
}
if (0 === strpos($pathinfo, '/multi')) {
elseif (0 === strpos($pathinfo, '/multi')) {
// helloWorld
if (0 === strpos($pathinfo, '/multi/hello') && preg_match('#^/multi/hello(?:/(?P<who>[^/]++))?$#s', $pathinfo, $matches)) {
if (0 === strpos($pathinfo, '/multi/hello') && preg_match('#^/multi/hello(?:/(?P<who>[^/]++))?$#sD', $pathinfo, $matches)) {
return $this->mergeDefaults(array_replace($matches, array('_route' => 'helloWorld')), array ( 'who' => 'World!',));
}
// overridden2
if ($pathinfo === '/multi/new') {
return array('_route' => 'overridden2');
// hey
if ('/multi/hey/' === $pathinfo) {
return array('_route' => 'hey');
}
// hey
if ($pathinfo === '/multi/hey/') {
return array('_route' => 'hey');
// overridden2
if ('/multi/new' === $pathinfo) {
return array('_route' => 'overridden2');
}
}
// foo3
if (preg_match('#^/(?P<_locale>[^/]++)/b/(?P<foo>[^/]++)$#s', $pathinfo, $matches)) {
if (preg_match('#^/(?P<_locale>[^/]++)/b/(?P<foo>[^/]++)$#sD', $pathinfo, $matches)) {
return $this->mergeDefaults(array_replace($matches, array('_route' => 'foo3')), array ());
}
// bar3
if (preg_match('#^/(?P<_locale>[^/]++)/b/(?P<bar>[^/]++)$#s', $pathinfo, $matches)) {
if (preg_match('#^/(?P<_locale>[^/]++)/b/(?P<bar>[^/]++)$#sD', $pathinfo, $matches)) {
return $this->mergeDefaults(array_replace($matches, array('_route' => 'bar3')), array ());
}
if (0 === strpos($pathinfo, '/aba')) {
// ababa
if ($pathinfo === '/ababa') {
if ('/ababa' === $pathinfo) {
return array('_route' => 'ababa');
}
// foo4
if (preg_match('#^/aba/(?P<foo>[^/]++)$#s', $pathinfo, $matches)) {
if (preg_match('#^/aba/(?P<foo>[^/]++)$#sD', $pathinfo, $matches)) {
return $this->mergeDefaults(array_replace($matches, array('_route' => 'foo4')), array ());
}
}
$host = $this->context->getHost();
$host = $context->getHost();
if (preg_match('#^a\\.example\\.com$#si', $host, $hostMatches)) {
if (preg_match('#^a\\.example\\.com$#sDi', $host, $hostMatches)) {
// route1
if ($pathinfo === '/route1') {
if ('/route1' === $pathinfo) {
return array('_route' => 'route1');
}
// route2
if ($pathinfo === '/c2/route2') {
if ('/c2/route2' === $pathinfo) {
return array('_route' => 'route2');
}
}
if (preg_match('#^b\\.example\\.com$#si', $host, $hostMatches)) {
if (preg_match('#^b\\.example\\.com$#sDi', $host, $hostMatches)) {
// route3
if ($pathinfo === '/c2/route3') {
if ('/c2/route3' === $pathinfo) {
return array('_route' => 'route3');
}
}
if (preg_match('#^a\\.example\\.com$#si', $host, $hostMatches)) {
if (preg_match('#^a\\.example\\.com$#sDi', $host, $hostMatches)) {
// route4
if ($pathinfo === '/route4') {
if ('/route4' === $pathinfo) {
return array('_route' => 'route4');
}
}
if (preg_match('#^c\\.example\\.com$#si', $host, $hostMatches)) {
if (preg_match('#^c\\.example\\.com$#sDi', $host, $hostMatches)) {
// route5
if ($pathinfo === '/route5') {
if ('/route5' === $pathinfo) {
return array('_route' => 'route5');
}
}
// route6
if ($pathinfo === '/route6') {
if ('/route6' === $pathinfo) {
return array('_route' => 'route6');
}
if (preg_match('#^(?P<var1>[^\\.]++)\\.example\\.com$#si', $host, $hostMatches)) {
if (preg_match('#^(?P<var1>[^\\.]++)\\.example\\.com$#sDi', $host, $hostMatches)) {
if (0 === strpos($pathinfo, '/route1')) {
// route11
if ($pathinfo === '/route11') {
if ('/route11' === $pathinfo) {
return $this->mergeDefaults(array_replace($hostMatches, array('_route' => 'route11')), array ());
}
// route12
if ($pathinfo === '/route12') {
if ('/route12' === $pathinfo) {
return $this->mergeDefaults(array_replace($hostMatches, array('_route' => 'route12')), array ( 'var1' => 'val',));
}
// route13
if (0 === strpos($pathinfo, '/route13') && preg_match('#^/route13/(?P<name>[^/]++)$#s', $pathinfo, $matches)) {
if (0 === strpos($pathinfo, '/route13') && preg_match('#^/route13/(?P<name>[^/]++)$#sD', $pathinfo, $matches)) {
return $this->mergeDefaults(array_replace($hostMatches, $matches, array('_route' => 'route13')), array ());
}
// route14
if (0 === strpos($pathinfo, '/route14') && preg_match('#^/route14/(?P<name>[^/]++)$#s', $pathinfo, $matches)) {
if (0 === strpos($pathinfo, '/route14') && preg_match('#^/route14/(?P<name>[^/]++)$#sD', $pathinfo, $matches)) {
return $this->mergeDefaults(array_replace($hostMatches, $matches, array('_route' => 'route14')), array ( 'var1' => 'val',));
}
@@ -265,46 +273,44 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
}
if (preg_match('#^c\\.example\\.com$#si', $host, $hostMatches)) {
if (preg_match('#^c\\.example\\.com$#sDi', $host, $hostMatches)) {
// route15
if (0 === strpos($pathinfo, '/route15') && preg_match('#^/route15/(?P<name>[^/]++)$#s', $pathinfo, $matches)) {
if (0 === strpos($pathinfo, '/route15') && preg_match('#^/route15/(?P<name>[^/]++)$#sD', $pathinfo, $matches)) {
return $this->mergeDefaults(array_replace($matches, array('_route' => 'route15')), array ());
}
}
if (0 === strpos($pathinfo, '/route1')) {
// route16
if (0 === strpos($pathinfo, '/route16') && preg_match('#^/route16/(?P<name>[^/]++)$#s', $pathinfo, $matches)) {
return $this->mergeDefaults(array_replace($matches, array('_route' => 'route16')), array ( 'var1' => 'val',));
// route16
if (0 === strpos($pathinfo, '/route16') && preg_match('#^/route16/(?P<name>[^/]++)$#sD', $pathinfo, $matches)) {
return $this->mergeDefaults(array_replace($matches, array('_route' => 'route16')), array ( 'var1' => 'val',));
}
// route17
if ('/route17' === $pathinfo) {
return array('_route' => 'route17');
}
// a
if ('/a/a...' === $pathinfo) {
return array('_route' => 'a');
}
if (0 === strpos($pathinfo, '/a/b')) {
// b
if (preg_match('#^/a/b/(?P<var>[^/]++)$#sD', $pathinfo, $matches)) {
return $this->mergeDefaults(array_replace($matches, array('_route' => 'b')), array ());
}
// route17
if ($pathinfo === '/route17') {
return array('_route' => 'route17');
// c
if (0 === strpos($pathinfo, '/a/b/c') && preg_match('#^/a/b/c/(?P<var>[^/]++)$#sD', $pathinfo, $matches)) {
return $this->mergeDefaults(array_replace($matches, array('_route' => 'c')), array ());
}
}
if (0 === strpos($pathinfo, '/a')) {
// a
if ($pathinfo === '/a/a...') {
return array('_route' => 'a');
}
if (0 === strpos($pathinfo, '/a/b')) {
// b
if (preg_match('#^/a/b/(?P<var>[^/]++)$#s', $pathinfo, $matches)) {
return $this->mergeDefaults(array_replace($matches, array('_route' => 'b')), array ());
}
// c
if (0 === strpos($pathinfo, '/a/b/c') && preg_match('#^/a/b/c/(?P<var>[^/]++)$#s', $pathinfo, $matches)) {
return $this->mergeDefaults(array_replace($matches, array('_route' => 'c')), array ());
}
}
if ('/' === $pathinfo && !$allow) {
throw new Symfony\Component\Routing\Exception\NoConfigurationException();
}
throw 0 < count($allow) ? new MethodNotAllowedException(array_unique($allow)) : new ResourceNotFoundException();

View File

@@ -1,7 +0,0 @@
# skip "real" requests
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .* - [QSA,L]
# foo
RewriteCond %{REQUEST_URI} ^/foo$
RewriteRule .* ap\ p_d\ ev.php [QSA,L,E=_ROUTING_route:foo]

View File

@@ -5,156 +5,176 @@ use Symfony\Component\Routing\Exception\ResourceNotFoundException;
use Symfony\Component\Routing\RequestContext;
/**
* ProjectUrlMatcher.
*
* This class has been auto-generated
* by the Symfony Routing Component.
*/
class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\RedirectableUrlMatcher
{
/**
* Constructor.
*/
public function __construct(RequestContext $context)
{
$this->context = $context;
}
public function match($pathinfo)
public function match($rawPathinfo)
{
$allow = array();
$pathinfo = rawurldecode($pathinfo);
$pathinfo = rawurldecode($rawPathinfo);
$trimmedPathinfo = rtrim($pathinfo, '/');
$context = $this->context;
$request = $this->request;
$request = $this->request ?: $this->createRequest($pathinfo);
$requestMethod = $canonicalMethod = $context->getMethod();
// foo
if (0 === strpos($pathinfo, '/foo') && preg_match('#^/foo/(?P<bar>baz|symfony)$#s', $pathinfo, $matches)) {
return $this->mergeDefaults(array_replace($matches, array('_route' => 'foo')), array ( 'def' => 'test',));
if ('HEAD' === $requestMethod) {
$canonicalMethod = 'GET';
}
if (0 === strpos($pathinfo, '/bar')) {
if (0 === strpos($pathinfo, '/foo')) {
// foo
if (preg_match('#^/foo/(?P<bar>baz|symfony)$#sD', $pathinfo, $matches)) {
return $this->mergeDefaults(array_replace($matches, array('_route' => 'foo')), array ( 'def' => 'test',));
}
// foofoo
if ('/foofoo' === $pathinfo) {
return array ( 'def' => 'test', '_route' => 'foofoo',);
}
}
elseif (0 === strpos($pathinfo, '/bar')) {
// bar
if (preg_match('#^/bar/(?P<foo>[^/]++)$#s', $pathinfo, $matches)) {
if (!in_array($this->context->getMethod(), array('GET', 'HEAD'))) {
if (preg_match('#^/bar/(?P<foo>[^/]++)$#sD', $pathinfo, $matches)) {
$ret = $this->mergeDefaults(array_replace($matches, array('_route' => 'bar')), array ());
if (!in_array($canonicalMethod, array('GET', 'HEAD'))) {
$allow = array_merge($allow, array('GET', 'HEAD'));
goto not_bar;
}
return $this->mergeDefaults(array_replace($matches, array('_route' => 'bar')), array ());
return $ret;
}
not_bar:
// barhead
if (0 === strpos($pathinfo, '/barhead') && preg_match('#^/barhead/(?P<foo>[^/]++)$#s', $pathinfo, $matches)) {
if (!in_array($this->context->getMethod(), array('GET', 'HEAD'))) {
$allow = array_merge($allow, array('GET', 'HEAD'));
if (0 === strpos($pathinfo, '/barhead') && preg_match('#^/barhead/(?P<foo>[^/]++)$#sD', $pathinfo, $matches)) {
$ret = $this->mergeDefaults(array_replace($matches, array('_route' => 'barhead')), array ());
if (!in_array($canonicalMethod, array('GET'))) {
$allow = array_merge($allow, array('GET'));
goto not_barhead;
}
return $this->mergeDefaults(array_replace($matches, array('_route' => 'barhead')), array ());
return $ret;
}
not_barhead:
}
if (0 === strpos($pathinfo, '/test')) {
elseif (0 === strpos($pathinfo, '/test')) {
if (0 === strpos($pathinfo, '/test/baz')) {
// baz
if ($pathinfo === '/test/baz') {
if ('/test/baz' === $pathinfo) {
return array('_route' => 'baz');
}
// baz2
if ($pathinfo === '/test/baz.html') {
if ('/test/baz.html' === $pathinfo) {
return array('_route' => 'baz2');
}
// baz3
if (rtrim($pathinfo, '/') === '/test/baz3') {
if (substr($pathinfo, -1) !== '/') {
return $this->redirect($pathinfo.'/', 'baz3');
if ('/test/baz3' === $trimmedPathinfo) {
$ret = array('_route' => 'baz3');
if ('/' === substr($pathinfo, -1)) {
// no-op
} elseif ('GET' !== $canonicalMethod) {
goto not_baz3;
} else {
return array_replace($ret, $this->redirect($rawPathinfo.'/', 'baz3'));
}
return array('_route' => 'baz3');
return $ret;
}
not_baz3:
}
// baz4
if (preg_match('#^/test/(?P<foo>[^/]++)/?$#s', $pathinfo, $matches)) {
if (substr($pathinfo, -1) !== '/') {
return $this->redirect($pathinfo.'/', 'baz4');
if (preg_match('#^/test/(?P<foo>[^/]++)/?$#sD', $pathinfo, $matches)) {
$ret = $this->mergeDefaults(array_replace($matches, array('_route' => 'baz4')), array ());
if ('/' === substr($pathinfo, -1)) {
// no-op
} elseif ('GET' !== $canonicalMethod) {
goto not_baz4;
} else {
return array_replace($ret, $this->redirect($rawPathinfo.'/', 'baz4'));
}
return $this->mergeDefaults(array_replace($matches, array('_route' => 'baz4')), array ());
return $ret;
}
not_baz4:
// baz5
if (preg_match('#^/test/(?P<foo>[^/]++)/$#s', $pathinfo, $matches)) {
if ($this->context->getMethod() != 'POST') {
$allow[] = 'POST';
if (preg_match('#^/test/(?P<foo>[^/]++)/$#sD', $pathinfo, $matches)) {
$ret = $this->mergeDefaults(array_replace($matches, array('_route' => 'baz5')), array ());
if (!in_array($requestMethod, array('POST'))) {
$allow = array_merge($allow, array('POST'));
goto not_baz5;
}
return $this->mergeDefaults(array_replace($matches, array('_route' => 'baz5')), array ());
return $ret;
}
not_baz5:
// baz.baz6
if (preg_match('#^/test/(?P<foo>[^/]++)/$#s', $pathinfo, $matches)) {
if ($this->context->getMethod() != 'PUT') {
$allow[] = 'PUT';
if (preg_match('#^/test/(?P<foo>[^/]++)/$#sD', $pathinfo, $matches)) {
$ret = $this->mergeDefaults(array_replace($matches, array('_route' => 'baz.baz6')), array ());
if (!in_array($requestMethod, array('PUT'))) {
$allow = array_merge($allow, array('PUT'));
goto not_bazbaz6;
}
return $this->mergeDefaults(array_replace($matches, array('_route' => 'baz.baz6')), array ());
return $ret;
}
not_bazbaz6:
}
// foofoo
if ($pathinfo === '/foofoo') {
return array ( 'def' => 'test', '_route' => 'foofoo',);
}
// quoter
if (preg_match('#^/(?P<quoter>[\']+)$#s', $pathinfo, $matches)) {
if (preg_match('#^/(?P<quoter>[\']+)$#sD', $pathinfo, $matches)) {
return $this->mergeDefaults(array_replace($matches, array('_route' => 'quoter')), array ());
}
// space
if ($pathinfo === '/spa ce') {
if ('/spa ce' === $pathinfo) {
return array('_route' => 'space');
}
if (0 === strpos($pathinfo, '/a')) {
if (0 === strpos($pathinfo, '/a/b\'b')) {
// foo1
if (preg_match('#^/a/b\'b/(?P<foo>[^/]++)$#s', $pathinfo, $matches)) {
if (preg_match('#^/a/b\'b/(?P<foo>[^/]++)$#sD', $pathinfo, $matches)) {
return $this->mergeDefaults(array_replace($matches, array('_route' => 'foo1')), array ());
}
// bar1
if (preg_match('#^/a/b\'b/(?P<bar>[^/]++)$#s', $pathinfo, $matches)) {
if (preg_match('#^/a/b\'b/(?P<bar>[^/]++)$#sD', $pathinfo, $matches)) {
return $this->mergeDefaults(array_replace($matches, array('_route' => 'bar1')), array ());
}
}
// overridden
if (preg_match('#^/a/(?P<var>.*)$#s', $pathinfo, $matches)) {
if (preg_match('#^/a/(?P<var>.*)$#sD', $pathinfo, $matches)) {
return $this->mergeDefaults(array_replace($matches, array('_route' => 'overridden')), array ());
}
if (0 === strpos($pathinfo, '/a/b\'b')) {
// foo2
if (preg_match('#^/a/b\'b/(?P<foo1>[^/]++)$#s', $pathinfo, $matches)) {
if (preg_match('#^/a/b\'b/(?P<foo1>[^/]++)$#sD', $pathinfo, $matches)) {
return $this->mergeDefaults(array_replace($matches, array('_route' => 'foo2')), array ());
}
// bar2
if (preg_match('#^/a/b\'b/(?P<bar1>[^/]++)$#s', $pathinfo, $matches)) {
if (preg_match('#^/a/b\'b/(?P<bar1>[^/]++)$#sD', $pathinfo, $matches)) {
return $this->mergeDefaults(array_replace($matches, array('_route' => 'bar2')), array ());
}
@@ -162,114 +182,120 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
}
if (0 === strpos($pathinfo, '/multi')) {
elseif (0 === strpos($pathinfo, '/multi')) {
// helloWorld
if (0 === strpos($pathinfo, '/multi/hello') && preg_match('#^/multi/hello(?:/(?P<who>[^/]++))?$#s', $pathinfo, $matches)) {
if (0 === strpos($pathinfo, '/multi/hello') && preg_match('#^/multi/hello(?:/(?P<who>[^/]++))?$#sD', $pathinfo, $matches)) {
return $this->mergeDefaults(array_replace($matches, array('_route' => 'helloWorld')), array ( 'who' => 'World!',));
}
// overridden2
if ($pathinfo === '/multi/new') {
return array('_route' => 'overridden2');
}
// hey
if (rtrim($pathinfo, '/') === '/multi/hey') {
if (substr($pathinfo, -1) !== '/') {
return $this->redirect($pathinfo.'/', 'hey');
if ('/multi/hey' === $trimmedPathinfo) {
$ret = array('_route' => 'hey');
if ('/' === substr($pathinfo, -1)) {
// no-op
} elseif ('GET' !== $canonicalMethod) {
goto not_hey;
} else {
return array_replace($ret, $this->redirect($rawPathinfo.'/', 'hey'));
}
return array('_route' => 'hey');
return $ret;
}
not_hey:
// overridden2
if ('/multi/new' === $pathinfo) {
return array('_route' => 'overridden2');
}
}
// foo3
if (preg_match('#^/(?P<_locale>[^/]++)/b/(?P<foo>[^/]++)$#s', $pathinfo, $matches)) {
if (preg_match('#^/(?P<_locale>[^/]++)/b/(?P<foo>[^/]++)$#sD', $pathinfo, $matches)) {
return $this->mergeDefaults(array_replace($matches, array('_route' => 'foo3')), array ());
}
// bar3
if (preg_match('#^/(?P<_locale>[^/]++)/b/(?P<bar>[^/]++)$#s', $pathinfo, $matches)) {
if (preg_match('#^/(?P<_locale>[^/]++)/b/(?P<bar>[^/]++)$#sD', $pathinfo, $matches)) {
return $this->mergeDefaults(array_replace($matches, array('_route' => 'bar3')), array ());
}
if (0 === strpos($pathinfo, '/aba')) {
// ababa
if ($pathinfo === '/ababa') {
if ('/ababa' === $pathinfo) {
return array('_route' => 'ababa');
}
// foo4
if (preg_match('#^/aba/(?P<foo>[^/]++)$#s', $pathinfo, $matches)) {
if (preg_match('#^/aba/(?P<foo>[^/]++)$#sD', $pathinfo, $matches)) {
return $this->mergeDefaults(array_replace($matches, array('_route' => 'foo4')), array ());
}
}
$host = $this->context->getHost();
$host = $context->getHost();
if (preg_match('#^a\\.example\\.com$#si', $host, $hostMatches)) {
if (preg_match('#^a\\.example\\.com$#sDi', $host, $hostMatches)) {
// route1
if ($pathinfo === '/route1') {
if ('/route1' === $pathinfo) {
return array('_route' => 'route1');
}
// route2
if ($pathinfo === '/c2/route2') {
if ('/c2/route2' === $pathinfo) {
return array('_route' => 'route2');
}
}
if (preg_match('#^b\\.example\\.com$#si', $host, $hostMatches)) {
if (preg_match('#^b\\.example\\.com$#sDi', $host, $hostMatches)) {
// route3
if ($pathinfo === '/c2/route3') {
if ('/c2/route3' === $pathinfo) {
return array('_route' => 'route3');
}
}
if (preg_match('#^a\\.example\\.com$#si', $host, $hostMatches)) {
if (preg_match('#^a\\.example\\.com$#sDi', $host, $hostMatches)) {
// route4
if ($pathinfo === '/route4') {
if ('/route4' === $pathinfo) {
return array('_route' => 'route4');
}
}
if (preg_match('#^c\\.example\\.com$#si', $host, $hostMatches)) {
if (preg_match('#^c\\.example\\.com$#sDi', $host, $hostMatches)) {
// route5
if ($pathinfo === '/route5') {
if ('/route5' === $pathinfo) {
return array('_route' => 'route5');
}
}
// route6
if ($pathinfo === '/route6') {
if ('/route6' === $pathinfo) {
return array('_route' => 'route6');
}
if (preg_match('#^(?P<var1>[^\\.]++)\\.example\\.com$#si', $host, $hostMatches)) {
if (preg_match('#^(?P<var1>[^\\.]++)\\.example\\.com$#sDi', $host, $hostMatches)) {
if (0 === strpos($pathinfo, '/route1')) {
// route11
if ($pathinfo === '/route11') {
if ('/route11' === $pathinfo) {
return $this->mergeDefaults(array_replace($hostMatches, array('_route' => 'route11')), array ());
}
// route12
if ($pathinfo === '/route12') {
if ('/route12' === $pathinfo) {
return $this->mergeDefaults(array_replace($hostMatches, array('_route' => 'route12')), array ( 'var1' => 'val',));
}
// route13
if (0 === strpos($pathinfo, '/route13') && preg_match('#^/route13/(?P<name>[^/]++)$#s', $pathinfo, $matches)) {
if (0 === strpos($pathinfo, '/route13') && preg_match('#^/route13/(?P<name>[^/]++)$#sD', $pathinfo, $matches)) {
return $this->mergeDefaults(array_replace($hostMatches, $matches, array('_route' => 'route13')), array ());
}
// route14
if (0 === strpos($pathinfo, '/route14') && preg_match('#^/route14/(?P<name>[^/]++)$#s', $pathinfo, $matches)) {
if (0 === strpos($pathinfo, '/route14') && preg_match('#^/route14/(?P<name>[^/]++)$#sD', $pathinfo, $matches)) {
return $this->mergeDefaults(array_replace($hostMatches, $matches, array('_route' => 'route14')), array ( 'var1' => 'val',));
}
@@ -277,66 +303,76 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
}
if (preg_match('#^c\\.example\\.com$#si', $host, $hostMatches)) {
if (preg_match('#^c\\.example\\.com$#sDi', $host, $hostMatches)) {
// route15
if (0 === strpos($pathinfo, '/route15') && preg_match('#^/route15/(?P<name>[^/]++)$#s', $pathinfo, $matches)) {
if (0 === strpos($pathinfo, '/route15') && preg_match('#^/route15/(?P<name>[^/]++)$#sD', $pathinfo, $matches)) {
return $this->mergeDefaults(array_replace($matches, array('_route' => 'route15')), array ());
}
}
if (0 === strpos($pathinfo, '/route1')) {
// route16
if (0 === strpos($pathinfo, '/route16') && preg_match('#^/route16/(?P<name>[^/]++)$#s', $pathinfo, $matches)) {
return $this->mergeDefaults(array_replace($matches, array('_route' => 'route16')), array ( 'var1' => 'val',));
}
// route17
if ($pathinfo === '/route17') {
return array('_route' => 'route17');
}
// route16
if (0 === strpos($pathinfo, '/route16') && preg_match('#^/route16/(?P<name>[^/]++)$#sD', $pathinfo, $matches)) {
return $this->mergeDefaults(array_replace($matches, array('_route' => 'route16')), array ( 'var1' => 'val',));
}
if (0 === strpos($pathinfo, '/a')) {
// a
if ($pathinfo === '/a/a...') {
return array('_route' => 'a');
// route17
if ('/route17' === $pathinfo) {
return array('_route' => 'route17');
}
// a
if ('/a/a...' === $pathinfo) {
return array('_route' => 'a');
}
if (0 === strpos($pathinfo, '/a/b')) {
// b
if (preg_match('#^/a/b/(?P<var>[^/]++)$#sD', $pathinfo, $matches)) {
return $this->mergeDefaults(array_replace($matches, array('_route' => 'b')), array ());
}
if (0 === strpos($pathinfo, '/a/b')) {
// b
if (preg_match('#^/a/b/(?P<var>[^/]++)$#s', $pathinfo, $matches)) {
return $this->mergeDefaults(array_replace($matches, array('_route' => 'b')), array ());
}
// c
if (0 === strpos($pathinfo, '/a/b/c') && preg_match('#^/a/b/c/(?P<var>[^/]++)$#s', $pathinfo, $matches)) {
return $this->mergeDefaults(array_replace($matches, array('_route' => 'c')), array ());
}
// c
if (0 === strpos($pathinfo, '/a/b/c') && preg_match('#^/a/b/c/(?P<var>[^/]++)$#sD', $pathinfo, $matches)) {
return $this->mergeDefaults(array_replace($matches, array('_route' => 'c')), array ());
}
}
// secure
if ($pathinfo === '/secure') {
if ('/secure' === $pathinfo) {
$ret = array('_route' => 'secure');
$requiredSchemes = array ( 'https' => 0,);
if (!isset($requiredSchemes[$this->context->getScheme()])) {
return $this->redirect($pathinfo, 'secure', key($requiredSchemes));
if (!isset($requiredSchemes[$context->getScheme()])) {
if ('GET' !== $canonicalMethod) {
goto not_secure;
}
return array_replace($ret, $this->redirect($rawPathinfo, 'secure', key($requiredSchemes)));
}
return array('_route' => 'secure');
return $ret;
}
not_secure:
// nonsecure
if ($pathinfo === '/nonsecure') {
if ('/nonsecure' === $pathinfo) {
$ret = array('_route' => 'nonsecure');
$requiredSchemes = array ( 'http' => 0,);
if (!isset($requiredSchemes[$this->context->getScheme()])) {
return $this->redirect($pathinfo, 'nonsecure', key($requiredSchemes));
if (!isset($requiredSchemes[$context->getScheme()])) {
if ('GET' !== $canonicalMethod) {
goto not_nonsecure;
}
return array_replace($ret, $this->redirect($rawPathinfo, 'nonsecure', key($requiredSchemes)));
}
return array('_route' => 'nonsecure');
return $ret;
}
not_nonsecure:
if ('/' === $pathinfo && !$allow) {
throw new Symfony\Component\Routing\Exception\NoConfigurationException();
}
throw 0 < count($allow) ? new MethodNotAllowedException(array_unique($allow)) : new ResourceNotFoundException();

View File

@@ -5,46 +5,51 @@ use Symfony\Component\Routing\Exception\ResourceNotFoundException;
use Symfony\Component\Routing\RequestContext;
/**
* ProjectUrlMatcher.
*
* This class has been auto-generated
* by the Symfony Routing Component.
*/
class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
{
/**
* Constructor.
*/
public function __construct(RequestContext $context)
{
$this->context = $context;
}
public function match($pathinfo)
public function match($rawPathinfo)
{
$allow = array();
$pathinfo = rawurldecode($pathinfo);
$pathinfo = rawurldecode($rawPathinfo);
$trimmedPathinfo = rtrim($pathinfo, '/');
$context = $this->context;
$request = $this->request;
$request = $this->request ?: $this->createRequest($pathinfo);
$requestMethod = $canonicalMethod = $context->getMethod();
if ('HEAD' === $requestMethod) {
$canonicalMethod = 'GET';
}
if (0 === strpos($pathinfo, '/rootprefix')) {
// static
if ($pathinfo === '/rootprefix/test') {
if ('/rootprefix/test' === $pathinfo) {
return array('_route' => 'static');
}
// dynamic
if (preg_match('#^/rootprefix/(?P<var>[^/]++)$#s', $pathinfo, $matches)) {
if (preg_match('#^/rootprefix/(?P<var>[^/]++)$#sD', $pathinfo, $matches)) {
return $this->mergeDefaults(array_replace($matches, array('_route' => 'dynamic')), array ());
}
}
// with-condition
if ($pathinfo === '/with-condition' && ($context->getMethod() == "GET")) {
if ('/with-condition' === $pathinfo && ($context->getMethod() == "GET")) {
return array('_route' => 'with-condition');
}
if ('/' === $pathinfo && !$allow) {
throw new Symfony\Component\Routing\Exception\NoConfigurationException();
}
throw 0 < count($allow) ? new MethodNotAllowedException(array_unique($allow)) : new ResourceNotFoundException();
}
}

View File

@@ -0,0 +1,112 @@
<?php
use Symfony\Component\Routing\Exception\MethodNotAllowedException;
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
use Symfony\Component\Routing\RequestContext;
/**
* This class has been auto-generated
* by the Symfony Routing Component.
*/
class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
{
public function __construct(RequestContext $context)
{
$this->context = $context;
}
public function match($rawPathinfo)
{
$allow = array();
$pathinfo = rawurldecode($rawPathinfo);
$trimmedPathinfo = rtrim($pathinfo, '/');
$context = $this->context;
$request = $this->request ?: $this->createRequest($pathinfo);
$requestMethod = $canonicalMethod = $context->getMethod();
if ('HEAD' === $requestMethod) {
$canonicalMethod = 'GET';
}
// just_head
if ('/just_head' === $pathinfo) {
$ret = array('_route' => 'just_head');
if (!in_array($requestMethod, array('HEAD'))) {
$allow = array_merge($allow, array('HEAD'));
goto not_just_head;
}
return $ret;
}
not_just_head:
// head_and_get
if ('/head_and_get' === $pathinfo) {
$ret = array('_route' => 'head_and_get');
if (!in_array($canonicalMethod, array('HEAD', 'GET'))) {
$allow = array_merge($allow, array('HEAD', 'GET'));
goto not_head_and_get;
}
return $ret;
}
not_head_and_get:
// get_and_head
if ('/get_and_head' === $pathinfo) {
$ret = array('_route' => 'get_and_head');
if (!in_array($canonicalMethod, array('GET', 'HEAD'))) {
$allow = array_merge($allow, array('GET', 'HEAD'));
goto not_get_and_head;
}
return $ret;
}
not_get_and_head:
// post_and_head
if ('/post_and_head' === $pathinfo) {
$ret = array('_route' => 'post_and_head');
if (!in_array($requestMethod, array('POST', 'HEAD'))) {
$allow = array_merge($allow, array('POST', 'HEAD'));
goto not_post_and_head;
}
return $ret;
}
not_post_and_head:
if (0 === strpos($pathinfo, '/put_and_post')) {
// put_and_post
if ('/put_and_post' === $pathinfo) {
$ret = array('_route' => 'put_and_post');
if (!in_array($requestMethod, array('PUT', 'POST'))) {
$allow = array_merge($allow, array('PUT', 'POST'));
goto not_put_and_post;
}
return $ret;
}
not_put_and_post:
// put_and_get_and_head
if ('/put_and_post' === $pathinfo) {
$ret = array('_route' => 'put_and_get_and_head');
if (!in_array($canonicalMethod, array('PUT', 'GET', 'HEAD'))) {
$allow = array_merge($allow, array('PUT', 'GET', 'HEAD'));
goto not_put_and_get_and_head;
}
return $ret;
}
not_put_and_get_and_head:
}
if ('/' === $pathinfo && !$allow) {
throw new Symfony\Component\Routing\Exception\NoConfigurationException();
}
throw 0 < count($allow) ? new MethodNotAllowedException(array_unique($allow)) : new ResourceNotFoundException();
}
}

View File

@@ -0,0 +1,209 @@
<?php
use Symfony\Component\Routing\Exception\MethodNotAllowedException;
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
use Symfony\Component\Routing\RequestContext;
/**
* This class has been auto-generated
* by the Symfony Routing Component.
*/
class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\RedirectableUrlMatcher
{
public function __construct(RequestContext $context)
{
$this->context = $context;
}
public function match($rawPathinfo)
{
$allow = array();
$pathinfo = rawurldecode($rawPathinfo);
$trimmedPathinfo = rtrim($pathinfo, '/');
$context = $this->context;
$request = $this->request ?: $this->createRequest($pathinfo);
$requestMethod = $canonicalMethod = $context->getMethod();
if ('HEAD' === $requestMethod) {
$canonicalMethod = 'GET';
}
if (0 === strpos($pathinfo, '/a')) {
// a_first
if ('/a/11' === $pathinfo) {
return array('_route' => 'a_first');
}
// a_second
if ('/a/22' === $pathinfo) {
return array('_route' => 'a_second');
}
// a_third
if ('/a/333' === $pathinfo) {
return array('_route' => 'a_third');
}
}
// a_wildcard
if (preg_match('#^/(?P<param>[^/]++)$#sD', $pathinfo, $matches)) {
return $this->mergeDefaults(array_replace($matches, array('_route' => 'a_wildcard')), array ());
}
if (0 === strpos($pathinfo, '/a')) {
// a_fourth
if ('/a/44' === $trimmedPathinfo) {
$ret = array('_route' => 'a_fourth');
if ('/' === substr($pathinfo, -1)) {
// no-op
} elseif ('GET' !== $canonicalMethod) {
goto not_a_fourth;
} else {
return array_replace($ret, $this->redirect($rawPathinfo.'/', 'a_fourth'));
}
return $ret;
}
not_a_fourth:
// a_fifth
if ('/a/55' === $trimmedPathinfo) {
$ret = array('_route' => 'a_fifth');
if ('/' === substr($pathinfo, -1)) {
// no-op
} elseif ('GET' !== $canonicalMethod) {
goto not_a_fifth;
} else {
return array_replace($ret, $this->redirect($rawPathinfo.'/', 'a_fifth'));
}
return $ret;
}
not_a_fifth:
// a_sixth
if ('/a/66' === $trimmedPathinfo) {
$ret = array('_route' => 'a_sixth');
if ('/' === substr($pathinfo, -1)) {
// no-op
} elseif ('GET' !== $canonicalMethod) {
goto not_a_sixth;
} else {
return array_replace($ret, $this->redirect($rawPathinfo.'/', 'a_sixth'));
}
return $ret;
}
not_a_sixth:
}
// nested_wildcard
if (0 === strpos($pathinfo, '/nested') && preg_match('#^/nested/(?P<param>[^/]++)$#sD', $pathinfo, $matches)) {
return $this->mergeDefaults(array_replace($matches, array('_route' => 'nested_wildcard')), array ());
}
if (0 === strpos($pathinfo, '/nested/group')) {
// nested_a
if ('/nested/group/a' === $trimmedPathinfo) {
$ret = array('_route' => 'nested_a');
if ('/' === substr($pathinfo, -1)) {
// no-op
} elseif ('GET' !== $canonicalMethod) {
goto not_nested_a;
} else {
return array_replace($ret, $this->redirect($rawPathinfo.'/', 'nested_a'));
}
return $ret;
}
not_nested_a:
// nested_b
if ('/nested/group/b' === $trimmedPathinfo) {
$ret = array('_route' => 'nested_b');
if ('/' === substr($pathinfo, -1)) {
// no-op
} elseif ('GET' !== $canonicalMethod) {
goto not_nested_b;
} else {
return array_replace($ret, $this->redirect($rawPathinfo.'/', 'nested_b'));
}
return $ret;
}
not_nested_b:
// nested_c
if ('/nested/group/c' === $trimmedPathinfo) {
$ret = array('_route' => 'nested_c');
if ('/' === substr($pathinfo, -1)) {
// no-op
} elseif ('GET' !== $canonicalMethod) {
goto not_nested_c;
} else {
return array_replace($ret, $this->redirect($rawPathinfo.'/', 'nested_c'));
}
return $ret;
}
not_nested_c:
}
elseif (0 === strpos($pathinfo, '/slashed/group')) {
// slashed_a
if ('/slashed/group' === $trimmedPathinfo) {
$ret = array('_route' => 'slashed_a');
if ('/' === substr($pathinfo, -1)) {
// no-op
} elseif ('GET' !== $canonicalMethod) {
goto not_slashed_a;
} else {
return array_replace($ret, $this->redirect($rawPathinfo.'/', 'slashed_a'));
}
return $ret;
}
not_slashed_a:
// slashed_b
if ('/slashed/group/b' === $trimmedPathinfo) {
$ret = array('_route' => 'slashed_b');
if ('/' === substr($pathinfo, -1)) {
// no-op
} elseif ('GET' !== $canonicalMethod) {
goto not_slashed_b;
} else {
return array_replace($ret, $this->redirect($rawPathinfo.'/', 'slashed_b'));
}
return $ret;
}
not_slashed_b:
// slashed_c
if ('/slashed/group/c' === $trimmedPathinfo) {
$ret = array('_route' => 'slashed_c');
if ('/' === substr($pathinfo, -1)) {
// no-op
} elseif ('GET' !== $canonicalMethod) {
goto not_slashed_c;
} else {
return array_replace($ret, $this->redirect($rawPathinfo.'/', 'slashed_c'));
}
return $ret;
}
not_slashed_c:
}
if ('/' === $pathinfo && !$allow) {
throw new Symfony\Component\Routing\Exception\NoConfigurationException();
}
throw 0 < count($allow) ? new MethodNotAllowedException(array_unique($allow)) : new ResourceNotFoundException();
}
}

View File

@@ -0,0 +1,213 @@
<?php
use Symfony\Component\Routing\Exception\MethodNotAllowedException;
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
use Symfony\Component\Routing\RequestContext;
/**
* This class has been auto-generated
* by the Symfony Routing Component.
*/
class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
{
public function __construct(RequestContext $context)
{
$this->context = $context;
}
public function match($rawPathinfo)
{
$allow = array();
$pathinfo = rawurldecode($rawPathinfo);
$trimmedPathinfo = rtrim($pathinfo, '/');
$context = $this->context;
$request = $this->request ?: $this->createRequest($pathinfo);
$requestMethod = $canonicalMethod = $context->getMethod();
if ('HEAD' === $requestMethod) {
$canonicalMethod = 'GET';
}
if (0 === strpos($pathinfo, '/trailing/simple')) {
// simple_trailing_slash_no_methods
if ('/trailing/simple/no-methods/' === $pathinfo) {
return array('_route' => 'simple_trailing_slash_no_methods');
}
// simple_trailing_slash_GET_method
if ('/trailing/simple/get-method/' === $pathinfo) {
$ret = array('_route' => 'simple_trailing_slash_GET_method');
if (!in_array($canonicalMethod, array('GET'))) {
$allow = array_merge($allow, array('GET'));
goto not_simple_trailing_slash_GET_method;
}
return $ret;
}
not_simple_trailing_slash_GET_method:
// simple_trailing_slash_HEAD_method
if ('/trailing/simple/head-method/' === $pathinfo) {
$ret = array('_route' => 'simple_trailing_slash_HEAD_method');
if (!in_array($requestMethod, array('HEAD'))) {
$allow = array_merge($allow, array('HEAD'));
goto not_simple_trailing_slash_HEAD_method;
}
return $ret;
}
not_simple_trailing_slash_HEAD_method:
// simple_trailing_slash_POST_method
if ('/trailing/simple/post-method/' === $pathinfo) {
$ret = array('_route' => 'simple_trailing_slash_POST_method');
if (!in_array($requestMethod, array('POST'))) {
$allow = array_merge($allow, array('POST'));
goto not_simple_trailing_slash_POST_method;
}
return $ret;
}
not_simple_trailing_slash_POST_method:
}
elseif (0 === strpos($pathinfo, '/trailing/regex')) {
// regex_trailing_slash_no_methods
if (0 === strpos($pathinfo, '/trailing/regex/no-methods') && preg_match('#^/trailing/regex/no\\-methods/(?P<param>[^/]++)/$#sD', $pathinfo, $matches)) {
return $this->mergeDefaults(array_replace($matches, array('_route' => 'regex_trailing_slash_no_methods')), array ());
}
// regex_trailing_slash_GET_method
if (0 === strpos($pathinfo, '/trailing/regex/get-method') && preg_match('#^/trailing/regex/get\\-method/(?P<param>[^/]++)/$#sD', $pathinfo, $matches)) {
$ret = $this->mergeDefaults(array_replace($matches, array('_route' => 'regex_trailing_slash_GET_method')), array ());
if (!in_array($canonicalMethod, array('GET'))) {
$allow = array_merge($allow, array('GET'));
goto not_regex_trailing_slash_GET_method;
}
return $ret;
}
not_regex_trailing_slash_GET_method:
// regex_trailing_slash_HEAD_method
if (0 === strpos($pathinfo, '/trailing/regex/head-method') && preg_match('#^/trailing/regex/head\\-method/(?P<param>[^/]++)/$#sD', $pathinfo, $matches)) {
$ret = $this->mergeDefaults(array_replace($matches, array('_route' => 'regex_trailing_slash_HEAD_method')), array ());
if (!in_array($requestMethod, array('HEAD'))) {
$allow = array_merge($allow, array('HEAD'));
goto not_regex_trailing_slash_HEAD_method;
}
return $ret;
}
not_regex_trailing_slash_HEAD_method:
// regex_trailing_slash_POST_method
if (0 === strpos($pathinfo, '/trailing/regex/post-method') && preg_match('#^/trailing/regex/post\\-method/(?P<param>[^/]++)/$#sD', $pathinfo, $matches)) {
$ret = $this->mergeDefaults(array_replace($matches, array('_route' => 'regex_trailing_slash_POST_method')), array ());
if (!in_array($requestMethod, array('POST'))) {
$allow = array_merge($allow, array('POST'));
goto not_regex_trailing_slash_POST_method;
}
return $ret;
}
not_regex_trailing_slash_POST_method:
}
elseif (0 === strpos($pathinfo, '/not-trailing/simple')) {
// simple_not_trailing_slash_no_methods
if ('/not-trailing/simple/no-methods' === $pathinfo) {
return array('_route' => 'simple_not_trailing_slash_no_methods');
}
// simple_not_trailing_slash_GET_method
if ('/not-trailing/simple/get-method' === $pathinfo) {
$ret = array('_route' => 'simple_not_trailing_slash_GET_method');
if (!in_array($canonicalMethod, array('GET'))) {
$allow = array_merge($allow, array('GET'));
goto not_simple_not_trailing_slash_GET_method;
}
return $ret;
}
not_simple_not_trailing_slash_GET_method:
// simple_not_trailing_slash_HEAD_method
if ('/not-trailing/simple/head-method' === $pathinfo) {
$ret = array('_route' => 'simple_not_trailing_slash_HEAD_method');
if (!in_array($requestMethod, array('HEAD'))) {
$allow = array_merge($allow, array('HEAD'));
goto not_simple_not_trailing_slash_HEAD_method;
}
return $ret;
}
not_simple_not_trailing_slash_HEAD_method:
// simple_not_trailing_slash_POST_method
if ('/not-trailing/simple/post-method' === $pathinfo) {
$ret = array('_route' => 'simple_not_trailing_slash_POST_method');
if (!in_array($requestMethod, array('POST'))) {
$allow = array_merge($allow, array('POST'));
goto not_simple_not_trailing_slash_POST_method;
}
return $ret;
}
not_simple_not_trailing_slash_POST_method:
}
elseif (0 === strpos($pathinfo, '/not-trailing/regex')) {
// regex_not_trailing_slash_no_methods
if (0 === strpos($pathinfo, '/not-trailing/regex/no-methods') && preg_match('#^/not\\-trailing/regex/no\\-methods/(?P<param>[^/]++)$#sD', $pathinfo, $matches)) {
return $this->mergeDefaults(array_replace($matches, array('_route' => 'regex_not_trailing_slash_no_methods')), array ());
}
// regex_not_trailing_slash_GET_method
if (0 === strpos($pathinfo, '/not-trailing/regex/get-method') && preg_match('#^/not\\-trailing/regex/get\\-method/(?P<param>[^/]++)$#sD', $pathinfo, $matches)) {
$ret = $this->mergeDefaults(array_replace($matches, array('_route' => 'regex_not_trailing_slash_GET_method')), array ());
if (!in_array($canonicalMethod, array('GET'))) {
$allow = array_merge($allow, array('GET'));
goto not_regex_not_trailing_slash_GET_method;
}
return $ret;
}
not_regex_not_trailing_slash_GET_method:
// regex_not_trailing_slash_HEAD_method
if (0 === strpos($pathinfo, '/not-trailing/regex/head-method') && preg_match('#^/not\\-trailing/regex/head\\-method/(?P<param>[^/]++)$#sD', $pathinfo, $matches)) {
$ret = $this->mergeDefaults(array_replace($matches, array('_route' => 'regex_not_trailing_slash_HEAD_method')), array ());
if (!in_array($requestMethod, array('HEAD'))) {
$allow = array_merge($allow, array('HEAD'));
goto not_regex_not_trailing_slash_HEAD_method;
}
return $ret;
}
not_regex_not_trailing_slash_HEAD_method:
// regex_not_trailing_slash_POST_method
if (0 === strpos($pathinfo, '/not-trailing/regex/post-method') && preg_match('#^/not\\-trailing/regex/post\\-method/(?P<param>[^/]++)$#sD', $pathinfo, $matches)) {
$ret = $this->mergeDefaults(array_replace($matches, array('_route' => 'regex_not_trailing_slash_POST_method')), array ());
if (!in_array($requestMethod, array('POST'))) {
$allow = array_merge($allow, array('POST'));
goto not_regex_not_trailing_slash_POST_method;
}
return $ret;
}
not_regex_not_trailing_slash_POST_method:
}
if ('/' === $pathinfo && !$allow) {
throw new Symfony\Component\Routing\Exception\NoConfigurationException();
}
throw 0 < count($allow) ? new MethodNotAllowedException(array_unique($allow)) : new ResourceNotFoundException();
}
}

View File

@@ -0,0 +1,249 @@
<?php
use Symfony\Component\Routing\Exception\MethodNotAllowedException;
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
use Symfony\Component\Routing\RequestContext;
/**
* This class has been auto-generated
* by the Symfony Routing Component.
*/
class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\RedirectableUrlMatcher
{
public function __construct(RequestContext $context)
{
$this->context = $context;
}
public function match($rawPathinfo)
{
$allow = array();
$pathinfo = rawurldecode($rawPathinfo);
$trimmedPathinfo = rtrim($pathinfo, '/');
$context = $this->context;
$request = $this->request ?: $this->createRequest($pathinfo);
$requestMethod = $canonicalMethod = $context->getMethod();
if ('HEAD' === $requestMethod) {
$canonicalMethod = 'GET';
}
if (0 === strpos($pathinfo, '/trailing/simple')) {
// simple_trailing_slash_no_methods
if ('/trailing/simple/no-methods' === $trimmedPathinfo) {
$ret = array('_route' => 'simple_trailing_slash_no_methods');
if ('/' === substr($pathinfo, -1)) {
// no-op
} elseif ('GET' !== $canonicalMethod) {
goto not_simple_trailing_slash_no_methods;
} else {
return array_replace($ret, $this->redirect($rawPathinfo.'/', 'simple_trailing_slash_no_methods'));
}
return $ret;
}
not_simple_trailing_slash_no_methods:
// simple_trailing_slash_GET_method
if ('/trailing/simple/get-method' === $trimmedPathinfo) {
$ret = array('_route' => 'simple_trailing_slash_GET_method');
if ('/' === substr($pathinfo, -1)) {
// no-op
} elseif ('GET' !== $canonicalMethod) {
goto not_simple_trailing_slash_GET_method;
} else {
return array_replace($ret, $this->redirect($rawPathinfo.'/', 'simple_trailing_slash_GET_method'));
}
if (!in_array($canonicalMethod, array('GET'))) {
$allow = array_merge($allow, array('GET'));
goto not_simple_trailing_slash_GET_method;
}
return $ret;
}
not_simple_trailing_slash_GET_method:
// simple_trailing_slash_HEAD_method
if ('/trailing/simple/head-method/' === $pathinfo) {
$ret = array('_route' => 'simple_trailing_slash_HEAD_method');
if (!in_array($requestMethod, array('HEAD'))) {
$allow = array_merge($allow, array('HEAD'));
goto not_simple_trailing_slash_HEAD_method;
}
return $ret;
}
not_simple_trailing_slash_HEAD_method:
// simple_trailing_slash_POST_method
if ('/trailing/simple/post-method/' === $pathinfo) {
$ret = array('_route' => 'simple_trailing_slash_POST_method');
if (!in_array($requestMethod, array('POST'))) {
$allow = array_merge($allow, array('POST'));
goto not_simple_trailing_slash_POST_method;
}
return $ret;
}
not_simple_trailing_slash_POST_method:
}
elseif (0 === strpos($pathinfo, '/trailing/regex')) {
// regex_trailing_slash_no_methods
if (0 === strpos($pathinfo, '/trailing/regex/no-methods') && preg_match('#^/trailing/regex/no\\-methods/(?P<param>[^/]++)/?$#sD', $pathinfo, $matches)) {
$ret = $this->mergeDefaults(array_replace($matches, array('_route' => 'regex_trailing_slash_no_methods')), array ());
if ('/' === substr($pathinfo, -1)) {
// no-op
} elseif ('GET' !== $canonicalMethod) {
goto not_regex_trailing_slash_no_methods;
} else {
return array_replace($ret, $this->redirect($rawPathinfo.'/', 'regex_trailing_slash_no_methods'));
}
return $ret;
}
not_regex_trailing_slash_no_methods:
// regex_trailing_slash_GET_method
if (0 === strpos($pathinfo, '/trailing/regex/get-method') && preg_match('#^/trailing/regex/get\\-method/(?P<param>[^/]++)/?$#sD', $pathinfo, $matches)) {
$ret = $this->mergeDefaults(array_replace($matches, array('_route' => 'regex_trailing_slash_GET_method')), array ());
if ('/' === substr($pathinfo, -1)) {
// no-op
} elseif ('GET' !== $canonicalMethod) {
goto not_regex_trailing_slash_GET_method;
} else {
return array_replace($ret, $this->redirect($rawPathinfo.'/', 'regex_trailing_slash_GET_method'));
}
if (!in_array($canonicalMethod, array('GET'))) {
$allow = array_merge($allow, array('GET'));
goto not_regex_trailing_slash_GET_method;
}
return $ret;
}
not_regex_trailing_slash_GET_method:
// regex_trailing_slash_HEAD_method
if (0 === strpos($pathinfo, '/trailing/regex/head-method') && preg_match('#^/trailing/regex/head\\-method/(?P<param>[^/]++)/$#sD', $pathinfo, $matches)) {
$ret = $this->mergeDefaults(array_replace($matches, array('_route' => 'regex_trailing_slash_HEAD_method')), array ());
if (!in_array($requestMethod, array('HEAD'))) {
$allow = array_merge($allow, array('HEAD'));
goto not_regex_trailing_slash_HEAD_method;
}
return $ret;
}
not_regex_trailing_slash_HEAD_method:
// regex_trailing_slash_POST_method
if (0 === strpos($pathinfo, '/trailing/regex/post-method') && preg_match('#^/trailing/regex/post\\-method/(?P<param>[^/]++)/$#sD', $pathinfo, $matches)) {
$ret = $this->mergeDefaults(array_replace($matches, array('_route' => 'regex_trailing_slash_POST_method')), array ());
if (!in_array($requestMethod, array('POST'))) {
$allow = array_merge($allow, array('POST'));
goto not_regex_trailing_slash_POST_method;
}
return $ret;
}
not_regex_trailing_slash_POST_method:
}
elseif (0 === strpos($pathinfo, '/not-trailing/simple')) {
// simple_not_trailing_slash_no_methods
if ('/not-trailing/simple/no-methods' === $pathinfo) {
return array('_route' => 'simple_not_trailing_slash_no_methods');
}
// simple_not_trailing_slash_GET_method
if ('/not-trailing/simple/get-method' === $pathinfo) {
$ret = array('_route' => 'simple_not_trailing_slash_GET_method');
if (!in_array($canonicalMethod, array('GET'))) {
$allow = array_merge($allow, array('GET'));
goto not_simple_not_trailing_slash_GET_method;
}
return $ret;
}
not_simple_not_trailing_slash_GET_method:
// simple_not_trailing_slash_HEAD_method
if ('/not-trailing/simple/head-method' === $pathinfo) {
$ret = array('_route' => 'simple_not_trailing_slash_HEAD_method');
if (!in_array($requestMethod, array('HEAD'))) {
$allow = array_merge($allow, array('HEAD'));
goto not_simple_not_trailing_slash_HEAD_method;
}
return $ret;
}
not_simple_not_trailing_slash_HEAD_method:
// simple_not_trailing_slash_POST_method
if ('/not-trailing/simple/post-method' === $pathinfo) {
$ret = array('_route' => 'simple_not_trailing_slash_POST_method');
if (!in_array($requestMethod, array('POST'))) {
$allow = array_merge($allow, array('POST'));
goto not_simple_not_trailing_slash_POST_method;
}
return $ret;
}
not_simple_not_trailing_slash_POST_method:
}
elseif (0 === strpos($pathinfo, '/not-trailing/regex')) {
// regex_not_trailing_slash_no_methods
if (0 === strpos($pathinfo, '/not-trailing/regex/no-methods') && preg_match('#^/not\\-trailing/regex/no\\-methods/(?P<param>[^/]++)$#sD', $pathinfo, $matches)) {
return $this->mergeDefaults(array_replace($matches, array('_route' => 'regex_not_trailing_slash_no_methods')), array ());
}
// regex_not_trailing_slash_GET_method
if (0 === strpos($pathinfo, '/not-trailing/regex/get-method') && preg_match('#^/not\\-trailing/regex/get\\-method/(?P<param>[^/]++)$#sD', $pathinfo, $matches)) {
$ret = $this->mergeDefaults(array_replace($matches, array('_route' => 'regex_not_trailing_slash_GET_method')), array ());
if (!in_array($canonicalMethod, array('GET'))) {
$allow = array_merge($allow, array('GET'));
goto not_regex_not_trailing_slash_GET_method;
}
return $ret;
}
not_regex_not_trailing_slash_GET_method:
// regex_not_trailing_slash_HEAD_method
if (0 === strpos($pathinfo, '/not-trailing/regex/head-method') && preg_match('#^/not\\-trailing/regex/head\\-method/(?P<param>[^/]++)$#sD', $pathinfo, $matches)) {
$ret = $this->mergeDefaults(array_replace($matches, array('_route' => 'regex_not_trailing_slash_HEAD_method')), array ());
if (!in_array($requestMethod, array('HEAD'))) {
$allow = array_merge($allow, array('HEAD'));
goto not_regex_not_trailing_slash_HEAD_method;
}
return $ret;
}
not_regex_not_trailing_slash_HEAD_method:
// regex_not_trailing_slash_POST_method
if (0 === strpos($pathinfo, '/not-trailing/regex/post-method') && preg_match('#^/not\\-trailing/regex/post\\-method/(?P<param>[^/]++)$#sD', $pathinfo, $matches)) {
$ret = $this->mergeDefaults(array_replace($matches, array('_route' => 'regex_not_trailing_slash_POST_method')), array ());
if (!in_array($requestMethod, array('POST'))) {
$allow = array_merge($allow, array('POST'));
goto not_regex_not_trailing_slash_POST_method;
}
return $ret;
}
not_regex_not_trailing_slash_POST_method:
}
if ('/' === $pathinfo && !$allow) {
throw new Symfony\Component\Routing\Exception\NoConfigurationException();
}
throw 0 < count($allow) ? new MethodNotAllowedException(array_unique($allow)) : new ResourceNotFoundException();
}
}

View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8" ?>
<routes xmlns="http://symfony.com/schema/routing"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/routing
http://symfony.com/schema/routing/routing-1.0.xsd">
<route id="bar_route" path="/bar" controller="AppBundle:Bar:view" />
</routes>

View File

@@ -0,0 +1,4 @@
bar_route:
path: /bar
defaults:
_controller: AppBundle:Bar:view

View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8" ?>
<routes xmlns="http://symfony.com/schema/routing"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/routing
http://symfony.com/schema/routing/routing-1.0.xsd">
<route id="baz_route" path="/baz" controller="AppBundle:Baz:view" />
</routes>

View File

@@ -0,0 +1,4 @@
baz_route:
path: /baz
defaults:
_controller: AppBundle:Baz:view

View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8" ?>
<routes xmlns="http://symfony.com/schema/routing"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/routing
http://symfony.com/schema/routing/routing-1.0.xsd">
<import resource="ba?.xml" />
</routes>

View File

@@ -0,0 +1,2 @@
_static:
resource: ba?.yml

View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8" ?>
<routes xmlns="http://symfony.com/schema/routing"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/routing
http://symfony.com/schema/routing/routing-1.0.xsd">
<import resource="b?r.xml" />
</routes>

View File

@@ -0,0 +1,2 @@
_static:
resource: b?r.yml

View File

@@ -0,0 +1,7 @@
<?php
namespace Symfony\Component\Routing\Loader\Configurator;
return function (RoutingConfigurator $routes) {
return $routes->import('php_dsl_ba?.php');
};

View File

@@ -0,0 +1,12 @@
<?php
namespace Symfony\Component\Routing\Loader\Configurator;
return function (RoutingConfigurator $routes) {
$collection = $routes->collection();
$collection->add('bar_route', '/bar')
->defaults(array('_controller' => 'AppBundle:Bar:view'));
return $collection;
};

View File

@@ -0,0 +1,12 @@
<?php
namespace Symfony\Component\Routing\Loader\Configurator;
return function (RoutingConfigurator $routes) {
$collection = $routes->collection();
$collection->add('baz_route', '/baz')
->defaults(array('_controller' => 'AppBundle:Baz:view'));
return $collection;
};

View File

@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8" ?>
<routes xmlns="http://symfony.com/schema/routing"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/routing
http://symfony.com/schema/routing/routing-1.0.xsd">
<route id="blog" path="/blog">
<default key="_controller">
<string>AcmeBlogBundle:Blog:index</string>
</default>
<default key="values">
<list>
<bool>true</bool>
<int>1</int>
<float>3.5</float>
<string>foo</string>
</list>
</default>
</route>
</routes>

View File

@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8" ?>
<routes xmlns="http://symfony.com/schema/routing"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/routing
http://symfony.com/schema/routing/routing-1.0.xsd">
<route id="blog" path="/blog">
<default key="_controller">
<string>AcmeBlogBundle:Blog:index</string>
</default>
<default key="values">
<list>
<list>
<bool>true</bool>
<int>1</int>
<float>3.5</float>
<string>foo</string>
</list>
</list>
</default>
</route>
</routes>

View File

@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8" ?>
<routes xmlns="http://symfony.com/schema/routing"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/routing
http://symfony.com/schema/routing/routing-1.0.xsd">
<route id="blog" path="/blog">
<default key="_controller">
<string>AcmeBlogBundle:Blog:index</string>
</default>
<default key="values">
<map>
<list key="list">
<bool>true</bool>
<int>1</int>
<float>3.5</float>
<string>foo</string>
</list>
</map>
</default>
</route>
</routes>

View File

@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8" ?>
<routes xmlns="http://symfony.com/schema/routing"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/routing
http://symfony.com/schema/routing/routing-1.0.xsd">
<route id="blog" path="/blog">
<default key="_controller">
<string>AcmeBlogBundle:Blog:index</string>
</default>
<default key="list">
<list>
<bool xsi:nil="true" />
<int xsi:nil="true" />
<float xsi:nil="1" />
<string xsi:nil="true" />
<list xsi:nil="true" />
<map xsi:nil="true" />
</list>
</default>
</route>
</routes>

View File

@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8" ?>
<routes xmlns="http://symfony.com/schema/routing"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/routing
http://symfony.com/schema/routing/routing-1.0.xsd">
<route id="blog" path="/blog">
<default key="_controller">
<string>AcmeBlogBundle:Blog:index</string>
</default>
<default key="values">
<map>
<bool key="public">true</bool>
<int key="page">1</int>
<float key="price">3.5</float>
<string key="title">foo</string>
</map>
</default>
</route>
</routes>

View File

@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8" ?>
<routes xmlns="http://symfony.com/schema/routing"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/routing
http://symfony.com/schema/routing/routing-1.0.xsd">
<route id="blog" path="/blog">
<default key="_controller">
<string>AcmeBlogBundle:Blog:index</string>
</default>
<default key="values">
<list>
<map>
<bool key="public">true</bool>
<int key="page">1</int>
<float key="price">3.5</float>
<string key="title">foo</string>
</map>
</list>
</default>
</route>
</routes>

View File

@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8" ?>
<routes xmlns="http://symfony.com/schema/routing"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/routing
http://symfony.com/schema/routing/routing-1.0.xsd">
<route id="blog" path="/blog">
<default key="_controller">
<string>AcmeBlogBundle:Blog:index</string>
</default>
<default key="values">
<map>
<map key="map">
<bool key="public">true</bool>
<int key="page">1</int>
<float key="price">3.5</float>
<string key="title">foo</string>
</map>
</map>
</default>
</route>
</routes>

View File

@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8" ?>
<routes xmlns="http://symfony.com/schema/routing"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/routing
http://symfony.com/schema/routing/routing-1.0.xsd">
<route id="blog" path="/blog">
<default key="_controller">
<string>AcmeBlogBundle:Blog:index</string>
</default>
<default key="map">
<map>
<bool key="boolean" xsi:nil="true" />
<int key="integer" xsi:nil="true" />
<float key="float" xsi:nil="true" />
<string key="string" xsi:nil="1" />
<list key="list" xsi:nil="true" />
<map key="map" xsi:nil="true" />
</map>
</default>
</route>
</routes>

View File

@@ -9,5 +9,8 @@
<requirement xmlns="http://symfony.com/schema/routing" key="slug">\w+</requirement>
<r2:requirement xmlns:r2="http://symfony.com/schema/routing" key="_locale">en|fr|de</r2:requirement>
<r:option key="compiler_class">RouteCompiler</r:option>
<r:default key="page">
<r3:int xmlns:r3="http://symfony.com/schema/routing">1</r3:int>
</r:default>
</r:route>
</r:routes>

View File

@@ -0,0 +1,22 @@
<?php
namespace Symfony\Component\Routing\Loader\Configurator;
return function (RoutingConfigurator $routes) {
$routes
->collection()
->add('foo', '/foo')
->condition('abc')
->options(array('utf8' => true))
->add('buz', 'zub')
->controller('foo:act');
$routes->import('php_dsl_sub.php')
->prefix('/sub')
->requirements(array('id' => '\d+'));
$routes->add('ouf', '/ouf')
->schemes(array('https'))
->methods(array('GET'))
->defaults(array('id' => 0));
};

View File

@@ -0,0 +1,14 @@
<?php
namespace Symfony\Component\Routing\Loader\Configurator;
return function (RoutingConfigurator $routes) {
$add = $routes->collection('c_')
->prefix('pub');
$add('bar', '/bar');
$add->collection('pub_')
->host('host')
->add('buz', 'buz');
};

View File

@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8" ?>
<routes xmlns="http://symfony.com/schema/routing"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/routing
http://symfony.com/schema/routing/routing-1.0.xsd">
<route id="blog" path="/blog">
<default key="_controller">
<string>AcmeBlogBundle:Blog:index</string>
</default>
<default key="slug" xsi:nil="true" />
<default key="published">
<bool>true</bool>
</default>
<default key="page">
<int>1</int>
</default>
<default key="price">
<float>3.5</float>
</default>
<default key="archived">
<bool>false</bool>
</default>
<default key="free">
<bool>1</bool>
</default>
<default key="locked">
<bool>0</bool>
</default>
<default key="foo" xsi:nil="true" />
<default key="bar" xsi:nil="1" />
</route>
</routes>

View File

@@ -1,7 +1,7 @@
<?php
use Symfony\Component\Routing\RouteCollection;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouteCollection;
$collection = new RouteCollection();
$collection->add('blog_show', new Route(

View File

@@ -11,13 +11,14 @@
namespace Symfony\Component\Routing\Tests\Generator\Dumper;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Routing\RouteCollection;
use Symfony\Component\Routing\Route;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Routing\Generator\Dumper\PhpGeneratorDumper;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Routing\RequestContext;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouteCollection;
class PhpGeneratorDumperTest extends \PHPUnit_Framework_TestCase
class PhpGeneratorDumperTest extends TestCase
{
/**
* @var RouteCollection
@@ -45,8 +46,8 @@ class PhpGeneratorDumperTest extends \PHPUnit_Framework_TestCase
$this->routeCollection = new RouteCollection();
$this->generatorDumper = new PhpGeneratorDumper($this->routeCollection);
$this->testTmpFilepath = sys_get_temp_dir().DIRECTORY_SEPARATOR.'php_generator.'.$this->getName().'.php';
$this->largeTestTmpFilepath = sys_get_temp_dir().DIRECTORY_SEPARATOR.'php_generator.'.$this->getName().'.large.php';
$this->testTmpFilepath = sys_get_temp_dir().\DIRECTORY_SEPARATOR.'php_generator.'.$this->getName().'.php';
$this->largeTestTmpFilepath = sys_get_temp_dir().\DIRECTORY_SEPARATOR.'php_generator.'.$this->getName().'.large.php';
@unlink($this->testTmpFilepath);
@unlink($this->largeTestTmpFilepath);
}
@@ -77,15 +78,15 @@ class PhpGeneratorDumperTest extends \PHPUnit_Framework_TestCase
$relativeUrlWithParameter = $projectUrlGenerator->generate('Test', array('foo' => 'bar'), UrlGeneratorInterface::ABSOLUTE_PATH);
$relativeUrlWithoutParameter = $projectUrlGenerator->generate('Test2', array(), UrlGeneratorInterface::ABSOLUTE_PATH);
$this->assertEquals($absoluteUrlWithParameter, 'http://localhost/app.php/testing/bar');
$this->assertEquals($absoluteUrlWithoutParameter, 'http://localhost/app.php/testing2');
$this->assertEquals($relativeUrlWithParameter, '/app.php/testing/bar');
$this->assertEquals($relativeUrlWithoutParameter, '/app.php/testing2');
$this->assertEquals('http://localhost/app.php/testing/bar', $absoluteUrlWithParameter);
$this->assertEquals('http://localhost/app.php/testing2', $absoluteUrlWithoutParameter);
$this->assertEquals('/app.php/testing/bar', $relativeUrlWithParameter);
$this->assertEquals('/app.php/testing2', $relativeUrlWithoutParameter);
}
public function testDumpWithTooManyRoutes()
{
if (defined('HHVM_VERSION_ID')) {
if (\defined('HHVM_VERSION_ID')) {
$this->markTestSkipped('HHVM consumes too much memory on this test.');
}
@@ -108,10 +109,10 @@ class PhpGeneratorDumperTest extends \PHPUnit_Framework_TestCase
$relativeUrlWithParameter = $projectUrlGenerator->generate('Test', array('foo' => 'bar'), UrlGeneratorInterface::ABSOLUTE_PATH);
$relativeUrlWithoutParameter = $projectUrlGenerator->generate('Test2', array(), UrlGeneratorInterface::ABSOLUTE_PATH);
$this->assertEquals($absoluteUrlWithParameter, 'http://localhost/app.php/testing/bar');
$this->assertEquals($absoluteUrlWithoutParameter, 'http://localhost/app.php/testing2');
$this->assertEquals($relativeUrlWithParameter, '/app.php/testing/bar');
$this->assertEquals($relativeUrlWithoutParameter, '/app.php/testing2');
$this->assertEquals('http://localhost/app.php/testing/bar', $absoluteUrlWithParameter);
$this->assertEquals('http://localhost/app.php/testing2', $absoluteUrlWithoutParameter);
$this->assertEquals('/app.php/testing/bar', $relativeUrlWithParameter);
$this->assertEquals('/app.php/testing2', $relativeUrlWithoutParameter);
}
/**
@@ -151,7 +152,7 @@ class PhpGeneratorDumperTest extends \PHPUnit_Framework_TestCase
$projectUrlGenerator = new \DefaultRoutesUrlGenerator(new RequestContext());
$url = $projectUrlGenerator->generate('Test', array());
$this->assertEquals($url, '/testing');
$this->assertEquals('/testing', $url);
}
public function testDumpWithSchemeRequirement()
@@ -166,15 +167,15 @@ class PhpGeneratorDumperTest extends \PHPUnit_Framework_TestCase
$absoluteUrl = $projectUrlGenerator->generate('Test1', array(), UrlGeneratorInterface::ABSOLUTE_URL);
$relativeUrl = $projectUrlGenerator->generate('Test1', array(), UrlGeneratorInterface::ABSOLUTE_PATH);
$this->assertEquals($absoluteUrl, 'ftp://localhost/app.php/testing');
$this->assertEquals($relativeUrl, 'ftp://localhost/app.php/testing');
$this->assertEquals('ftp://localhost/app.php/testing', $absoluteUrl);
$this->assertEquals('ftp://localhost/app.php/testing', $relativeUrl);
$projectUrlGenerator = new \SchemeUrlGenerator(new RequestContext('/app.php', 'GET', 'localhost', 'https'));
$absoluteUrl = $projectUrlGenerator->generate('Test1', array(), UrlGeneratorInterface::ABSOLUTE_URL);
$relativeUrl = $projectUrlGenerator->generate('Test1', array(), UrlGeneratorInterface::ABSOLUTE_PATH);
$this->assertEquals($absoluteUrl, 'https://localhost/app.php/testing');
$this->assertEquals($relativeUrl, '/app.php/testing');
$this->assertEquals('https://localhost/app.php/testing', $absoluteUrl);
$this->assertEquals('/app.php/testing', $relativeUrl);
}
}

View File

@@ -11,13 +11,14 @@
namespace Symfony\Component\Routing\Tests\Generator;
use Symfony\Component\Routing\RouteCollection;
use Symfony\Component\Routing\Route;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Routing\Generator\UrlGenerator;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Routing\RequestContext;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouteCollection;
class UrlGeneratorTest extends \PHPUnit_Framework_TestCase
class UrlGeneratorTest extends TestCase
{
public function testAbsoluteUrlWithPort80()
{
@@ -208,7 +209,7 @@ class UrlGeneratorTest extends \PHPUnit_Framework_TestCase
public function testGenerateForRouteWithInvalidOptionalParameterNonStrictWithLogger()
{
$routes = $this->getRoutes('test', new Route('/testing/{foo}', array('foo' => '1'), array('foo' => 'd+')));
$logger = $this->getMock('Psr\Log\LoggerInterface');
$logger = $this->getMockBuilder('Psr\Log\LoggerInterface')->getMock();
$logger->expects($this->once())
->method('error');
$generator = $this->getGenerator($routes, array(), $logger);
@@ -233,6 +234,15 @@ class UrlGeneratorTest extends \PHPUnit_Framework_TestCase
$this->getGenerator($routes)->generate('test', array('foo' => 'bar'), UrlGeneratorInterface::ABSOLUTE_URL);
}
/**
* @expectedException \Symfony\Component\Routing\Exception\InvalidParameterException
*/
public function testGenerateForRouteWithInvalidUtf8Parameter()
{
$routes = $this->getRoutes('test', new Route('/testing/{foo}', array(), array('foo' => '\pL+'), array('utf8' => true)));
$this->getGenerator($routes)->generate('test', array('foo' => 'abc123'), UrlGeneratorInterface::ABSOLUTE_URL);
}
/**
* @expectedException \Symfony\Component\Routing\Exception\InvalidParameterException
*/
@@ -325,18 +335,18 @@ class UrlGeneratorTest extends \PHPUnit_Framework_TestCase
public function testUrlEncoding()
{
$expectedPath = '/app.php/@:%5B%5D/%28%29*%27%22%20+,;-._~%26%24%3C%3E|%7B%7D%25%5C%5E%60!%3Ffoo=bar%23id'
.'/@:%5B%5D/%28%29*%27%22%20+,;-._~%26%24%3C%3E|%7B%7D%25%5C%5E%60!%3Ffoo=bar%23id'
.'?query=%40%3A%5B%5D/%28%29%2A%27%22%20%2B%2C%3B-._~%26%24%3C%3E%7C%7B%7D%25%5C%5E%60%21%3Ffoo%3Dbar%23id';
// This tests the encoding of reserved characters that are used for delimiting of URI components (defined in RFC 3986)
// and other special ASCII chars. These chars are tested as static text path, variable path and query param.
$chars = '@:[]/()*\'" +,;-._~&$<>|{}%\\^`!?foo=bar#id';
$routes = $this->getRoutes('test', new Route("/$chars/{varpath}", array(), array('varpath' => '.+')));
$this->assertSame('/app.php/@:%5B%5D/%28%29*%27%22%20+,;-._~%26%24%3C%3E|%7B%7D%25%5C%5E%60!%3Ffoo=bar%23id'
.'/@:%5B%5D/%28%29*%27%22%20+,;-._~%26%24%3C%3E|%7B%7D%25%5C%5E%60!%3Ffoo=bar%23id'
.'?query=%40%3A%5B%5D/%28%29%2A%27%22+%2B%2C%3B-._%7E%26%24%3C%3E%7C%7B%7D%25%5C%5E%60%21%3Ffoo%3Dbar%23id',
$this->getGenerator($routes)->generate('test', array(
'varpath' => $chars,
'query' => $chars,
))
);
$this->assertSame($expectedPath, $this->getGenerator($routes)->generate('test', array(
'varpath' => $chars,
'query' => $chars,
)));
}
public function testEncodingOfRelativePathSegments()
@@ -358,7 +368,7 @@ class UrlGeneratorTest extends \PHPUnit_Framework_TestCase
// The default requirement for 'x' should not allow the separator '.' in this case because it would otherwise match everything
// and following optional variables like _format could never match.
$this->setExpectedException('Symfony\Component\Routing\Exception\InvalidParameterException');
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Routing\Exception\InvalidParameterException');
$generator->generate('test', array('x' => 'do.t', 'y' => '123', 'z' => 'bar', '_format' => 'xml'));
}
@@ -468,6 +478,38 @@ class UrlGeneratorTest extends \PHPUnit_Framework_TestCase
$this->assertSame('//EN.FooBar.com/app.php/', $generator->generate('test', array('locale' => 'EN'), UrlGeneratorInterface::NETWORK_PATH));
}
public function testDefaultHostIsUsedWhenContextHostIsEmpty()
{
$routes = $this->getRoutes('test', new Route('/route', array('domain' => 'my.fallback.host'), array('domain' => '.+'), array(), '{domain}', array('http')));
$generator = $this->getGenerator($routes);
$generator->getContext()->setHost('');
$this->assertSame('http://my.fallback.host/app.php/route', $generator->generate('test', array(), UrlGeneratorInterface::ABSOLUTE_URL));
}
public function testDefaultHostIsUsedWhenContextHostIsEmptyAndSchemeIsNot()
{
$routes = $this->getRoutes('test', new Route('/route', array('domain' => 'my.fallback.host'), array('domain' => '.+'), array(), '{domain}', array('http', 'https')));
$generator = $this->getGenerator($routes);
$generator->getContext()->setHost('');
$generator->getContext()->setScheme('https');
$this->assertSame('https://my.fallback.host/app.php/route', $generator->generate('test', array(), UrlGeneratorInterface::ABSOLUTE_URL));
}
public function testAbsoluteUrlFallbackToRelativeIfHostIsEmptyAndSchemeIsNot()
{
$routes = $this->getRoutes('test', new Route('/route', array(), array(), array(), '', array('http', 'https')));
$generator = $this->getGenerator($routes);
$generator->getContext()->setHost('');
$generator->getContext()->setScheme('https');
$this->assertSame('/app.php/route', $generator->generate('test', array(), UrlGeneratorInterface::ABSOLUTE_URL));
}
public function testGenerateNetworkPath()
{
$routes = $this->getRoutes('test', new Route('/{name}', array(), array(), array(), '{locale}.example.com', array('http')));
@@ -634,6 +676,33 @@ class UrlGeneratorTest extends \PHPUnit_Framework_TestCase
);
}
public function testFragmentsCanBeAppendedToUrls()
{
$routes = $this->getRoutes('test', new Route('/testing'));
$url = $this->getGenerator($routes)->generate('test', array('_fragment' => 'frag ment'), UrlGeneratorInterface::ABSOLUTE_PATH);
$this->assertEquals('/app.php/testing#frag%20ment', $url);
$url = $this->getGenerator($routes)->generate('test', array('_fragment' => '0'), UrlGeneratorInterface::ABSOLUTE_PATH);
$this->assertEquals('/app.php/testing#0', $url);
}
public function testFragmentsDoNotEscapeValidCharacters()
{
$routes = $this->getRoutes('test', new Route('/testing'));
$url = $this->getGenerator($routes)->generate('test', array('_fragment' => '?/'), UrlGeneratorInterface::ABSOLUTE_PATH);
$this->assertEquals('/app.php/testing#?/', $url);
}
public function testFragmentsCanBeDefinedAsDefaults()
{
$routes = $this->getRoutes('test', new Route('/testing', array('_fragment' => 'fragment')));
$url = $this->getGenerator($routes)->generate('test', array(), UrlGeneratorInterface::ABSOLUTE_PATH);
$this->assertEquals('/app.php/testing#fragment', $url);
}
protected function getGenerator(RouteCollection $routes, array $parameters = array(), $logger = null)
{
$context = new RequestContext('/app.php');

View File

@@ -11,7 +11,9 @@
namespace Symfony\Component\Routing\Tests\Loader;
abstract class AbstractAnnotationLoaderTest extends \PHPUnit_Framework_TestCase
use PHPUnit\Framework\TestCase;
abstract class AbstractAnnotationLoaderTest extends TestCase
{
public function getReader()
{

View File

@@ -127,20 +127,19 @@ class AnnotationClassLoaderTest extends AbstractAnnotationLoaderTest
$this->assertSame($routeData['path'], $route->getPath(), '->load preserves path annotation');
$this->assertCount(
count($routeData['requirements']),
\count($routeData['requirements']),
array_intersect_assoc($routeData['requirements'], $route->getRequirements()),
'->load preserves requirements annotation'
);
$this->assertCount(
count($routeData['options']),
\count($routeData['options']),
array_intersect_assoc($routeData['options'], $route->getOptions()),
'->load preserves options annotation'
);
$defaults = array_replace($methodArgs, $routeData['defaults']);
$this->assertCount(
count($defaults),
array_intersect_assoc($defaults, $route->getDefaults()),
'->load preserves defaults annotation and merges them with default arguments in method signature'
\count($routeData['defaults']),
$route->getDefaults(),
'->load preserves defaults annotation'
);
$this->assertEquals($routeData['schemes'], $route->getSchemes(), '->load preserves schemes annotation');
$this->assertEquals($routeData['methods'], $route->getMethods(), '->load preserves methods annotation');
@@ -150,6 +149,7 @@ class AnnotationClassLoaderTest extends AbstractAnnotationLoaderTest
public function testClassRouteLoad()
{
$classRouteData = array(
'name' => 'prefix_',
'path' => '/prefix',
'schemes' => array('https'),
'methods' => array('GET'),
@@ -174,7 +174,115 @@ class AnnotationClassLoaderTest extends AbstractAnnotationLoaderTest
;
$routeCollection = $this->loader->load('Symfony\Component\Routing\Tests\Fixtures\AnnotatedClasses\BarClass');
$route = $routeCollection->get($methodRouteData['name']);
$route = $routeCollection->get($classRouteData['name'].$methodRouteData['name']);
$this->assertSame($classRouteData['path'].$methodRouteData['path'], $route->getPath(), '->load concatenates class and method route path');
$this->assertEquals(array_merge($classRouteData['schemes'], $methodRouteData['schemes']), $route->getSchemes(), '->load merges class and method route schemes');
$this->assertEquals(array_merge($classRouteData['methods'], $methodRouteData['methods']), $route->getMethods(), '->load merges class and method route methods');
}
public function testInvokableClassRouteLoad()
{
$classRouteData = array(
'name' => 'route1',
'path' => '/',
'schemes' => array('https'),
'methods' => array('GET'),
);
$this->reader
->expects($this->exactly(1))
->method('getClassAnnotations')
->will($this->returnValue(array($this->getAnnotatedRoute($classRouteData))))
;
$this->reader
->expects($this->once())
->method('getMethodAnnotations')
->will($this->returnValue(array()))
;
$routeCollection = $this->loader->load('Symfony\Component\Routing\Tests\Fixtures\AnnotatedClasses\BazClass');
$route = $routeCollection->get($classRouteData['name']);
$this->assertSame($classRouteData['path'], $route->getPath(), '->load preserves class route path');
$this->assertEquals($classRouteData['schemes'], $route->getSchemes(), '->load preserves class route schemes');
$this->assertEquals($classRouteData['methods'], $route->getMethods(), '->load preserves class route methods');
}
public function testInvokableClassMultipleRouteLoad()
{
$classRouteData1 = array(
'name' => 'route1',
'path' => '/1',
'schemes' => array('https'),
'methods' => array('GET'),
);
$classRouteData2 = array(
'name' => 'route2',
'path' => '/2',
'schemes' => array('https'),
'methods' => array('GET'),
);
$this->reader
->expects($this->exactly(1))
->method('getClassAnnotations')
->will($this->returnValue(array($this->getAnnotatedRoute($classRouteData1), $this->getAnnotatedRoute($classRouteData2))))
;
$this->reader
->expects($this->once())
->method('getMethodAnnotations')
->will($this->returnValue(array()))
;
$routeCollection = $this->loader->load('Symfony\Component\Routing\Tests\Fixtures\AnnotatedClasses\BazClass');
$route = $routeCollection->get($classRouteData1['name']);
$this->assertSame($classRouteData1['path'], $route->getPath(), '->load preserves class route path');
$this->assertEquals($classRouteData1['schemes'], $route->getSchemes(), '->load preserves class route schemes');
$this->assertEquals($classRouteData1['methods'], $route->getMethods(), '->load preserves class route methods');
$route = $routeCollection->get($classRouteData2['name']);
$this->assertSame($classRouteData2['path'], $route->getPath(), '->load preserves class route path');
$this->assertEquals($classRouteData2['schemes'], $route->getSchemes(), '->load preserves class route schemes');
$this->assertEquals($classRouteData2['methods'], $route->getMethods(), '->load preserves class route methods');
}
public function testInvokableClassWithMethodRouteLoad()
{
$classRouteData = array(
'name' => 'route1',
'path' => '/prefix',
'schemes' => array('https'),
'methods' => array('GET'),
);
$methodRouteData = array(
'name' => 'route2',
'path' => '/path',
'schemes' => array('http'),
'methods' => array('POST', 'PUT'),
);
$this->reader
->expects($this->once())
->method('getClassAnnotation')
->will($this->returnValue($this->getAnnotatedRoute($classRouteData)))
;
$this->reader
->expects($this->once())
->method('getMethodAnnotations')
->will($this->returnValue(array($this->getAnnotatedRoute($methodRouteData))))
;
$routeCollection = $this->loader->load('Symfony\Component\Routing\Tests\Fixtures\AnnotatedClasses\BazClass');
$route = $routeCollection->get($classRouteData['name']);
$this->assertNull($route, '->load ignores class route');
$route = $routeCollection->get($classRouteData['name'].$methodRouteData['name']);
$this->assertSame($classRouteData['path'].$methodRouteData['path'], $route->getPath(), '->load concatenates class and method route path');
$this->assertEquals(array_merge($classRouteData['schemes'], $methodRouteData['schemes']), $route->getSchemes(), '->load merges class and method route schemes');

View File

@@ -11,8 +11,8 @@
namespace Symfony\Component\Routing\Tests\Loader;
use Symfony\Component\Routing\Loader\AnnotationDirectoryLoader;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\Routing\Loader\AnnotationDirectoryLoader;
class AnnotationDirectoryLoaderTest extends AbstractAnnotationLoaderTest
{
@@ -29,7 +29,7 @@ class AnnotationDirectoryLoaderTest extends AbstractAnnotationLoaderTest
public function testLoad()
{
$this->reader->expects($this->exactly(2))->method('getClassAnnotation');
$this->reader->expects($this->exactly(3))->method('getClassAnnotation');
$this->reader
->expects($this->any())
@@ -37,6 +37,35 @@ class AnnotationDirectoryLoaderTest extends AbstractAnnotationLoaderTest
->will($this->returnValue(array()))
;
$this->reader
->expects($this->any())
->method('getClassAnnotations')
->will($this->returnValue(array()))
;
$this->loader->load(__DIR__.'/../Fixtures/AnnotatedClasses');
}
public function testLoadIgnoresHiddenDirectories()
{
$this->expectAnnotationsToBeReadFrom(array(
'Symfony\Component\Routing\Tests\Fixtures\AnnotatedClasses\BarClass',
'Symfony\Component\Routing\Tests\Fixtures\AnnotatedClasses\BazClass',
'Symfony\Component\Routing\Tests\Fixtures\AnnotatedClasses\FooClass',
));
$this->reader
->expects($this->any())
->method('getMethodAnnotations')
->will($this->returnValue(array()))
;
$this->reader
->expects($this->any())
->method('getClassAnnotations')
->will($this->returnValue(array()))
;
$this->loader->load(__DIR__.'/../Fixtures/AnnotatedClasses');
}
@@ -50,4 +79,31 @@ class AnnotationDirectoryLoaderTest extends AbstractAnnotationLoaderTest
$this->assertTrue($this->loader->supports($fixturesDir, 'annotation'), '->supports() checks the resource type if specified');
$this->assertFalse($this->loader->supports($fixturesDir, 'foo'), '->supports() checks the resource type if specified');
}
public function testItSupportsAnyAnnotation()
{
$this->assertTrue($this->loader->supports(__DIR__.'/../Fixtures/even-with-not-existing-folder', 'annotation'));
}
public function testLoadFileIfLocatedResourceIsFile()
{
$this->reader->expects($this->exactly(1))->method('getClassAnnotation');
$this->reader
->expects($this->any())
->method('getMethodAnnotations')
->will($this->returnValue(array()))
;
$this->loader->load(__DIR__.'/../Fixtures/AnnotatedClasses/FooClass.php');
}
private function expectAnnotationsToBeReadFrom(array $classes)
{
$this->reader->expects($this->exactly(\count($classes)))
->method('getClassAnnotation')
->with($this->callback(function (\ReflectionClass $class) use ($classes) {
return \in_array($class->getName(), $classes);
}));
}
}

View File

@@ -11,9 +11,9 @@
namespace Symfony\Component\Routing\Tests\Loader;
use Symfony\Component\Routing\Loader\AnnotationFileLoader;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Routing\Loader\AnnotationFileLoader;
class AnnotationFileLoaderTest extends AbstractAnnotationLoaderTest
{
@@ -45,6 +45,15 @@ class AnnotationFileLoaderTest extends AbstractAnnotationLoaderTest
$this->loader->load(__DIR__.'/../Fixtures/AnnotatedClasses/FooTrait.php');
}
/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage Did you forgot to add the "<?php" start tag at the beginning of the file?
*/
public function testLoadFileWithoutStartTag()
{
$this->loader->load(__DIR__.'/../Fixtures/OtherAnnotatedClasses/NoStartTagClass.php');
}
/**
* @requires PHP 5.6
*/
@@ -58,6 +67,17 @@ class AnnotationFileLoaderTest extends AbstractAnnotationLoaderTest
$this->loader->load(__DIR__.'/../Fixtures/OtherAnnotatedClasses/VariadicClass.php');
}
/**
* @requires PHP 7.0
*/
public function testLoadAnonymousClass()
{
$this->reader->expects($this->never())->method('getClassAnnotation');
$this->reader->expects($this->never())->method('getMethodAnnotations');
$this->loader->load(__DIR__.'/../Fixtures/OtherAnnotatedClasses/AnonymousClassInTrait.php');
}
public function testSupports()
{
$fixture = __DIR__.'/../Fixtures/annotated.php';

View File

@@ -11,11 +11,12 @@
namespace Symfony\Component\Routing\Tests\Loader;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Routing\Loader\ClosureLoader;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouteCollection;
class ClosureLoaderTest extends \PHPUnit_Framework_TestCase
class ClosureLoaderTest extends TestCase
{
public function testSupports()
{

View File

@@ -11,11 +11,11 @@
namespace Symfony\Component\Routing\Tests\Loader;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\Config\Loader\LoaderResolver;
use Symfony\Component\Routing\Loader\AnnotationFileLoader;
use Symfony\Component\Routing\Loader\DirectoryLoader;
use Symfony\Component\Routing\Loader\YamlFileLoader;
use Symfony\Component\Routing\Loader\AnnotationFileLoader;
use Symfony\Component\Config\Loader\LoaderResolver;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\Routing\RouteCollection;
class DirectoryLoaderTest extends AbstractAnnotationLoaderTest

View File

@@ -0,0 +1,45 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Routing\Tests\Loader;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\Config\Resource\GlobResource;
use Symfony\Component\Routing\Loader\GlobFileLoader;
use Symfony\Component\Routing\RouteCollection;
class GlobFileLoaderTest extends TestCase
{
public function testSupports()
{
$loader = new GlobFileLoader(new FileLocator());
$this->assertTrue($loader->supports('any-path', 'glob'), '->supports() returns true if the resource has the glob type');
$this->assertFalse($loader->supports('any-path'), '->supports() returns false if the resource is not of glob type');
}
public function testLoadAddsTheGlobResourceToTheContainer()
{
$loader = new GlobFileLoaderWithoutImport(new FileLocator());
$collection = $loader->load(__DIR__.'/../Fixtures/directory/*.yml');
$this->assertEquals(new GlobResource(__DIR__.'/../Fixtures/directory', '/*.yml', false), $collection->getResources()[0]);
}
}
class GlobFileLoaderWithoutImport extends GlobFileLoader
{
public function import($resource, $type = null, $ignoreErrors = false, $sourceResource = null)
{
return new RouteCollection();
}
}

View File

@@ -11,11 +11,12 @@
namespace Symfony\Component\Routing\Tests\Loader;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Routing\Loader\ObjectRouteLoader;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouteCollection;
class ObjectRouteLoaderTest extends \PHPUnit_Framework_TestCase
class ObjectRouteLoaderTest extends TestCase
{
public function testLoadCallsServiceAndReturnsCollection()
{

View File

@@ -11,14 +11,18 @@
namespace Symfony\Component\Routing\Tests\Loader;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\Config\Resource\FileResource;
use Symfony\Component\Routing\Loader\PhpFileLoader;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouteCollection;
class PhpFileLoaderTest extends \PHPUnit_Framework_TestCase
class PhpFileLoaderTest extends TestCase
{
public function testSupports()
{
$loader = new PhpFileLoader($this->getMock('Symfony\Component\Config\FileLocator'));
$loader = new PhpFileLoader($this->getMockBuilder('Symfony\Component\Config\FileLocator')->getMock());
$this->assertTrue($loader->supports('foo.php'), '->supports() returns true if the resource is loadable');
$this->assertFalse($loader->supports('foo.foo'), '->supports() returns true if the resource is loadable');
@@ -79,4 +83,51 @@ class PhpFileLoaderTest extends \PHPUnit_Framework_TestCase
(string) $fileResource
);
}
public function testRoutingConfigurator()
{
$locator = new FileLocator(array(__DIR__.'/../Fixtures'));
$loader = new PhpFileLoader($locator);
$routeCollection = $loader->load('php_dsl.php');
$expectedCollection = new RouteCollection();
$expectedCollection->add('foo', (new Route('/foo'))
->setOptions(array('utf8' => true))
->setCondition('abc')
);
$expectedCollection->add('buz', (new Route('/zub'))
->setDefaults(array('_controller' => 'foo:act'))
);
$expectedCollection->add('c_bar', (new Route('/sub/pub/bar'))
->setRequirements(array('id' => '\d+'))
);
$expectedCollection->add('c_pub_buz', (new Route('/sub/pub/buz'))
->setHost('host')
->setRequirements(array('id' => '\d+'))
);
$expectedCollection->add('ouf', (new Route('/ouf'))
->setSchemes(array('https'))
->setMethods(array('GET'))
->setDefaults(array('id' => 0))
);
$expectedCollection->addResource(new FileResource(realpath(__DIR__.'/../Fixtures/php_dsl_sub.php')));
$expectedCollection->addResource(new FileResource(realpath(__DIR__.'/../Fixtures/php_dsl.php')));
$this->assertEquals($expectedCollection, $routeCollection);
}
public function testRoutingConfiguratorCanImportGlobPatterns()
{
$locator = new FileLocator(array(__DIR__.'/../Fixtures/glob'));
$loader = new PhpFileLoader($locator);
$routeCollection = $loader->load('php_dsl.php');
$route = $routeCollection->get('bar_route');
$this->assertSame('AppBundle:Bar:view', $route->getDefault('_controller'));
$route = $routeCollection->get('baz_route');
$this->assertSame('AppBundle:Baz:view', $route->getDefault('_controller'));
}
}

View File

@@ -11,15 +11,16 @@
namespace Symfony\Component\Routing\Tests\Loader;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\Routing\Loader\XmlFileLoader;
use Symfony\Component\Routing\Tests\Fixtures\CustomXmlFileLoader;
class XmlFileLoaderTest extends \PHPUnit_Framework_TestCase
class XmlFileLoaderTest extends TestCase
{
public function testSupports()
{
$loader = new XmlFileLoader($this->getMock('Symfony\Component\Config\FileLocator'));
$loader = new XmlFileLoader($this->getMockBuilder('Symfony\Component\Config\FileLocator')->getMock());
$this->assertTrue($loader->supports('foo.xml'), '->supports() returns true if the resource is loadable');
$this->assertFalse($loader->supports('foo.foo'), '->supports() returns true if the resource is loadable');
@@ -60,6 +61,7 @@ class XmlFileLoaderTest extends \PHPUnit_Framework_TestCase
$this->assertSame('en|fr|de', $route->getRequirement('_locale'));
$this->assertNull($route->getDefault('slug'));
$this->assertSame('RouteCompiler', $route->getOption('compiler_class'));
$this->assertSame(1, $route->getDefault('page'));
}
public function testLoadWithImport()
@@ -129,4 +131,255 @@ class XmlFileLoaderTest extends \PHPUnit_Framework_TestCase
$this->assertEquals('foo', $route->getDefault('foobar'));
$this->assertEquals('bar', $route->getDefault('baz'));
}
public function testScalarDataTypeDefaults()
{
$loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
$routeCollection = $loader->load('scalar_defaults.xml');
$route = $routeCollection->get('blog');
$this->assertSame(
array(
'_controller' => 'AcmeBlogBundle:Blog:index',
'slug' => null,
'published' => true,
'page' => 1,
'price' => 3.5,
'archived' => false,
'free' => true,
'locked' => false,
'foo' => null,
'bar' => null,
),
$route->getDefaults()
);
}
public function testListDefaults()
{
$loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
$routeCollection = $loader->load('list_defaults.xml');
$route = $routeCollection->get('blog');
$this->assertSame(
array(
'_controller' => 'AcmeBlogBundle:Blog:index',
'values' => array(true, 1, 3.5, 'foo'),
),
$route->getDefaults()
);
}
public function testListInListDefaults()
{
$loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
$routeCollection = $loader->load('list_in_list_defaults.xml');
$route = $routeCollection->get('blog');
$this->assertSame(
array(
'_controller' => 'AcmeBlogBundle:Blog:index',
'values' => array(array(true, 1, 3.5, 'foo')),
),
$route->getDefaults()
);
}
public function testListInMapDefaults()
{
$loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
$routeCollection = $loader->load('list_in_map_defaults.xml');
$route = $routeCollection->get('blog');
$this->assertSame(
array(
'_controller' => 'AcmeBlogBundle:Blog:index',
'values' => array('list' => array(true, 1, 3.5, 'foo')),
),
$route->getDefaults()
);
}
public function testMapDefaults()
{
$loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
$routeCollection = $loader->load('map_defaults.xml');
$route = $routeCollection->get('blog');
$this->assertSame(
array(
'_controller' => 'AcmeBlogBundle:Blog:index',
'values' => array(
'public' => true,
'page' => 1,
'price' => 3.5,
'title' => 'foo',
),
),
$route->getDefaults()
);
}
public function testMapInListDefaults()
{
$loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
$routeCollection = $loader->load('map_in_list_defaults.xml');
$route = $routeCollection->get('blog');
$this->assertSame(
array(
'_controller' => 'AcmeBlogBundle:Blog:index',
'values' => array(array(
'public' => true,
'page' => 1,
'price' => 3.5,
'title' => 'foo',
)),
),
$route->getDefaults()
);
}
public function testMapInMapDefaults()
{
$loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
$routeCollection = $loader->load('map_in_map_defaults.xml');
$route = $routeCollection->get('blog');
$this->assertSame(
array(
'_controller' => 'AcmeBlogBundle:Blog:index',
'values' => array('map' => array(
'public' => true,
'page' => 1,
'price' => 3.5,
'title' => 'foo',
)),
),
$route->getDefaults()
);
}
public function testNullValuesInList()
{
$loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
$routeCollection = $loader->load('list_null_values.xml');
$route = $routeCollection->get('blog');
$this->assertSame(array(null, null, null, null, null, null), $route->getDefault('list'));
}
public function testNullValuesInMap()
{
$loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
$routeCollection = $loader->load('map_null_values.xml');
$route = $routeCollection->get('blog');
$this->assertSame(
array(
'boolean' => null,
'integer' => null,
'float' => null,
'string' => null,
'list' => null,
'map' => null,
),
$route->getDefault('map')
);
}
public function testLoadRouteWithControllerAttribute()
{
$loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures/controller')));
$routeCollection = $loader->load('routing.xml');
$route = $routeCollection->get('app_homepage');
$this->assertSame('AppBundle:Homepage:show', $route->getDefault('_controller'));
}
public function testLoadRouteWithoutControllerAttribute()
{
$loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures/controller')));
$routeCollection = $loader->load('routing.xml');
$route = $routeCollection->get('app_logout');
$this->assertNull($route->getDefault('_controller'));
}
public function testLoadRouteWithControllerSetInDefaults()
{
$loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures/controller')));
$routeCollection = $loader->load('routing.xml');
$route = $routeCollection->get('app_blog');
$this->assertSame('AppBundle:Blog:list', $route->getDefault('_controller'));
}
/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessageRegExp /The routing file "[^"]*" must not specify both the "controller" attribute and the defaults key "_controller" for "app_blog"/
*/
public function testOverrideControllerInDefaults()
{
$loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures/controller')));
$loader->load('override_defaults.xml');
}
/**
* @dataProvider provideFilesImportingRoutesWithControllers
*/
public function testImportRouteWithController($file)
{
$loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures/controller')));
$routeCollection = $loader->load($file);
$route = $routeCollection->get('app_homepage');
$this->assertSame('FrameworkBundle:Template:template', $route->getDefault('_controller'));
$route = $routeCollection->get('app_blog');
$this->assertSame('FrameworkBundle:Template:template', $route->getDefault('_controller'));
$route = $routeCollection->get('app_logout');
$this->assertSame('FrameworkBundle:Template:template', $route->getDefault('_controller'));
}
public function provideFilesImportingRoutesWithControllers()
{
yield array('import_controller.xml');
yield array('import__controller.xml');
}
/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessageRegExp /The routing file "[^"]*" must not specify both the "controller" attribute and the defaults key "_controller" for the "import" tag/
*/
public function testImportWithOverriddenController()
{
$loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures/controller')));
$loader->load('import_override_defaults.xml');
}
public function testImportRouteWithGlobMatchingSingleFile()
{
$loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures/glob')));
$routeCollection = $loader->load('import_single.xml');
$route = $routeCollection->get('bar_route');
$this->assertSame('AppBundle:Bar:view', $route->getDefault('_controller'));
}
public function testImportRouteWithGlobMatchingMultipleFiles()
{
$loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures/glob')));
$routeCollection = $loader->load('import_multiple.xml');
$route = $routeCollection->get('bar_route');
$this->assertSame('AppBundle:Bar:view', $route->getDefault('_controller'));
$route = $routeCollection->get('baz_route');
$this->assertSame('AppBundle:Baz:view', $route->getDefault('_controller'));
}
}

View File

@@ -11,15 +11,16 @@
namespace Symfony\Component\Routing\Tests\Loader;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\Routing\Loader\YamlFileLoader;
use Symfony\Component\Config\Resource\FileResource;
use Symfony\Component\Routing\Loader\YamlFileLoader;
class YamlFileLoaderTest extends \PHPUnit_Framework_TestCase
class YamlFileLoaderTest extends TestCase
{
public function testSupports()
{
$loader = new YamlFileLoader($this->getMock('Symfony\Component\Config\FileLocator'));
$loader = new YamlFileLoader($this->getMockBuilder('Symfony\Component\Config\FileLocator')->getMock());
$this->assertTrue($loader->supports('foo.yml'), '->supports() returns true if the resource is loadable');
$this->assertTrue($loader->supports('foo.yaml'), '->supports() returns true if the resource is loadable');
@@ -107,4 +108,99 @@ class YamlFileLoaderTest extends \PHPUnit_Framework_TestCase
$this->assertSame('context.getMethod() == "POST"', $route->getCondition());
}
}
public function testLoadRouteWithControllerAttribute()
{
$loader = new YamlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures/controller')));
$routeCollection = $loader->load('routing.yml');
$route = $routeCollection->get('app_homepage');
$this->assertSame('AppBundle:Homepage:show', $route->getDefault('_controller'));
}
public function testLoadRouteWithoutControllerAttribute()
{
$loader = new YamlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures/controller')));
$routeCollection = $loader->load('routing.yml');
$route = $routeCollection->get('app_logout');
$this->assertNull($route->getDefault('_controller'));
}
public function testLoadRouteWithControllerSetInDefaults()
{
$loader = new YamlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures/controller')));
$routeCollection = $loader->load('routing.yml');
$route = $routeCollection->get('app_blog');
$this->assertSame('AppBundle:Blog:list', $route->getDefault('_controller'));
}
/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessageRegExp /The routing file "[^"]*" must not specify both the "controller" key and the defaults key "_controller" for "app_blog"/
*/
public function testOverrideControllerInDefaults()
{
$loader = new YamlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures/controller')));
$loader->load('override_defaults.yml');
}
/**
* @dataProvider provideFilesImportingRoutesWithControllers
*/
public function testImportRouteWithController($file)
{
$loader = new YamlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures/controller')));
$routeCollection = $loader->load($file);
$route = $routeCollection->get('app_homepage');
$this->assertSame('FrameworkBundle:Template:template', $route->getDefault('_controller'));
$route = $routeCollection->get('app_blog');
$this->assertSame('FrameworkBundle:Template:template', $route->getDefault('_controller'));
$route = $routeCollection->get('app_logout');
$this->assertSame('FrameworkBundle:Template:template', $route->getDefault('_controller'));
}
public function provideFilesImportingRoutesWithControllers()
{
yield array('import_controller.yml');
yield array('import__controller.yml');
}
/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessageRegExp /The routing file "[^"]*" must not specify both the "controller" key and the defaults key "_controller" for "_static"/
*/
public function testImportWithOverriddenController()
{
$loader = new YamlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures/controller')));
$loader->load('import_override_defaults.yml');
}
public function testImportRouteWithGlobMatchingSingleFile()
{
$loader = new YamlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures/glob')));
$routeCollection = $loader->load('import_single.yml');
$route = $routeCollection->get('bar_route');
$this->assertSame('AppBundle:Bar:view', $route->getDefault('_controller'));
}
public function testImportRouteWithGlobMatchingMultipleFiles()
{
$loader = new YamlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures/glob')));
$routeCollection = $loader->load('import_multiple.yml');
$route = $routeCollection->get('bar_route');
$this->assertSame('AppBundle:Bar:view', $route->getDefault('_controller'));
$route = $routeCollection->get('baz_route');
$this->assertSame('AppBundle:Baz:view', $route->getDefault('_controller'));
}
}

View File

@@ -0,0 +1,43 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Routing\Tests\Matcher;
use Symfony\Component\Routing\Matcher\Dumper\PhpMatcherDumper;
use Symfony\Component\Routing\Matcher\RedirectableUrlMatcherInterface;
use Symfony\Component\Routing\Matcher\UrlMatcher;
use Symfony\Component\Routing\RequestContext;
use Symfony\Component\Routing\RouteCollection;
class DumpedRedirectableUrlMatcherTest extends RedirectableUrlMatcherTest
{
protected function getUrlMatcher(RouteCollection $routes, RequestContext $context = null)
{
static $i = 0;
$class = 'DumpedRedirectableUrlMatcher'.++$i;
$dumper = new PhpMatcherDumper($routes);
eval('?>'.$dumper->dump(array('class' => $class, 'base_class' => 'Symfony\Component\Routing\Tests\Matcher\TestDumpedRedirectableUrlMatcher')));
return $this->getMockBuilder($class)
->setConstructorArgs(array($context ?: new RequestContext()))
->setMethods(array('redirect'))
->getMock();
}
}
class TestDumpedRedirectableUrlMatcher extends UrlMatcher implements RedirectableUrlMatcherInterface
{
public function redirect($path, $route, $scheme = null)
{
return array();
}
}

View File

@@ -0,0 +1,48 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Routing\Tests\Matcher;
use Symfony\Component\Routing\Matcher\Dumper\PhpMatcherDumper;
use Symfony\Component\Routing\RequestContext;
use Symfony\Component\Routing\RouteCollection;
class DumpedUrlMatcherTest extends UrlMatcherTest
{
/**
* @expectedException \LogicException
* @expectedExceptionMessage The "schemes" requirement is only supported for URL matchers that implement RedirectableUrlMatcherInterface.
*/
public function testSchemeRequirement()
{
parent::testSchemeRequirement();
}
/**
* @expectedException \LogicException
* @expectedExceptionMessage The "schemes" requirement is only supported for URL matchers that implement RedirectableUrlMatcherInterface.
*/
public function testSchemeAndMethodMismatch()
{
parent::testSchemeRequirement();
}
protected function getUrlMatcher(RouteCollection $routes, RequestContext $context = null)
{
static $i = 0;
$class = 'DumpedUrlMatcher'.++$i;
$dumper = new PhpMatcherDumper($routes);
eval('?>'.$dumper->dump(array('class' => $class)));
return new $class($context ?: new RequestContext());
}
}

View File

@@ -11,9 +11,10 @@
namespace Symfony\Component\Routing\Tests\Matcher\Dumper;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Routing\Matcher\Dumper\DumperCollection;
class DumperCollectionTest extends \PHPUnit_Framework_TestCase
class DumperCollectionTest extends TestCase
{
public function testGetRoot()
{

View File

@@ -1,123 +0,0 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Routing\Tests\Matcher\Dumper;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\Matcher\Dumper\DumperPrefixCollection;
use Symfony\Component\Routing\Matcher\Dumper\DumperRoute;
use Symfony\Component\Routing\Matcher\Dumper\DumperCollection;
class DumperPrefixCollectionTest extends \PHPUnit_Framework_TestCase
{
public function testAddPrefixRoute()
{
$coll = new DumperPrefixCollection();
$coll->setPrefix('');
$route = new DumperRoute('bar', new Route('/foo/bar'));
$coll = $coll->addPrefixRoute($route);
$route = new DumperRoute('bar2', new Route('/foo/bar'));
$coll = $coll->addPrefixRoute($route);
$route = new DumperRoute('qux', new Route('/foo/qux'));
$coll = $coll->addPrefixRoute($route);
$route = new DumperRoute('bar3', new Route('/foo/bar'));
$coll = $coll->addPrefixRoute($route);
$route = new DumperRoute('bar4', new Route(''));
$result = $coll->addPrefixRoute($route);
$expect = <<<'EOF'
|-coll /
| |-coll /f
| | |-coll /fo
| | | |-coll /foo
| | | | |-coll /foo/
| | | | | |-coll /foo/b
| | | | | | |-coll /foo/ba
| | | | | | | |-coll /foo/bar
| | | | | | | | |-route bar /foo/bar
| | | | | | | | |-route bar2 /foo/bar
| | | | | |-coll /foo/q
| | | | | | |-coll /foo/qu
| | | | | | | |-coll /foo/qux
| | | | | | | | |-route qux /foo/qux
| | | | | |-coll /foo/b
| | | | | | |-coll /foo/ba
| | | | | | | |-coll /foo/bar
| | | | | | | | |-route bar3 /foo/bar
| |-route bar4 /
EOF;
$this->assertSame($expect, $this->collectionToString($result->getRoot(), ' '));
}
public function testMergeSlashNodes()
{
$coll = new DumperPrefixCollection();
$coll->setPrefix('');
$route = new DumperRoute('bar', new Route('/foo/bar'));
$coll = $coll->addPrefixRoute($route);
$route = new DumperRoute('bar2', new Route('/foo/bar'));
$coll = $coll->addPrefixRoute($route);
$route = new DumperRoute('qux', new Route('/foo/qux'));
$coll = $coll->addPrefixRoute($route);
$route = new DumperRoute('bar3', new Route('/foo/bar'));
$result = $coll->addPrefixRoute($route);
$result->getRoot()->mergeSlashNodes();
$expect = <<<'EOF'
|-coll /f
| |-coll /fo
| | |-coll /foo
| | | |-coll /foo/b
| | | | |-coll /foo/ba
| | | | | |-coll /foo/bar
| | | | | | |-route bar /foo/bar
| | | | | | |-route bar2 /foo/bar
| | | |-coll /foo/q
| | | | |-coll /foo/qu
| | | | | |-coll /foo/qux
| | | | | | |-route qux /foo/qux
| | | |-coll /foo/b
| | | | |-coll /foo/ba
| | | | | |-coll /foo/bar
| | | | | | |-route bar3 /foo/bar
EOF;
$this->assertSame($expect, $this->collectionToString($result->getRoot(), ' '));
}
private function collectionToString(DumperCollection $collection, $prefix)
{
$string = '';
foreach ($collection as $route) {
if ($route instanceof DumperCollection) {
$string .= sprintf("%s|-coll %s\n", $prefix, $route->getPrefix());
$string .= $this->collectionToString($route, $prefix.'| ');
} else {
$string .= sprintf("%s|-route %s %s\n", $prefix, $route->getName(), $route->getRoute()->getPath());
}
}
return $string;
}
}

View File

@@ -11,12 +11,41 @@
namespace Symfony\Component\Routing\Tests\Matcher\Dumper;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Routing\Matcher\Dumper\PhpMatcherDumper;
use Symfony\Component\Routing\Matcher\RedirectableUrlMatcherInterface;
use Symfony\Component\Routing\Matcher\UrlMatcher;
use Symfony\Component\Routing\RequestContext;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouteCollection;
class PhpMatcherDumperTest extends \PHPUnit_Framework_TestCase
class PhpMatcherDumperTest extends TestCase
{
/**
* @var string
*/
private $matcherClass;
/**
* @var string
*/
private $dumpPath;
protected function setUp()
{
parent::setUp();
$this->matcherClass = uniqid('ProjectUrlMatcher');
$this->dumpPath = sys_get_temp_dir().\DIRECTORY_SEPARATOR.'php_matcher.'.$this->matcherClass.'.php';
}
protected function tearDown()
{
parent::tearDown();
@unlink($this->dumpPath);
}
/**
* @expectedException \LogicException
*/
@@ -35,6 +64,23 @@ class PhpMatcherDumperTest extends \PHPUnit_Framework_TestCase
$dumper->dump();
}
public function testRedirectPreservesUrlEncoding()
{
$collection = new RouteCollection();
$collection->add('foo', new Route('/foo:bar/'));
$class = $this->generateDumpedMatcher($collection, true);
$matcher = $this->getMockBuilder($class)
->setMethods(array('redirect'))
->setConstructorArgs(array(new RequestContext()))
->getMock();
$matcher->expects($this->once())->method('redirect')->with('/foo%3Abar/', 'foo')->willReturn(array());
$matcher->match('/foo%3Abar');
}
/**
* @dataProvider getRouteCollections
*/
@@ -278,10 +324,136 @@ class PhpMatcherDumperTest extends \PHPUnit_Framework_TestCase
$route->setCondition('context.getMethod() == "GET"');
$rootprefixCollection->add('with-condition', $route);
/* test case 4 */
$headMatchCasesCollection = new RouteCollection();
$headMatchCasesCollection->add('just_head', new Route(
'/just_head',
array(),
array(),
array(),
'',
array(),
array('HEAD')
));
$headMatchCasesCollection->add('head_and_get', new Route(
'/head_and_get',
array(),
array(),
array(),
'',
array(),
array('HEAD', 'GET')
));
$headMatchCasesCollection->add('get_and_head', new Route(
'/get_and_head',
array(),
array(),
array(),
'',
array(),
array('GET', 'HEAD')
));
$headMatchCasesCollection->add('post_and_head', new Route(
'/post_and_head',
array(),
array(),
array(),
'',
array(),
array('POST', 'HEAD')
));
$headMatchCasesCollection->add('put_and_post', new Route(
'/put_and_post',
array(),
array(),
array(),
'',
array(),
array('PUT', 'POST')
));
$headMatchCasesCollection->add('put_and_get_and_head', new Route(
'/put_and_post',
array(),
array(),
array(),
'',
array(),
array('PUT', 'GET', 'HEAD')
));
/* test case 5 */
$groupOptimisedCollection = new RouteCollection();
$groupOptimisedCollection->add('a_first', new Route('/a/11'));
$groupOptimisedCollection->add('a_second', new Route('/a/22'));
$groupOptimisedCollection->add('a_third', new Route('/a/333'));
$groupOptimisedCollection->add('a_wildcard', new Route('/{param}'));
$groupOptimisedCollection->add('a_fourth', new Route('/a/44/'));
$groupOptimisedCollection->add('a_fifth', new Route('/a/55/'));
$groupOptimisedCollection->add('a_sixth', new Route('/a/66/'));
$groupOptimisedCollection->add('nested_wildcard', new Route('/nested/{param}'));
$groupOptimisedCollection->add('nested_a', new Route('/nested/group/a/'));
$groupOptimisedCollection->add('nested_b', new Route('/nested/group/b/'));
$groupOptimisedCollection->add('nested_c', new Route('/nested/group/c/'));
$groupOptimisedCollection->add('slashed_a', new Route('/slashed/group/'));
$groupOptimisedCollection->add('slashed_b', new Route('/slashed/group/b/'));
$groupOptimisedCollection->add('slashed_c', new Route('/slashed/group/c/'));
$trailingSlashCollection = new RouteCollection();
$trailingSlashCollection->add('simple_trailing_slash_no_methods', new Route('/trailing/simple/no-methods/', array(), array(), array(), '', array(), array()));
$trailingSlashCollection->add('simple_trailing_slash_GET_method', new Route('/trailing/simple/get-method/', array(), array(), array(), '', array(), array('GET')));
$trailingSlashCollection->add('simple_trailing_slash_HEAD_method', new Route('/trailing/simple/head-method/', array(), array(), array(), '', array(), array('HEAD')));
$trailingSlashCollection->add('simple_trailing_slash_POST_method', new Route('/trailing/simple/post-method/', array(), array(), array(), '', array(), array('POST')));
$trailingSlashCollection->add('regex_trailing_slash_no_methods', new Route('/trailing/regex/no-methods/{param}/', array(), array(), array(), '', array(), array()));
$trailingSlashCollection->add('regex_trailing_slash_GET_method', new Route('/trailing/regex/get-method/{param}/', array(), array(), array(), '', array(), array('GET')));
$trailingSlashCollection->add('regex_trailing_slash_HEAD_method', new Route('/trailing/regex/head-method/{param}/', array(), array(), array(), '', array(), array('HEAD')));
$trailingSlashCollection->add('regex_trailing_slash_POST_method', new Route('/trailing/regex/post-method/{param}/', array(), array(), array(), '', array(), array('POST')));
$trailingSlashCollection->add('simple_not_trailing_slash_no_methods', new Route('/not-trailing/simple/no-methods', array(), array(), array(), '', array(), array()));
$trailingSlashCollection->add('simple_not_trailing_slash_GET_method', new Route('/not-trailing/simple/get-method', array(), array(), array(), '', array(), array('GET')));
$trailingSlashCollection->add('simple_not_trailing_slash_HEAD_method', new Route('/not-trailing/simple/head-method', array(), array(), array(), '', array(), array('HEAD')));
$trailingSlashCollection->add('simple_not_trailing_slash_POST_method', new Route('/not-trailing/simple/post-method', array(), array(), array(), '', array(), array('POST')));
$trailingSlashCollection->add('regex_not_trailing_slash_no_methods', new Route('/not-trailing/regex/no-methods/{param}', array(), array(), array(), '', array(), array()));
$trailingSlashCollection->add('regex_not_trailing_slash_GET_method', new Route('/not-trailing/regex/get-method/{param}', array(), array(), array(), '', array(), array('GET')));
$trailingSlashCollection->add('regex_not_trailing_slash_HEAD_method', new Route('/not-trailing/regex/head-method/{param}', array(), array(), array(), '', array(), array('HEAD')));
$trailingSlashCollection->add('regex_not_trailing_slash_POST_method', new Route('/not-trailing/regex/post-method/{param}', array(), array(), array(), '', array(), array('POST')));
return array(
array(new RouteCollection(), 'url_matcher0.php', array()),
array($collection, 'url_matcher1.php', array()),
array($redirectCollection, 'url_matcher2.php', array('base_class' => 'Symfony\Component\Routing\Tests\Fixtures\RedirectableUrlMatcher')),
array($rootprefixCollection, 'url_matcher3.php', array()),
array($headMatchCasesCollection, 'url_matcher4.php', array()),
array($groupOptimisedCollection, 'url_matcher5.php', array('base_class' => 'Symfony\Component\Routing\Tests\Fixtures\RedirectableUrlMatcher')),
array($trailingSlashCollection, 'url_matcher6.php', array()),
array($trailingSlashCollection, 'url_matcher7.php', array('base_class' => 'Symfony\Component\Routing\Tests\Fixtures\RedirectableUrlMatcher')),
);
}
/**
* @param $dumper
*/
private function generateDumpedMatcher(RouteCollection $collection, $redirectableStub = false)
{
$options = array('class' => $this->matcherClass);
if ($redirectableStub) {
$options['base_class'] = '\Symfony\Component\Routing\Tests\Matcher\Dumper\RedirectableUrlMatcherStub';
}
$dumper = new PhpMatcherDumper($collection);
$code = $dumper->dump($options);
file_put_contents($this->dumpPath, $code);
include $this->dumpPath;
return $this->matcherClass;
}
}
abstract class RedirectableUrlMatcherStub extends UrlMatcher implements RedirectableUrlMatcherInterface
{
public function redirect($path, $route, $scheme = null)
{
}
}

View File

@@ -0,0 +1,175 @@
<?php
namespace Symfony\Component\Routing\Tests\Matcher\Dumper;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Routing\Matcher\Dumper\StaticPrefixCollection;
use Symfony\Component\Routing\Route;
class StaticPrefixCollectionTest extends TestCase
{
/**
* @dataProvider routeProvider
*/
public function testGrouping(array $routes, $expected)
{
$collection = new StaticPrefixCollection('/');
foreach ($routes as $route) {
list($path, $name) = $route;
$staticPrefix = (new Route($path))->compile()->getStaticPrefix();
$collection->addRoute($staticPrefix, $name);
}
$collection->optimizeGroups();
$dumped = $this->dumpCollection($collection);
$this->assertEquals($expected, $dumped);
}
public function routeProvider()
{
return array(
'Simple - not nested' => array(
array(
array('/', 'root'),
array('/prefix/segment/', 'prefix_segment'),
array('/leading/segment/', 'leading_segment'),
),
<<<EOF
/ root
/prefix/segment prefix_segment
/leading/segment leading_segment
EOF
),
'Not nested - group too small' => array(
array(
array('/', 'root'),
array('/prefix/segment/aa', 'prefix_segment'),
array('/prefix/segment/bb', 'leading_segment'),
),
<<<EOF
/ root
/prefix/segment/aa prefix_segment
/prefix/segment/bb leading_segment
EOF
),
'Nested - contains item at intersection' => array(
array(
array('/', 'root'),
array('/prefix/segment/', 'prefix_segment'),
array('/prefix/segment/bb', 'leading_segment'),
),
<<<EOF
/ root
/prefix/segment
-> /prefix/segment prefix_segment
-> /prefix/segment/bb leading_segment
EOF
),
'Simple one level nesting' => array(
array(
array('/', 'root'),
array('/group/segment/', 'nested_segment'),
array('/group/thing/', 'some_segment'),
array('/group/other/', 'other_segment'),
),
<<<EOF
/ root
/group
-> /group/segment nested_segment
-> /group/thing some_segment
-> /group/other other_segment
EOF
),
'Retain matching order with groups' => array(
array(
array('/group/aa/', 'aa'),
array('/group/bb/', 'bb'),
array('/group/cc/', 'cc'),
array('/', 'root'),
array('/group/dd/', 'dd'),
array('/group/ee/', 'ee'),
array('/group/ff/', 'ff'),
),
<<<EOF
/group
-> /group/aa aa
-> /group/bb bb
-> /group/cc cc
/ root
/group
-> /group/dd dd
-> /group/ee ee
-> /group/ff ff
EOF
),
'Retain complex matching order with groups at base' => array(
array(
array('/aaa/111/', 'first_aaa'),
array('/prefixed/group/aa/', 'aa'),
array('/prefixed/group/bb/', 'bb'),
array('/prefixed/group/cc/', 'cc'),
array('/prefixed/', 'root'),
array('/prefixed/group/dd/', 'dd'),
array('/prefixed/group/ee/', 'ee'),
array('/prefixed/group/ff/', 'ff'),
array('/aaa/222/', 'second_aaa'),
array('/aaa/333/', 'third_aaa'),
),
<<<EOF
/aaa
-> /aaa/111 first_aaa
-> /aaa/222 second_aaa
-> /aaa/333 third_aaa
/prefixed
-> /prefixed/group
-> -> /prefixed/group/aa aa
-> -> /prefixed/group/bb bb
-> -> /prefixed/group/cc cc
-> /prefixed root
-> /prefixed/group
-> -> /prefixed/group/dd dd
-> -> /prefixed/group/ee ee
-> -> /prefixed/group/ff ff
EOF
),
'Group regardless of segments' => array(
array(
array('/aaa-111/', 'a1'),
array('/aaa-222/', 'a2'),
array('/aaa-333/', 'a3'),
array('/group-aa/', 'g1'),
array('/group-bb/', 'g2'),
array('/group-cc/', 'g3'),
),
<<<EOF
/aaa-
-> /aaa-111 a1
-> /aaa-222 a2
-> /aaa-333 a3
/group-
-> /group-aa g1
-> /group-bb g2
-> /group-cc g3
EOF
),
);
}
private function dumpCollection(StaticPrefixCollection $collection, $prefix = '')
{
$lines = array();
foreach ($collection->getItems() as $item) {
if ($item instanceof StaticPrefixCollection) {
$lines[] = $prefix.$item->getPrefix();
$lines[] = $this->dumpCollection($item, $prefix.'-> ');
} else {
$lines[] = $prefix.implode(' ', $item);
}
}
return implode("\n", $lines);
}
}

View File

@@ -11,19 +11,19 @@
namespace Symfony\Component\Routing\Tests\Matcher;
use Symfony\Component\Routing\RequestContext;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouteCollection;
use Symfony\Component\Routing\RequestContext;
class RedirectableUrlMatcherTest extends \PHPUnit_Framework_TestCase
class RedirectableUrlMatcherTest extends UrlMatcherTest
{
public function testRedirectWhenNoSlash()
public function testMissingTrailingSlash()
{
$coll = new RouteCollection();
$coll->add('foo', new Route('/foo/'));
$matcher = $this->getMockForAbstractClass('Symfony\Component\Routing\Matcher\RedirectableUrlMatcher', array($coll, new RequestContext()));
$matcher->expects($this->once())->method('redirect');
$matcher = $this->getUrlMatcher($coll);
$matcher->expects($this->once())->method('redirect')->will($this->returnValue(array()));
$matcher->match('/foo');
}
@@ -37,7 +37,7 @@ class RedirectableUrlMatcherTest extends \PHPUnit_Framework_TestCase
$context = new RequestContext();
$context->setMethod('POST');
$matcher = $this->getMockForAbstractClass('Symfony\Component\Routing\Matcher\RedirectableUrlMatcher', array($coll, $context));
$matcher = $this->getUrlMatcher($coll, $context);
$matcher->match('/foo');
}
@@ -46,7 +46,7 @@ class RedirectableUrlMatcherTest extends \PHPUnit_Framework_TestCase
$coll = new RouteCollection();
$coll->add('foo', new Route('/foo', array(), array(), array(), '', array('FTP', 'HTTPS')));
$matcher = $this->getMockForAbstractClass('Symfony\Component\Routing\Matcher\RedirectableUrlMatcher', array($coll, new RequestContext()));
$matcher = $this->getUrlMatcher($coll);
$matcher
->expects($this->once())
->method('redirect')
@@ -56,16 +56,69 @@ class RedirectableUrlMatcherTest extends \PHPUnit_Framework_TestCase
$matcher->match('/foo');
}
public function testNoSchemaRedirectIfOnOfMultipleSchemesMatches()
public function testNoSchemaRedirectIfOneOfMultipleSchemesMatches()
{
$coll = new RouteCollection();
$coll->add('foo', new Route('/foo', array(), array(), array(), '', array('https', 'http')));
$matcher = $this->getMockForAbstractClass('Symfony\Component\Routing\Matcher\RedirectableUrlMatcher', array($coll, new RequestContext()));
$matcher = $this->getUrlMatcher($coll);
$matcher
->expects($this->never())
->method('redirect')
;
->method('redirect');
$matcher->match('/foo');
}
public function testSchemeRedirectWithParams()
{
$coll = new RouteCollection();
$coll->add('foo', new Route('/foo/{bar}', array(), array(), array(), '', array('https')));
$matcher = $this->getUrlMatcher($coll);
$matcher
->expects($this->once())
->method('redirect')
->with('/foo/baz', 'foo', 'https')
->will($this->returnValue(array('redirect' => 'value')))
;
$this->assertEquals(array('_route' => 'foo', 'bar' => 'baz', 'redirect' => 'value'), $matcher->match('/foo/baz'));
}
public function testSlashRedirectWithParams()
{
$coll = new RouteCollection();
$coll->add('foo', new Route('/foo/{bar}/'));
$matcher = $this->getUrlMatcher($coll);
$matcher
->expects($this->once())
->method('redirect')
->with('/foo/baz/', 'foo', null)
->will($this->returnValue(array('redirect' => 'value')))
;
$this->assertEquals(array('_route' => 'foo', 'bar' => 'baz', 'redirect' => 'value'), $matcher->match('/foo/baz'));
}
public function testRedirectPreservesUrlEncoding()
{
$coll = new RouteCollection();
$coll->add('foo', new Route('/foo:bar/'));
$matcher = $this->getUrlMatcher($coll);
$matcher->expects($this->once())->method('redirect')->with('/foo%3Abar/')->willReturn(array());
$matcher->match('/foo%3Abar');
}
public function testSchemeRequirement()
{
$coll = new RouteCollection();
$coll->add('foo', new Route('/foo', array(), array(), array(), '', array('https')));
$matcher = $this->getUrlMatcher($coll, new RequestContext());
$matcher->expects($this->once())->method('redirect')->with('/foo', 'foo', 'https')->willReturn(array());
$this->assertSame(array('_route' => 'foo'), $matcher->match('/foo'));
}
protected function getUrlMatcher(RouteCollection $routes, RequestContext $context = null)
{
return $this->getMockForAbstractClass('Symfony\Component\Routing\Matcher\RedirectableUrlMatcher', array($routes, $context ?: new RequestContext()));
}
}

View File

@@ -11,13 +11,14 @@
namespace Symfony\Component\Routing\Tests\Matcher;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Matcher\TraceableUrlMatcher;
use Symfony\Component\Routing\RequestContext;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouteCollection;
use Symfony\Component\Routing\RequestContext;
use Symfony\Component\Routing\Matcher\TraceableUrlMatcher;
class TraceableUrlMatcherTest extends \PHPUnit_Framework_TestCase
class TraceableUrlMatcherTest extends TestCase
{
public function test()
{

View File

@@ -11,21 +11,22 @@
namespace Symfony\Component\Routing\Tests\Matcher;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Routing\Exception\MethodNotAllowedException;
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
use Symfony\Component\Routing\Matcher\UrlMatcher;
use Symfony\Component\Routing\RequestContext;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouteCollection;
use Symfony\Component\Routing\RequestContext;
class UrlMatcherTest extends \PHPUnit_Framework_TestCase
class UrlMatcherTest extends TestCase
{
public function testNoMethodSoAllowed()
{
$coll = new RouteCollection();
$coll->add('foo', new Route('/foo'));
$matcher = new UrlMatcher($coll, new RequestContext());
$matcher = $this->getUrlMatcher($coll);
$this->assertInternalType('array', $matcher->match('/foo'));
}
@@ -34,7 +35,7 @@ class UrlMatcherTest extends \PHPUnit_Framework_TestCase
$coll = new RouteCollection();
$coll->add('foo', new Route('/foo', array(), array(), array(), '', array(), array('post')));
$matcher = new UrlMatcher($coll, new RequestContext());
$matcher = $this->getUrlMatcher($coll);
try {
$matcher->match('/foo');
@@ -44,12 +45,27 @@ class UrlMatcherTest extends \PHPUnit_Framework_TestCase
}
}
public function testMethodNotAllowedOnRoot()
{
$coll = new RouteCollection();
$coll->add('foo', new Route('/', array(), array(), array(), '', array(), array('GET')));
$matcher = $this->getUrlMatcher($coll, new RequestContext('', 'POST'));
try {
$matcher->match('/');
$this->fail();
} catch (MethodNotAllowedException $e) {
$this->assertEquals(array('GET'), $e->getAllowedMethods());
}
}
public function testHeadAllowedWhenRequirementContainsGet()
{
$coll = new RouteCollection();
$coll->add('foo', new Route('/foo', array(), array(), array(), '', array(), array('get')));
$matcher = new UrlMatcher($coll, new RequestContext('', 'head'));
$matcher = $this->getUrlMatcher($coll, new RequestContext('', 'head'));
$this->assertInternalType('array', $matcher->match('/foo'));
}
@@ -59,7 +75,7 @@ class UrlMatcherTest extends \PHPUnit_Framework_TestCase
$coll->add('foo1', new Route('/foo', array(), array(), array(), '', array(), array('post')));
$coll->add('foo2', new Route('/foo', array(), array(), array(), '', array(), array('put', 'delete')));
$matcher = new UrlMatcher($coll, new RequestContext());
$matcher = $this->getUrlMatcher($coll);
try {
$matcher->match('/foo');
@@ -74,7 +90,7 @@ class UrlMatcherTest extends \PHPUnit_Framework_TestCase
// test the patterns are matched and parameters are returned
$collection = new RouteCollection();
$collection->add('foo', new Route('/foo/{bar}'));
$matcher = new UrlMatcher($collection, new RequestContext());
$matcher = $this->getUrlMatcher($collection);
try {
$matcher->match('/no-match');
$this->fail();
@@ -85,17 +101,17 @@ class UrlMatcherTest extends \PHPUnit_Framework_TestCase
// test that defaults are merged
$collection = new RouteCollection();
$collection->add('foo', new Route('/foo/{bar}', array('def' => 'test')));
$matcher = new UrlMatcher($collection, new RequestContext());
$matcher = $this->getUrlMatcher($collection);
$this->assertEquals(array('_route' => 'foo', 'bar' => 'baz', 'def' => 'test'), $matcher->match('/foo/baz'));
// test that route "method" is ignored if no method is given in the context
$collection = new RouteCollection();
$collection->add('foo', new Route('/foo', array(), array(), array(), '', array(), array('get', 'head')));
$matcher = new UrlMatcher($collection, new RequestContext());
$matcher = $this->getUrlMatcher($collection);
$this->assertInternalType('array', $matcher->match('/foo'));
// route does not match with POST method context
$matcher = new UrlMatcher($collection, new RequestContext('', 'post'));
$matcher = $this->getUrlMatcher($collection, new RequestContext('', 'post'));
try {
$matcher->match('/foo');
$this->fail();
@@ -103,28 +119,28 @@ class UrlMatcherTest extends \PHPUnit_Framework_TestCase
}
// route does match with GET or HEAD method context
$matcher = new UrlMatcher($collection, new RequestContext());
$matcher = $this->getUrlMatcher($collection);
$this->assertInternalType('array', $matcher->match('/foo'));
$matcher = new UrlMatcher($collection, new RequestContext('', 'head'));
$matcher = $this->getUrlMatcher($collection, new RequestContext('', 'head'));
$this->assertInternalType('array', $matcher->match('/foo'));
// route with an optional variable as the first segment
$collection = new RouteCollection();
$collection->add('bar', new Route('/{bar}/foo', array('bar' => 'bar'), array('bar' => 'foo|bar')));
$matcher = new UrlMatcher($collection, new RequestContext());
$matcher = $this->getUrlMatcher($collection);
$this->assertEquals(array('_route' => 'bar', 'bar' => 'bar'), $matcher->match('/bar/foo'));
$this->assertEquals(array('_route' => 'bar', 'bar' => 'foo'), $matcher->match('/foo/foo'));
$collection = new RouteCollection();
$collection->add('bar', new Route('/{bar}', array('bar' => 'bar'), array('bar' => 'foo|bar')));
$matcher = new UrlMatcher($collection, new RequestContext());
$matcher = $this->getUrlMatcher($collection);
$this->assertEquals(array('_route' => 'bar', 'bar' => 'foo'), $matcher->match('/foo'));
$this->assertEquals(array('_route' => 'bar', 'bar' => 'bar'), $matcher->match('/'));
// route with only optional variables
$collection = new RouteCollection();
$collection->add('bar', new Route('/{foo}/{bar}', array('foo' => 'foo', 'bar' => 'bar'), array()));
$matcher = new UrlMatcher($collection, new RequestContext());
$matcher = $this->getUrlMatcher($collection);
$this->assertEquals(array('_route' => 'bar', 'foo' => 'foo', 'bar' => 'bar'), $matcher->match('/'));
$this->assertEquals(array('_route' => 'bar', 'foo' => 'a', 'bar' => 'bar'), $matcher->match('/a'));
$this->assertEquals(array('_route' => 'bar', 'foo' => 'a', 'bar' => 'b'), $matcher->match('/a/b'));
@@ -137,7 +153,7 @@ class UrlMatcherTest extends \PHPUnit_Framework_TestCase
$collection->addPrefix('/b');
$collection->addPrefix('/a');
$matcher = new UrlMatcher($collection, new RequestContext());
$matcher = $this->getUrlMatcher($collection);
$this->assertEquals(array('_route' => 'foo', 'foo' => 'foo'), $matcher->match('/a/b/foo'));
}
@@ -148,7 +164,7 @@ class UrlMatcherTest extends \PHPUnit_Framework_TestCase
$collection->addPrefix('/b');
$collection->addPrefix('/{_locale}');
$matcher = new UrlMatcher($collection, new RequestContext());
$matcher = $this->getUrlMatcher($collection);
$this->assertEquals(array('_locale' => 'fr', '_route' => 'foo', 'foo' => 'foo'), $matcher->match('/fr/b/foo'));
}
@@ -157,17 +173,29 @@ class UrlMatcherTest extends \PHPUnit_Framework_TestCase
$collection = new RouteCollection();
$collection->add('$péß^a|', new Route('/bar'));
$matcher = new UrlMatcher($collection, new RequestContext());
$matcher = $this->getUrlMatcher($collection);
$this->assertEquals(array('_route' => '$péß^a|'), $matcher->match('/bar'));
}
/**
* @expectedException \Symfony\Component\Routing\Exception\ResourceNotFoundException
*/
public function testTrailingEncodedNewlineIsNotOverlooked()
{
$collection = new RouteCollection();
$collection->add('foo', new Route('/foo'));
$matcher = $this->getUrlMatcher($collection);
$matcher->match('/foo%0a');
}
public function testMatchNonAlpha()
{
$collection = new RouteCollection();
$chars = '!"$%éà &\'()*+,./:;<=>@ABCDEFGHIJKLMNOPQRSTUVWXYZ\\[]^_`abcdefghijklmnopqrstuvwxyz{|}~-';
$collection->add('foo', new Route('/{foo}/bar', array(), array('foo' => '['.preg_quote($chars).']+')));
$collection->add('foo', new Route('/{foo}/bar', array(), array('foo' => '['.preg_quote($chars).']+'), array('utf8' => true)));
$matcher = new UrlMatcher($collection, new RequestContext());
$matcher = $this->getUrlMatcher($collection);
$this->assertEquals(array('_route' => 'foo', 'foo' => $chars), $matcher->match('/'.rawurlencode($chars).'/bar'));
$this->assertEquals(array('_route' => 'foo', 'foo' => $chars), $matcher->match('/'.strtr($chars, array('%' => '%25')).'/bar'));
}
@@ -177,7 +205,7 @@ class UrlMatcherTest extends \PHPUnit_Framework_TestCase
$collection = new RouteCollection();
$collection->add('foo', new Route('/{foo}/bar', array(), array('foo' => '.+')));
$matcher = new UrlMatcher($collection, new RequestContext());
$matcher = $this->getUrlMatcher($collection);
$this->assertEquals(array('_route' => 'foo', 'foo' => "\n"), $matcher->match('/'.urlencode("\n").'/bar'), 'linefeed character is matched');
}
@@ -191,10 +219,10 @@ class UrlMatcherTest extends \PHPUnit_Framework_TestCase
$collection->addCollection($collection1);
$matcher = new UrlMatcher($collection, new RequestContext());
$matcher = $this->getUrlMatcher($collection);
$this->assertEquals(array('_route' => 'foo'), $matcher->match('/foo1'));
$this->setExpectedException('Symfony\Component\Routing\Exception\ResourceNotFoundException');
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Routing\Exception\ResourceNotFoundException');
$this->assertEquals(array(), $matcher->match('/foo'));
}
@@ -204,12 +232,12 @@ class UrlMatcherTest extends \PHPUnit_Framework_TestCase
$coll->add('foo', new Route('/foo/{foo}'));
$coll->add('bar', new Route('/foo/bar/{foo}'));
$matcher = new UrlMatcher($coll, new RequestContext());
$matcher = $this->getUrlMatcher($coll);
$this->assertEquals(array('foo' => 'bar', '_route' => 'bar'), $matcher->match('/foo/bar/bar'));
$collection = new RouteCollection();
$collection->add('foo', new Route('/{bar}'));
$matcher = new UrlMatcher($collection, new RequestContext());
$matcher = $this->getUrlMatcher($collection);
try {
$matcher->match('/');
$this->fail();
@@ -222,7 +250,7 @@ class UrlMatcherTest extends \PHPUnit_Framework_TestCase
$coll = new RouteCollection();
$coll->add('test', new Route('/{page}.{_format}', array('page' => 'index', '_format' => 'html')));
$matcher = new UrlMatcher($coll, new RequestContext());
$matcher = $this->getUrlMatcher($coll);
$this->assertEquals(array('page' => 'my-page', '_format' => 'xml', '_route' => 'test'), $matcher->match('/my-page.xml'));
}
@@ -231,7 +259,7 @@ class UrlMatcherTest extends \PHPUnit_Framework_TestCase
$coll = new RouteCollection();
$coll->add('test', new Route('/{foo}-{bar}-', array(), array('foo' => '.+', 'bar' => '.+')));
$matcher = new UrlMatcher($coll, new RequestContext());
$matcher = $this->getUrlMatcher($coll);
$this->assertEquals(array('foo' => 'text1-text2-text3', 'bar' => 'text4', '_route' => 'test'), $matcher->match('/text1-text2-text3-text4-'));
}
@@ -240,7 +268,7 @@ class UrlMatcherTest extends \PHPUnit_Framework_TestCase
$coll = new RouteCollection();
$coll->add('test', new Route('/{w}{x}{y}{z}.{_format}', array('z' => 'default-z', '_format' => 'html'), array('y' => 'y|Y')));
$matcher = new UrlMatcher($coll, new RequestContext());
$matcher = $this->getUrlMatcher($coll);
// 'w' eagerly matches as much as possible and the other variables match the remaining chars.
// This also shows that the variables w-z must all exclude the separating char (the dot '.' in this case) by default requirement.
// Otherwise they would also consume '.xml' and _format would never match as it's an optional variable.
@@ -251,7 +279,7 @@ class UrlMatcherTest extends \PHPUnit_Framework_TestCase
// z and _format are optional.
$this->assertEquals(array('w' => 'wwwww', 'x' => 'x', 'y' => 'y', 'z' => 'default-z', '_format' => 'html', '_route' => 'test'), $matcher->match('/wwwwwxy'));
$this->setExpectedException('Symfony\Component\Routing\Exception\ResourceNotFoundException');
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Routing\Exception\ResourceNotFoundException');
$matcher->match('/wxy.html');
}
@@ -259,14 +287,14 @@ class UrlMatcherTest extends \PHPUnit_Framework_TestCase
{
$coll = new RouteCollection();
$coll->add('test', new Route('/get{what}', array('what' => 'All')));
$matcher = new UrlMatcher($coll, new RequestContext());
$matcher = $this->getUrlMatcher($coll);
$this->assertEquals(array('what' => 'All', '_route' => 'test'), $matcher->match('/get'));
$this->assertEquals(array('what' => 'Sites', '_route' => 'test'), $matcher->match('/getSites'));
// Usually the character in front of an optional parameter can be left out, e.g. with pattern '/get/{what}' just '/get' would match.
// But here the 't' in 'get' is not a separating character, so it makes no sense to match without it.
$this->setExpectedException('Symfony\Component\Routing\Exception\ResourceNotFoundException');
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Routing\Exception\ResourceNotFoundException');
$matcher->match('/ge');
}
@@ -274,7 +302,7 @@ class UrlMatcherTest extends \PHPUnit_Framework_TestCase
{
$coll = new RouteCollection();
$coll->add('test', new Route('/get{what}Suffix'));
$matcher = new UrlMatcher($coll, new RequestContext());
$matcher = $this->getUrlMatcher($coll);
$this->assertEquals(array('what' => 'Sites', '_route' => 'test'), $matcher->match('/getSitesSuffix'));
}
@@ -283,7 +311,7 @@ class UrlMatcherTest extends \PHPUnit_Framework_TestCase
{
$coll = new RouteCollection();
$coll->add('test', new Route('/{page}.{_format}'));
$matcher = new UrlMatcher($coll, new RequestContext());
$matcher = $this->getUrlMatcher($coll);
$this->assertEquals(array('page' => 'index', '_format' => 'mobile.html', '_route' => 'test'), $matcher->match('/index.mobile.html'));
}
@@ -295,7 +323,7 @@ class UrlMatcherTest extends \PHPUnit_Framework_TestCase
{
$coll = new RouteCollection();
$coll->add('test', new Route('/{page}.{_format}'));
$matcher = new UrlMatcher($coll, new RequestContext());
$matcher = $this->getUrlMatcher($coll);
$matcher->match('/index.sl/ash');
}
@@ -307,7 +335,7 @@ class UrlMatcherTest extends \PHPUnit_Framework_TestCase
{
$coll = new RouteCollection();
$coll->add('test', new Route('/{page}.{_format}', array(), array('_format' => 'html|xml')));
$matcher = new UrlMatcher($coll, new RequestContext());
$matcher = $this->getUrlMatcher($coll);
$matcher->match('/do.t.html');
}
@@ -319,7 +347,7 @@ class UrlMatcherTest extends \PHPUnit_Framework_TestCase
{
$coll = new RouteCollection();
$coll->add('foo', new Route('/foo', array(), array(), array(), '', array('https')));
$matcher = new UrlMatcher($coll, new RequestContext());
$matcher = $this->getUrlMatcher($coll);
$matcher->match('/foo');
}
@@ -332,16 +360,26 @@ class UrlMatcherTest extends \PHPUnit_Framework_TestCase
$route = new Route('/foo');
$route->setCondition('context.getMethod() == "POST"');
$coll->add('foo', $route);
$matcher = new UrlMatcher($coll, new RequestContext());
$matcher = $this->getUrlMatcher($coll);
$matcher->match('/foo');
}
public function testRequestCondition()
{
$coll = new RouteCollection();
$route = new Route('/foo/{bar}');
$route->setCondition('request.getBaseUrl() == "/sub/front.php" and request.getPathInfo() == "/foo/bar"');
$coll->add('foo', $route);
$matcher = $this->getUrlMatcher($coll, new RequestContext('/sub/front.php'));
$this->assertEquals(array('bar' => 'bar', '_route' => 'foo'), $matcher->match('/foo/bar'));
}
public function testDecodeOnce()
{
$coll = new RouteCollection();
$coll->add('foo', new Route('/foo/{foo}'));
$matcher = new UrlMatcher($coll, new RequestContext());
$matcher = $this->getUrlMatcher($coll);
$this->assertEquals(array('foo' => 'bar%23', '_route' => 'foo'), $matcher->match('/foo/bar%2523'));
}
@@ -357,7 +395,7 @@ class UrlMatcherTest extends \PHPUnit_Framework_TestCase
$coll->addCollection($subColl);
$matcher = new UrlMatcher($coll, new RequestContext());
$matcher = $this->getUrlMatcher($coll);
$this->assertEquals(array('_route' => 'bar'), $matcher->match('/new'));
}
@@ -366,7 +404,7 @@ class UrlMatcherTest extends \PHPUnit_Framework_TestCase
$coll = new RouteCollection();
$coll->add('foo', new Route('/foo/{foo}', array(), array(), array(), '{locale}.example.com'));
$matcher = new UrlMatcher($coll, new RequestContext('', 'GET', 'en.example.com'));
$matcher = $this->getUrlMatcher($coll, new RequestContext('', 'GET', 'en.example.com'));
$this->assertEquals(array('foo' => 'bar', '_route' => 'foo', 'locale' => 'en'), $matcher->match('/foo/bar'));
}
@@ -377,10 +415,10 @@ class UrlMatcherTest extends \PHPUnit_Framework_TestCase
$coll->add('bar', new Route('/bar/{foo}', array(), array(), array(), '{locale}.example.net'));
$coll->setHost('{locale}.example.com');
$matcher = new UrlMatcher($coll, new RequestContext('', 'GET', 'en.example.com'));
$matcher = $this->getUrlMatcher($coll, new RequestContext('', 'GET', 'en.example.com'));
$this->assertEquals(array('foo' => 'bar', '_route' => 'foo', 'locale' => 'en'), $matcher->match('/foo/bar'));
$matcher = new UrlMatcher($coll, new RequestContext('', 'GET', 'en.example.com'));
$matcher = $this->getUrlMatcher($coll, new RequestContext('', 'GET', 'en.example.com'));
$this->assertEquals(array('foo' => 'bar', '_route' => 'bar', 'locale' => 'en'), $matcher->match('/bar/bar'));
}
@@ -392,7 +430,7 @@ class UrlMatcherTest extends \PHPUnit_Framework_TestCase
$coll = new RouteCollection();
$coll->add('foo', new Route('/foo/{foo}', array(), array(), array(), '{locale}.example.com'));
$matcher = new UrlMatcher($coll, new RequestContext('', 'GET', 'example.com'));
$matcher = $this->getUrlMatcher($coll, new RequestContext('', 'GET', 'example.com'));
$matcher->match('/foo/bar');
}
@@ -404,7 +442,7 @@ class UrlMatcherTest extends \PHPUnit_Framework_TestCase
$coll = new RouteCollection();
$coll->add('foo', new Route('/locale', array(), array('locale' => 'EN|FR|DE')));
$matcher = new UrlMatcher($coll, new RequestContext());
$matcher = $this->getUrlMatcher($coll);
$matcher->match('/en');
}
@@ -413,7 +451,59 @@ class UrlMatcherTest extends \PHPUnit_Framework_TestCase
$coll = new RouteCollection();
$coll->add('foo', new Route('/', array(), array('locale' => 'EN|FR|DE'), array(), '{locale}.example.com'));
$matcher = new UrlMatcher($coll, new RequestContext('', 'GET', 'en.example.com'));
$matcher = $this->getUrlMatcher($coll, new RequestContext('', 'GET', 'en.example.com'));
$this->assertEquals(array('_route' => 'foo', 'locale' => 'en'), $matcher->match('/'));
}
/**
* @expectedException \Symfony\Component\Routing\Exception\NoConfigurationException
*/
public function testNoConfiguration()
{
$coll = new RouteCollection();
$matcher = $this->getUrlMatcher($coll);
$matcher->match('/');
}
public function testNestedCollections()
{
$coll = new RouteCollection();
$subColl = new RouteCollection();
$subColl->add('a', new Route('/a'));
$subColl->add('b', new Route('/b'));
$subColl->add('c', new Route('/c'));
$subColl->addPrefix('/p');
$coll->addCollection($subColl);
$coll->add('baz', new Route('/{baz}'));
$subColl = new RouteCollection();
$subColl->add('buz', new Route('/buz'));
$subColl->addPrefix('/prefix');
$coll->addCollection($subColl);
$matcher = $this->getUrlMatcher($coll);
$this->assertEquals(array('_route' => 'a'), $matcher->match('/p/a'));
$this->assertEquals(array('_route' => 'baz', 'baz' => 'p'), $matcher->match('/p'));
$this->assertEquals(array('_route' => 'buz'), $matcher->match('/prefix/buz'));
}
/**
* @expectedException \Symfony\Component\Routing\Exception\ResourceNotFoundException
*/
public function testSchemeAndMethodMismatch()
{
$coll = new RouteCollection();
$coll->add('foo', new Route('/', array(), array(), array(), null, array('https'), array('POST')));
$matcher = $this->getUrlMatcher($coll);
$matcher->match('/');
}
protected function getUrlMatcher(RouteCollection $routes, RequestContext $context = null)
{
return new UrlMatcher($routes, $context ?: new RequestContext());
}
}

View File

@@ -11,10 +11,11 @@
namespace Symfony\Component\Routing\Tests;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\RequestContext;
class RequestContextTest extends \PHPUnit_Framework_TestCase
class RequestContextTest extends TestCase
{
public function testConstruct()
{

View File

@@ -11,17 +11,20 @@
namespace Symfony\Component\Routing\Tests;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\Config\Resource\FileResource;
use Symfony\Component\Routing\Loader\YamlFileLoader;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouteCollection;
use Symfony\Component\Routing\RouteCollectionBuilder;
class RouteCollectionBuilderTest extends \PHPUnit_Framework_TestCase
class RouteCollectionBuilderTest extends TestCase
{
public function testImport()
{
$resolvedLoader = $this->getMock('Symfony\Component\Config\Loader\LoaderInterface');
$resolver = $this->getMock('Symfony\Component\Config\Loader\LoaderResolverInterface');
$resolvedLoader = $this->getMockBuilder('Symfony\Component\Config\Loader\LoaderInterface')->getMock();
$resolver = $this->getMockBuilder('Symfony\Component\Config\Loader\LoaderResolverInterface')->getMock();
$resolver->expects($this->once())
->method('resolve')
->with('admin_routing.yml', 'yaml')
@@ -38,7 +41,7 @@ class RouteCollectionBuilderTest extends \PHPUnit_Framework_TestCase
->with('admin_routing.yml', 'yaml')
->will($this->returnValue($expectedCollection));
$loader = $this->getMock('Symfony\Component\Config\Loader\LoaderInterface');
$loader = $this->getMockBuilder('Symfony\Component\Config\Loader\LoaderInterface')->getMock();
$loader->expects($this->any())
->method('getResolver')
->will($this->returnValue($resolver));
@@ -58,7 +61,18 @@ class RouteCollectionBuilderTest extends \PHPUnit_Framework_TestCase
$this->assertCount(1, $addedCollection->getResources());
// make sure the routes were imported into the top-level builder
$routeCollection = $routes->build();
$this->assertCount(1, $routes->build());
$this->assertCount(1, $routeCollection->getResources());
}
public function testImportAddResources()
{
$routeCollectionBuilder = new RouteCollectionBuilder(new YamlFileLoader(new FileLocator(array(__DIR__.'/Fixtures/'))));
$routeCollectionBuilder->import('file_resource.yml');
$routeCollection = $routeCollectionBuilder->build();
$this->assertCount(1, $routeCollection->getResources());
}
/**
@@ -89,7 +103,7 @@ class RouteCollectionBuilderTest extends \PHPUnit_Framework_TestCase
$importedCollection->add('imported_route1', new Route('/imported/foo1'));
$importedCollection->add('imported_route2', new Route('/imported/foo2'));
$loader = $this->getMock('Symfony\Component\Config\Loader\LoaderInterface');
$loader = $this->getMockBuilder('Symfony\Component\Config\Loader\LoaderInterface')->getMock();
// make this loader able to do the import - keeps mocking simple
$loader->expects($this->any())
->method('supports')
@@ -252,7 +266,7 @@ class RouteCollectionBuilderTest extends \PHPUnit_Framework_TestCase
public function testFlushSetsPrefixedWithMultipleLevels()
{
$loader = $this->getMock('Symfony\Component\Config\Loader\LoaderInterface');
$loader = $this->getMockBuilder('Symfony\Component\Config\Loader\LoaderInterface')->getMock();
$routes = new RouteCollectionBuilder($loader);
$routes->add('homepage', 'MainController::homepageAction', 'homepage');
@@ -321,4 +335,30 @@ class RouteCollectionBuilderTest extends \PHPUnit_Framework_TestCase
// there are 2 routes (i.e. with non-conflicting names)
$this->assertCount(3, $collection->all());
}
public function testAddsThePrefixOnlyOnceWhenLoadingMultipleCollections()
{
$firstCollection = new RouteCollection();
$firstCollection->add('a', new Route('/a'));
$secondCollection = new RouteCollection();
$secondCollection->add('b', new Route('/b'));
$loader = $this->getMockBuilder('Symfony\Component\Config\Loader\LoaderInterface')->getMock();
$loader->expects($this->any())
->method('supports')
->will($this->returnValue(true));
$loader
->expects($this->any())
->method('load')
->will($this->returnValue(array($firstCollection, $secondCollection)));
$routeCollectionBuilder = new RouteCollectionBuilder($loader);
$routeCollectionBuilder->import('/directory/recurse/*', '/other/', 'glob');
$routes = $routeCollectionBuilder->build()->all();
$this->assertCount(2, $routes);
$this->assertEquals('/other/a', $routes['a']->getPath());
$this->assertEquals('/other/b', $routes['b']->getPath());
}
}

View File

@@ -11,11 +11,12 @@
namespace Symfony\Component\Routing\Tests;
use Symfony\Component\Routing\RouteCollection;
use Symfony\Component\Routing\Route;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Config\Resource\FileResource;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouteCollection;
class RouteCollectionTest extends \PHPUnit_Framework_TestCase
class RouteCollectionTest extends TestCase
{
public function testRoute()
{

View File

@@ -11,9 +11,11 @@
namespace Symfony\Component\Routing\Tests;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouteCompiler;
class RouteCompilerTest extends \PHPUnit_Framework_TestCase
class RouteCompilerTest extends TestCase
{
/**
* @dataProvider provideCompileData
@@ -36,7 +38,7 @@ class RouteCompilerTest extends \PHPUnit_Framework_TestCase
array(
'Static route',
array('/foo'),
'/foo', '#^/foo$#s', array(), array(
'/foo', '#^/foo$#sD', array(), array(
array('text', '/foo'),
),
),
@@ -44,7 +46,7 @@ class RouteCompilerTest extends \PHPUnit_Framework_TestCase
array(
'Route with a variable',
array('/foo/{bar}'),
'/foo', '#^/foo/(?P<bar>[^/]++)$#s', array('bar'), array(
'/foo', '#^/foo/(?P<bar>[^/]++)$#sD', array('bar'), array(
array('variable', '/', '[^/]++', 'bar'),
array('text', '/foo'),
),
@@ -53,7 +55,7 @@ class RouteCompilerTest extends \PHPUnit_Framework_TestCase
array(
'Route with a variable that has a default value',
array('/foo/{bar}', array('bar' => 'bar')),
'/foo', '#^/foo(?:/(?P<bar>[^/]++))?$#s', array('bar'), array(
'/foo', '#^/foo(?:/(?P<bar>[^/]++))?$#sD', array('bar'), array(
array('variable', '/', '[^/]++', 'bar'),
array('text', '/foo'),
),
@@ -62,7 +64,7 @@ class RouteCompilerTest extends \PHPUnit_Framework_TestCase
array(
'Route with several variables',
array('/foo/{bar}/{foobar}'),
'/foo', '#^/foo/(?P<bar>[^/]++)/(?P<foobar>[^/]++)$#s', array('bar', 'foobar'), array(
'/foo', '#^/foo/(?P<bar>[^/]++)/(?P<foobar>[^/]++)$#sD', array('bar', 'foobar'), array(
array('variable', '/', '[^/]++', 'foobar'),
array('variable', '/', '[^/]++', 'bar'),
array('text', '/foo'),
@@ -72,7 +74,7 @@ class RouteCompilerTest extends \PHPUnit_Framework_TestCase
array(
'Route with several variables that have default values',
array('/foo/{bar}/{foobar}', array('bar' => 'bar', 'foobar' => '')),
'/foo', '#^/foo(?:/(?P<bar>[^/]++)(?:/(?P<foobar>[^/]++))?)?$#s', array('bar', 'foobar'), array(
'/foo', '#^/foo(?:/(?P<bar>[^/]++)(?:/(?P<foobar>[^/]++))?)?$#sD', array('bar', 'foobar'), array(
array('variable', '/', '[^/]++', 'foobar'),
array('variable', '/', '[^/]++', 'bar'),
array('text', '/foo'),
@@ -82,7 +84,7 @@ class RouteCompilerTest extends \PHPUnit_Framework_TestCase
array(
'Route with several variables but some of them have no default values',
array('/foo/{bar}/{foobar}', array('bar' => 'bar')),
'/foo', '#^/foo/(?P<bar>[^/]++)/(?P<foobar>[^/]++)$#s', array('bar', 'foobar'), array(
'/foo', '#^/foo/(?P<bar>[^/]++)/(?P<foobar>[^/]++)$#sD', array('bar', 'foobar'), array(
array('variable', '/', '[^/]++', 'foobar'),
array('variable', '/', '[^/]++', 'bar'),
array('text', '/foo'),
@@ -92,7 +94,7 @@ class RouteCompilerTest extends \PHPUnit_Framework_TestCase
array(
'Route with an optional variable as the first segment',
array('/{bar}', array('bar' => 'bar')),
'', '#^/(?P<bar>[^/]++)?$#s', array('bar'), array(
'', '#^/(?P<bar>[^/]++)?$#sD', array('bar'), array(
array('variable', '/', '[^/]++', 'bar'),
),
),
@@ -100,7 +102,7 @@ class RouteCompilerTest extends \PHPUnit_Framework_TestCase
array(
'Route with a requirement of 0',
array('/{bar}', array('bar' => null), array('bar' => '0')),
'', '#^/(?P<bar>0)?$#s', array('bar'), array(
'', '#^/(?P<bar>0)?$#sD', array('bar'), array(
array('variable', '/', '0', 'bar'),
),
),
@@ -108,7 +110,7 @@ class RouteCompilerTest extends \PHPUnit_Framework_TestCase
array(
'Route with an optional variable as the first segment with requirements',
array('/{bar}', array('bar' => 'bar'), array('bar' => '(foo|bar)')),
'', '#^/(?P<bar>(foo|bar))?$#s', array('bar'), array(
'', '#^/(?P<bar>(foo|bar))?$#sD', array('bar'), array(
array('variable', '/', '(foo|bar)', 'bar'),
),
),
@@ -116,7 +118,7 @@ class RouteCompilerTest extends \PHPUnit_Framework_TestCase
array(
'Route with only optional variables',
array('/{foo}/{bar}', array('foo' => 'foo', 'bar' => 'bar')),
'', '#^/(?P<foo>[^/]++)?(?:/(?P<bar>[^/]++))?$#s', array('foo', 'bar'), array(
'', '#^/(?P<foo>[^/]++)?(?:/(?P<bar>[^/]++))?$#sD', array('foo', 'bar'), array(
array('variable', '/', '[^/]++', 'bar'),
array('variable', '/', '[^/]++', 'foo'),
),
@@ -125,7 +127,7 @@ class RouteCompilerTest extends \PHPUnit_Framework_TestCase
array(
'Route with a variable in last position',
array('/foo-{bar}'),
'/foo', '#^/foo\-(?P<bar>[^/]++)$#s', array('bar'), array(
'/foo-', '#^/foo\-(?P<bar>[^/]++)$#sD', array('bar'), array(
array('variable', '-', '[^/]++', 'bar'),
array('text', '/foo'),
),
@@ -134,7 +136,7 @@ class RouteCompilerTest extends \PHPUnit_Framework_TestCase
array(
'Route with nested placeholders',
array('/{static{var}static}'),
'/{static', '#^/\{static(?P<var>[^/]+)static\}$#s', array('var'), array(
'/{static', '#^/\{static(?P<var>[^/]+)static\}$#sD', array('var'), array(
array('text', 'static}'),
array('variable', '', '[^/]+', 'var'),
array('text', '/{static'),
@@ -144,7 +146,7 @@ class RouteCompilerTest extends \PHPUnit_Framework_TestCase
array(
'Route without separator between variables',
array('/{w}{x}{y}{z}.{_format}', array('z' => 'default-z', '_format' => 'html'), array('y' => '(y|Y)')),
'', '#^/(?P<w>[^/\.]+)(?P<x>[^/\.]+)(?P<y>(y|Y))(?:(?P<z>[^/\.]++)(?:\.(?P<_format>[^/]++))?)?$#s', array('w', 'x', 'y', 'z', '_format'), array(
'', '#^/(?P<w>[^/\.]+)(?P<x>[^/\.]+)(?P<y>(y|Y))(?:(?P<z>[^/\.]++)(?:\.(?P<_format>[^/]++))?)?$#sD', array('w', 'x', 'y', 'z', '_format'), array(
array('variable', '.', '[^/]++', '_format'),
array('variable', '', '[^/\.]++', 'z'),
array('variable', '', '(y|Y)', 'y'),
@@ -156,12 +158,88 @@ class RouteCompilerTest extends \PHPUnit_Framework_TestCase
array(
'Route with a format',
array('/foo/{bar}.{_format}'),
'/foo', '#^/foo/(?P<bar>[^/\.]++)\.(?P<_format>[^/]++)$#s', array('bar', '_format'), array(
'/foo', '#^/foo/(?P<bar>[^/\.]++)\.(?P<_format>[^/]++)$#sD', array('bar', '_format'), array(
array('variable', '.', '[^/]++', '_format'),
array('variable', '/', '[^/\.]++', 'bar'),
array('text', '/foo'),
),
),
array(
'Static non UTF-8 route',
array("/fo\xE9"),
"/fo\xE9", "#^/fo\xE9$#sD", array(), array(
array('text', "/fo\xE9"),
),
),
array(
'Route with an explicit UTF-8 requirement',
array('/{bar}', array('bar' => null), array('bar' => '.'), array('utf8' => true)),
'', '#^/(?P<bar>.)?$#sDu', array('bar'), array(
array('variable', '/', '.', 'bar', true),
),
),
);
}
/**
* @group legacy
* @dataProvider provideCompileImplicitUtf8Data
* @expectedDeprecation Using UTF-8 route %s without setting the "utf8" option is deprecated %s.
*/
public function testCompileImplicitUtf8Data($name, $arguments, $prefix, $regex, $variables, $tokens, $deprecationType)
{
$r = new \ReflectionClass('Symfony\\Component\\Routing\\Route');
$route = $r->newInstanceArgs($arguments);
$compiled = $route->compile();
$this->assertEquals($prefix, $compiled->getStaticPrefix(), $name.' (static prefix)');
$this->assertEquals($regex, $compiled->getRegex(), $name.' (regex)');
$this->assertEquals($variables, $compiled->getVariables(), $name.' (variables)');
$this->assertEquals($tokens, $compiled->getTokens(), $name.' (tokens)');
}
public function provideCompileImplicitUtf8Data()
{
return array(
array(
'Static UTF-8 route',
array('/foé'),
'/foé', '#^/foé$#sDu', array(), array(
array('text', '/foé'),
),
'patterns',
),
array(
'Route with an implicit UTF-8 requirement',
array('/{bar}', array('bar' => null), array('bar' => 'é')),
'', '#^/(?P<bar>é)?$#sDu', array('bar'), array(
array('variable', '/', 'é', 'bar', true),
),
'requirements',
),
array(
'Route with a UTF-8 class requirement',
array('/{bar}', array('bar' => null), array('bar' => '\pM')),
'', '#^/(?P<bar>\pM)?$#sDu', array('bar'), array(
array('variable', '/', '\pM', 'bar', true),
),
'requirements',
),
array(
'Route with a UTF-8 separator',
array('/foo/{bar}§{_format}', array(), array(), array('compiler_class' => Utf8RouteCompiler::class)),
'/foo', '#^/foo/(?P<bar>[^/§]++)§(?P<_format>[^/]++)$#sDu', array('bar', '_format'), array(
array('variable', '§', '[^/]++', '_format', true),
array('variable', '/', '[^/§]++', 'bar', true),
array('text', '/foo'),
),
'patterns',
),
);
}
@@ -176,16 +254,46 @@ class RouteCompilerTest extends \PHPUnit_Framework_TestCase
}
/**
* @dataProvider getNumericVariableNames
* @expectedException \LogicException
*/
public function testRouteCharsetMismatch()
{
$route = new Route("/\xE9/{bar}", array(), array('bar' => '.'), array('utf8' => true));
$compiled = $route->compile();
}
/**
* @expectedException \LogicException
*/
public function testRequirementCharsetMismatch()
{
$route = new Route('/foo/{bar}', array(), array('bar' => "\xE9"), array('utf8' => true));
$compiled = $route->compile();
}
/**
* @expectedException \InvalidArgumentException
*/
public function testRouteWithFragmentAsPathParameter()
{
$route = new Route('/{_fragment}');
$compiled = $route->compile();
}
/**
* @dataProvider getVariableNamesStartingWithADigit
* @expectedException \DomainException
*/
public function testRouteWithNumericVariableName($name)
public function testRouteWithVariableNameStartingWithADigit($name)
{
$route = new Route('/{'.$name.'}');
$route->compile();
}
public function getNumericVariableNames()
public function getVariableNamesStartingWithADigit()
{
return array(
array('09'),
@@ -219,21 +327,21 @@ class RouteCompilerTest extends \PHPUnit_Framework_TestCase
array(
'Route with host pattern',
array('/hello', array(), array(), array(), 'www.example.com'),
'/hello', '#^/hello$#s', array(), array(), array(
'/hello', '#^/hello$#sD', array(), array(), array(
array('text', '/hello'),
),
'#^www\.example\.com$#si', array(), array(
'#^www\.example\.com$#sDi', array(), array(
array('text', 'www.example.com'),
),
),
array(
'Route with host pattern and some variables',
array('/hello/{name}', array(), array(), array(), 'www.example.{tld}'),
'/hello', '#^/hello/(?P<name>[^/]++)$#s', array('tld', 'name'), array('name'), array(
'/hello', '#^/hello/(?P<name>[^/]++)$#sD', array('tld', 'name'), array('name'), array(
array('variable', '/', '[^/]++', 'name'),
array('text', '/hello'),
),
'#^www\.example\.(?P<tld>[^\.]++)$#si', array('tld'), array(
'#^www\.example\.(?P<tld>[^\.]++)$#sDi', array('tld'), array(
array('variable', '.', '[^\.]++', 'tld'),
array('text', 'www.example'),
),
@@ -241,10 +349,10 @@ class RouteCompilerTest extends \PHPUnit_Framework_TestCase
array(
'Route with variable at beginning of host',
array('/hello', array(), array(), array(), '{locale}.example.{tld}'),
'/hello', '#^/hello$#s', array('locale', 'tld'), array(), array(
'/hello', '#^/hello$#sD', array('locale', 'tld'), array(), array(
array('text', '/hello'),
),
'#^(?P<locale>[^\.]++)\.example\.(?P<tld>[^\.]++)$#si', array('locale', 'tld'), array(
'#^(?P<locale>[^\.]++)\.example\.(?P<tld>[^\.]++)$#sDi', array('locale', 'tld'), array(
array('variable', '.', '[^\.]++', 'tld'),
array('text', '.example'),
array('variable', '', '[^\.]++', 'locale'),
@@ -253,10 +361,10 @@ class RouteCompilerTest extends \PHPUnit_Framework_TestCase
array(
'Route with host variables that has a default value',
array('/hello', array('locale' => 'a', 'tld' => 'b'), array(), array(), '{locale}.example.{tld}'),
'/hello', '#^/hello$#s', array('locale', 'tld'), array(), array(
'/hello', '#^/hello$#sD', array('locale', 'tld'), array(), array(
array('text', '/hello'),
),
'#^(?P<locale>[^\.]++)\.example\.(?P<tld>[^\.]++)$#si', array('locale', 'tld'), array(
'#^(?P<locale>[^\.]++)\.example\.(?P<tld>[^\.]++)$#sDi', array('locale', 'tld'), array(
array('variable', '.', '[^\.]++', 'tld'),
array('text', '.example'),
array('variable', '', '[^\.]++', 'locale'),
@@ -264,4 +372,18 @@ class RouteCompilerTest extends \PHPUnit_Framework_TestCase
),
);
}
/**
* @expectedException \DomainException
*/
public function testRouteWithTooLongVariableName()
{
$route = new Route(sprintf('/{%s}', str_repeat('a', RouteCompiler::VARIABLE_MAXIMUM_LENGTH + 1)));
$route->compile();
}
}
class Utf8RouteCompiler extends RouteCompiler
{
const SEPARATORS = '/§';
}

View File

@@ -11,9 +11,10 @@
namespace Symfony\Component\Routing\Tests;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Routing\Route;
class RouteTest extends \PHPUnit_Framework_TestCase
class RouteTest extends TestCase
{
public function testConstructor()
{
@@ -219,6 +220,24 @@ class RouteTest extends \PHPUnit_Framework_TestCase
$this->assertNotSame($route, $unserialized);
}
/**
* Tests that unserialization does not fail when the compiled Route is of a
* class other than CompiledRoute, such as a subclass of it.
*/
public function testSerializeWhenCompiledWithClass()
{
$route = new Route('/', array(), array(), array('compiler_class' => '\Symfony\Component\Routing\Tests\Fixtures\CustomRouteCompiler'));
$this->assertInstanceOf('\Symfony\Component\Routing\Tests\Fixtures\CustomCompiledRoute', $route->compile(), '->compile() returned a proper route');
$serialized = serialize($route);
try {
$unserialized = unserialize($serialized);
$this->assertInstanceOf('\Symfony\Component\Routing\Tests\Fixtures\CustomCompiledRoute', $unserialized->compile(), 'the unserialized route compiled successfully');
} catch (\Exception $e) {
$this->fail('unserializing a route which uses a custom compiled route class');
}
}
/**
* Tests that the serialized representation of a route in one symfony version
* also works in later symfony versions, i.e. the unserialized route is in the
@@ -226,7 +245,7 @@ class RouteTest extends \PHPUnit_Framework_TestCase
*/
public function testSerializedRepresentationKeepsWorking()
{
$serialized = 'C:31:"Symfony\Component\Routing\Route":934:{a:8:{s:4:"path";s:13:"/prefix/{foo}";s:4:"host";s:20:"{locale}.example.net";s:8:"defaults";a:1:{s:3:"foo";s:7:"default";}s:12:"requirements";a:1:{s:3:"foo";s:3:"\d+";}s:7:"options";a:1:{s:14:"compiler_class";s:39:"Symfony\Component\Routing\RouteCompiler";}s:7:"schemes";a:0:{}s:7:"methods";a:0:{}s:8:"compiled";C:39:"Symfony\Component\Routing\CompiledRoute":569:{a:8:{s:4:"vars";a:2:{i:0;s:6:"locale";i:1;s:3:"foo";}s:11:"path_prefix";s:7:"/prefix";s:10:"path_regex";s:30:"#^/prefix(?:/(?P<foo>\d+))?$#s";s:11:"path_tokens";a:2:{i:0;a:4:{i:0;s:8:"variable";i:1;s:1:"/";i:2;s:3:"\d+";i:3;s:3:"foo";}i:1;a:2:{i:0;s:4:"text";i:1;s:7:"/prefix";}}s:9:"path_vars";a:1:{i:0;s:3:"foo";}s:10:"host_regex";s:39:"#^(?P<locale>[^\.]++)\.example\.net$#si";s:11:"host_tokens";a:2:{i:0;a:2:{i:0;s:4:"text";i:1;s:12:".example.net";}i:1;a:4:{i:0;s:8:"variable";i:1;s:0:"";i:2;s:7:"[^\.]++";i:3;s:6:"locale";}}s:9:"host_vars";a:1:{i:0;s:6:"locale";}}}}}';
$serialized = 'C:31:"Symfony\Component\Routing\Route":936:{a:8:{s:4:"path";s:13:"/prefix/{foo}";s:4:"host";s:20:"{locale}.example.net";s:8:"defaults";a:1:{s:3:"foo";s:7:"default";}s:12:"requirements";a:1:{s:3:"foo";s:3:"\d+";}s:7:"options";a:1:{s:14:"compiler_class";s:39:"Symfony\Component\Routing\RouteCompiler";}s:7:"schemes";a:0:{}s:7:"methods";a:0:{}s:8:"compiled";C:39:"Symfony\Component\Routing\CompiledRoute":571:{a:8:{s:4:"vars";a:2:{i:0;s:6:"locale";i:1;s:3:"foo";}s:11:"path_prefix";s:7:"/prefix";s:10:"path_regex";s:31:"#^/prefix(?:/(?P<foo>\d+))?$#sD";s:11:"path_tokens";a:2:{i:0;a:4:{i:0;s:8:"variable";i:1;s:1:"/";i:2;s:3:"\d+";i:3;s:3:"foo";}i:1;a:2:{i:0;s:4:"text";i:1;s:7:"/prefix";}}s:9:"path_vars";a:1:{i:0;s:3:"foo";}s:10:"host_regex";s:40:"#^(?P<locale>[^\.]++)\.example\.net$#sDi";s:11:"host_tokens";a:2:{i:0;a:2:{i:0;s:4:"text";i:1;s:12:".example.net";}i:1;a:4:{i:0;s:8:"variable";i:1;s:0:"";i:2;s:7:"[^\.]++";i:3;s:6:"locale";}}s:9:"host_vars";a:1:{i:0;s:6:"locale";}}}}}';
$unserialized = unserialize($serialized);
$route = new Route('/prefix/{foo}', array('foo' => 'default'), array('foo' => '\d+'));

View File

@@ -11,10 +11,12 @@
namespace Symfony\Component\Routing\Tests;
use Symfony\Component\Routing\Router;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\RouteCollection;
use Symfony\Component\Routing\Router;
class RouterTest extends \PHPUnit_Framework_TestCase
class RouterTest extends TestCase
{
private $router = null;
@@ -22,7 +24,7 @@ class RouterTest extends \PHPUnit_Framework_TestCase
protected function setUp()
{
$this->loader = $this->getMock('Symfony\Component\Config\Loader\LoaderInterface');
$this->loader = $this->getMockBuilder('Symfony\Component\Config\Loader\LoaderInterface')->getMock();
$this->router = new Router($this->loader, 'routing.yml');
}
@@ -82,7 +84,7 @@ class RouterTest extends \PHPUnit_Framework_TestCase
{
$this->router->setOption('resource_type', 'ResourceType');
$routeCollection = $this->getMock('Symfony\Component\Routing\RouteCollection');
$routeCollection = new RouteCollection();
$this->loader->expects($this->once())
->method('load')->with('routing.yml', 'ResourceType')
@@ -100,7 +102,7 @@ class RouterTest extends \PHPUnit_Framework_TestCase
$this->loader->expects($this->once())
->method('load')->with('routing.yml', null)
->will($this->returnValue($this->getMock('Symfony\Component\Routing\RouteCollection')));
->will($this->returnValue(new RouteCollection()));
$this->assertInstanceOf('Symfony\\Component\\Routing\\Matcher\\UrlMatcher', $this->router->getMatcher());
}
@@ -122,7 +124,7 @@ class RouterTest extends \PHPUnit_Framework_TestCase
$this->loader->expects($this->once())
->method('load')->with('routing.yml', null)
->will($this->returnValue($this->getMock('Symfony\Component\Routing\RouteCollection')));
->will($this->returnValue(new RouteCollection()));
$this->assertInstanceOf('Symfony\\Component\\Routing\\Generator\\UrlGenerator', $this->router->getGenerator());
}
@@ -137,7 +139,7 @@ class RouterTest extends \PHPUnit_Framework_TestCase
public function testMatchRequestWithUrlMatcherInterface()
{
$matcher = $this->getMock('Symfony\Component\Routing\Matcher\UrlMatcherInterface');
$matcher = $this->getMockBuilder('Symfony\Component\Routing\Matcher\UrlMatcherInterface')->getMock();
$matcher->expects($this->once())->method('match');
$p = new \ReflectionProperty($this->router, 'matcher');
@@ -149,7 +151,7 @@ class RouterTest extends \PHPUnit_Framework_TestCase
public function testMatchRequestWithRequestMatcherInterface()
{
$matcher = $this->getMock('Symfony\Component\Routing\Matcher\RequestMatcherInterface');
$matcher = $this->getMockBuilder('Symfony\Component\Routing\Matcher\RequestMatcherInterface')->getMock();
$matcher->expects($this->once())->method('matchRequest');
$p = new \ReflectionProperty($this->router, 'matcher');