updated packages

This commit is contained in:
2019-05-18 09:06:43 +00:00
parent 901d16349e
commit e9487fa58a
2025 changed files with 30366 additions and 49653 deletions

View File

@@ -21,7 +21,7 @@ class RouteTest extends TestCase
*/
public function testInvalidRouteParameter()
{
$route = new Route(array('foo' => 'bar'));
$route = new Route(['foo' => 'bar']);
}
/**
@@ -29,7 +29,7 @@ class RouteTest extends TestCase
*/
public function testTryingToSetLocalesDirectly()
{
$route = new Route(array('locales' => array('nl' => 'bar')));
$route = new Route(['locales' => ['nl' => 'bar']]);
}
/**
@@ -37,23 +37,23 @@ class RouteTest extends TestCase
*/
public function testRouteParameters($parameter, $value, $getter)
{
$route = new Route(array($parameter => $value));
$route = new Route([$parameter => $value]);
$this->assertEquals($route->$getter(), $value);
}
public function getValidParameters()
{
return array(
array('value', '/Blog', 'getPath'),
array('requirements', array('locale' => 'en'), 'getRequirements'),
array('options', array('compiler_class' => 'RouteCompiler'), 'getOptions'),
array('name', 'blog_index', 'getName'),
array('defaults', array('_controller' => 'MyBlogBundle:Blog:index'), 'getDefaults'),
array('schemes', array('https'), 'getSchemes'),
array('methods', array('GET', 'POST'), 'getMethods'),
array('host', '{locale}.example.com', 'getHost'),
array('condition', 'context.getMethod() == "GET"', 'getCondition'),
array('value', array('nl' => '/hier', 'en' => '/here'), 'getLocalizedPaths'),
);
return [
['value', '/Blog', 'getPath'],
['requirements', ['locale' => 'en'], 'getRequirements'],
['options', ['compiler_class' => 'RouteCompiler'], 'getOptions'],
['name', 'blog_index', 'getName'],
['defaults', ['_controller' => 'MyBlogBundle:Blog:index'], 'getDefaults'],
['schemes', ['https'], 'getSchemes'],
['methods', ['GET', 'POST'], 'getMethods'],
['host', '{locale}.example.com', 'getHost'],
['condition', 'context.getMethod() == "GET"', 'getCondition'],
['value', ['nl' => '/hier', 'en' => '/here'], 'getLocalizedPaths'],
];
}
}

View File

@@ -18,10 +18,10 @@ class CompiledRouteTest extends TestCase
{
public function testAccessors()
{
$compiled = new CompiledRoute('prefix', 'regex', array('tokens'), array(), null, array(), array(), array('variables'));
$compiled = new CompiledRoute('prefix', 'regex', ['tokens'], [], null, [], [], ['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');
$this->assertEquals(array('variables'), $compiled->getVariables(), '__construct() takes an array of variables as its ninth argument');
$this->assertEquals(['tokens'], $compiled->getTokens(), '__construct() takes an array of tokens as its fourth argument');
$this->assertEquals(['variables'], $compiled->getVariables(), '__construct() takes an array of variables as its ninth argument');
}
}

View File

@@ -29,7 +29,7 @@ class RoutingResolverPassTest extends TestCase
(new RoutingResolverPass())->process($container);
$this->assertEquals(
array(array('addLoader', array(new Reference('loader1'))), array('addLoader', array(new Reference('loader2')))),
[['addLoader', [new Reference('loader1')]], ['addLoader', [new Reference('loader2')]]],
$container->getDefinition('routing.resolver')->getMethodCalls()
);
}

View File

@@ -13,4 +13,9 @@ namespace Symfony\Component\Routing\Tests\Fixtures\AnnotatedClasses;
abstract class AbstractClass
{
abstract public function abstractRouteAction();
public function routeAction($arg1, $arg2 = 'defaultValue2', $arg3 = 'defaultValue3')
{
}
}

View File

@@ -12,4 +12,12 @@ class DefaultValueController
public function action($default = 'value')
{
}
/**
* @Route("/hello/{name<\w+>}", name="hello_without_default")
* @Route("/hello/{name<\w+>?Symfony}", name="hello_with_default")
*/
public function hello(string $name = 'World')
{
}
}

View File

@@ -21,6 +21,6 @@ class CustomRouteCompiler extends RouteCompiler
*/
public static function compile(Route $route)
{
return new CustomCompiledRoute('', '', array(), array());
return new CustomCompiledRoute('', '', [], []);
}
}

View File

@@ -21,10 +21,10 @@ class RedirectableUrlMatcher extends UrlMatcher implements RedirectableUrlMatche
{
public function redirect($path, $route, $scheme = null)
{
return array(
return [
'_controller' => 'Some controller reference...',
'path' => $path,
'scheme' => $scheme,
);
];
}
}

View File

@@ -2,7 +2,7 @@
<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">
https://symfony.com/schema/routing/routing-1.0.xsd">
<import resource="routing.xml">
<default key="_controller">FrameworkBundle:Template:template</default>

View File

@@ -2,7 +2,7 @@
<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">
https://symfony.com/schema/routing/routing-1.0.xsd">
<import resource="routing.xml" controller="FrameworkBundle:Template:template" />
</routes>

View File

@@ -2,7 +2,7 @@
<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">
https://symfony.com/schema/routing/routing-1.0.xsd">
<import resource="routing.xml" controller="FrameworkBundle:Template:template">
<default key="_controller">AppBundle:Blog:index</default>

View File

@@ -2,7 +2,7 @@
<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">
https://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>

View File

@@ -2,7 +2,7 @@
<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">
https://symfony.com/schema/routing/routing-1.0.xsd">
<route id="app_homepage" path="/" controller="AppBundle:Homepage:show" />

View File

@@ -15,26 +15,26 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
{
$this->context = $context;
$this->matchHost = true;
$this->staticRoutes = array(
'/test/baz' => array(array(array('_route' => 'baz'), null, null, null, false, false, null)),
'/test/baz.html' => array(array(array('_route' => 'baz2'), null, null, null, false, false, null)),
'/test/baz3' => array(array(array('_route' => 'baz3'), null, null, null, true, false, null)),
'/foofoo' => array(array(array('_route' => 'foofoo', 'def' => 'test'), null, null, null, false, false, null)),
'/spa ce' => array(array(array('_route' => 'space'), null, null, null, false, false, null)),
'/multi/new' => array(array(array('_route' => 'overridden2'), null, null, null, false, false, null)),
'/multi/hey' => array(array(array('_route' => 'hey'), null, null, null, true, false, null)),
'/ababa' => array(array(array('_route' => 'ababa'), null, null, null, false, false, null)),
'/route1' => array(array(array('_route' => 'route1'), 'a.example.com', null, null, false, false, null)),
'/c2/route2' => array(array(array('_route' => 'route2'), 'a.example.com', null, null, false, false, null)),
'/route4' => array(array(array('_route' => 'route4'), 'a.example.com', null, null, false, false, null)),
'/c2/route3' => array(array(array('_route' => 'route3'), 'b.example.com', null, null, false, false, null)),
'/route5' => array(array(array('_route' => 'route5'), 'c.example.com', null, null, false, false, null)),
'/route6' => array(array(array('_route' => 'route6'), null, null, null, false, false, null)),
'/route11' => array(array(array('_route' => 'route11'), '#^(?P<var1>[^\\.]++)\\.example\\.com$#sDi', null, null, false, false, null)),
'/route12' => array(array(array('_route' => 'route12', 'var1' => 'val'), '#^(?P<var1>[^\\.]++)\\.example\\.com$#sDi', null, null, false, false, null)),
'/route17' => array(array(array('_route' => 'route17'), null, null, null, false, false, null)),
);
$this->regexpList = array(
$this->staticRoutes = [
'/test/baz' => [[['_route' => 'baz'], null, null, null, false, false, null]],
'/test/baz.html' => [[['_route' => 'baz2'], null, null, null, false, false, null]],
'/test/baz3' => [[['_route' => 'baz3'], null, null, null, true, false, null]],
'/foofoo' => [[['_route' => 'foofoo', 'def' => 'test'], null, null, null, false, false, null]],
'/spa ce' => [[['_route' => 'space'], null, null, null, false, false, null]],
'/multi/new' => [[['_route' => 'overridden2'], null, null, null, false, false, null]],
'/multi/hey' => [[['_route' => 'hey'], null, null, null, true, false, null]],
'/ababa' => [[['_route' => 'ababa'], null, null, null, false, false, null]],
'/route1' => [[['_route' => 'route1'], 'a.example.com', null, null, false, false, null]],
'/c2/route2' => [[['_route' => 'route2'], 'a.example.com', null, null, false, false, null]],
'/route4' => [[['_route' => 'route4'], 'a.example.com', null, null, false, false, null]],
'/c2/route3' => [[['_route' => 'route3'], 'b.example.com', null, null, false, false, null]],
'/route5' => [[['_route' => 'route5'], 'c.example.com', null, null, false, false, null]],
'/route6' => [[['_route' => 'route6'], null, null, null, false, false, null]],
'/route11' => [[['_route' => 'route11'], '#^(?P<var1>[^\\.]++)\\.example\\.com$#sDi', null, null, false, false, null]],
'/route12' => [[['_route' => 'route12', 'var1' => 'val'], '#^(?P<var1>[^\\.]++)\\.example\\.com$#sDi', null, null, false, false, null]],
'/route17' => [[['_route' => 'route17'], null, null, null, false, false, null]],
];
$this->regexpList = [
0 => '{^(?'
.'|(?:(?:[^./]*+\\.)++)(?'
.'|/foo/(baz|symfony)(*:47)'
@@ -81,33 +81,33 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
.')'
.')'
.')/?$}sD',
);
$this->dynamicRoutes = array(
47 => array(array(array('_route' => 'foo', 'def' => 'test'), array('bar'), null, null, false, true, null)),
70 => array(array(array('_route' => 'bar'), array('foo'), array('GET' => 0, 'HEAD' => 1), null, false, true, null)),
90 => array(array(array('_route' => 'barhead'), array('foo'), array('GET' => 0), null, false, true, null)),
115 => array(
array(array('_route' => 'baz4'), array('foo'), null, null, true, true, null),
array(array('_route' => 'baz5'), array('foo'), array('POST' => 0), null, true, true, null),
array(array('_route' => 'baz.baz6'), array('foo'), array('PUT' => 0), null, true, true, null),
),
131 => array(array(array('_route' => 'quoter'), array('quoter'), null, null, false, true, null)),
160 => array(array(array('_route' => 'foo1'), array('foo'), array('PUT' => 0), null, false, true, null)),
168 => array(array(array('_route' => 'bar1'), array('bar'), null, null, false, true, null)),
181 => array(array(array('_route' => 'overridden'), array('var'), null, null, false, true, null)),
204 => array(array(array('_route' => 'foo2'), array('foo1'), null, null, false, true, null)),
212 => array(array(array('_route' => 'bar2'), array('bar1'), null, null, false, true, null)),
248 => array(array(array('_route' => 'helloWorld', 'who' => 'World!'), array('who'), null, null, false, true, null)),
279 => array(array(array('_route' => 'foo3'), array('_locale', 'foo'), null, null, false, true, null)),
287 => array(array(array('_route' => 'bar3'), array('_locale', 'bar'), null, null, false, true, null)),
309 => array(array(array('_route' => 'foo4'), array('foo'), null, null, false, true, null)),
371 => array(array(array('_route' => 'route13'), array('var1', 'name'), null, null, false, true, null)),
389 => array(array(array('_route' => 'route14', 'var1' => 'val'), array('var1', 'name'), null, null, false, true, null)),
441 => array(array(array('_route' => 'route15'), array('name'), null, null, false, true, null)),
489 => array(array(array('_route' => 'route16', 'var1' => 'val'), array('name'), null, null, false, true, null)),
510 => array(array(array('_route' => 'a'), array(), null, null, false, false, null)),
531 => array(array(array('_route' => 'b'), array('var'), null, null, false, true, null)),
549 => array(array(array('_route' => 'c'), array('var'), null, null, false, true, null)),
);
];
$this->dynamicRoutes = [
47 => [[['_route' => 'foo', 'def' => 'test'], ['bar'], null, null, false, true, null]],
70 => [[['_route' => 'bar'], ['foo'], ['GET' => 0, 'HEAD' => 1], null, false, true, null]],
90 => [[['_route' => 'barhead'], ['foo'], ['GET' => 0], null, false, true, null]],
115 => [
[['_route' => 'baz4'], ['foo'], null, null, true, true, null],
[['_route' => 'baz5'], ['foo'], ['POST' => 0], null, true, true, null],
[['_route' => 'baz.baz6'], ['foo'], ['PUT' => 0], null, true, true, null],
],
131 => [[['_route' => 'quoter'], ['quoter'], null, null, false, true, null]],
160 => [[['_route' => 'foo1'], ['foo'], ['PUT' => 0], null, false, true, null]],
168 => [[['_route' => 'bar1'], ['bar'], null, null, false, true, null]],
181 => [[['_route' => 'overridden'], ['var'], null, null, false, true, null]],
204 => [[['_route' => 'foo2'], ['foo1'], null, null, false, true, null]],
212 => [[['_route' => 'bar2'], ['bar1'], null, null, false, true, null]],
248 => [[['_route' => 'helloWorld', 'who' => 'World!'], ['who'], null, null, false, true, null]],
279 => [[['_route' => 'foo3'], ['_locale', 'foo'], null, null, false, true, null]],
287 => [[['_route' => 'bar3'], ['_locale', 'bar'], null, null, false, true, null]],
309 => [[['_route' => 'foo4'], ['foo'], null, null, false, true, null]],
371 => [[['_route' => 'route13'], ['var1', 'name'], null, null, false, true, null]],
389 => [[['_route' => 'route14', 'var1' => 'val'], ['var1', 'name'], null, null, false, true, null]],
441 => [[['_route' => 'route15'], ['name'], null, null, false, true, null]],
489 => [[['_route' => 'route16', 'var1' => 'val'], ['name'], null, null, false, true, null]],
510 => [[['_route' => 'a'], [], null, null, false, false, null]],
531 => [[['_route' => 'b'], ['var'], null, null, false, true, null]],
549 => [[['_route' => 'c'], ['var'], null, null, false, true, null]],
];
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -14,7 +14,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
public function __construct(RequestContext $context)
{
$this->context = $context;
$this->regexpList = array(
$this->regexpList = [
0 => '{^(?'
.'|/(en|fr)/(?'
.'|admin/post(?'
@@ -45,22 +45,22 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
.')'
.'|/(en|fr)?(*:264)'
.')/?$}sD',
);
$this->dynamicRoutes = array(
32 => array(array(array('_route' => 'a', '_locale' => 'en'), array('_locale'), null, null, true, false, null)),
46 => array(array(array('_route' => 'b', '_locale' => 'en'), array('_locale'), null, null, false, false, null)),
58 => array(array(array('_route' => 'c', '_locale' => 'en'), array('_locale', 'id'), null, null, false, true, null)),
75 => array(array(array('_route' => 'd', '_locale' => 'en'), array('_locale', 'id'), null, null, false, false, null)),
94 => array(array(array('_route' => 'e', '_locale' => 'en'), array('_locale', 'id'), null, null, false, false, null)),
110 => array(array(array('_route' => 'f', '_locale' => 'en'), array('_locale'), null, null, true, false, null)),
130 => array(array(array('_route' => 'g', '_locale' => 'en'), array('_locale'), null, null, false, false, null)),
154 => array(array(array('_route' => 'h', '_locale' => 'en'), array('_locale', 'page'), null, null, false, true, null)),
175 => array(array(array('_route' => 'i', '_locale' => 'en'), array('_locale', 'page'), null, null, false, true, null)),
202 => array(array(array('_route' => 'j', '_locale' => 'en'), array('_locale', 'id'), null, null, false, false, null)),
216 => array(array(array('_route' => 'k', '_locale' => 'en'), array('_locale'), null, null, false, false, null)),
234 => array(array(array('_route' => 'l', '_locale' => 'en'), array('_locale'), null, null, false, false, null)),
245 => array(array(array('_route' => 'm', '_locale' => 'en'), array('_locale'), null, null, false, false, null)),
264 => array(array(array('_route' => 'n', '_locale' => 'en'), array('_locale'), null, null, false, true, null)),
);
];
$this->dynamicRoutes = [
32 => [[['_route' => 'a', '_locale' => 'en'], ['_locale'], null, null, true, false, null]],
46 => [[['_route' => 'b', '_locale' => 'en'], ['_locale'], null, null, false, false, null]],
58 => [[['_route' => 'c', '_locale' => 'en'], ['_locale', 'id'], null, null, false, true, null]],
75 => [[['_route' => 'd', '_locale' => 'en'], ['_locale', 'id'], null, null, false, false, null]],
94 => [[['_route' => 'e', '_locale' => 'en'], ['_locale', 'id'], null, null, false, false, null]],
110 => [[['_route' => 'f', '_locale' => 'en'], ['_locale'], null, null, true, false, null]],
130 => [[['_route' => 'g', '_locale' => 'en'], ['_locale'], null, null, false, false, null]],
154 => [[['_route' => 'h', '_locale' => 'en'], ['_locale', 'page'], null, null, false, true, null]],
175 => [[['_route' => 'i', '_locale' => 'en'], ['_locale', 'page'], null, null, false, true, null]],
202 => [[['_route' => 'j', '_locale' => 'en'], ['_locale', 'id'], null, null, false, false, null]],
216 => [[['_route' => 'k', '_locale' => 'en'], ['_locale'], null, null, false, false, null]],
234 => [[['_route' => 'l', '_locale' => 'en'], ['_locale'], null, null, false, false, null]],
245 => [[['_route' => 'm', '_locale' => 'en'], ['_locale'], null, null, false, false, null]],
264 => [[['_route' => 'n', '_locale' => 'en'], ['_locale'], null, null, false, true, null]],
];
}
}

View File

@@ -14,7 +14,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
public function __construct(RequestContext $context)
{
$this->context = $context;
$this->regexpList = array(
$this->regexpList = [
0 => '{^(?'
.'|/abc([^/]++)/(?'
.'|1(?'
@@ -33,14 +33,14 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
.')'
.')'
.')/?$}sD',
);
$this->dynamicRoutes = array(
27 => array(array(array('_route' => 'r1'), array('foo'), null, null, false, false, null)),
38 => array(array(array('_route' => 'r10'), array('foo'), null, null, false, false, null)),
46 => array(array(array('_route' => 'r100'), array('foo'), null, null, false, false, null)),
59 => array(array(array('_route' => 'r2'), array('foo'), null, null, false, false, null)),
70 => array(array(array('_route' => 'r20'), array('foo'), null, null, false, false, null)),
78 => array(array(array('_route' => 'r200'), array('foo'), null, null, false, false, null)),
);
];
$this->dynamicRoutes = [
27 => [[['_route' => 'r1'], ['foo'], null, null, false, false, null]],
38 => [[['_route' => 'r10'], ['foo'], null, null, false, false, null]],
46 => [[['_route' => 'r100'], ['foo'], null, null, false, false, null]],
59 => [[['_route' => 'r2'], ['foo'], null, null, false, false, null]],
70 => [[['_route' => 'r20'], ['foo'], null, null, false, false, null]],
78 => [[['_route' => 'r200'], ['foo'], null, null, false, false, null]],
];
}
}

View File

@@ -15,7 +15,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
{
$this->context = $context;
$this->matchHost = true;
$this->regexpList = array(
$this->regexpList = [
0 => '{^(?'
.'|(?i:([^\\.]++)\\.exampple\\.com)\\.(?'
.'|/abc([^/]++)(?'
@@ -23,12 +23,12 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
.')'
.')'
.')/?$}sD',
);
$this->dynamicRoutes = array(
56 => array(
array(array('_route' => 'r1'), array('foo', 'foo'), null, null, false, true, null),
array(array('_route' => 'r2'), array('foo', 'foo'), null, null, false, true, null),
),
);
];
$this->dynamicRoutes = [
56 => [
[['_route' => 'r1'], ['foo', 'foo'], null, null, false, true, null],
[['_route' => 'r2'], ['foo', 'foo'], null, null, false, true, null],
],
];
}
}

View File

@@ -15,28 +15,28 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
{
$this->context = $context;
$this->matchHost = true;
$this->staticRoutes = array(
'/test/baz' => array(array(array('_route' => 'baz'), null, null, null, false, false, null)),
'/test/baz.html' => array(array(array('_route' => 'baz2'), null, null, null, false, false, null)),
'/test/baz3' => array(array(array('_route' => 'baz3'), null, null, null, true, false, null)),
'/foofoo' => array(array(array('_route' => 'foofoo', 'def' => 'test'), null, null, null, false, false, null)),
'/spa ce' => array(array(array('_route' => 'space'), null, null, null, false, false, null)),
'/multi/new' => array(array(array('_route' => 'overridden2'), null, null, null, false, false, null)),
'/multi/hey' => array(array(array('_route' => 'hey'), null, null, null, true, false, null)),
'/ababa' => array(array(array('_route' => 'ababa'), null, null, null, false, false, null)),
'/route1' => array(array(array('_route' => 'route1'), 'a.example.com', null, null, false, false, null)),
'/c2/route2' => array(array(array('_route' => 'route2'), 'a.example.com', null, null, false, false, null)),
'/route4' => array(array(array('_route' => 'route4'), 'a.example.com', null, null, false, false, null)),
'/c2/route3' => array(array(array('_route' => 'route3'), 'b.example.com', null, null, false, false, null)),
'/route5' => array(array(array('_route' => 'route5'), 'c.example.com', null, null, false, false, null)),
'/route6' => array(array(array('_route' => 'route6'), null, null, null, false, false, null)),
'/route11' => array(array(array('_route' => 'route11'), '#^(?P<var1>[^\\.]++)\\.example\\.com$#sDi', null, null, false, false, null)),
'/route12' => array(array(array('_route' => 'route12', 'var1' => 'val'), '#^(?P<var1>[^\\.]++)\\.example\\.com$#sDi', null, null, false, false, null)),
'/route17' => array(array(array('_route' => 'route17'), null, null, null, false, false, null)),
'/secure' => array(array(array('_route' => 'secure'), null, null, array('https' => 0), false, false, null)),
'/nonsecure' => array(array(array('_route' => 'nonsecure'), null, null, array('http' => 0), false, false, null)),
);
$this->regexpList = array(
$this->staticRoutes = [
'/test/baz' => [[['_route' => 'baz'], null, null, null, false, false, null]],
'/test/baz.html' => [[['_route' => 'baz2'], null, null, null, false, false, null]],
'/test/baz3' => [[['_route' => 'baz3'], null, null, null, true, false, null]],
'/foofoo' => [[['_route' => 'foofoo', 'def' => 'test'], null, null, null, false, false, null]],
'/spa ce' => [[['_route' => 'space'], null, null, null, false, false, null]],
'/multi/new' => [[['_route' => 'overridden2'], null, null, null, false, false, null]],
'/multi/hey' => [[['_route' => 'hey'], null, null, null, true, false, null]],
'/ababa' => [[['_route' => 'ababa'], null, null, null, false, false, null]],
'/route1' => [[['_route' => 'route1'], 'a.example.com', null, null, false, false, null]],
'/c2/route2' => [[['_route' => 'route2'], 'a.example.com', null, null, false, false, null]],
'/route4' => [[['_route' => 'route4'], 'a.example.com', null, null, false, false, null]],
'/c2/route3' => [[['_route' => 'route3'], 'b.example.com', null, null, false, false, null]],
'/route5' => [[['_route' => 'route5'], 'c.example.com', null, null, false, false, null]],
'/route6' => [[['_route' => 'route6'], null, null, null, false, false, null]],
'/route11' => [[['_route' => 'route11'], '#^(?P<var1>[^\\.]++)\\.example\\.com$#sDi', null, null, false, false, null]],
'/route12' => [[['_route' => 'route12', 'var1' => 'val'], '#^(?P<var1>[^\\.]++)\\.example\\.com$#sDi', null, null, false, false, null]],
'/route17' => [[['_route' => 'route17'], null, null, null, false, false, null]],
'/secure' => [[['_route' => 'secure'], null, null, ['https' => 0], false, false, null]],
'/nonsecure' => [[['_route' => 'nonsecure'], null, null, ['http' => 0], false, false, null]],
];
$this->regexpList = [
0 => '{^(?'
.'|(?:(?:[^./]*+\\.)++)(?'
.'|/foo/(baz|symfony)(*:47)'
@@ -83,33 +83,33 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
.')'
.')'
.')/?$}sD',
);
$this->dynamicRoutes = array(
47 => array(array(array('_route' => 'foo', 'def' => 'test'), array('bar'), null, null, false, true, null)),
70 => array(array(array('_route' => 'bar'), array('foo'), array('GET' => 0, 'HEAD' => 1), null, false, true, null)),
90 => array(array(array('_route' => 'barhead'), array('foo'), array('GET' => 0), null, false, true, null)),
115 => array(
array(array('_route' => 'baz4'), array('foo'), null, null, true, true, null),
array(array('_route' => 'baz5'), array('foo'), array('POST' => 0), null, true, true, null),
array(array('_route' => 'baz.baz6'), array('foo'), array('PUT' => 0), null, true, true, null),
),
131 => array(array(array('_route' => 'quoter'), array('quoter'), null, null, false, true, null)),
160 => array(array(array('_route' => 'foo1'), array('foo'), array('PUT' => 0), null, false, true, null)),
168 => array(array(array('_route' => 'bar1'), array('bar'), null, null, false, true, null)),
181 => array(array(array('_route' => 'overridden'), array('var'), null, null, false, true, null)),
204 => array(array(array('_route' => 'foo2'), array('foo1'), null, null, false, true, null)),
212 => array(array(array('_route' => 'bar2'), array('bar1'), null, null, false, true, null)),
248 => array(array(array('_route' => 'helloWorld', 'who' => 'World!'), array('who'), null, null, false, true, null)),
279 => array(array(array('_route' => 'foo3'), array('_locale', 'foo'), null, null, false, true, null)),
287 => array(array(array('_route' => 'bar3'), array('_locale', 'bar'), null, null, false, true, null)),
309 => array(array(array('_route' => 'foo4'), array('foo'), null, null, false, true, null)),
371 => array(array(array('_route' => 'route13'), array('var1', 'name'), null, null, false, true, null)),
389 => array(array(array('_route' => 'route14', 'var1' => 'val'), array('var1', 'name'), null, null, false, true, null)),
441 => array(array(array('_route' => 'route15'), array('name'), null, null, false, true, null)),
489 => array(array(array('_route' => 'route16', 'var1' => 'val'), array('name'), null, null, false, true, null)),
510 => array(array(array('_route' => 'a'), array(), null, null, false, false, null)),
531 => array(array(array('_route' => 'b'), array('var'), null, null, false, true, null)),
549 => array(array(array('_route' => 'c'), array('var'), null, null, false, true, null)),
);
];
$this->dynamicRoutes = [
47 => [[['_route' => 'foo', 'def' => 'test'], ['bar'], null, null, false, true, null]],
70 => [[['_route' => 'bar'], ['foo'], ['GET' => 0, 'HEAD' => 1], null, false, true, null]],
90 => [[['_route' => 'barhead'], ['foo'], ['GET' => 0], null, false, true, null]],
115 => [
[['_route' => 'baz4'], ['foo'], null, null, true, true, null],
[['_route' => 'baz5'], ['foo'], ['POST' => 0], null, true, true, null],
[['_route' => 'baz.baz6'], ['foo'], ['PUT' => 0], null, true, true, null],
],
131 => [[['_route' => 'quoter'], ['quoter'], null, null, false, true, null]],
160 => [[['_route' => 'foo1'], ['foo'], ['PUT' => 0], null, false, true, null]],
168 => [[['_route' => 'bar1'], ['bar'], null, null, false, true, null]],
181 => [[['_route' => 'overridden'], ['var'], null, null, false, true, null]],
204 => [[['_route' => 'foo2'], ['foo1'], null, null, false, true, null]],
212 => [[['_route' => 'bar2'], ['bar1'], null, null, false, true, null]],
248 => [[['_route' => 'helloWorld', 'who' => 'World!'], ['who'], null, null, false, true, null]],
279 => [[['_route' => 'foo3'], ['_locale', 'foo'], null, null, false, true, null]],
287 => [[['_route' => 'bar3'], ['_locale', 'bar'], null, null, false, true, null]],
309 => [[['_route' => 'foo4'], ['foo'], null, null, false, true, null]],
371 => [[['_route' => 'route13'], ['var1', 'name'], null, null, false, true, null]],
389 => [[['_route' => 'route14', 'var1' => 'val'], ['var1', 'name'], null, null, false, true, null]],
441 => [[['_route' => 'route15'], ['name'], null, null, false, true, null]],
489 => [[['_route' => 'route16', 'var1' => 'val'], ['name'], null, null, false, true, null]],
510 => [[['_route' => 'a'], [], null, null, false, false, null]],
531 => [[['_route' => 'b'], ['var'], null, null, false, true, null]],
549 => [[['_route' => 'c'], ['var'], null, null, false, true, null]],
];
}
}

View File

@@ -14,18 +14,18 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
public function __construct(RequestContext $context)
{
$this->context = $context;
$this->staticRoutes = array(
'/rootprefix/test' => array(array(array('_route' => 'static'), null, null, null, false, false, null)),
'/with-condition' => array(array(array('_route' => 'with-condition'), null, null, null, false, false, -1)),
);
$this->regexpList = array(
$this->staticRoutes = [
'/rootprefix/test' => [[['_route' => 'static'], null, null, null, false, false, null]],
'/with-condition' => [[['_route' => 'with-condition'], null, null, null, false, false, -1]],
];
$this->regexpList = [
0 => '{^(?'
.'|/rootprefix/([^/]++)(*:27)'
.')/?$}sD',
);
$this->dynamicRoutes = array(
27 => array(array(array('_route' => 'dynamic'), array('var'), null, null, false, true, null)),
);
];
$this->dynamicRoutes = [
27 => [[['_route' => 'dynamic'], ['var'], null, null, false, true, null]],
];
$this->checkCondition = static function ($condition, $context, $request) {
switch ($condition) {
case -1: return ($context->getMethod() == "GET");

View File

@@ -14,15 +14,15 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
public function __construct(RequestContext $context)
{
$this->context = $context;
$this->staticRoutes = array(
'/just_head' => array(array(array('_route' => 'just_head'), null, array('HEAD' => 0), null, false, false, null)),
'/head_and_get' => array(array(array('_route' => 'head_and_get'), null, array('HEAD' => 0, 'GET' => 1), null, false, false, null)),
'/get_and_head' => array(array(array('_route' => 'get_and_head'), null, array('GET' => 0, 'HEAD' => 1), null, false, false, null)),
'/post_and_head' => array(array(array('_route' => 'post_and_head'), null, array('POST' => 0, 'HEAD' => 1), null, false, false, null)),
'/put_and_post' => array(
array(array('_route' => 'put_and_post'), null, array('PUT' => 0, 'POST' => 1), null, false, false, null),
array(array('_route' => 'put_and_get_and_head'), null, array('PUT' => 0, 'GET' => 1, 'HEAD' => 2), null, false, false, null),
),
);
$this->staticRoutes = [
'/just_head' => [[['_route' => 'just_head'], null, ['HEAD' => 0], null, false, false, null]],
'/head_and_get' => [[['_route' => 'head_and_get'], null, ['HEAD' => 0, 'GET' => 1], null, false, false, null]],
'/get_and_head' => [[['_route' => 'get_and_head'], null, ['GET' => 0, 'HEAD' => 1], null, false, false, null]],
'/post_and_head' => [[['_route' => 'post_and_head'], null, ['POST' => 0, 'HEAD' => 1], null, false, false, null]],
'/put_and_post' => [
[['_route' => 'put_and_post'], null, ['PUT' => 0, 'POST' => 1], null, false, false, null],
[['_route' => 'put_and_get_and_head'], null, ['PUT' => 0, 'GET' => 1, 'HEAD' => 2], null, false, false, null],
],
];
}
}

View File

@@ -14,29 +14,29 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
public function __construct(RequestContext $context)
{
$this->context = $context;
$this->staticRoutes = array(
'/a/11' => array(array(array('_route' => 'a_first'), null, null, null, false, false, null)),
'/a/22' => array(array(array('_route' => 'a_second'), null, null, null, false, false, null)),
'/a/333' => array(array(array('_route' => 'a_third'), null, null, null, false, false, null)),
'/a/44' => array(array(array('_route' => 'a_fourth'), null, null, null, true, false, null)),
'/a/55' => array(array(array('_route' => 'a_fifth'), null, null, null, true, false, null)),
'/a/66' => array(array(array('_route' => 'a_sixth'), null, null, null, true, false, null)),
'/nested/group/a' => array(array(array('_route' => 'nested_a'), null, null, null, true, false, null)),
'/nested/group/b' => array(array(array('_route' => 'nested_b'), null, null, null, true, false, null)),
'/nested/group/c' => array(array(array('_route' => 'nested_c'), null, null, null, true, false, null)),
'/slashed/group' => array(array(array('_route' => 'slashed_a'), null, null, null, true, false, null)),
'/slashed/group/b' => array(array(array('_route' => 'slashed_b'), null, null, null, true, false, null)),
'/slashed/group/c' => array(array(array('_route' => 'slashed_c'), null, null, null, true, false, null)),
);
$this->regexpList = array(
$this->staticRoutes = [
'/a/11' => [[['_route' => 'a_first'], null, null, null, false, false, null]],
'/a/22' => [[['_route' => 'a_second'], null, null, null, false, false, null]],
'/a/333' => [[['_route' => 'a_third'], null, null, null, false, false, null]],
'/a/44' => [[['_route' => 'a_fourth'], null, null, null, true, false, null]],
'/a/55' => [[['_route' => 'a_fifth'], null, null, null, true, false, null]],
'/a/66' => [[['_route' => 'a_sixth'], null, null, null, true, false, null]],
'/nested/group/a' => [[['_route' => 'nested_a'], null, null, null, true, false, null]],
'/nested/group/b' => [[['_route' => 'nested_b'], null, null, null, true, false, null]],
'/nested/group/c' => [[['_route' => 'nested_c'], null, null, null, true, false, null]],
'/slashed/group' => [[['_route' => 'slashed_a'], null, null, null, true, false, null]],
'/slashed/group/b' => [[['_route' => 'slashed_b'], null, null, null, true, false, null]],
'/slashed/group/c' => [[['_route' => 'slashed_c'], null, null, null, true, false, null]],
];
$this->regexpList = [
0 => '{^(?'
.'|/([^/]++)(*:16)'
.'|/nested/([^/]++)(*:39)'
.')/?$}sD',
);
$this->dynamicRoutes = array(
16 => array(array(array('_route' => 'a_wildcard'), array('param'), null, null, false, true, null)),
39 => array(array(array('_route' => 'nested_wildcard'), array('param'), null, null, false, true, null)),
);
];
$this->dynamicRoutes = [
16 => [[['_route' => 'a_wildcard'], ['param'], null, null, false, true, null]],
39 => [[['_route' => 'nested_wildcard'], ['param'], null, null, false, true, null]],
];
}
}

View File

@@ -14,17 +14,17 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
public function __construct(RequestContext $context)
{
$this->context = $context;
$this->staticRoutes = array(
'/trailing/simple/no-methods' => array(array(array('_route' => 'simple_trailing_slash_no_methods'), null, null, null, true, false, null)),
'/trailing/simple/get-method' => array(array(array('_route' => 'simple_trailing_slash_GET_method'), null, array('GET' => 0), null, true, false, null)),
'/trailing/simple/head-method' => array(array(array('_route' => 'simple_trailing_slash_HEAD_method'), null, array('HEAD' => 0), null, true, false, null)),
'/trailing/simple/post-method' => array(array(array('_route' => 'simple_trailing_slash_POST_method'), null, array('POST' => 0), null, true, false, null)),
'/not-trailing/simple/no-methods' => array(array(array('_route' => 'simple_not_trailing_slash_no_methods'), null, null, null, false, false, null)),
'/not-trailing/simple/get-method' => array(array(array('_route' => 'simple_not_trailing_slash_GET_method'), null, array('GET' => 0), null, false, false, null)),
'/not-trailing/simple/head-method' => array(array(array('_route' => 'simple_not_trailing_slash_HEAD_method'), null, array('HEAD' => 0), null, false, false, null)),
'/not-trailing/simple/post-method' => array(array(array('_route' => 'simple_not_trailing_slash_POST_method'), null, array('POST' => 0), null, false, false, null)),
);
$this->regexpList = array(
$this->staticRoutes = [
'/trailing/simple/no-methods' => [[['_route' => 'simple_trailing_slash_no_methods'], null, null, null, true, false, null]],
'/trailing/simple/get-method' => [[['_route' => 'simple_trailing_slash_GET_method'], null, ['GET' => 0], null, true, false, null]],
'/trailing/simple/head-method' => [[['_route' => 'simple_trailing_slash_HEAD_method'], null, ['HEAD' => 0], null, true, false, null]],
'/trailing/simple/post-method' => [[['_route' => 'simple_trailing_slash_POST_method'], null, ['POST' => 0], null, true, false, null]],
'/not-trailing/simple/no-methods' => [[['_route' => 'simple_not_trailing_slash_no_methods'], null, null, null, false, false, null]],
'/not-trailing/simple/get-method' => [[['_route' => 'simple_not_trailing_slash_GET_method'], null, ['GET' => 0], null, false, false, null]],
'/not-trailing/simple/head-method' => [[['_route' => 'simple_not_trailing_slash_HEAD_method'], null, ['HEAD' => 0], null, false, false, null]],
'/not-trailing/simple/post-method' => [[['_route' => 'simple_not_trailing_slash_POST_method'], null, ['POST' => 0], null, false, false, null]],
];
$this->regexpList = [
0 => '{^(?'
.'|/trailing/regex/(?'
.'|no\\-methods/([^/]++)(*:46)'
@@ -39,16 +39,16 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
.'|post\\-method/([^/]++)(*:269)'
.')'
.')/?$}sD',
);
$this->dynamicRoutes = array(
46 => array(array(array('_route' => 'regex_trailing_slash_no_methods'), array('param'), null, null, true, true, null)),
73 => array(array(array('_route' => 'regex_trailing_slash_GET_method'), array('param'), array('GET' => 0), null, true, true, null)),
101 => array(array(array('_route' => 'regex_trailing_slash_HEAD_method'), array('param'), array('HEAD' => 0), null, true, true, null)),
130 => array(array(array('_route' => 'regex_trailing_slash_POST_method'), array('param'), array('POST' => 0), null, true, true, null)),
183 => array(array(array('_route' => 'regex_not_trailing_slash_no_methods'), array('param'), null, null, false, true, null)),
211 => array(array(array('_route' => 'regex_not_trailing_slash_GET_method'), array('param'), array('GET' => 0), null, false, true, null)),
240 => array(array(array('_route' => 'regex_not_trailing_slash_HEAD_method'), array('param'), array('HEAD' => 0), null, false, true, null)),
269 => array(array(array('_route' => 'regex_not_trailing_slash_POST_method'), array('param'), array('POST' => 0), null, false, true, null)),
);
];
$this->dynamicRoutes = [
46 => [[['_route' => 'regex_trailing_slash_no_methods'], ['param'], null, null, true, true, null]],
73 => [[['_route' => 'regex_trailing_slash_GET_method'], ['param'], ['GET' => 0], null, true, true, null]],
101 => [[['_route' => 'regex_trailing_slash_HEAD_method'], ['param'], ['HEAD' => 0], null, true, true, null]],
130 => [[['_route' => 'regex_trailing_slash_POST_method'], ['param'], ['POST' => 0], null, true, true, null]],
183 => [[['_route' => 'regex_not_trailing_slash_no_methods'], ['param'], null, null, false, true, null]],
211 => [[['_route' => 'regex_not_trailing_slash_GET_method'], ['param'], ['GET' => 0], null, false, true, null]],
240 => [[['_route' => 'regex_not_trailing_slash_HEAD_method'], ['param'], ['HEAD' => 0], null, false, true, null]],
269 => [[['_route' => 'regex_not_trailing_slash_POST_method'], ['param'], ['POST' => 0], null, false, true, null]],
];
}
}

View File

@@ -14,17 +14,17 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
public function __construct(RequestContext $context)
{
$this->context = $context;
$this->staticRoutes = array(
'/trailing/simple/no-methods' => array(array(array('_route' => 'simple_trailing_slash_no_methods'), null, null, null, true, false, null)),
'/trailing/simple/get-method' => array(array(array('_route' => 'simple_trailing_slash_GET_method'), null, array('GET' => 0), null, true, false, null)),
'/trailing/simple/head-method' => array(array(array('_route' => 'simple_trailing_slash_HEAD_method'), null, array('HEAD' => 0), null, true, false, null)),
'/trailing/simple/post-method' => array(array(array('_route' => 'simple_trailing_slash_POST_method'), null, array('POST' => 0), null, true, false, null)),
'/not-trailing/simple/no-methods' => array(array(array('_route' => 'simple_not_trailing_slash_no_methods'), null, null, null, false, false, null)),
'/not-trailing/simple/get-method' => array(array(array('_route' => 'simple_not_trailing_slash_GET_method'), null, array('GET' => 0), null, false, false, null)),
'/not-trailing/simple/head-method' => array(array(array('_route' => 'simple_not_trailing_slash_HEAD_method'), null, array('HEAD' => 0), null, false, false, null)),
'/not-trailing/simple/post-method' => array(array(array('_route' => 'simple_not_trailing_slash_POST_method'), null, array('POST' => 0), null, false, false, null)),
);
$this->regexpList = array(
$this->staticRoutes = [
'/trailing/simple/no-methods' => [[['_route' => 'simple_trailing_slash_no_methods'], null, null, null, true, false, null]],
'/trailing/simple/get-method' => [[['_route' => 'simple_trailing_slash_GET_method'], null, ['GET' => 0], null, true, false, null]],
'/trailing/simple/head-method' => [[['_route' => 'simple_trailing_slash_HEAD_method'], null, ['HEAD' => 0], null, true, false, null]],
'/trailing/simple/post-method' => [[['_route' => 'simple_trailing_slash_POST_method'], null, ['POST' => 0], null, true, false, null]],
'/not-trailing/simple/no-methods' => [[['_route' => 'simple_not_trailing_slash_no_methods'], null, null, null, false, false, null]],
'/not-trailing/simple/get-method' => [[['_route' => 'simple_not_trailing_slash_GET_method'], null, ['GET' => 0], null, false, false, null]],
'/not-trailing/simple/head-method' => [[['_route' => 'simple_not_trailing_slash_HEAD_method'], null, ['HEAD' => 0], null, false, false, null]],
'/not-trailing/simple/post-method' => [[['_route' => 'simple_not_trailing_slash_POST_method'], null, ['POST' => 0], null, false, false, null]],
];
$this->regexpList = [
0 => '{^(?'
.'|/trailing/regex/(?'
.'|no\\-methods/([^/]++)(*:46)'
@@ -39,16 +39,16 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Tests\Fixtures\Redirec
.'|post\\-method/([^/]++)(*:269)'
.')'
.')/?$}sD',
);
$this->dynamicRoutes = array(
46 => array(array(array('_route' => 'regex_trailing_slash_no_methods'), array('param'), null, null, true, true, null)),
73 => array(array(array('_route' => 'regex_trailing_slash_GET_method'), array('param'), array('GET' => 0), null, true, true, null)),
101 => array(array(array('_route' => 'regex_trailing_slash_HEAD_method'), array('param'), array('HEAD' => 0), null, true, true, null)),
130 => array(array(array('_route' => 'regex_trailing_slash_POST_method'), array('param'), array('POST' => 0), null, true, true, null)),
183 => array(array(array('_route' => 'regex_not_trailing_slash_no_methods'), array('param'), null, null, false, true, null)),
211 => array(array(array('_route' => 'regex_not_trailing_slash_GET_method'), array('param'), array('GET' => 0), null, false, true, null)),
240 => array(array(array('_route' => 'regex_not_trailing_slash_HEAD_method'), array('param'), array('HEAD' => 0), null, false, true, null)),
269 => array(array(array('_route' => 'regex_not_trailing_slash_POST_method'), array('param'), array('POST' => 0), null, false, true, null)),
);
];
$this->dynamicRoutes = [
46 => [[['_route' => 'regex_trailing_slash_no_methods'], ['param'], null, null, true, true, null]],
73 => [[['_route' => 'regex_trailing_slash_GET_method'], ['param'], ['GET' => 0], null, true, true, null]],
101 => [[['_route' => 'regex_trailing_slash_HEAD_method'], ['param'], ['HEAD' => 0], null, true, true, null]],
130 => [[['_route' => 'regex_trailing_slash_POST_method'], ['param'], ['POST' => 0], null, true, true, null]],
183 => [[['_route' => 'regex_not_trailing_slash_no_methods'], ['param'], null, null, false, true, null]],
211 => [[['_route' => 'regex_not_trailing_slash_GET_method'], ['param'], ['GET' => 0], null, false, true, null]],
240 => [[['_route' => 'regex_not_trailing_slash_HEAD_method'], ['param'], ['HEAD' => 0], null, false, true, null]],
269 => [[['_route' => 'regex_not_trailing_slash_POST_method'], ['param'], ['POST' => 0], null, false, true, null]],
];
}
}

View File

@@ -14,7 +14,7 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
public function __construct(RequestContext $context)
{
$this->context = $context;
$this->regexpList = array(
$this->regexpList = [
0 => '{^(?'
.'|/(a)(*:11)'
.')/?$}sD',
@@ -24,11 +24,11 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
22 => '{^(?'
.'|/(.)(*:33)'
.')/?$}sD',
);
$this->dynamicRoutes = array(
11 => array(array(array('_route' => 'a'), array('a'), null, null, false, true, null)),
22 => array(array(array('_route' => 'b'), array('a'), null, null, false, true, null)),
33 => array(array(array('_route' => 'c'), array('a'), null, null, false, true, null)),
);
];
$this->dynamicRoutes = [
11 => [[['_route' => 'a'], ['a'], null, null, false, true, null]],
22 => [[['_route' => 'b'], ['a'], null, null, false, true, null]],
33 => [[['_route' => 'c'], ['a'], null, null, false, true, null]],
];
}
}

View File

@@ -15,12 +15,12 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
{
$this->context = $context;
$this->matchHost = true;
$this->staticRoutes = array(
'/' => array(
array(array('_route' => 'a'), '#^(?P<d>[^\\.]++)\\.e\\.c\\.b\\.a$#sDi', null, null, false, false, null),
array(array('_route' => 'c'), '#^(?P<e>[^\\.]++)\\.e\\.c\\.b\\.a$#sDi', null, null, false, false, null),
array(array('_route' => 'b'), 'd.c.b.a', null, null, false, false, null),
),
);
$this->staticRoutes = [
'/' => [
[['_route' => 'a'], '#^(?P<d>[^\\.]++)\\.e\\.c\\.b\\.a$#sDi', null, null, false, false, null],
[['_route' => 'c'], '#^(?P<e>[^\\.]++)\\.e\\.c\\.b\\.a$#sDi', null, null, false, false, null],
[['_route' => 'b'], 'd.c.b.a', null, null, false, false, null],
],
];
}
}

View File

@@ -2,7 +2,7 @@
<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">
https://symfony.com/schema/routing/routing-1.0.xsd">
<route id="bar_route" path="/bar" controller="AppBundle:Bar:view" />
</routes>

View File

@@ -2,7 +2,7 @@
<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">
https://symfony.com/schema/routing/routing-1.0.xsd">
<route id="baz_route" path="/baz" controller="AppBundle:Baz:view" />
</routes>

View File

@@ -2,7 +2,7 @@
<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">
https://symfony.com/schema/routing/routing-1.0.xsd">
<import resource="ba?.xml" />
</routes>

View File

@@ -2,7 +2,7 @@
<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">
https://symfony.com/schema/routing/routing-1.0.xsd">
<import resource="b?r.xml" />
</routes>

View File

@@ -6,7 +6,7 @@ return function (RoutingConfigurator $routes) {
$collection = $routes->collection();
$collection->add('bar_route', '/bar')
->defaults(array('_controller' => 'AppBundle:Bar:view'));
->defaults(['_controller' => 'AppBundle:Bar:view']);
return $collection;
};

View File

@@ -6,7 +6,7 @@ return function (RoutingConfigurator $routes) {
$collection = $routes->collection();
$collection->add('baz_route', '/baz')
->defaults(array('_controller' => 'AppBundle:Baz:view'));
->defaults(['_controller' => 'AppBundle:Baz:view']);
return $collection;
};

View File

@@ -2,7 +2,7 @@
<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">
https://symfony.com/schema/routing/routing-1.0.xsd">
<import resource="../controller/routing.xml" />
<import resource="../controller/routing.xml" prefix="/api" name-prefix="api_" />

View File

@@ -2,7 +2,7 @@
<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">
https://symfony.com/schema/routing/routing-1.0.xsd">
<import resource="../controller/routing.xml" prefix="/slash" name-prefix="a_" />
<import resource="../controller/routing.xml" prefix="/no-slash" name-prefix="b_" trailing-slash-on-root="false" />

View File

@@ -2,7 +2,7 @@
<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">
https://symfony.com/schema/routing/routing-1.0.xsd">
<route id="blog" path="/blog">
<default key="_controller">

View File

@@ -2,7 +2,7 @@
<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">
https://symfony.com/schema/routing/routing-1.0.xsd">
<route id="blog" path="/blog">
<default key="_controller">

View File

@@ -2,7 +2,7 @@
<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">
https://symfony.com/schema/routing/routing-1.0.xsd">
<route id="blog" path="/blog">
<default key="_controller">

View File

@@ -2,7 +2,7 @@
<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">
https://symfony.com/schema/routing/routing-1.0.xsd">
<route id="blog" path="/blog">
<default key="_controller">

View File

@@ -2,7 +2,7 @@
<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">
xsi:schemaLocation="http://symfony.com/schema/routing https://symfony.com/schema/routing/routing-1.0.xsd">
<route id="localized">
<default key="_controller">MyBundle:Blog:show</default>

View File

@@ -2,7 +2,7 @@
<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">
https://symfony.com/schema/routing/routing-1.0.xsd">
<route id="imported" path="/suffix">
<default key="_controller">MyBundle:Blog:show</default>
</route>

View File

@@ -2,7 +2,7 @@
<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">
https://symfony.com/schema/routing/routing-1.0.xsd">
<route id="imported">
<default key="_controller">MyBundle:Blog:show</default>
<path locale="en">/suffix</path>

View File

@@ -2,7 +2,7 @@
<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">
https://symfony.com/schema/routing/routing-1.0.xsd">
<import resource="./imported-with-locale-but-not-localized.xml">
<prefix locale="fr">/le-prefix</prefix>
<prefix locale="en">/the-prefix</prefix>

View File

@@ -2,7 +2,7 @@
<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">
https://symfony.com/schema/routing/routing-1.0.xsd">
<import resource="./imported-with-locale.xml">
<prefix locale="fr">/le-prefix</prefix>
<prefix locale="en">/the-prefix</prefix>

View File

@@ -2,7 +2,7 @@
<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">
https://symfony.com/schema/routing/routing-1.0.xsd">
<route id="blog" path="/blog">
<default key="_controller">

View File

@@ -2,7 +2,7 @@
<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">
https://symfony.com/schema/routing/routing-1.0.xsd">
<route id="blog" path="/blog">
<default key="_controller">

View File

@@ -2,7 +2,7 @@
<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">
https://symfony.com/schema/routing/routing-1.0.xsd">
<route id="blog" path="/blog">
<default key="_controller">

View File

@@ -2,7 +2,7 @@
<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">
https://symfony.com/schema/routing/routing-1.0.xsd">
<route id="blog" path="/blog">
<default key="_controller">

View File

@@ -2,7 +2,7 @@
<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">
xsi:schemaLocation="http://symfony.com/schema/routing https://symfony.com/schema/routing/routing-1.0.xsd">
<route path="/test"></route>
</routes>

View File

@@ -2,7 +2,7 @@
<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">
xsi:schemaLocation="http://symfony.com/schema/routing https://symfony.com/schema/routing/routing-1.0.xsd">
<route id="myroute"></route>
</routes>

View File

@@ -2,7 +2,7 @@
<r:routes xmlns:r="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">
xsi:schemaLocation="http://symfony.com/schema/routing https://symfony.com/schema/routing/routing-1.0.xsd">
<r:route id="blog_show" path="/blog/{slug}" host="{_locale}.example.com">
<r:default key="_controller">MyBundle:Blog:show</r:default>

View File

@@ -2,7 +2,7 @@
<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">
xsi:schemaLocation="http://symfony.com/schema/routing https://symfony.com/schema/routing/routing-1.0.xsd">
<route id="blog_show" path="/blog/{slug}">
<default key="_controller">MyBundle:Blog:show</default>

View File

@@ -2,7 +2,7 @@
<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">
xsi:schemaLocation="http://symfony.com/schema/routing https://symfony.com/schema/routing/routing-1.0.xsd">
<foo>bar</foo>
</routes>

View File

@@ -2,7 +2,7 @@
<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">
xsi:schemaLocation="http://symfony.com/schema/routing https://symfony.com/schema/routing/routing-1.0.xsd">
<route id="blog_show" path="/blog/{slug}">
<default key="_controller">MyBundle:Blog:show</default>

View File

@@ -1,7 +1,7 @@
<?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">
xsi:schemaLocation="http://symfony.com/schema/routing https://symfony.com/schema/routing/routing-1.0.xsd">
<route id="blog_show" path="/blog/{slug}">
<default key="foo" xsi:nil="true" />

View File

@@ -7,13 +7,13 @@ return function (RoutingConfigurator $routes) {
->collection()
->add('foo', '/foo')
->condition('abc')
->options(array('utf8' => true))
->options(['utf8' => true])
->add('buz', 'zub')
->controller('foo:act');
$routes->import('php_dsl_sub.php')
->prefix('/sub')
->requirements(array('id' => '\d+'));
->requirements(['id' => '\d+']);
$routes->import('php_dsl_sub.php')
->namePrefix('z_')
@@ -23,7 +23,7 @@ return function (RoutingConfigurator $routes) {
->prefix('/bus', false);
$routes->add('ouf', '/ouf')
->schemes(array('https'))
->methods(array('GET'))
->defaults(array('id' => 0));
->schemes(['https'])
->methods(['GET'])
->defaults(['id' => 0]);
};

View File

@@ -5,13 +5,13 @@ namespace Symfony\Component\Routing\Loader\Configurator;
return function (RoutingConfigurator $routes) {
$routes
->collection()
->prefix(array('en' => '/glish'))
->prefix(['en' => '/glish'])
->add('foo', '/foo')
->add('bar', array('en' => '/bar'));
->add('bar', ['en' => '/bar']);
$routes
->add('baz', array('en' => '/baz'));
->add('baz', ['en' => '/baz']);
$routes->import('php_dsl_sub_i18n.php')
->prefix(array('fr' => '/ench'));
->prefix(['fr' => '/ench']);
};

View File

@@ -6,6 +6,6 @@ return function (RoutingConfigurator $routes) {
$add = $routes->collection('c_')
->prefix('pub');
$add('foo', array('fr' => '/foo'));
$add('bar', array('fr' => '/bar'));
$add('foo', ['fr' => '/foo']);
$add('bar', ['fr' => '/bar']);
};

View File

@@ -9,13 +9,13 @@ return new class() {
->collection()
->add('foo', '/foo')
->condition('abc')
->options(array('utf8' => true))
->options(['utf8' => true])
->add('buz', 'zub')
->controller('foo:act');
$routes->import('php_dsl_sub.php')
->prefix('/sub')
->requirements(array('id' => '\d+'));
->requirements(['id' => '\d+']);
$routes->import('php_dsl_sub.php')
->namePrefix('z_')
@@ -25,8 +25,8 @@ return new class() {
->prefix('/bus', false);
$routes->add('ouf', '/ouf')
->schemes(array('https'))
->methods(array('GET'))
->defaults(array('id' => 0));
->schemes(['https'])
->methods(['GET'])
->defaults(['id' => 0]);
}
};

View File

@@ -2,7 +2,7 @@
<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">
https://symfony.com/schema/routing/routing-1.0.xsd">
<route id="blog" path="/blog">
<default key="_controller">

View File

@@ -6,12 +6,12 @@ use Symfony\Component\Routing\RouteCollection;
$collection = new RouteCollection();
$collection->add('blog_show', new Route(
'/blog/{slug}',
array('_controller' => 'MyBlogBundle:Blog:show'),
array('locale' => '\w+'),
array('compiler_class' => 'RouteCompiler'),
['_controller' => 'MyBlogBundle:Blog:show'],
['locale' => '\w+'],
['compiler_class' => 'RouteCompiler'],
'{locale}.example.com',
array('https'),
array('GET', 'POST', 'put', 'OpTiOnS'),
['https'],
['GET', 'POST', 'put', 'OpTiOnS'],
'context.getMethod() == "GET"'
));

View File

@@ -2,7 +2,7 @@
<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">
xsi:schemaLocation="http://symfony.com/schema/routing https://symfony.com/schema/routing/routing-1.0.xsd">
<route id="blog_show" path="/blog/{slug}" host="{locale}.example.com" methods="GET|POST put,OpTiOnS" schemes="hTTps">
<default key="_controller">MyBundle:Blog:show</default>

View File

@@ -3,15 +3,15 @@
/** @var $loader \Symfony\Component\Routing\Loader\PhpFileLoader */
/** @var \Symfony\Component\Routing\RouteCollection $collection */
$collection = $loader->import('validpattern.php');
$collection->addDefaults(array(
$collection->addDefaults([
'foo' => 123,
));
$collection->addRequirements(array(
]);
$collection->addRequirements([
'foo' => '\d+',
));
$collection->addOptions(array(
]);
$collection->addOptions([
'foo' => 'bar',
));
]);
$collection->setCondition('context.getMethod() == "POST"');
$collection->addPrefix('/prefix');

View File

@@ -2,7 +2,7 @@
<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">
xsi:schemaLocation="http://symfony.com/schema/routing https://symfony.com/schema/routing/routing-1.0.xsd">
<import resource="validpattern.xml" prefix="/{foo}" host="">
<default key="foo">123</default>

View File

@@ -73,10 +73,10 @@ class PhpGeneratorDumperTest extends TestCase
$projectUrlGenerator = new \ProjectUrlGenerator(new RequestContext('/app.php'));
$absoluteUrlWithParameter = $projectUrlGenerator->generate('Test', array('foo' => 'bar'), UrlGeneratorInterface::ABSOLUTE_URL);
$absoluteUrlWithoutParameter = $projectUrlGenerator->generate('Test2', array(), UrlGeneratorInterface::ABSOLUTE_URL);
$relativeUrlWithParameter = $projectUrlGenerator->generate('Test', array('foo' => 'bar'), UrlGeneratorInterface::ABSOLUTE_PATH);
$relativeUrlWithoutParameter = $projectUrlGenerator->generate('Test2', array(), UrlGeneratorInterface::ABSOLUTE_PATH);
$absoluteUrlWithParameter = $projectUrlGenerator->generate('Test', ['foo' => 'bar'], UrlGeneratorInterface::ABSOLUTE_URL);
$absoluteUrlWithoutParameter = $projectUrlGenerator->generate('Test2', [], UrlGeneratorInterface::ABSOLUTE_URL);
$relativeUrlWithParameter = $projectUrlGenerator->generate('Test', ['foo' => 'bar'], UrlGeneratorInterface::ABSOLUTE_PATH);
$relativeUrlWithoutParameter = $projectUrlGenerator->generate('Test2', [], UrlGeneratorInterface::ABSOLUTE_PATH);
$this->assertEquals('http://localhost/app.php/testing/bar', $absoluteUrlWithParameter);
$this->assertEquals('http://localhost/app.php/testing2', $absoluteUrlWithoutParameter);
@@ -90,9 +90,9 @@ class PhpGeneratorDumperTest extends TestCase
$this->routeCollection->add('test.en', (new Route('/testing/is/fun'))->setDefault('_locale', 'en')->setDefault('_canonical_route', 'test'));
$this->routeCollection->add('test.nl', (new Route('/testen/is/leuk'))->setDefault('_locale', 'nl')->setDefault('_canonical_route', 'test'));
$code = $this->generatorDumper->dump(array(
$code = $this->generatorDumper->dump([
'class' => 'SimpleLocalizedProjectUrlGenerator',
));
]);
file_put_contents($this->testTmpFilepath, $code);
include $this->testTmpFilepath;
@@ -100,7 +100,7 @@ class PhpGeneratorDumperTest extends TestCase
$projectUrlGenerator = new \SimpleLocalizedProjectUrlGenerator($context, null, 'en');
$urlWithDefaultLocale = $projectUrlGenerator->generate('test');
$urlWithSpecifiedLocale = $projectUrlGenerator->generate('test', array('_locale' => 'nl'));
$urlWithSpecifiedLocale = $projectUrlGenerator->generate('test', ['_locale' => 'nl']);
$context->setParameter('_locale', 'en');
$urlWithEnglishContext = $projectUrlGenerator->generate('test');
$context->setParameter('_locale', 'nl');
@@ -127,9 +127,9 @@ class PhpGeneratorDumperTest extends TestCase
{
$this->routeCollection->add('test.en', (new Route('/testing/is/fun'))->setDefault('_locale', 'en')->setDefault('_canonical_route', 'test'));
$code = $this->generatorDumper->dump(array(
$code = $this->generatorDumper->dump([
'class' => 'RouteNotFoundLocalizedProjectUrlGenerator',
));
]);
file_put_contents($this->testTmpFilepath, $code);
include $this->testTmpFilepath;
@@ -143,9 +143,9 @@ class PhpGeneratorDumperTest extends TestCase
$this->routeCollection->add('test.nl', (new Route('/testen/is/leuk'))->setDefault('_canonical_route', 'test'));
$this->routeCollection->add('test.fr', (new Route('/tester/est/amusant'))->setDefault('_canonical_route', 'test'));
$code = $this->generatorDumper->dump(array(
$code = $this->generatorDumper->dump([
'class' => 'FallbackLocaleLocalizedProjectUrlGenerator',
));
]);
file_put_contents($this->testTmpFilepath, $code);
include $this->testTmpFilepath;
@@ -156,7 +156,7 @@ class PhpGeneratorDumperTest extends TestCase
// test with context _locale
$this->assertEquals('/app.php/testing/is/fun', $projectUrlGenerator->generate('test'));
// test with parameters _locale
$this->assertEquals('/app.php/testen/is/leuk', $projectUrlGenerator->generate('test', array('_locale' => 'nl_BE')));
$this->assertEquals('/app.php/testen/is/leuk', $projectUrlGenerator->generate('test', ['_locale' => 'nl_BE']));
$projectUrlGenerator = new \FallbackLocaleLocalizedProjectUrlGenerator(new RequestContext('/app.php'), null, 'fr_CA');
// test with default locale
@@ -171,18 +171,18 @@ class PhpGeneratorDumperTest extends TestCase
}
$this->routeCollection->add('Test2', new Route('/testing2'));
file_put_contents($this->largeTestTmpFilepath, $this->generatorDumper->dump(array(
file_put_contents($this->largeTestTmpFilepath, $this->generatorDumper->dump([
'class' => 'ProjectLargeUrlGenerator',
)));
]));
$this->routeCollection = $this->generatorDumper = null;
include $this->largeTestTmpFilepath;
$projectUrlGenerator = new \ProjectLargeUrlGenerator(new RequestContext('/app.php'));
$absoluteUrlWithParameter = $projectUrlGenerator->generate('Test', array('foo' => 'bar'), UrlGeneratorInterface::ABSOLUTE_URL);
$absoluteUrlWithoutParameter = $projectUrlGenerator->generate('Test2', array(), UrlGeneratorInterface::ABSOLUTE_URL);
$relativeUrlWithParameter = $projectUrlGenerator->generate('Test', array('foo' => 'bar'), UrlGeneratorInterface::ABSOLUTE_PATH);
$relativeUrlWithoutParameter = $projectUrlGenerator->generate('Test2', array(), UrlGeneratorInterface::ABSOLUTE_PATH);
$absoluteUrlWithParameter = $projectUrlGenerator->generate('Test', ['foo' => 'bar'], UrlGeneratorInterface::ABSOLUTE_URL);
$absoluteUrlWithoutParameter = $projectUrlGenerator->generate('Test2', [], UrlGeneratorInterface::ABSOLUTE_URL);
$relativeUrlWithParameter = $projectUrlGenerator->generate('Test', ['foo' => 'bar'], UrlGeneratorInterface::ABSOLUTE_PATH);
$relativeUrlWithoutParameter = $projectUrlGenerator->generate('Test2', [], UrlGeneratorInterface::ABSOLUTE_PATH);
$this->assertEquals('http://localhost/app.php/testing/bar', $absoluteUrlWithParameter);
$this->assertEquals('http://localhost/app.php/testing2', $absoluteUrlWithoutParameter);
@@ -195,12 +195,12 @@ class PhpGeneratorDumperTest extends TestCase
*/
public function testDumpWithoutRoutes()
{
file_put_contents($this->testTmpFilepath, $this->generatorDumper->dump(array('class' => 'WithoutRoutesUrlGenerator')));
file_put_contents($this->testTmpFilepath, $this->generatorDumper->dump(['class' => 'WithoutRoutesUrlGenerator']));
include $this->testTmpFilepath;
$projectUrlGenerator = new \WithoutRoutesUrlGenerator(new RequestContext('/app.php'));
$projectUrlGenerator->generate('Test', array());
$projectUrlGenerator->generate('Test', []);
}
/**
@@ -210,45 +210,45 @@ class PhpGeneratorDumperTest extends TestCase
{
$this->routeCollection->add('Test', new Route('/test'));
file_put_contents($this->testTmpFilepath, $this->generatorDumper->dump(array('class' => 'NonExistingRoutesUrlGenerator')));
file_put_contents($this->testTmpFilepath, $this->generatorDumper->dump(['class' => 'NonExistingRoutesUrlGenerator']));
include $this->testTmpFilepath;
$projectUrlGenerator = new \NonExistingRoutesUrlGenerator(new RequestContext());
$url = $projectUrlGenerator->generate('NonExisting', array());
$url = $projectUrlGenerator->generate('NonExisting', []);
}
public function testDumpForRouteWithDefaults()
{
$this->routeCollection->add('Test', new Route('/testing/{foo}', array('foo' => 'bar')));
$this->routeCollection->add('Test', new Route('/testing/{foo}', ['foo' => 'bar']));
file_put_contents($this->testTmpFilepath, $this->generatorDumper->dump(array('class' => 'DefaultRoutesUrlGenerator')));
file_put_contents($this->testTmpFilepath, $this->generatorDumper->dump(['class' => 'DefaultRoutesUrlGenerator']));
include $this->testTmpFilepath;
$projectUrlGenerator = new \DefaultRoutesUrlGenerator(new RequestContext());
$url = $projectUrlGenerator->generate('Test', array());
$url = $projectUrlGenerator->generate('Test', []);
$this->assertEquals('/testing', $url);
}
public function testDumpWithSchemeRequirement()
{
$this->routeCollection->add('Test1', new Route('/testing', array(), array(), array(), '', array('ftp', 'https')));
$this->routeCollection->add('Test1', new Route('/testing', [], [], [], '', ['ftp', 'https']));
file_put_contents($this->testTmpFilepath, $this->generatorDumper->dump(array('class' => 'SchemeUrlGenerator')));
file_put_contents($this->testTmpFilepath, $this->generatorDumper->dump(['class' => 'SchemeUrlGenerator']));
include $this->testTmpFilepath;
$projectUrlGenerator = new \SchemeUrlGenerator(new RequestContext('/app.php'));
$absoluteUrl = $projectUrlGenerator->generate('Test1', array(), UrlGeneratorInterface::ABSOLUTE_URL);
$relativeUrl = $projectUrlGenerator->generate('Test1', array(), UrlGeneratorInterface::ABSOLUTE_PATH);
$absoluteUrl = $projectUrlGenerator->generate('Test1', [], UrlGeneratorInterface::ABSOLUTE_URL);
$relativeUrl = $projectUrlGenerator->generate('Test1', [], UrlGeneratorInterface::ABSOLUTE_PATH);
$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);
$absoluteUrl = $projectUrlGenerator->generate('Test1', [], UrlGeneratorInterface::ABSOLUTE_URL);
$relativeUrl = $projectUrlGenerator->generate('Test1', [], UrlGeneratorInterface::ABSOLUTE_PATH);
$this->assertEquals('https://localhost/app.php/testing', $absoluteUrl);
$this->assertEquals('/app.php/testing', $relativeUrl);

View File

@@ -23,7 +23,7 @@ class UrlGeneratorTest extends TestCase
public function testAbsoluteUrlWithPort80()
{
$routes = $this->getRoutes('test', new Route('/testing'));
$url = $this->getGenerator($routes)->generate('test', array(), UrlGeneratorInterface::ABSOLUTE_URL);
$url = $this->getGenerator($routes)->generate('test', [], UrlGeneratorInterface::ABSOLUTE_URL);
$this->assertEquals('http://localhost/app.php/testing', $url);
}
@@ -31,7 +31,7 @@ class UrlGeneratorTest extends TestCase
public function testAbsoluteSecureUrlWithPort443()
{
$routes = $this->getRoutes('test', new Route('/testing'));
$url = $this->getGenerator($routes, array('scheme' => 'https'))->generate('test', array(), UrlGeneratorInterface::ABSOLUTE_URL);
$url = $this->getGenerator($routes, ['scheme' => 'https'])->generate('test', [], UrlGeneratorInterface::ABSOLUTE_URL);
$this->assertEquals('https://localhost/app.php/testing', $url);
}
@@ -39,7 +39,7 @@ class UrlGeneratorTest extends TestCase
public function testAbsoluteUrlWithNonStandardPort()
{
$routes = $this->getRoutes('test', new Route('/testing'));
$url = $this->getGenerator($routes, array('httpPort' => 8080))->generate('test', array(), UrlGeneratorInterface::ABSOLUTE_URL);
$url = $this->getGenerator($routes, ['httpPort' => 8080])->generate('test', [], UrlGeneratorInterface::ABSOLUTE_URL);
$this->assertEquals('http://localhost:8080/app.php/testing', $url);
}
@@ -47,7 +47,7 @@ class UrlGeneratorTest extends TestCase
public function testAbsoluteSecureUrlWithNonStandardPort()
{
$routes = $this->getRoutes('test', new Route('/testing'));
$url = $this->getGenerator($routes, array('httpsPort' => 8080, 'scheme' => 'https'))->generate('test', array(), UrlGeneratorInterface::ABSOLUTE_URL);
$url = $this->getGenerator($routes, ['httpsPort' => 8080, 'scheme' => 'https'])->generate('test', [], UrlGeneratorInterface::ABSOLUTE_URL);
$this->assertEquals('https://localhost:8080/app.php/testing', $url);
}
@@ -55,7 +55,7 @@ class UrlGeneratorTest extends TestCase
public function testRelativeUrlWithoutParameters()
{
$routes = $this->getRoutes('test', new Route('/testing'));
$url = $this->getGenerator($routes)->generate('test', array(), UrlGeneratorInterface::ABSOLUTE_PATH);
$url = $this->getGenerator($routes)->generate('test', [], UrlGeneratorInterface::ABSOLUTE_PATH);
$this->assertEquals('/app.php/testing', $url);
}
@@ -63,15 +63,15 @@ class UrlGeneratorTest extends TestCase
public function testRelativeUrlWithParameter()
{
$routes = $this->getRoutes('test', new Route('/testing/{foo}'));
$url = $this->getGenerator($routes)->generate('test', array('foo' => 'bar'), UrlGeneratorInterface::ABSOLUTE_PATH);
$url = $this->getGenerator($routes)->generate('test', ['foo' => 'bar'], UrlGeneratorInterface::ABSOLUTE_PATH);
$this->assertEquals('/app.php/testing/bar', $url);
}
public function testRelativeUrlWithNullParameter()
{
$routes = $this->getRoutes('test', new Route('/testing.{format}', array('format' => null)));
$url = $this->getGenerator($routes)->generate('test', array(), UrlGeneratorInterface::ABSOLUTE_PATH);
$routes = $this->getRoutes('test', new Route('/testing.{format}', ['format' => null]));
$url = $this->getGenerator($routes)->generate('test', [], UrlGeneratorInterface::ABSOLUTE_PATH);
$this->assertEquals('/app.php/testing', $url);
}
@@ -81,31 +81,31 @@ class UrlGeneratorTest extends TestCase
*/
public function testRelativeUrlWithNullParameterButNotOptional()
{
$routes = $this->getRoutes('test', new Route('/testing/{foo}/bar', array('foo' => null)));
$routes = $this->getRoutes('test', new Route('/testing/{foo}/bar', ['foo' => null]));
// This must raise an exception because the default requirement for "foo" is "[^/]+" which is not met with these params.
// Generating path "/testing//bar" would be wrong as matching this route would fail.
$this->getGenerator($routes)->generate('test', array(), UrlGeneratorInterface::ABSOLUTE_PATH);
$this->getGenerator($routes)->generate('test', [], UrlGeneratorInterface::ABSOLUTE_PATH);
}
public function testRelativeUrlWithOptionalZeroParameter()
{
$routes = $this->getRoutes('test', new Route('/testing/{page}'));
$url = $this->getGenerator($routes)->generate('test', array('page' => 0), UrlGeneratorInterface::ABSOLUTE_PATH);
$url = $this->getGenerator($routes)->generate('test', ['page' => 0], UrlGeneratorInterface::ABSOLUTE_PATH);
$this->assertEquals('/app.php/testing/0', $url);
}
public function testNotPassedOptionalParameterInBetween()
{
$routes = $this->getRoutes('test', new Route('/{slug}/{page}', array('slug' => 'index', 'page' => 0)));
$this->assertSame('/app.php/index/1', $this->getGenerator($routes)->generate('test', array('page' => 1)));
$routes = $this->getRoutes('test', new Route('/{slug}/{page}', ['slug' => 'index', 'page' => 0]));
$this->assertSame('/app.php/index/1', $this->getGenerator($routes)->generate('test', ['page' => 1]));
$this->assertSame('/app.php/', $this->getGenerator($routes)->generate('test'));
}
public function testRelativeUrlWithExtraParameters()
{
$routes = $this->getRoutes('test', new Route('/testing'));
$url = $this->getGenerator($routes)->generate('test', array('foo' => 'bar'), UrlGeneratorInterface::ABSOLUTE_PATH);
$url = $this->getGenerator($routes)->generate('test', ['foo' => 'bar'], UrlGeneratorInterface::ABSOLUTE_PATH);
$this->assertEquals('/app.php/testing?foo=bar', $url);
}
@@ -113,7 +113,7 @@ class UrlGeneratorTest extends TestCase
public function testAbsoluteUrlWithExtraParameters()
{
$routes = $this->getRoutes('test', new Route('/testing'));
$url = $this->getGenerator($routes)->generate('test', array('foo' => 'bar'), UrlGeneratorInterface::ABSOLUTE_URL);
$url = $this->getGenerator($routes)->generate('test', ['foo' => 'bar'], UrlGeneratorInterface::ABSOLUTE_URL);
$this->assertEquals('http://localhost/app.php/testing?foo=bar', $url);
}
@@ -121,7 +121,7 @@ class UrlGeneratorTest extends TestCase
public function testUrlWithNullExtraParameters()
{
$routes = $this->getRoutes('test', new Route('/testing'));
$url = $this->getGenerator($routes)->generate('test', array('foo' => null), UrlGeneratorInterface::ABSOLUTE_URL);
$url = $this->getGenerator($routes)->generate('test', ['foo' => null], UrlGeneratorInterface::ABSOLUTE_URL);
$this->assertEquals('http://localhost/app.php/testing', $url);
}
@@ -133,7 +133,7 @@ class UrlGeneratorTest extends TestCase
$context = new RequestContext('/app.php');
$context->setParameter('bar', 'bar');
$generator->setContext($context);
$url = $generator->generate('test', array('foo' => 'bar'));
$url = $generator->generate('test', ['foo' => 'bar']);
$this->assertEquals('/app.php/testing?foo=bar', $url);
}
@@ -145,30 +145,129 @@ class UrlGeneratorTest extends TestCase
$context = new RequestContext('/app.php');
$context->setParameter('foo', 'bar');
$generator->setContext($context);
$url = $generator->generate('test', array());
$url = $generator->generate('test', []);
$this->assertEquals('/app.php/testing/bar', $url);
}
public function testGlobalParameterHasHigherPriorityThanDefault()
{
$routes = $this->getRoutes('test', new Route('/{_locale}', array('_locale' => 'en')));
$routes = $this->getRoutes('test', new Route('/{_locale}', ['_locale' => 'en']));
$generator = $this->getGenerator($routes);
$context = new RequestContext('/app.php');
$context->setParameter('_locale', 'de');
$generator->setContext($context);
$url = $generator->generate('test', array());
$url = $generator->generate('test', []);
$this->assertSame('/app.php/de', $url);
}
public function testGenerateWithDefaultLocale()
{
$routes = new RouteCollection();
$route = new Route('');
$name = 'test';
foreach (['hr' => '/foo', 'en' => '/bar'] as $locale => $path) {
$localizedRoute = clone $route;
$localizedRoute->setDefault('_locale', $locale);
$localizedRoute->setDefault('_canonical_route', $name);
$localizedRoute->setPath($path);
$routes->add($name.'.'.$locale, $localizedRoute);
}
$generator = $this->getGenerator($routes, [], null, 'hr');
$this->assertSame(
'http://localhost/app.php/foo',
$generator->generate($name, [], UrlGeneratorInterface::ABSOLUTE_URL)
);
}
public function testGenerateWithOverriddenParameterLocale()
{
$routes = new RouteCollection();
$route = new Route('');
$name = 'test';
foreach (['hr' => '/foo', 'en' => '/bar'] as $locale => $path) {
$localizedRoute = clone $route;
$localizedRoute->setDefault('_locale', $locale);
$localizedRoute->setDefault('_canonical_route', $name);
$localizedRoute->setPath($path);
$routes->add($name.'.'.$locale, $localizedRoute);
}
$generator = $this->getGenerator($routes, [], null, 'hr');
$this->assertSame(
'http://localhost/app.php/bar',
$generator->generate($name, ['_locale' => 'en'], UrlGeneratorInterface::ABSOLUTE_URL)
);
}
public function testGenerateWithOverriddenParameterLocaleFromRequestContext()
{
$routes = new RouteCollection();
$route = new Route('');
$name = 'test';
foreach (['hr' => '/foo', 'en' => '/bar'] as $locale => $path) {
$localizedRoute = clone $route;
$localizedRoute->setDefault('_locale', $locale);
$localizedRoute->setDefault('_canonical_route', $name);
$localizedRoute->setPath($path);
$routes->add($name.'.'.$locale, $localizedRoute);
}
$generator = $this->getGenerator($routes, [], null, 'hr');
$context = new RequestContext('/app.php');
$context->setParameter('_locale', 'en');
$generator->setContext($context);
$this->assertSame(
'http://localhost/app.php/bar',
$generator->generate($name, [], UrlGeneratorInterface::ABSOLUTE_URL)
);
}
/**
* @expectedException \Symfony\Component\Routing\Exception\RouteNotFoundException
*/
public function testGenerateWithoutRoutes()
{
$routes = $this->getRoutes('foo', new Route('/testing/{foo}'));
$this->getGenerator($routes)->generate('test', array(), UrlGeneratorInterface::ABSOLUTE_URL);
$this->getGenerator($routes)->generate('test', [], UrlGeneratorInterface::ABSOLUTE_URL);
}
/**
* @expectedException \Symfony\Component\Routing\Exception\RouteNotFoundException
*/
public function testGenerateWithInvalidLocale()
{
$routes = new RouteCollection();
$route = new Route('');
$name = 'test';
foreach (['hr' => '/foo', 'en' => '/bar'] as $locale => $path) {
$localizedRoute = clone $route;
$localizedRoute->setDefault('_locale', $locale);
$localizedRoute->setDefault('_canonical_route', $name);
$localizedRoute->setPath($path);
$routes->add($name.'.'.$locale, $localizedRoute);
}
$generator = $this->getGenerator($routes, [], null, 'fr');
$generator->generate($name);
}
/**
@@ -177,7 +276,7 @@ class UrlGeneratorTest extends TestCase
public function testGenerateForRouteWithoutMandatoryParameter()
{
$routes = $this->getRoutes('test', new Route('/testing/{foo}'));
$this->getGenerator($routes)->generate('test', array(), UrlGeneratorInterface::ABSOLUTE_URL);
$this->getGenerator($routes)->generate('test', [], UrlGeneratorInterface::ABSOLUTE_URL);
}
/**
@@ -185,8 +284,8 @@ class UrlGeneratorTest extends TestCase
*/
public function testGenerateForRouteWithInvalidOptionalParameter()
{
$routes = $this->getRoutes('test', new Route('/testing/{foo}', array('foo' => '1'), array('foo' => 'd+')));
$this->getGenerator($routes)->generate('test', array('foo' => 'bar'), UrlGeneratorInterface::ABSOLUTE_URL);
$routes = $this->getRoutes('test', new Route('/testing/{foo}', ['foo' => '1'], ['foo' => 'd+']));
$this->getGenerator($routes)->generate('test', ['foo' => 'bar'], UrlGeneratorInterface::ABSOLUTE_URL);
}
/**
@@ -194,35 +293,35 @@ class UrlGeneratorTest extends TestCase
*/
public function testGenerateForRouteWithInvalidParameter()
{
$routes = $this->getRoutes('test', new Route('/testing/{foo}', array(), array('foo' => '1|2')));
$this->getGenerator($routes)->generate('test', array('foo' => '0'), UrlGeneratorInterface::ABSOLUTE_URL);
$routes = $this->getRoutes('test', new Route('/testing/{foo}', [], ['foo' => '1|2']));
$this->getGenerator($routes)->generate('test', ['foo' => '0'], UrlGeneratorInterface::ABSOLUTE_URL);
}
public function testGenerateForRouteWithInvalidOptionalParameterNonStrict()
{
$routes = $this->getRoutes('test', new Route('/testing/{foo}', array('foo' => '1'), array('foo' => 'd+')));
$routes = $this->getRoutes('test', new Route('/testing/{foo}', ['foo' => '1'], ['foo' => 'd+']));
$generator = $this->getGenerator($routes);
$generator->setStrictRequirements(false);
$this->assertNull($generator->generate('test', array('foo' => 'bar'), UrlGeneratorInterface::ABSOLUTE_URL));
$this->assertNull($generator->generate('test', ['foo' => 'bar'], UrlGeneratorInterface::ABSOLUTE_URL));
}
public function testGenerateForRouteWithInvalidOptionalParameterNonStrictWithLogger()
{
$routes = $this->getRoutes('test', new Route('/testing/{foo}', array('foo' => '1'), array('foo' => 'd+')));
$routes = $this->getRoutes('test', new Route('/testing/{foo}', ['foo' => '1'], ['foo' => 'd+']));
$logger = $this->getMockBuilder('Psr\Log\LoggerInterface')->getMock();
$logger->expects($this->once())
->method('error');
$generator = $this->getGenerator($routes, array(), $logger);
$generator = $this->getGenerator($routes, [], $logger);
$generator->setStrictRequirements(false);
$this->assertNull($generator->generate('test', array('foo' => 'bar'), UrlGeneratorInterface::ABSOLUTE_URL));
$this->assertNull($generator->generate('test', ['foo' => 'bar'], UrlGeneratorInterface::ABSOLUTE_URL));
}
public function testGenerateForRouteWithInvalidParameterButDisabledRequirementsCheck()
{
$routes = $this->getRoutes('test', new Route('/testing/{foo}', array('foo' => '1'), array('foo' => 'd+')));
$routes = $this->getRoutes('test', new Route('/testing/{foo}', ['foo' => '1'], ['foo' => 'd+']));
$generator = $this->getGenerator($routes);
$generator->setStrictRequirements(null);
$this->assertSame('/app.php/testing/bar', $generator->generate('test', array('foo' => 'bar')));
$this->assertSame('/app.php/testing/bar', $generator->generate('test', ['foo' => 'bar']));
}
/**
@@ -230,8 +329,8 @@ class UrlGeneratorTest extends TestCase
*/
public function testGenerateForRouteWithInvalidMandatoryParameter()
{
$routes = $this->getRoutes('test', new Route('/testing/{foo}', array(), array('foo' => 'd+')));
$this->getGenerator($routes)->generate('test', array('foo' => 'bar'), UrlGeneratorInterface::ABSOLUTE_URL);
$routes = $this->getRoutes('test', new Route('/testing/{foo}', [], ['foo' => 'd+']));
$this->getGenerator($routes)->generate('test', ['foo' => 'bar'], UrlGeneratorInterface::ABSOLUTE_URL);
}
/**
@@ -239,8 +338,8 @@ class UrlGeneratorTest extends TestCase
*/
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);
$routes = $this->getRoutes('test', new Route('/testing/{foo}', [], ['foo' => '\pL+'], ['utf8' => true]));
$this->getGenerator($routes)->generate('test', ['foo' => 'abc123'], UrlGeneratorInterface::ABSOLUTE_URL);
}
/**
@@ -248,31 +347,31 @@ class UrlGeneratorTest extends TestCase
*/
public function testRequiredParamAndEmptyPassed()
{
$routes = $this->getRoutes('test', new Route('/{slug}', array(), array('slug' => '.+')));
$this->getGenerator($routes)->generate('test', array('slug' => ''));
$routes = $this->getRoutes('test', new Route('/{slug}', [], ['slug' => '.+']));
$this->getGenerator($routes)->generate('test', ['slug' => '']);
}
public function testSchemeRequirementDoesNothingIfSameCurrentScheme()
{
$routes = $this->getRoutes('test', new Route('/', array(), array(), array(), '', array('http')));
$routes = $this->getRoutes('test', new Route('/', [], [], [], '', ['http']));
$this->assertEquals('/app.php/', $this->getGenerator($routes)->generate('test'));
$routes = $this->getRoutes('test', new Route('/', array(), array(), array(), '', array('https')));
$this->assertEquals('/app.php/', $this->getGenerator($routes, array('scheme' => 'https'))->generate('test'));
$routes = $this->getRoutes('test', new Route('/', [], [], [], '', ['https']));
$this->assertEquals('/app.php/', $this->getGenerator($routes, ['scheme' => 'https'])->generate('test'));
}
public function testSchemeRequirementForcesAbsoluteUrl()
{
$routes = $this->getRoutes('test', new Route('/', array(), array(), array(), '', array('https')));
$routes = $this->getRoutes('test', new Route('/', [], [], [], '', ['https']));
$this->assertEquals('https://localhost/app.php/', $this->getGenerator($routes)->generate('test'));
$routes = $this->getRoutes('test', new Route('/', array(), array(), array(), '', array('http')));
$this->assertEquals('http://localhost/app.php/', $this->getGenerator($routes, array('scheme' => 'https'))->generate('test'));
$routes = $this->getRoutes('test', new Route('/', [], [], [], '', ['http']));
$this->assertEquals('http://localhost/app.php/', $this->getGenerator($routes, ['scheme' => 'https'])->generate('test'));
}
public function testSchemeRequirementCreatesUrlForFirstRequiredScheme()
{
$routes = $this->getRoutes('test', new Route('/', array(), array(), array(), '', array('Ftp', 'https')));
$routes = $this->getRoutes('test', new Route('/', [], [], [], '', ['Ftp', 'https']));
$this->assertEquals('ftp://localhost/app.php/', $this->getGenerator($routes)->generate('test'));
}
@@ -281,48 +380,48 @@ class UrlGeneratorTest extends TestCase
$routes = $this->getRoutes('test', new Route('//path-and-not-domain'));
// this must not generate '//path-and-not-domain' because that would be a network path
$this->assertSame('/path-and-not-domain', $this->getGenerator($routes, array('BaseUrl' => ''))->generate('test'));
$this->assertSame('/path-and-not-domain', $this->getGenerator($routes, ['BaseUrl' => ''])->generate('test'));
}
public function testNoTrailingSlashForMultipleOptionalParameters()
{
$routes = $this->getRoutes('test', new Route('/category/{slug1}/{slug2}/{slug3}', array('slug2' => null, 'slug3' => null)));
$routes = $this->getRoutes('test', new Route('/category/{slug1}/{slug2}/{slug3}', ['slug2' => null, 'slug3' => null]));
$this->assertEquals('/app.php/category/foo', $this->getGenerator($routes)->generate('test', array('slug1' => 'foo')));
$this->assertEquals('/app.php/category/foo', $this->getGenerator($routes)->generate('test', ['slug1' => 'foo']));
}
public function testWithAnIntegerAsADefaultValue()
{
$routes = $this->getRoutes('test', new Route('/{default}', array('default' => 0)));
$routes = $this->getRoutes('test', new Route('/{default}', ['default' => 0]));
$this->assertEquals('/app.php/foo', $this->getGenerator($routes)->generate('test', array('default' => 'foo')));
$this->assertEquals('/app.php/foo', $this->getGenerator($routes)->generate('test', ['default' => 'foo']));
}
public function testNullForOptionalParameterIsIgnored()
{
$routes = $this->getRoutes('test', new Route('/test/{default}', array('default' => 0)));
$routes = $this->getRoutes('test', new Route('/test/{default}', ['default' => 0]));
$this->assertEquals('/app.php/test', $this->getGenerator($routes)->generate('test', array('default' => null)));
$this->assertEquals('/app.php/test', $this->getGenerator($routes)->generate('test', ['default' => null]));
}
public function testQueryParamSameAsDefault()
{
$routes = $this->getRoutes('test', new Route('/test', array('page' => 1)));
$routes = $this->getRoutes('test', new Route('/test', ['page' => 1]));
$this->assertSame('/app.php/test?page=2', $this->getGenerator($routes)->generate('test', array('page' => 2)));
$this->assertSame('/app.php/test', $this->getGenerator($routes)->generate('test', array('page' => 1)));
$this->assertSame('/app.php/test', $this->getGenerator($routes)->generate('test', array('page' => '1')));
$this->assertSame('/app.php/test?page=2', $this->getGenerator($routes)->generate('test', ['page' => 2]));
$this->assertSame('/app.php/test', $this->getGenerator($routes)->generate('test', ['page' => 1]));
$this->assertSame('/app.php/test', $this->getGenerator($routes)->generate('test', ['page' => '1']));
$this->assertSame('/app.php/test', $this->getGenerator($routes)->generate('test'));
}
public function testArrayQueryParamSameAsDefault()
{
$routes = $this->getRoutes('test', new Route('/test', array('array' => array('foo', 'bar'))));
$routes = $this->getRoutes('test', new Route('/test', ['array' => ['foo', 'bar']]));
$this->assertSame('/app.php/test?array%5B0%5D=bar&array%5B1%5D=foo', $this->getGenerator($routes)->generate('test', array('array' => array('bar', 'foo'))));
$this->assertSame('/app.php/test?array%5Ba%5D=foo&array%5Bb%5D=bar', $this->getGenerator($routes)->generate('test', array('array' => array('a' => 'foo', 'b' => 'bar'))));
$this->assertSame('/app.php/test', $this->getGenerator($routes)->generate('test', array('array' => array('foo', 'bar'))));
$this->assertSame('/app.php/test', $this->getGenerator($routes)->generate('test', array('array' => array(1 => 'bar', 0 => 'foo'))));
$this->assertSame('/app.php/test?array%5B0%5D=bar&array%5B1%5D=foo', $this->getGenerator($routes)->generate('test', ['array' => ['bar', 'foo']]));
$this->assertSame('/app.php/test?array%5Ba%5D=foo&array%5Bb%5D=bar', $this->getGenerator($routes)->generate('test', ['array' => ['a' => 'foo', 'b' => 'bar']]));
$this->assertSame('/app.php/test', $this->getGenerator($routes)->generate('test', ['array' => ['foo', 'bar']]));
$this->assertSame('/app.php/test', $this->getGenerator($routes)->generate('test', ['array' => [1 => 'bar', 0 => 'foo']]));
$this->assertSame('/app.php/test', $this->getGenerator($routes)->generate('test'));
}
@@ -342,11 +441,11 @@ class UrlGeneratorTest extends TestCase
// 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($expectedPath, $this->getGenerator($routes)->generate('test', array(
$routes = $this->getRoutes('test', new Route("/$chars/{varpath}", [], ['varpath' => '.+']));
$this->assertSame($expectedPath, $this->getGenerator($routes)->generate('test', [
'varpath' => $chars,
'query' => $chars,
)));
]));
}
public function testEncodingOfRelativePathSegments()
@@ -361,24 +460,24 @@ class UrlGeneratorTest extends TestCase
public function testAdjacentVariables()
{
$routes = $this->getRoutes('test', new Route('/{x}{y}{z}.{_format}', array('z' => 'default-z', '_format' => 'html'), array('y' => '\d+')));
$routes = $this->getRoutes('test', new Route('/{x}{y}{z}.{_format}', ['z' => 'default-z', '_format' => 'html'], ['y' => '\d+']));
$generator = $this->getGenerator($routes);
$this->assertSame('/app.php/foo123', $generator->generate('test', array('x' => 'foo', 'y' => '123')));
$this->assertSame('/app.php/foo123bar.xml', $generator->generate('test', array('x' => 'foo', 'y' => '123', 'z' => 'bar', '_format' => 'xml')));
$this->assertSame('/app.php/foo123', $generator->generate('test', ['x' => 'foo', 'y' => '123']));
$this->assertSame('/app.php/foo123bar.xml', $generator->generate('test', ['x' => 'foo', 'y' => '123', 'z' => 'bar', '_format' => 'xml']));
// 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->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Routing\Exception\InvalidParameterException');
$generator->generate('test', array('x' => 'do.t', 'y' => '123', 'z' => 'bar', '_format' => 'xml'));
$generator->generate('test', ['x' => 'do.t', 'y' => '123', 'z' => 'bar', '_format' => 'xml']);
}
public function testOptionalVariableWithNoRealSeparator()
{
$routes = $this->getRoutes('test', new Route('/get{what}', array('what' => 'All')));
$routes = $this->getRoutes('test', new Route('/get{what}', ['what' => 'All']));
$generator = $this->getGenerator($routes);
$this->assertSame('/app.php/get', $generator->generate('test'));
$this->assertSame('/app.php/getSites', $generator->generate('test', array('what' => 'Sites')));
$this->assertSame('/app.php/getSites', $generator->generate('test', ['what' => 'Sites']));
}
public function testRequiredVariableWithNoRealSeparator()
@@ -386,7 +485,7 @@ class UrlGeneratorTest extends TestCase
$routes = $this->getRoutes('test', new Route('/get{what}Suffix'));
$generator = $this->getGenerator($routes);
$this->assertSame('/app.php/getSitesSuffix', $generator->generate('test', array('what' => 'Sites')));
$this->assertSame('/app.php/getSitesSuffix', $generator->generate('test', ['what' => 'Sites']));
}
public function testDefaultRequirementOfVariable()
@@ -394,7 +493,7 @@ class UrlGeneratorTest extends TestCase
$routes = $this->getRoutes('test', new Route('/{page}.{_format}'));
$generator = $this->getGenerator($routes);
$this->assertSame('/app.php/index.mobile.html', $generator->generate('test', array('page' => 'index', '_format' => 'mobile.html')));
$this->assertSame('/app.php/index.mobile.html', $generator->generate('test', ['page' => 'index', '_format' => 'mobile.html']));
}
/**
@@ -403,7 +502,7 @@ class UrlGeneratorTest extends TestCase
public function testDefaultRequirementOfVariableDisallowsSlash()
{
$routes = $this->getRoutes('test', new Route('/{page}.{_format}'));
$this->getGenerator($routes)->generate('test', array('page' => 'index', '_format' => 'sl/ash'));
$this->getGenerator($routes)->generate('test', ['page' => 'index', '_format' => 'sl/ash']);
}
/**
@@ -412,28 +511,28 @@ class UrlGeneratorTest extends TestCase
public function testDefaultRequirementOfVariableDisallowsNextSeparator()
{
$routes = $this->getRoutes('test', new Route('/{page}.{_format}'));
$this->getGenerator($routes)->generate('test', array('page' => 'do.t', '_format' => 'html'));
$this->getGenerator($routes)->generate('test', ['page' => 'do.t', '_format' => 'html']);
}
public function testWithHostDifferentFromContext()
{
$routes = $this->getRoutes('test', new Route('/{name}', array(), array(), array(), '{locale}.example.com'));
$routes = $this->getRoutes('test', new Route('/{name}', [], [], [], '{locale}.example.com'));
$this->assertEquals('//fr.example.com/app.php/Fabien', $this->getGenerator($routes)->generate('test', array('name' => 'Fabien', 'locale' => 'fr')));
$this->assertEquals('//fr.example.com/app.php/Fabien', $this->getGenerator($routes)->generate('test', ['name' => 'Fabien', 'locale' => 'fr']));
}
public function testWithHostSameAsContext()
{
$routes = $this->getRoutes('test', new Route('/{name}', array(), array(), array(), '{locale}.example.com'));
$routes = $this->getRoutes('test', new Route('/{name}', [], [], [], '{locale}.example.com'));
$this->assertEquals('/app.php/Fabien', $this->getGenerator($routes, array('host' => 'fr.example.com'))->generate('test', array('name' => 'Fabien', 'locale' => 'fr')));
$this->assertEquals('/app.php/Fabien', $this->getGenerator($routes, ['host' => 'fr.example.com'])->generate('test', ['name' => 'Fabien', 'locale' => 'fr']));
}
public function testWithHostSameAsContextAndAbsolute()
{
$routes = $this->getRoutes('test', new Route('/{name}', array(), array(), array(), '{locale}.example.com'));
$routes = $this->getRoutes('test', new Route('/{name}', [], [], [], '{locale}.example.com'));
$this->assertEquals('http://fr.example.com/app.php/Fabien', $this->getGenerator($routes, array('host' => 'fr.example.com'))->generate('test', array('name' => 'Fabien', 'locale' => 'fr'), UrlGeneratorInterface::ABSOLUTE_URL));
$this->assertEquals('http://fr.example.com/app.php/Fabien', $this->getGenerator($routes, ['host' => 'fr.example.com'])->generate('test', ['name' => 'Fabien', 'locale' => 'fr'], UrlGeneratorInterface::ABSOLUTE_URL));
}
/**
@@ -441,8 +540,8 @@ class UrlGeneratorTest extends TestCase
*/
public function testUrlWithInvalidParameterInHost()
{
$routes = $this->getRoutes('test', new Route('/', array(), array('foo' => 'bar'), array(), '{foo}.example.com'));
$this->getGenerator($routes)->generate('test', array('foo' => 'baz'), UrlGeneratorInterface::ABSOLUTE_PATH);
$routes = $this->getRoutes('test', new Route('/', [], ['foo' => 'bar'], [], '{foo}.example.com'));
$this->getGenerator($routes)->generate('test', ['foo' => 'baz'], UrlGeneratorInterface::ABSOLUTE_PATH);
}
/**
@@ -450,8 +549,8 @@ class UrlGeneratorTest extends TestCase
*/
public function testUrlWithInvalidParameterInHostWhenParamHasADefaultValue()
{
$routes = $this->getRoutes('test', new Route('/', array('foo' => 'bar'), array('foo' => 'bar'), array(), '{foo}.example.com'));
$this->getGenerator($routes)->generate('test', array('foo' => 'baz'), UrlGeneratorInterface::ABSOLUTE_PATH);
$routes = $this->getRoutes('test', new Route('/', ['foo' => 'bar'], ['foo' => 'bar'], [], '{foo}.example.com'));
$this->getGenerator($routes)->generate('test', ['foo' => 'baz'], UrlGeneratorInterface::ABSOLUTE_PATH);
}
/**
@@ -459,72 +558,72 @@ class UrlGeneratorTest extends TestCase
*/
public function testUrlWithInvalidParameterEqualsDefaultValueInHost()
{
$routes = $this->getRoutes('test', new Route('/', array('foo' => 'baz'), array('foo' => 'bar'), array(), '{foo}.example.com'));
$this->getGenerator($routes)->generate('test', array('foo' => 'baz'), UrlGeneratorInterface::ABSOLUTE_PATH);
$routes = $this->getRoutes('test', new Route('/', ['foo' => 'baz'], ['foo' => 'bar'], [], '{foo}.example.com'));
$this->getGenerator($routes)->generate('test', ['foo' => 'baz'], UrlGeneratorInterface::ABSOLUTE_PATH);
}
public function testUrlWithInvalidParameterInHostInNonStrictMode()
{
$routes = $this->getRoutes('test', new Route('/', array(), array('foo' => 'bar'), array(), '{foo}.example.com'));
$routes = $this->getRoutes('test', new Route('/', [], ['foo' => 'bar'], [], '{foo}.example.com'));
$generator = $this->getGenerator($routes);
$generator->setStrictRequirements(false);
$this->assertNull($generator->generate('test', array('foo' => 'baz'), UrlGeneratorInterface::ABSOLUTE_PATH));
$this->assertNull($generator->generate('test', ['foo' => 'baz'], UrlGeneratorInterface::ABSOLUTE_PATH));
}
public function testHostIsCaseInsensitive()
{
$routes = $this->getRoutes('test', new Route('/', array(), array('locale' => 'en|de|fr'), array(), '{locale}.FooBar.com'));
$routes = $this->getRoutes('test', new Route('/', [], ['locale' => 'en|de|fr'], [], '{locale}.FooBar.com'));
$generator = $this->getGenerator($routes);
$this->assertSame('//EN.FooBar.com/app.php/', $generator->generate('test', array('locale' => 'EN'), UrlGeneratorInterface::NETWORK_PATH));
$this->assertSame('//EN.FooBar.com/app.php/', $generator->generate('test', ['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')));
$routes = $this->getRoutes('test', new Route('/route', ['domain' => 'my.fallback.host'], ['domain' => '.+'], [], '{domain}', ['http']));
$generator = $this->getGenerator($routes);
$generator->getContext()->setHost('');
$this->assertSame('http://my.fallback.host/app.php/route', $generator->generate('test', array(), UrlGeneratorInterface::ABSOLUTE_URL));
$this->assertSame('http://my.fallback.host/app.php/route', $generator->generate('test', [], 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')));
$routes = $this->getRoutes('test', new Route('/route', ['domain' => 'my.fallback.host'], ['domain' => '.+'], [], '{domain}', ['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));
$this->assertSame('https://my.fallback.host/app.php/route', $generator->generate('test', [], UrlGeneratorInterface::ABSOLUTE_URL));
}
public function testAbsoluteUrlFallbackToRelativeIfHostIsEmptyAndSchemeIsNot()
{
$routes = $this->getRoutes('test', new Route('/route', array(), array(), array(), '', array('http', 'https')));
$routes = $this->getRoutes('test', new Route('/route', [], [], [], '', ['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));
$this->assertSame('/app.php/route', $generator->generate('test', [], UrlGeneratorInterface::ABSOLUTE_URL));
}
public function testGenerateNetworkPath()
{
$routes = $this->getRoutes('test', new Route('/{name}', array(), array(), array(), '{locale}.example.com', array('http')));
$routes = $this->getRoutes('test', new Route('/{name}', [], [], [], '{locale}.example.com', ['http']));
$this->assertSame('//fr.example.com/app.php/Fabien', $this->getGenerator($routes)->generate('test',
array('name' => 'Fabien', 'locale' => 'fr'), UrlGeneratorInterface::NETWORK_PATH), 'network path with different host'
['name' => 'Fabien', 'locale' => 'fr'], UrlGeneratorInterface::NETWORK_PATH), 'network path with different host'
);
$this->assertSame('//fr.example.com/app.php/Fabien?query=string', $this->getGenerator($routes, array('host' => 'fr.example.com'))->generate('test',
array('name' => 'Fabien', 'locale' => 'fr', 'query' => 'string'), UrlGeneratorInterface::NETWORK_PATH), 'network path although host same as context'
$this->assertSame('//fr.example.com/app.php/Fabien?query=string', $this->getGenerator($routes, ['host' => 'fr.example.com'])->generate('test',
['name' => 'Fabien', 'locale' => 'fr', 'query' => 'string'], UrlGeneratorInterface::NETWORK_PATH), 'network path although host same as context'
);
$this->assertSame('http://fr.example.com/app.php/Fabien', $this->getGenerator($routes, array('scheme' => 'https'))->generate('test',
array('name' => 'Fabien', 'locale' => 'fr'), UrlGeneratorInterface::NETWORK_PATH), 'absolute URL because scheme requirement does not match context'
$this->assertSame('http://fr.example.com/app.php/Fabien', $this->getGenerator($routes, ['scheme' => 'https'])->generate('test',
['name' => 'Fabien', 'locale' => 'fr'], UrlGeneratorInterface::NETWORK_PATH), 'absolute URL because scheme requirement does not match context'
);
$this->assertSame('http://fr.example.com/app.php/Fabien', $this->getGenerator($routes)->generate('test',
array('name' => 'Fabien', 'locale' => 'fr'), UrlGeneratorInterface::ABSOLUTE_URL), 'absolute URL with same scheme because it is requested'
['name' => 'Fabien', 'locale' => 'fr'], UrlGeneratorInterface::ABSOLUTE_URL), 'absolute URL with same scheme because it is requested'
);
}
@@ -533,32 +632,32 @@ class UrlGeneratorTest extends TestCase
$routes = new RouteCollection();
$routes->add('article', new Route('/{author}/{article}/'));
$routes->add('comments', new Route('/{author}/{article}/comments'));
$routes->add('host', new Route('/{article}', array(), array(), array(), '{author}.example.com'));
$routes->add('scheme', new Route('/{author}/blog', array(), array(), array(), '', array('https')));
$routes->add('host', new Route('/{article}', [], [], [], '{author}.example.com'));
$routes->add('scheme', new Route('/{author}/blog', [], [], [], '', ['https']));
$routes->add('unrelated', new Route('/about'));
$generator = $this->getGenerator($routes, array('host' => 'example.com', 'pathInfo' => '/fabien/symfony-is-great/'));
$generator = $this->getGenerator($routes, ['host' => 'example.com', 'pathInfo' => '/fabien/symfony-is-great/']);
$this->assertSame('comments', $generator->generate('comments',
array('author' => 'fabien', 'article' => 'symfony-is-great'), UrlGeneratorInterface::RELATIVE_PATH)
['author' => 'fabien', 'article' => 'symfony-is-great'], UrlGeneratorInterface::RELATIVE_PATH)
);
$this->assertSame('comments?page=2', $generator->generate('comments',
array('author' => 'fabien', 'article' => 'symfony-is-great', 'page' => 2), UrlGeneratorInterface::RELATIVE_PATH)
['author' => 'fabien', 'article' => 'symfony-is-great', 'page' => 2], UrlGeneratorInterface::RELATIVE_PATH)
);
$this->assertSame('../twig-is-great/', $generator->generate('article',
array('author' => 'fabien', 'article' => 'twig-is-great'), UrlGeneratorInterface::RELATIVE_PATH)
['author' => 'fabien', 'article' => 'twig-is-great'], UrlGeneratorInterface::RELATIVE_PATH)
);
$this->assertSame('../../bernhard/forms-are-great/', $generator->generate('article',
array('author' => 'bernhard', 'article' => 'forms-are-great'), UrlGeneratorInterface::RELATIVE_PATH)
['author' => 'bernhard', 'article' => 'forms-are-great'], UrlGeneratorInterface::RELATIVE_PATH)
);
$this->assertSame('//bernhard.example.com/app.php/forms-are-great', $generator->generate('host',
array('author' => 'bernhard', 'article' => 'forms-are-great'), UrlGeneratorInterface::RELATIVE_PATH)
['author' => 'bernhard', 'article' => 'forms-are-great'], UrlGeneratorInterface::RELATIVE_PATH)
);
$this->assertSame('https://example.com/app.php/bernhard/blog', $generator->generate('scheme',
array('author' => 'bernhard'), UrlGeneratorInterface::RELATIVE_PATH)
['author' => 'bernhard'], UrlGeneratorInterface::RELATIVE_PATH)
);
$this->assertSame('../../about', $generator->generate('unrelated',
array(), UrlGeneratorInterface::RELATIVE_PATH)
[], UrlGeneratorInterface::RELATIVE_PATH)
);
}
@@ -572,138 +671,155 @@ class UrlGeneratorTest extends TestCase
public function provideRelativePaths()
{
return array(
array(
return [
[
'/same/dir/',
'/same/dir/',
'',
),
array(
],
[
'/same/file',
'/same/file',
'',
),
array(
],
[
'/',
'/file',
'file',
),
array(
],
[
'/',
'/dir/file',
'dir/file',
),
array(
],
[
'/dir/file.html',
'/dir/different-file.html',
'different-file.html',
),
array(
],
[
'/same/dir/extra-file',
'/same/dir/',
'./',
),
array(
],
[
'/parent/dir/',
'/parent/',
'../',
),
array(
],
[
'/parent/dir/extra-file',
'/parent/',
'../',
),
array(
],
[
'/a/b/',
'/x/y/z/',
'../../x/y/z/',
),
array(
],
[
'/a/b/c/d/e',
'/a/c/d',
'../../../c/d',
),
array(
],
[
'/a/b/c//',
'/a/b/c/',
'../',
),
array(
],
[
'/a/b/c/',
'/a/b/c//',
'.//',
),
array(
],
[
'/root/a/b/c/',
'/root/x/b/c/',
'../../../x/b/c/',
),
array(
],
[
'/a/b/c/d/',
'/a',
'../../../../a',
),
array(
],
[
'/special-chars/sp%20ce/1€/mäh/e=mc²',
'/special-chars/sp%20ce/1€/<µ>/e=mc²',
'../<µ>/e=mc²',
),
array(
],
[
'not-rooted',
'dir/file',
'dir/file',
),
array(
],
[
'//dir/',
'',
'../../',
),
array(
],
[
'/dir/',
'/dir/file:with-colon',
'./file:with-colon',
),
array(
],
[
'/dir/',
'/dir/subdir/file:with-colon',
'subdir/file:with-colon',
),
array(
],
[
'/dir/',
'/dir/:subdir/',
'./:subdir/',
),
);
],
];
}
public function testFragmentsCanBeAppendedToUrls()
{
$routes = $this->getRoutes('test', new Route('/testing'));
$url = $this->getGenerator($routes)->generate('test', array('_fragment' => 'frag ment'), UrlGeneratorInterface::ABSOLUTE_PATH);
$url = $this->getGenerator($routes)->generate('test', ['_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);
$url = $this->getGenerator($routes)->generate('test', ['_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);
$url = $this->getGenerator($routes)->generate('test', ['_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);
$routes = $this->getRoutes('test', new Route('/testing', ['_fragment' => 'fragment']));
$url = $this->getGenerator($routes)->generate('test', [], UrlGeneratorInterface::ABSOLUTE_PATH);
$this->assertEquals('/app.php/testing#fragment', $url);
}
protected function getGenerator(RouteCollection $routes, array $parameters = array(), $logger = null)
/**
* @dataProvider provideLookAroundRequirementsInPath
*/
public function testLookRoundRequirementsInPath($expected, $path, $requirement)
{
$routes = $this->getRoutes('test', new Route($path, [], ['foo' => $requirement, 'baz' => '.+?']));
$this->assertSame($expected, $this->getGenerator($routes)->generate('test', ['foo' => 'a/b', 'baz' => 'c/d/e']));
}
public function provideLookAroundRequirementsInPath()
{
yield ['/app.php/a/b/b%28ar/c/d/e', '/{foo}/b(ar/{baz}', '.+(?=/b\\(ar/)'];
yield ['/app.php/a/b/bar/c/d/e', '/{foo}/bar/{baz}', '.+(?!$)'];
yield ['/app.php/bar/a/b/bam/c/d/e', '/bar/{foo}/bam/{baz}', '(?<=/bar/).+'];
yield ['/app.php/bar/a/b/bam/c/d/e', '/bar/{foo}/bam/{baz}', '(?<!^).+'];
}
protected function getGenerator(RouteCollection $routes, array $parameters = [], $logger = null, string $defaultLocale = null)
{
$context = new RequestContext('/app.php');
foreach ($parameters as $key => $value) {
@@ -711,7 +827,7 @@ class UrlGeneratorTest extends TestCase
$context->$method($value);
}
return new UrlGenerator($routes, $context, $logger);
return new UrlGenerator($routes, $context, $logger, $defaultLocale);
}
protected function getRoutes($name, Route $route)

View File

@@ -26,7 +26,7 @@ abstract class AbstractAnnotationLoaderTest extends TestCase
public function getClassLoader($reader)
{
return $this->getMockBuilder('Symfony\Component\Routing\Loader\AnnotationClassLoader')
->setConstructorArgs(array($reader))
->setConstructorArgs([$reader])
->getMockForAbstractClass()
;
}

View File

@@ -64,15 +64,15 @@ class AnnotationClassLoaderTest extends AbstractAnnotationLoaderTest
public function provideTestSupportsChecksResource()
{
return array(
array('class', true),
array('\fully\qualified\class\name', true),
array('namespaced\class\without\leading\slash', true),
array('ÿClassWithLegalSpecialCharacters', true),
array('5', false),
array('foo.foo', false),
array(null, false),
);
return [
['class', true],
['\fully\qualified\class\name', true],
['namespaced\class\without\leading\slash', true],
['ÿClassWithLegalSpecialCharacters', true],
['5', false],
['foo.foo', false],
[null, false],
];
}
public function testSupportsChecksTypeIfSpecified()
@@ -105,8 +105,8 @@ class AnnotationClassLoaderTest extends AbstractAnnotationLoaderTest
$routes = $this->loader->load(InvokableController::class);
$this->assertCount(1, $routes);
$this->assertEquals('/here', $routes->get('lol')->getPath());
$this->assertEquals(array('GET', 'POST'), $routes->get('lol')->getMethods());
$this->assertEquals(array('https'), $routes->get('lol')->getSchemes());
$this->assertEquals(['GET', 'POST'], $routes->get('lol')->getMethods());
$this->assertEquals(['https'], $routes->get('lol')->getSchemes());
}
public function testInvokableLocalizedControllerLoading()
@@ -136,9 +136,11 @@ class AnnotationClassLoaderTest extends AbstractAnnotationLoaderTest
public function testDefaultValuesForMethods()
{
$routes = $this->loader->load(DefaultValueController::class);
$this->assertCount(1, $routes);
$this->assertCount(3, $routes);
$this->assertEquals('/{default}/path', $routes->get('action')->getPath());
$this->assertEquals('value', $routes->get('action')->getDefault('default'));
$this->assertEquals('Symfony', $routes->get('hello_with_default')->getDefault('name'));
$this->assertEquals('World', $routes->get('hello_without_default')->getDefault('name'));
}
public function testMethodActionControllers()
@@ -185,30 +187,30 @@ class AnnotationClassLoaderTest extends AbstractAnnotationLoaderTest
public function testInvokableClassMultipleRouteLoad()
{
$classRouteData1 = array(
$classRouteData1 = [
'name' => 'route1',
'path' => '/1',
'schemes' => array('https'),
'methods' => array('GET'),
);
'schemes' => ['https'],
'methods' => ['GET'],
];
$classRouteData2 = array(
$classRouteData2 = [
'name' => 'route2',
'path' => '/2',
'schemes' => array('https'),
'methods' => array('GET'),
);
'schemes' => ['https'],
'methods' => ['GET'],
];
$reader = $this->getReader();
$reader
->expects($this->exactly(1))
->method('getClassAnnotations')
->will($this->returnValue(array(new RouteAnnotation($classRouteData1), new RouteAnnotation($classRouteData2))))
->will($this->returnValue([new RouteAnnotation($classRouteData1), new RouteAnnotation($classRouteData2)]))
;
$reader
->expects($this->once())
->method('getMethodAnnotations')
->will($this->returnValue(array()))
->will($this->returnValue([]))
;
$loader = new class($reader) extends AnnotationClassLoader {
protected function configureRoute(Route $route, \ReflectionClass $class, \ReflectionMethod $method, $annot)

View File

@@ -34,13 +34,13 @@ class AnnotationDirectoryLoaderTest extends AbstractAnnotationLoaderTest
$this->reader
->expects($this->any())
->method('getMethodAnnotations')
->will($this->returnValue(array()))
->will($this->returnValue([]))
;
$this->reader
->expects($this->any())
->method('getClassAnnotations')
->will($this->returnValue(array()))
->will($this->returnValue([]))
;
$this->loader->load(__DIR__.'/../Fixtures/AnnotatedClasses');
@@ -48,22 +48,22 @@ class AnnotationDirectoryLoaderTest extends AbstractAnnotationLoaderTest
public function testLoadIgnoresHiddenDirectories()
{
$this->expectAnnotationsToBeReadFrom(array(
$this->expectAnnotationsToBeReadFrom([
'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()))
->will($this->returnValue([]))
;
$this->reader
->expects($this->any())
->method('getClassAnnotations')
->will($this->returnValue(array()))
->will($this->returnValue([]))
;
$this->loader->load(__DIR__.'/../Fixtures/AnnotatedClasses');
@@ -92,7 +92,7 @@ class AnnotationDirectoryLoaderTest extends AbstractAnnotationLoaderTest
$this->reader
->expects($this->any())
->method('getMethodAnnotations')
->will($this->returnValue(array()))
->will($this->returnValue([]))
;
$this->loader->load(__DIR__.'/../Fixtures/AnnotatedClasses/FooClass.php');

View File

@@ -53,10 +53,10 @@ class AnnotationFileLoaderTest extends AbstractAnnotationLoaderTest
public function testLoadVariadic()
{
$route = new Route(array('path' => '/path/to/{id}'));
$route = new Route(['path' => '/path/to/{id}']);
$this->reader->expects($this->once())->method('getClassAnnotation');
$this->reader->expects($this->once())->method('getMethodAnnotations')
->will($this->returnValue(array($route)));
->will($this->returnValue([$route]));
$this->loader->load(__DIR__.'/../Fixtures/OtherAnnotatedClasses/VariadicClass.php');
}
@@ -72,6 +72,14 @@ class AnnotationFileLoaderTest extends AbstractAnnotationLoaderTest
$this->loader->load(__DIR__.'/../Fixtures/OtherAnnotatedClasses/AnonymousClassInTrait.php');
}
public function testLoadAbstractClass()
{
$this->reader->expects($this->never())->method('getClassAnnotation');
$this->reader->expects($this->never())->method('getMethodAnnotations');
$this->loader->load(__DIR__.'/../Fixtures/AnnotatedClasses/AbstractClass.php');
}
public function testSupports()
{
$fixture = __DIR__.'/../Fixtures/annotated.php';

View File

@@ -30,11 +30,11 @@ class DirectoryLoaderTest extends AbstractAnnotationLoaderTest
$locator = new FileLocator();
$this->reader = $this->getReader();
$this->loader = new DirectoryLoader($locator);
$resolver = new LoaderResolver(array(
$resolver = new LoaderResolver([
new YamlFileLoader($locator),
new AnnotationFileLoader($locator, $this->getClassLoader($this->reader)),
$this->loader,
));
]);
$this->loader->setResolver($resolver);
}

View File

@@ -30,9 +30,9 @@ class ObjectRouteLoaderTest extends TestCase
$collection = new RouteCollection();
$collection->add('foo', new Route('/foo'));
$loader->loaderMap = array(
$loader->loaderMap = [
'my_route_provider_service' => new RouteService($collection),
);
];
$actualRoutes = $loader->load(
'my_route_provider_service:loadRoutes',
@@ -52,9 +52,9 @@ class ObjectRouteLoaderTest extends TestCase
$collection = new RouteCollection();
$collection->add('foo', new Route('/foo'));
$loader->loaderMap = array(
$loader->loaderMap = [
'my_route_provider_service' => new RouteService($collection),
);
];
$actualRoutes = $loader->load(
'my_route_provider_service::loadRoutes',
@@ -78,10 +78,10 @@ class ObjectRouteLoaderTest extends TestCase
public function getBadResourceStrings()
{
return array(
array('Foo'),
array('Foo:Bar:baz'),
);
return [
['Foo'],
['Foo:Bar:baz'],
];
}
/**
@@ -90,7 +90,7 @@ class ObjectRouteLoaderTest extends TestCase
public function testExceptionOnNoObjectReturned()
{
$loader = new ObjectRouteLoaderForTest();
$loader->loaderMap = array('my_service' => 'NOT_AN_OBJECT');
$loader->loaderMap = ['my_service' => 'NOT_AN_OBJECT'];
$loader->load('my_service::method');
}
@@ -100,7 +100,7 @@ class ObjectRouteLoaderTest extends TestCase
public function testExceptionOnBadMethod()
{
$loader = new ObjectRouteLoaderForTest();
$loader->loaderMap = array('my_service' => new \stdClass());
$loader->loaderMap = ['my_service' => new \stdClass()];
$loader->load('my_service::method');
}
@@ -110,21 +110,21 @@ class ObjectRouteLoaderTest extends TestCase
public function testExceptionOnMethodNotReturningCollection()
{
$service = $this->getMockBuilder('stdClass')
->setMethods(array('loadRoutes'))
->setMethods(['loadRoutes'])
->getMock();
$service->expects($this->once())
->method('loadRoutes')
->will($this->returnValue('NOT_A_COLLECTION'));
$loader = new ObjectRouteLoaderForTest();
$loader->loaderMap = array('my_service' => $service);
$loader->loaderMap = ['my_service' => $service];
$loader->load('my_service::loadRoutes');
}
}
class ObjectRouteLoaderForTest extends ObjectRouteLoader
{
public $loaderMap = array();
public $loaderMap = [];
protected function getServiceObject($id)
{

View File

@@ -33,7 +33,7 @@ class PhpFileLoaderTest extends TestCase
public function testLoadWithRoute()
{
$loader = new PhpFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
$loader = new PhpFileLoader(new FileLocator([__DIR__.'/../Fixtures']));
$routeCollection = $loader->load('validpattern.php');
$routes = $routeCollection->all();
@@ -45,14 +45,14 @@ class PhpFileLoaderTest extends TestCase
$this->assertSame('MyBlogBundle:Blog:show', $route->getDefault('_controller'));
$this->assertSame('{locale}.example.com', $route->getHost());
$this->assertSame('RouteCompiler', $route->getOption('compiler_class'));
$this->assertEquals(array('GET', 'POST', 'PUT', 'OPTIONS'), $route->getMethods());
$this->assertEquals(array('https'), $route->getSchemes());
$this->assertEquals(['GET', 'POST', 'PUT', 'OPTIONS'], $route->getMethods());
$this->assertEquals(['https'], $route->getSchemes());
}
}
public function testLoadWithImport()
{
$loader = new PhpFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
$loader = new PhpFileLoader(new FileLocator([__DIR__.'/../Fixtures']));
$routeCollection = $loader->load('validresource.php');
$routes = $routeCollection->all();
@@ -64,14 +64,14 @@ class PhpFileLoaderTest extends TestCase
$this->assertSame('MyBlogBundle:Blog:show', $route->getDefault('_controller'));
$this->assertSame('{locale}.example.com', $route->getHost());
$this->assertSame('RouteCompiler', $route->getOption('compiler_class'));
$this->assertEquals(array('GET', 'POST', 'PUT', 'OPTIONS'), $route->getMethods());
$this->assertEquals(array('https'), $route->getSchemes());
$this->assertEquals(['GET', 'POST', 'PUT', 'OPTIONS'], $route->getMethods());
$this->assertEquals(['https'], $route->getSchemes());
}
}
public function testThatDefiningVariableInConfigFileHasNoSideEffects()
{
$locator = new FileLocator(array(__DIR__.'/../Fixtures'));
$locator = new FileLocator([__DIR__.'/../Fixtures']);
$loader = new PhpFileLoader($locator);
$routeCollection = $loader->load('with_define_path_variable.php');
$resources = $routeCollection->getResources();
@@ -86,7 +86,7 @@ class PhpFileLoaderTest extends TestCase
public function testRoutingConfigurator()
{
$locator = new FileLocator(array(__DIR__.'/../Fixtures'));
$locator = new FileLocator([__DIR__.'/../Fixtures']);
$loader = new PhpFileLoader($locator);
$routeCollectionClosure = $loader->load('php_dsl.php');
$routeCollectionObject = $loader->load('php_object_dsl.php');
@@ -94,21 +94,21 @@ class PhpFileLoaderTest extends TestCase
$expectedCollection = new RouteCollection();
$expectedCollection->add('foo', (new Route('/foo'))
->setOptions(array('utf8' => true))
->setOptions(['utf8' => true])
->setCondition('abc')
);
$expectedCollection->add('buz', (new Route('/zub'))
->setDefaults(array('_controller' => 'foo:act'))
->setDefaults(['_controller' => 'foo:act'])
);
$expectedCollection->add('c_root', (new Route('/sub/pub/'))
->setRequirements(array('id' => '\d+'))
->setRequirements(['id' => '\d+'])
);
$expectedCollection->add('c_bar', (new Route('/sub/pub/bar'))
->setRequirements(array('id' => '\d+'))
->setRequirements(['id' => '\d+'])
);
$expectedCollection->add('c_pub_buz', (new Route('/sub/pub/buz'))
->setHost('host')
->setRequirements(array('id' => '\d+'))
->setRequirements(['id' => '\d+'])
);
$expectedCollection->add('z_c_root', new Route('/zub/pub/'));
$expectedCollection->add('z_c_bar', new Route('/zub/pub/bar'));
@@ -116,9 +116,9 @@ class PhpFileLoaderTest extends TestCase
$expectedCollection->add('r_root', new Route('/bus'));
$expectedCollection->add('r_bar', new Route('/bus/bar/'));
$expectedCollection->add('ouf', (new Route('/ouf'))
->setSchemes(array('https'))
->setMethods(array('GET'))
->setDefaults(array('id' => 0))
->setSchemes(['https'])
->setMethods(['GET'])
->setDefaults(['id' => 0])
);
$expectedCollection->addResource(new FileResource(realpath(__DIR__.'/../Fixtures/php_dsl_sub.php')));
@@ -136,7 +136,7 @@ class PhpFileLoaderTest extends TestCase
public function testRoutingConfiguratorCanImportGlobPatterns()
{
$locator = new FileLocator(array(__DIR__.'/../Fixtures/glob'));
$locator = new FileLocator([__DIR__.'/../Fixtures/glob']);
$loader = new PhpFileLoader($locator);
$routeCollection = $loader->load('php_dsl.php');
@@ -149,17 +149,17 @@ class PhpFileLoaderTest extends TestCase
public function testRoutingI18nConfigurator()
{
$locator = new FileLocator(array(__DIR__.'/../Fixtures'));
$locator = new FileLocator([__DIR__.'/../Fixtures']);
$loader = new PhpFileLoader($locator);
$routeCollection = $loader->load('php_dsl_i18n.php');
$expectedCollection = new RouteCollection();
$expectedCollection->add('foo.en', (new Route('/glish/foo'))->setDefaults(array('_locale' => 'en', '_canonical_route' => 'foo')));
$expectedCollection->add('bar.en', (new Route('/glish/bar'))->setDefaults(array('_locale' => 'en', '_canonical_route' => 'bar')));
$expectedCollection->add('baz.en', (new Route('/baz'))->setDefaults(array('_locale' => 'en', '_canonical_route' => 'baz')));
$expectedCollection->add('c_foo.fr', (new Route('/ench/pub/foo'))->setDefaults(array('_locale' => 'fr', '_canonical_route' => 'c_foo')));
$expectedCollection->add('c_bar.fr', (new Route('/ench/pub/bar'))->setDefaults(array('_locale' => 'fr', '_canonical_route' => 'c_bar')));
$expectedCollection->add('foo.en', (new Route('/glish/foo'))->setDefaults(['_locale' => 'en', '_canonical_route' => 'foo']));
$expectedCollection->add('bar.en', (new Route('/glish/bar'))->setDefaults(['_locale' => 'en', '_canonical_route' => 'bar']));
$expectedCollection->add('baz.en', (new Route('/baz'))->setDefaults(['_locale' => 'en', '_canonical_route' => 'baz']));
$expectedCollection->add('c_foo.fr', (new Route('/ench/pub/foo'))->setDefaults(['_locale' => 'fr', '_canonical_route' => 'c_foo']));
$expectedCollection->add('c_bar.fr', (new Route('/ench/pub/bar'))->setDefaults(['_locale' => 'fr', '_canonical_route' => 'c_bar']));
$expectedCollection->addResource(new FileResource(realpath(__DIR__.'/../Fixtures/php_dsl_sub_i18n.php')));
$expectedCollection->addResource(new FileResource(realpath(__DIR__.'/../Fixtures/php_dsl_i18n.php')));

View File

@@ -31,7 +31,7 @@ class XmlFileLoaderTest extends TestCase
public function testLoadWithRoute()
{
$loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
$loader = new XmlFileLoader(new FileLocator([__DIR__.'/../Fixtures']));
$routeCollection = $loader->load('validpattern.xml');
$route = $routeCollection->get('blog_show');
@@ -41,14 +41,14 @@ class XmlFileLoaderTest extends TestCase
$this->assertSame('MyBundle:Blog:show', $route->getDefault('_controller'));
$this->assertSame('\w+', $route->getRequirement('locale'));
$this->assertSame('RouteCompiler', $route->getOption('compiler_class'));
$this->assertEquals(array('GET', 'POST', 'PUT', 'OPTIONS'), $route->getMethods());
$this->assertEquals(array('https'), $route->getSchemes());
$this->assertEquals(['GET', 'POST', 'PUT', 'OPTIONS'], $route->getMethods());
$this->assertEquals(['https'], $route->getSchemes());
$this->assertEquals('context.getMethod() == "GET"', $route->getCondition());
}
public function testLoadWithNamespacePrefix()
{
$loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
$loader = new XmlFileLoader(new FileLocator([__DIR__.'/../Fixtures']));
$routeCollection = $loader->load('namespaceprefix.xml');
$this->assertCount(1, $routeCollection->all(), 'One route is loaded');
@@ -66,7 +66,7 @@ class XmlFileLoaderTest extends TestCase
public function testLoadWithImport()
{
$loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
$loader = new XmlFileLoader(new FileLocator([__DIR__.'/../Fixtures']));
$routeCollection = $loader->load('validresource.xml');
$routes = $routeCollection->all();
@@ -83,9 +83,29 @@ class XmlFileLoaderTest extends TestCase
}
}
public function testUtf8Route()
{
$loader = new XmlFileLoader(new FileLocator([__DIR__.'/../Fixtures/localized']));
$routeCollection = $loader->load('utf8.xml');
$routes = $routeCollection->all();
$this->assertCount(2, $routes, 'Two routes are loaded');
$this->assertContainsOnly('Symfony\Component\Routing\Route', $routes);
$utf8Route = $routeCollection->get('app_utf8');
$this->assertSame('/utf8', $utf8Route->getPath());
$this->assertTrue($utf8Route->getOption('utf8'), 'Must be utf8');
$noUtf8Route = $routeCollection->get('app_no_utf8');
$this->assertSame('/no-utf8', $noUtf8Route->getPath());
$this->assertFalse($noUtf8Route->getOption('utf8'), 'Must not be utf8');
}
public function testLoadLocalized()
{
$loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
$loader = new XmlFileLoader(new FileLocator([__DIR__.'/../Fixtures']));
$routeCollection = $loader->load('localized.xml');
$routes = $routeCollection->all();
@@ -98,7 +118,7 @@ class XmlFileLoaderTest extends TestCase
public function testLocalizedImports()
{
$loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures/localized')));
$loader = new XmlFileLoader(new FileLocator([__DIR__.'/../Fixtures/localized']));
$routeCollection = $loader->load('importer-with-locale.xml');
$routes = $routeCollection->all();
@@ -111,7 +131,7 @@ class XmlFileLoaderTest extends TestCase
public function testLocalizedImportsOfNotLocalizedRoutes()
{
$loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures/localized')));
$loader = new XmlFileLoader(new FileLocator([__DIR__.'/../Fixtures/localized']));
$routeCollection = $loader->load('importer-with-locale-imports-non-localized-route.xml');
$routes = $routeCollection->all();
@@ -128,7 +148,7 @@ class XmlFileLoaderTest extends TestCase
*/
public function testLoadThrowsExceptionWithInvalidFile($filePath)
{
$loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
$loader = new XmlFileLoader(new FileLocator([__DIR__.'/../Fixtures']));
$loader->load($filePath);
}
@@ -138,13 +158,13 @@ class XmlFileLoaderTest extends TestCase
*/
public function testLoadThrowsExceptionWithInvalidFileEvenWithoutSchemaValidation($filePath)
{
$loader = new CustomXmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
$loader = new CustomXmlFileLoader(new FileLocator([__DIR__.'/../Fixtures']));
$loader->load($filePath);
}
public function getPathsToInvalidFiles()
{
return array(array('nonvalidnode.xml'), array('nonvalidroute.xml'), array('nonvalid.xml'), array('missing_id.xml'), array('missing_path.xml'));
return [['nonvalidnode.xml'], ['nonvalidroute.xml'], ['nonvalid.xml'], ['missing_id.xml'], ['missing_path.xml']];
}
/**
@@ -153,13 +173,13 @@ class XmlFileLoaderTest extends TestCase
*/
public function testDocTypeIsNotAllowed()
{
$loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
$loader = new XmlFileLoader(new FileLocator([__DIR__.'/../Fixtures']));
$loader->load('withdoctype.xml');
}
public function testNullValues()
{
$loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
$loader = new XmlFileLoader(new FileLocator([__DIR__.'/../Fixtures']));
$routeCollection = $loader->load('null_values.xml');
$route = $routeCollection->get('blog_show');
@@ -173,12 +193,12 @@ class XmlFileLoaderTest extends TestCase
public function testScalarDataTypeDefaults()
{
$loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
$loader = new XmlFileLoader(new FileLocator([__DIR__.'/../Fixtures']));
$routeCollection = $loader->load('scalar_defaults.xml');
$route = $routeCollection->get('blog');
$this->assertSame(
array(
[
'_controller' => 'AcmeBlogBundle:Blog:index',
'slug' => null,
'published' => true,
@@ -189,147 +209,147 @@ class XmlFileLoaderTest extends TestCase
'locked' => false,
'foo' => null,
'bar' => null,
),
],
$route->getDefaults()
);
}
public function testListDefaults()
{
$loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
$loader = new XmlFileLoader(new FileLocator([__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'),
),
'values' => [true, 1, 3.5, 'foo'],
],
$route->getDefaults()
);
}
public function testListInListDefaults()
{
$loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
$loader = new XmlFileLoader(new FileLocator([__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')),
),
'values' => [[true, 1, 3.5, 'foo']],
],
$route->getDefaults()
);
}
public function testListInMapDefaults()
{
$loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
$loader = new XmlFileLoader(new FileLocator([__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')),
),
'values' => ['list' => [true, 1, 3.5, 'foo']],
],
$route->getDefaults()
);
}
public function testMapDefaults()
{
$loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
$loader = new XmlFileLoader(new FileLocator([__DIR__.'/../Fixtures']));
$routeCollection = $loader->load('map_defaults.xml');
$route = $routeCollection->get('blog');
$this->assertSame(
array(
[
'_controller' => 'AcmeBlogBundle:Blog:index',
'values' => array(
'values' => [
'public' => true,
'page' => 1,
'price' => 3.5,
'title' => 'foo',
),
),
],
],
$route->getDefaults()
);
}
public function testMapInListDefaults()
{
$loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
$loader = new XmlFileLoader(new FileLocator([__DIR__.'/../Fixtures']));
$routeCollection = $loader->load('map_in_list_defaults.xml');
$route = $routeCollection->get('blog');
$this->assertSame(
array(
[
'_controller' => 'AcmeBlogBundle:Blog:index',
'values' => array(array(
'values' => [[
'public' => true,
'page' => 1,
'price' => 3.5,
'title' => 'foo',
)),
),
]],
],
$route->getDefaults()
);
}
public function testMapInMapDefaults()
{
$loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
$loader = new XmlFileLoader(new FileLocator([__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(
'values' => ['map' => [
'public' => true,
'page' => 1,
'price' => 3.5,
'title' => 'foo',
)),
),
]],
],
$route->getDefaults()
);
}
public function testNullValuesInList()
{
$loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
$loader = new XmlFileLoader(new FileLocator([__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'));
$this->assertSame([null, null, null, null, null, null], $route->getDefault('list'));
}
public function testNullValuesInMap()
{
$loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
$loader = new XmlFileLoader(new FileLocator([__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')));
$loader = new XmlFileLoader(new FileLocator([__DIR__.'/../Fixtures/controller']));
$routeCollection = $loader->load('routing.xml');
$route = $routeCollection->get('app_homepage');
@@ -339,7 +359,7 @@ class XmlFileLoaderTest extends TestCase
public function testLoadRouteWithoutControllerAttribute()
{
$loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures/controller')));
$loader = new XmlFileLoader(new FileLocator([__DIR__.'/../Fixtures/controller']));
$routeCollection = $loader->load('routing.xml');
$route = $routeCollection->get('app_logout');
@@ -349,7 +369,7 @@ class XmlFileLoaderTest extends TestCase
public function testLoadRouteWithControllerSetInDefaults()
{
$loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures/controller')));
$loader = new XmlFileLoader(new FileLocator([__DIR__.'/../Fixtures/controller']));
$routeCollection = $loader->load('routing.xml');
$route = $routeCollection->get('app_blog');
@@ -363,7 +383,7 @@ class XmlFileLoaderTest extends TestCase
*/
public function testOverrideControllerInDefaults()
{
$loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures/controller')));
$loader = new XmlFileLoader(new FileLocator([__DIR__.'/../Fixtures/controller']));
$loader->load('override_defaults.xml');
}
@@ -372,7 +392,7 @@ class XmlFileLoaderTest extends TestCase
*/
public function testImportRouteWithController($file)
{
$loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures/controller')));
$loader = new XmlFileLoader(new FileLocator([__DIR__.'/../Fixtures/controller']));
$routeCollection = $loader->load($file);
$route = $routeCollection->get('app_homepage');
@@ -387,8 +407,8 @@ class XmlFileLoaderTest extends TestCase
public function provideFilesImportingRoutesWithControllers()
{
yield array('import_controller.xml');
yield array('import__controller.xml');
yield ['import_controller.xml'];
yield ['import__controller.xml'];
}
/**
@@ -397,13 +417,13 @@ class XmlFileLoaderTest extends TestCase
*/
public function testImportWithOverriddenController()
{
$loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures/controller')));
$loader = new XmlFileLoader(new FileLocator([__DIR__.'/../Fixtures/controller']));
$loader->load('import_override_defaults.xml');
}
public function testImportRouteWithGlobMatchingSingleFile()
{
$loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures/glob')));
$loader = new XmlFileLoader(new FileLocator([__DIR__.'/../Fixtures/glob']));
$routeCollection = $loader->load('import_single.xml');
$route = $routeCollection->get('bar_route');
@@ -412,7 +432,7 @@ class XmlFileLoaderTest extends TestCase
public function testImportRouteWithGlobMatchingMultipleFiles()
{
$loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures/glob')));
$loader = new XmlFileLoader(new FileLocator([__DIR__.'/../Fixtures/glob']));
$routeCollection = $loader->load('import_multiple.xml');
$route = $routeCollection->get('bar_route');
@@ -424,7 +444,7 @@ class XmlFileLoaderTest extends TestCase
public function testImportRouteWithNamePrefix()
{
$loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures/import_with_name_prefix')));
$loader = new XmlFileLoader(new FileLocator([__DIR__.'/../Fixtures/import_with_name_prefix']));
$routeCollection = $loader->load('routing.xml');
$this->assertNotNull($routeCollection->get('app_blog'));
@@ -435,7 +455,7 @@ class XmlFileLoaderTest extends TestCase
public function testImportRouteWithNoTrailingSlash()
{
$loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures/import_with_no_trailing_slash')));
$loader = new XmlFileLoader(new FileLocator([__DIR__.'/../Fixtures/import_with_no_trailing_slash']));
$routeCollection = $loader->load('routing.xml');
$this->assertEquals('/slash/', $routeCollection->get('a_app_homepage')->getPath());

View File

@@ -33,11 +33,11 @@ class YamlFileLoaderTest extends TestCase
public function testLoadDoesNothingIfEmpty()
{
$loader = new YamlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
$loader = new YamlFileLoader(new FileLocator([__DIR__.'/../Fixtures']));
$collection = $loader->load('empty.yml');
$this->assertEquals(array(), $collection->all());
$this->assertEquals(array(new FileResource(realpath(__DIR__.'/../Fixtures/empty.yml'))), $collection->getResources());
$this->assertEquals([], $collection->all());
$this->assertEquals([new FileResource(realpath(__DIR__.'/../Fixtures/empty.yml'))], $collection->getResources());
}
/**
@@ -46,26 +46,26 @@ class YamlFileLoaderTest extends TestCase
*/
public function testLoadThrowsExceptionWithInvalidFile($filePath)
{
$loader = new YamlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
$loader = new YamlFileLoader(new FileLocator([__DIR__.'/../Fixtures']));
$loader->load($filePath);
}
public function getPathsToInvalidFiles()
{
return array(
array('nonvalid.yml'),
array('nonvalid2.yml'),
array('incomplete.yml'),
array('nonvalidkeys.yml'),
array('nonesense_resource_plus_path.yml'),
array('nonesense_type_without_resource.yml'),
array('bad_format.yml'),
);
return [
['nonvalid.yml'],
['nonvalid2.yml'],
['incomplete.yml'],
['nonvalidkeys.yml'],
['nonesense_resource_plus_path.yml'],
['nonesense_type_without_resource.yml'],
['bad_format.yml'],
];
}
public function testLoadSpecialRouteName()
{
$loader = new YamlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
$loader = new YamlFileLoader(new FileLocator([__DIR__.'/../Fixtures']));
$routeCollection = $loader->load('special_route_name.yml');
$route = $routeCollection->get('#$péß^a|');
@@ -75,7 +75,7 @@ class YamlFileLoaderTest extends TestCase
public function testLoadWithRoute()
{
$loader = new YamlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
$loader = new YamlFileLoader(new FileLocator([__DIR__.'/../Fixtures']));
$routeCollection = $loader->load('validpattern.yml');
$route = $routeCollection->get('blog_show');
@@ -85,14 +85,14 @@ class YamlFileLoaderTest extends TestCase
$this->assertSame('MyBundle:Blog:show', $route->getDefault('_controller'));
$this->assertSame('\w+', $route->getRequirement('locale'));
$this->assertSame('RouteCompiler', $route->getOption('compiler_class'));
$this->assertEquals(array('GET', 'POST', 'PUT', 'OPTIONS'), $route->getMethods());
$this->assertEquals(array('https'), $route->getSchemes());
$this->assertEquals(['GET', 'POST', 'PUT', 'OPTIONS'], $route->getMethods());
$this->assertEquals(['https'], $route->getSchemes());
$this->assertEquals('context.getMethod() == "GET"', $route->getCondition());
}
public function testLoadWithResource()
{
$loader = new YamlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
$loader = new YamlFileLoader(new FileLocator([__DIR__.'/../Fixtures']));
$routeCollection = $loader->load('validresource.yml');
$routes = $routeCollection->all();
@@ -111,7 +111,7 @@ class YamlFileLoaderTest extends TestCase
public function testLoadRouteWithControllerAttribute()
{
$loader = new YamlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures/controller')));
$loader = new YamlFileLoader(new FileLocator([__DIR__.'/../Fixtures/controller']));
$routeCollection = $loader->load('routing.yml');
$route = $routeCollection->get('app_homepage');
@@ -121,7 +121,7 @@ class YamlFileLoaderTest extends TestCase
public function testLoadRouteWithoutControllerAttribute()
{
$loader = new YamlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures/controller')));
$loader = new YamlFileLoader(new FileLocator([__DIR__.'/../Fixtures/controller']));
$routeCollection = $loader->load('routing.yml');
$route = $routeCollection->get('app_logout');
@@ -131,7 +131,7 @@ class YamlFileLoaderTest extends TestCase
public function testLoadRouteWithControllerSetInDefaults()
{
$loader = new YamlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures/controller')));
$loader = new YamlFileLoader(new FileLocator([__DIR__.'/../Fixtures/controller']));
$routeCollection = $loader->load('routing.yml');
$route = $routeCollection->get('app_blog');
@@ -145,7 +145,7 @@ class YamlFileLoaderTest extends TestCase
*/
public function testOverrideControllerInDefaults()
{
$loader = new YamlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures/controller')));
$loader = new YamlFileLoader(new FileLocator([__DIR__.'/../Fixtures/controller']));
$loader->load('override_defaults.yml');
}
@@ -154,7 +154,7 @@ class YamlFileLoaderTest extends TestCase
*/
public function testImportRouteWithController($file)
{
$loader = new YamlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures/controller')));
$loader = new YamlFileLoader(new FileLocator([__DIR__.'/../Fixtures/controller']));
$routeCollection = $loader->load($file);
$route = $routeCollection->get('app_homepage');
@@ -169,8 +169,8 @@ class YamlFileLoaderTest extends TestCase
public function provideFilesImportingRoutesWithControllers()
{
yield array('import_controller.yml');
yield array('import__controller.yml');
yield ['import_controller.yml'];
yield ['import__controller.yml'];
}
/**
@@ -179,13 +179,13 @@ class YamlFileLoaderTest extends TestCase
*/
public function testImportWithOverriddenController()
{
$loader = new YamlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures/controller')));
$loader = new YamlFileLoader(new FileLocator([__DIR__.'/../Fixtures/controller']));
$loader->load('import_override_defaults.yml');
}
public function testImportRouteWithGlobMatchingSingleFile()
{
$loader = new YamlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures/glob')));
$loader = new YamlFileLoader(new FileLocator([__DIR__.'/../Fixtures/glob']));
$routeCollection = $loader->load('import_single.yml');
$route = $routeCollection->get('bar_route');
@@ -194,7 +194,7 @@ class YamlFileLoaderTest extends TestCase
public function testImportRouteWithGlobMatchingMultipleFiles()
{
$loader = new YamlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures/glob')));
$loader = new YamlFileLoader(new FileLocator([__DIR__.'/../Fixtures/glob']));
$routeCollection = $loader->load('import_multiple.yml');
$route = $routeCollection->get('bar_route');
@@ -206,7 +206,7 @@ class YamlFileLoaderTest extends TestCase
public function testImportRouteWithNamePrefix()
{
$loader = new YamlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures/import_with_name_prefix')));
$loader = new YamlFileLoader(new FileLocator([__DIR__.'/../Fixtures/import_with_name_prefix']));
$routeCollection = $loader->load('routing.yml');
$this->assertNotNull($routeCollection->get('app_blog'));
@@ -224,7 +224,7 @@ class YamlFileLoaderTest extends TestCase
public function testLoadingLocalizedRoute()
{
$loader = new YamlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures/localized')));
$loader = new YamlFileLoader(new FileLocator([__DIR__.'/../Fixtures/localized']));
$routes = $loader->load('localized-route.yml');
$this->assertCount(3, $routes);
@@ -232,7 +232,7 @@ class YamlFileLoaderTest extends TestCase
public function testImportingRoutesFromDefinition()
{
$loader = new YamlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures/localized')));
$loader = new YamlFileLoader(new FileLocator([__DIR__.'/../Fixtures/localized']));
$routes = $loader->load('importing-localized-route.yml');
$this->assertCount(3, $routes);
@@ -243,7 +243,7 @@ class YamlFileLoaderTest extends TestCase
public function testImportingRoutesWithLocales()
{
$loader = new YamlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures/localized')));
$loader = new YamlFileLoader(new FileLocator([__DIR__.'/../Fixtures/localized']));
$routes = $loader->load('importer-with-locale.yml');
$this->assertCount(2, $routes);
@@ -253,7 +253,7 @@ class YamlFileLoaderTest extends TestCase
public function testImportingNonLocalizedRoutesWithLocales()
{
$loader = new YamlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures/localized')));
$loader = new YamlFileLoader(new FileLocator([__DIR__.'/../Fixtures/localized']));
$routes = $loader->load('importer-with-locale-imports-non-localized-route.yml');
$this->assertCount(2, $routes);
@@ -263,7 +263,7 @@ class YamlFileLoaderTest extends TestCase
public function testImportingRoutesWithOfficialLocales()
{
$loader = new YamlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures/localized')));
$loader = new YamlFileLoader(new FileLocator([__DIR__.'/../Fixtures/localized']));
$routes = $loader->load('officially_formatted_locales.yml');
$this->assertCount(3, $routes);
@@ -274,21 +274,21 @@ class YamlFileLoaderTest extends TestCase
public function testImportingRoutesFromDefinitionMissingLocalePrefix()
{
$loader = new YamlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures/localized')));
$loader = new YamlFileLoader(new FileLocator([__DIR__.'/../Fixtures/localized']));
$this->expectException(\InvalidArgumentException::class);
$loader->load('missing-locale-in-importer.yml');
}
public function testImportingRouteWithoutPathOrLocales()
{
$loader = new YamlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures/localized')));
$loader = new YamlFileLoader(new FileLocator([__DIR__.'/../Fixtures/localized']));
$this->expectException(\InvalidArgumentException::class);
$loader->load('route-without-path-or-locales.yml');
}
public function testImportingWithControllerDefault()
{
$loader = new YamlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures/localized')));
$loader = new YamlFileLoader(new FileLocator([__DIR__.'/../Fixtures/localized']));
$routes = $loader->load('importer-with-controller-default.yml');
$this->assertCount(3, $routes);
$this->assertEquals('DefaultController::defaultAction', $routes->get('home.en')->getDefault('_controller'));
@@ -298,7 +298,7 @@ class YamlFileLoaderTest extends TestCase
public function testImportRouteWithNoTrailingSlash()
{
$loader = new YamlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures/import_with_no_trailing_slash')));
$loader = new YamlFileLoader(new FileLocator([__DIR__.'/../Fixtures/import_with_no_trailing_slash']));
$routeCollection = $loader->load('routing.yml');
$this->assertEquals('/slash/', $routeCollection->get('a_app_homepage')->getPath());
@@ -311,7 +311,7 @@ class YamlFileLoaderTest extends TestCase
*/
public function testRequirementsWithoutPlaceholderName()
{
$loader = new YamlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
$loader = new YamlFileLoader(new FileLocator([__DIR__.'/../Fixtures']));
$loader->load('requirements_without_placeholder_name.yml');
}
}

View File

@@ -25,11 +25,11 @@ class DumpedRedirectableUrlMatcherTest extends RedirectableUrlMatcherTest
$class = 'DumpedRedirectableUrlMatcher'.++$i;
$dumper = new PhpMatcherDumper($routes);
eval('?>'.$dumper->dump(array('class' => $class, 'base_class' => 'Symfony\Component\Routing\Tests\Matcher\TestDumpedRedirectableUrlMatcher')));
eval('?>'.$dumper->dump(['class' => $class, 'base_class' => 'Symfony\Component\Routing\Tests\Matcher\TestDumpedRedirectableUrlMatcher']));
return $this->getMockBuilder($class)
->setConstructorArgs(array($context ?: new RequestContext()))
->setMethods(array('redirect'))
->setConstructorArgs([$context ?: new RequestContext()])
->setMethods(['redirect'])
->getMock();
}
}
@@ -38,6 +38,6 @@ class TestDumpedRedirectableUrlMatcher extends UrlMatcher implements Redirectabl
{
public function redirect($path, $route, $scheme = null)
{
return array();
return [];
}
}

View File

@@ -23,7 +23,7 @@ class DumpedUrlMatcherTest extends UrlMatcherTest
$class = 'DumpedUrlMatcher'.++$i;
$dumper = new PhpMatcherDumper($routes);
eval('?>'.$dumper->dump(array('class' => $class)));
eval('?>'.$dumper->dump(['class' => $class]));
return new $class($context ?: new RequestContext());
}

View File

@@ -54,11 +54,11 @@ class PhpMatcherDumperTest extends TestCase
$class = $this->generateDumpedMatcher($collection, true);
$matcher = $this->getMockBuilder($class)
->setMethods(array('redirect'))
->setConstructorArgs(array(new RequestContext()))
->setMethods(['redirect'])
->setConstructorArgs([new RequestContext()])
->getMock();
$matcher->expects($this->once())->method('redirect')->with('/foo%3Abar/', 'foo')->willReturn(array());
$matcher->expects($this->once())->method('redirect')->with('/foo%3Abar/', 'foo')->willReturn([]);
$matcher->match('/foo%3Abar');
}
@@ -66,7 +66,7 @@ class PhpMatcherDumperTest extends TestCase
/**
* @dataProvider getRouteCollections
*/
public function testDump(RouteCollection $collection, $fixture, $options = array())
public function testDump(RouteCollection $collection, $fixture, $options = [])
{
$basePath = __DIR__.'/../../Fixtures/dumper/';
@@ -85,28 +85,28 @@ class PhpMatcherDumperTest extends TestCase
// defaults and requirements
$collection->add('foo', new Route(
'/foo/{bar}',
array('def' => 'test'),
array('bar' => 'baz|symfony')
['def' => 'test'],
['bar' => 'baz|symfony']
));
// method requirement
$collection->add('bar', new Route(
'/bar/{foo}',
array(),
array(),
array(),
[],
[],
[],
'',
array(),
array('GET', 'head')
[],
['GET', 'head']
));
// GET method requirement automatically adds HEAD as valid
$collection->add('barhead', new Route(
'/barhead/{foo}',
array(),
array(),
array(),
[],
[],
[],
'',
array(),
array('GET')
[],
['GET']
));
// simple
$collection->add('baz', new Route(
@@ -127,33 +127,33 @@ class PhpMatcherDumperTest extends TestCase
// trailing slash and method
$collection->add('baz5', new Route(
'/test/{foo}/',
array(),
array(),
array(),
[],
[],
[],
'',
array(),
array('post')
[],
['post']
));
// complex name
$collection->add('baz.baz6', new Route(
'/test/{foo}/',
array(),
array(),
array(),
[],
[],
[],
'',
array(),
array('put')
[],
['put']
));
// defaults without variable
$collection->add('foofoo', new Route(
'/foofoo',
array('def' => 'test')
['def' => 'test']
));
// pattern with quotes
$collection->add('quoter', new Route(
'/{quoter}',
array(),
array('quoter' => '[\']+')
[],
['quoter' => '[\']+']
));
// space in pattern
$collection->add('space', new Route(
@@ -168,7 +168,7 @@ class PhpMatcherDumperTest extends TestCase
$collection1->addPrefix('/b\'b');
$collection2 = new RouteCollection();
$collection2->addCollection($collection1);
$collection2->add('overridden', new Route('/{var}', array(), array('var' => '.*')));
$collection2->add('overridden', new Route('/{var}', [], ['var' => '.*']));
$collection1 = new RouteCollection();
$collection1->add('foo2', new Route('/{foo1}'));
$collection1->add('bar2', new Route('/{bar1}'));
@@ -180,7 +180,7 @@ class PhpMatcherDumperTest extends TestCase
// overridden through addCollection() and multiple sub-collections with no own prefix
$collection1 = new RouteCollection();
$collection1->add('overridden2', new Route('/old'));
$collection1->add('helloWorld', new Route('/hello/{who}', array('who' => 'World!')));
$collection1->add('helloWorld', new Route('/hello/{who}', ['who' => 'World!']));
$collection2 = new RouteCollection();
$collection3 = new RouteCollection();
$collection3->add('overridden2', new Route('/new'));
@@ -211,22 +211,22 @@ class PhpMatcherDumperTest extends TestCase
$collection1 = new RouteCollection();
$route1 = new Route('/route1', array(), array(), array(), 'a.example.com');
$route1 = new Route('/route1', [], [], [], 'a.example.com');
$collection1->add('route1', $route1);
$route2 = new Route('/c2/route2', array(), array(), array(), 'a.example.com');
$route2 = new Route('/c2/route2', [], [], [], 'a.example.com');
$collection1->add('route2', $route2);
$route3 = new Route('/c2/route3', array(), array(), array(), 'b.example.com');
$route3 = new Route('/c2/route3', [], [], [], 'b.example.com');
$collection1->add('route3', $route3);
$route4 = new Route('/route4', array(), array(), array(), 'a.example.com');
$route4 = new Route('/route4', [], [], [], 'a.example.com');
$collection1->add('route4', $route4);
$route5 = new Route('/route5', array(), array(), array(), 'c.example.com');
$route5 = new Route('/route5', [], [], [], 'c.example.com');
$collection1->add('route5', $route5);
$route6 = new Route('/route6', array(), array(), array(), null);
$route6 = new Route('/route6', [], [], [], null);
$collection1->add('route6', $route6);
$collection->addCollection($collection1);
@@ -235,25 +235,25 @@ class PhpMatcherDumperTest extends TestCase
$collection1 = new RouteCollection();
$route11 = new Route('/route11', array(), array(), array(), '{var1}.example.com');
$route11 = new Route('/route11', [], [], [], '{var1}.example.com');
$collection1->add('route11', $route11);
$route12 = new Route('/route12', array('var1' => 'val'), array(), array(), '{var1}.example.com');
$route12 = new Route('/route12', ['var1' => 'val'], [], [], '{var1}.example.com');
$collection1->add('route12', $route12);
$route13 = new Route('/route13/{name}', array(), array(), array(), '{var1}.example.com');
$route13 = new Route('/route13/{name}', [], [], [], '{var1}.example.com');
$collection1->add('route13', $route13);
$route14 = new Route('/route14/{name}', array('var1' => 'val'), array(), array(), '{var1}.example.com');
$route14 = new Route('/route14/{name}', ['var1' => 'val'], [], [], '{var1}.example.com');
$collection1->add('route14', $route14);
$route15 = new Route('/route15/{name}', array(), array(), array(), 'c.example.com');
$route15 = new Route('/route15/{name}', [], [], [], 'c.example.com');
$collection1->add('route15', $route15);
$route16 = new Route('/route16/{name}', array('var1' => 'val'), array(), array(), null);
$route16 = new Route('/route16/{name}', ['var1' => 'val'], [], [], null);
$collection1->add('route16', $route16);
$route17 = new Route('/route17', array(), array(), array(), null);
$route17 = new Route('/route17', [], [], [], null);
$collection1->add('route17', $route17);
$collection->addCollection($collection1);
@@ -279,21 +279,21 @@ class PhpMatcherDumperTest extends TestCase
// force HTTPS redirection
$redirectCollection->add('secure', new Route(
'/secure',
array(),
array(),
array(),
[],
[],
[],
'',
array('https')
['https']
));
// force HTTP redirection
$redirectCollection->add('nonsecure', new Route(
'/nonsecure',
array(),
array(),
array(),
[],
[],
[],
'',
array('http')
['http']
));
/* test case 3 */
@@ -310,57 +310,57 @@ class PhpMatcherDumperTest extends TestCase
$headMatchCasesCollection = new RouteCollection();
$headMatchCasesCollection->add('just_head', new Route(
'/just_head',
array(),
array(),
array(),
[],
[],
[],
'',
array(),
array('HEAD')
[],
['HEAD']
));
$headMatchCasesCollection->add('head_and_get', new Route(
'/head_and_get',
array(),
array(),
array(),
[],
[],
[],
'',
array(),
array('HEAD', 'GET')
[],
['HEAD', 'GET']
));
$headMatchCasesCollection->add('get_and_head', new Route(
'/get_and_head',
array(),
array(),
array(),
[],
[],
[],
'',
array(),
array('GET', 'HEAD')
[],
['GET', 'HEAD']
));
$headMatchCasesCollection->add('post_and_head', new Route(
'/post_and_head',
array(),
array(),
array(),
[],
[],
[],
'',
array(),
array('POST', 'HEAD')
[],
['POST', 'HEAD']
));
$headMatchCasesCollection->add('put_and_post', new Route(
'/put_and_post',
array(),
array(),
array(),
[],
[],
[],
'',
array(),
array('PUT', 'POST')
[],
['PUT', 'POST']
));
$headMatchCasesCollection->add('put_and_get_and_head', new Route(
'/put_and_post',
array(),
array(),
array(),
[],
[],
[],
'',
array(),
array('PUT', 'GET', 'HEAD')
[],
['PUT', 'GET', 'HEAD']
));
/* test case 5 */
@@ -383,29 +383,29 @@ class PhpMatcherDumperTest extends TestCase
/* test case 6 & 7 */
$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_trailing_slash_no_methods', new Route('/trailing/simple/no-methods/', [], [], [], '', [], []));
$trailingSlashCollection->add('simple_trailing_slash_GET_method', new Route('/trailing/simple/get-method/', [], [], [], '', [], ['GET']));
$trailingSlashCollection->add('simple_trailing_slash_HEAD_method', new Route('/trailing/simple/head-method/', [], [], [], '', [], ['HEAD']));
$trailingSlashCollection->add('simple_trailing_slash_POST_method', new Route('/trailing/simple/post-method/', [], [], [], '', [], ['POST']));
$trailingSlashCollection->add('regex_trailing_slash_no_methods', new Route('/trailing/regex/no-methods/{param}/', [], [], [], '', [], []));
$trailingSlashCollection->add('regex_trailing_slash_GET_method', new Route('/trailing/regex/get-method/{param}/', [], [], [], '', [], ['GET']));
$trailingSlashCollection->add('regex_trailing_slash_HEAD_method', new Route('/trailing/regex/head-method/{param}/', [], [], [], '', [], ['HEAD']));
$trailingSlashCollection->add('regex_trailing_slash_POST_method', new Route('/trailing/regex/post-method/{param}/', [], [], [], '', [], ['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')));
$trailingSlashCollection->add('simple_not_trailing_slash_no_methods', new Route('/not-trailing/simple/no-methods', [], [], [], '', [], []));
$trailingSlashCollection->add('simple_not_trailing_slash_GET_method', new Route('/not-trailing/simple/get-method', [], [], [], '', [], ['GET']));
$trailingSlashCollection->add('simple_not_trailing_slash_HEAD_method', new Route('/not-trailing/simple/head-method', [], [], [], '', [], ['HEAD']));
$trailingSlashCollection->add('simple_not_trailing_slash_POST_method', new Route('/not-trailing/simple/post-method', [], [], [], '', [], ['POST']));
$trailingSlashCollection->add('regex_not_trailing_slash_no_methods', new Route('/not-trailing/regex/no-methods/{param}', [], [], [], '', [], []));
$trailingSlashCollection->add('regex_not_trailing_slash_GET_method', new Route('/not-trailing/regex/get-method/{param}', [], [], [], '', [], ['GET']));
$trailingSlashCollection->add('regex_not_trailing_slash_HEAD_method', new Route('/not-trailing/regex/head-method/{param}', [], [], [], '', [], ['HEAD']));
$trailingSlashCollection->add('regex_not_trailing_slash_POST_method', new Route('/not-trailing/regex/post-method/{param}', [], [], [], '', [], ['POST']));
/* test case 8 */
$unicodeCollection = new RouteCollection();
$unicodeCollection->add('a', new Route('/{a}', array(), array('a' => 'a'), array('utf8' => false)));
$unicodeCollection->add('b', new Route('/{a}', array(), array('a' => '.'), array('utf8' => true)));
$unicodeCollection->add('c', new Route('/{a}', array(), array('a' => '.'), array('utf8' => false)));
$unicodeCollection->add('a', new Route('/{a}', [], ['a' => 'a'], ['utf8' => false]));
$unicodeCollection->add('b', new Route('/{a}', [], ['a' => '.'], ['utf8' => true]));
$unicodeCollection->add('c', new Route('/{a}', [], ['a' => '.'], ['utf8' => false]));
/* test case 9 */
$hostTreeCollection = new RouteCollection();
@@ -424,21 +424,21 @@ class PhpMatcherDumperTest extends TestCase
$demoCollection = new RouteCollection();
$demoCollection->add('a', new Route('/admin/post/'));
$demoCollection->add('b', new Route('/admin/post/new'));
$demoCollection->add('c', (new Route('/admin/post/{id}'))->setRequirements(array('id' => '\d+')));
$demoCollection->add('d', (new Route('/admin/post/{id}/edit'))->setRequirements(array('id' => '\d+')));
$demoCollection->add('e', (new Route('/admin/post/{id}/delete'))->setRequirements(array('id' => '\d+')));
$demoCollection->add('c', (new Route('/admin/post/{id}'))->setRequirements(['id' => '\d+']));
$demoCollection->add('d', (new Route('/admin/post/{id}/edit'))->setRequirements(['id' => '\d+']));
$demoCollection->add('e', (new Route('/admin/post/{id}/delete'))->setRequirements(['id' => '\d+']));
$demoCollection->add('f', new Route('/blog/'));
$demoCollection->add('g', new Route('/blog/rss.xml'));
$demoCollection->add('h', (new Route('/blog/page/{page}'))->setRequirements(array('id' => '\d+')));
$demoCollection->add('i', (new Route('/blog/posts/{page}'))->setRequirements(array('id' => '\d+')));
$demoCollection->add('j', (new Route('/blog/comments/{id}/new'))->setRequirements(array('id' => '\d+')));
$demoCollection->add('h', (new Route('/blog/page/{page}'))->setRequirements(['id' => '\d+']));
$demoCollection->add('i', (new Route('/blog/posts/{page}'))->setRequirements(['id' => '\d+']));
$demoCollection->add('j', (new Route('/blog/comments/{id}/new'))->setRequirements(['id' => '\d+']));
$demoCollection->add('k', new Route('/blog/search'));
$demoCollection->add('l', new Route('/login'));
$demoCollection->add('m', new Route('/logout'));
$demoCollection->addPrefix('/{_locale}');
$demoCollection->add('n', new Route('/{_locale}'));
$demoCollection->addRequirements(array('_locale' => 'en|fr'));
$demoCollection->addDefaults(array('_locale' => 'en'));
$demoCollection->addRequirements(['_locale' => 'en|fr']);
$demoCollection->addDefaults(['_locale' => 'en']);
/* test case 12 */
$suffixCollection = new RouteCollection();
@@ -454,27 +454,27 @@ class PhpMatcherDumperTest extends TestCase
$hostCollection->add('r1', (new Route('abc{foo}'))->setHost('{foo}.exampple.com'));
$hostCollection->add('r2', (new Route('abc{foo}'))->setHost('{foo}.exampple.com'));
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')),
array($unicodeCollection, 'url_matcher8.php', array()),
array($hostTreeCollection, 'url_matcher9.php', array()),
array($chunkedCollection, 'url_matcher10.php', array()),
array($demoCollection, 'url_matcher11.php', array('base_class' => 'Symfony\Component\Routing\Tests\Fixtures\RedirectableUrlMatcher')),
array($suffixCollection, 'url_matcher12.php', array()),
array($hostCollection, 'url_matcher13.php', array()),
);
return [
[new RouteCollection(), 'url_matcher0.php', []],
[$collection, 'url_matcher1.php', []],
[$redirectCollection, 'url_matcher2.php', ['base_class' => 'Symfony\Component\Routing\Tests\Fixtures\RedirectableUrlMatcher']],
[$rootprefixCollection, 'url_matcher3.php', []],
[$headMatchCasesCollection, 'url_matcher4.php', []],
[$groupOptimisedCollection, 'url_matcher5.php', ['base_class' => 'Symfony\Component\Routing\Tests\Fixtures\RedirectableUrlMatcher']],
[$trailingSlashCollection, 'url_matcher6.php', []],
[$trailingSlashCollection, 'url_matcher7.php', ['base_class' => 'Symfony\Component\Routing\Tests\Fixtures\RedirectableUrlMatcher']],
[$unicodeCollection, 'url_matcher8.php', []],
[$hostTreeCollection, 'url_matcher9.php', []],
[$chunkedCollection, 'url_matcher10.php', []],
[$demoCollection, 'url_matcher11.php', ['base_class' => 'Symfony\Component\Routing\Tests\Fixtures\RedirectableUrlMatcher']],
[$suffixCollection, 'url_matcher12.php', []],
[$hostCollection, 'url_matcher13.php', []],
];
}
private function generateDumpedMatcher(RouteCollection $collection, $redirectableStub = false)
{
$options = array('class' => $this->matcherClass);
$options = ['class' => $this->matcherClass];
if ($redirectableStub) {
$options['base_class'] = '\Symfony\Component\Routing\Tests\Matcher\Dumper\RedirectableUrlMatcherStub';
@@ -496,7 +496,7 @@ class PhpMatcherDumperTest extends TestCase
public function testGenerateDumperMatcherWithObject()
{
$routeCollection = new RouteCollection();
$routeCollection->add('_', new Route('/', array(new \stdClass())));
$routeCollection->add('_', new Route('/', [new \stdClass()]));
$dumper = new PhpMatcherDumper($routeCollection);
$dumper->dump();
}

View File

@@ -18,7 +18,7 @@ class StaticPrefixCollectionTest extends TestCase
foreach ($routes as $route) {
list($path, $name) = $route;
$staticPrefix = (new Route($path))->compile()->getStaticPrefix();
$collection->addRoute($staticPrefix, array($name));
$collection->addRoute($staticPrefix, [$name]);
}
$dumped = $this->dumpCollection($collection);
@@ -27,52 +27,52 @@ class StaticPrefixCollectionTest extends TestCase
public function routeProvider()
{
return array(
'Simple - not nested' => array(
array(
array('/', 'root'),
array('/prefix/segment/', 'prefix_segment'),
array('/leading/segment/', 'leading_segment'),
),
return [
'Simple - not nested' => [
[
['/', 'root'],
['/prefix/segment/', 'prefix_segment'],
['/leading/segment/', 'leading_segment'],
],
<<<EOF
root
prefix_segment
leading_segment
EOF
),
'Nested - small group' => array(
array(
array('/', 'root'),
array('/prefix/segment/aa', 'prefix_segment'),
array('/prefix/segment/bb', 'leading_segment'),
),
],
'Nested - small group' => [
[
['/', 'root'],
['/prefix/segment/aa', 'prefix_segment'],
['/prefix/segment/bb', 'leading_segment'],
],
<<<EOF
root
/prefix/segment/
-> prefix_segment
-> leading_segment
EOF
),
'Nested - contains item at intersection' => array(
array(
array('/', 'root'),
array('/prefix/segment/', 'prefix_segment'),
array('/prefix/segment/bb', 'leading_segment'),
),
],
'Nested - contains item at intersection' => [
[
['/', 'root'],
['/prefix/segment/', 'prefix_segment'],
['/prefix/segment/bb', 'leading_segment'],
],
<<<EOF
root
/prefix/segment/
-> prefix_segment
-> 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'),
),
],
'Simple one level nesting' => [
[
['/', 'root'],
['/group/segment/', 'nested_segment'],
['/group/thing/', 'some_segment'],
['/group/other/', 'other_segment'],
],
<<<EOF
root
/group/
@@ -80,17 +80,17 @@ root
-> some_segment
-> 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'),
),
],
'Retain matching order with groups' => [
[
['/group/aa/', 'aa'],
['/group/bb/', 'bb'],
['/group/cc/', 'cc'],
['/(.*)', 'root'],
['/group/dd/', 'dd'],
['/group/ee/', 'ee'],
['/group/ff/', 'ff'],
],
<<<EOF
/group/
-> aa
@@ -102,21 +102,21 @@ root
-> ee
-> 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/', 'parent'),
array('/prefixed/group/ff/', 'ff'),
array('/aaa/222/', 'second_aaa'),
array('/aaa/333/', 'third_aaa'),
),
],
'Retain complex matching order with groups at base' => [
[
['/aaa/111/', 'first_aaa'],
['/prefixed/group/aa/', 'aa'],
['/prefixed/group/bb/', 'bb'],
['/prefixed/group/cc/', 'cc'],
['/prefixed/(.*)', 'root'],
['/prefixed/group/dd/', 'dd'],
['/prefixed/group/ee/', 'ee'],
['/prefixed/', 'parent'],
['/prefixed/group/ff/', 'ff'],
['/aaa/222/', 'second_aaa'],
['/aaa/333/', 'third_aaa'],
],
<<<EOF
/aaa/
-> first_aaa
@@ -134,17 +134,17 @@ EOF
-> -> ff
-> parent
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'),
),
'Group regardless of segments' => [
[
['/aaa-111/', 'a1'],
['/aaa-222/', 'a2'],
['/aaa-333/', 'a3'],
['/group-aa/', 'g1'],
['/group-bb/', 'g2'],
['/group-cc/', 'g3'],
],
<<<EOF
/aaa-
-> a1
@@ -155,13 +155,13 @@ EOF
-> g2
-> g3
EOF
),
);
],
];
}
private function dumpCollection(StaticPrefixCollection $collection, $prefix = '')
{
$lines = array();
$lines = [];
foreach ($collection->getRoutes() as $item) {
if ($item instanceof StaticPrefixCollection) {

View File

@@ -23,7 +23,7 @@ class RedirectableUrlMatcherTest extends UrlMatcherTest
$coll->add('foo', new Route('/foo/'));
$matcher = $this->getUrlMatcher($coll);
$matcher->expects($this->once())->method('redirect')->will($this->returnValue(array()));
$matcher->expects($this->once())->method('redirect')->will($this->returnValue([]));
$matcher->match('/foo');
}
@@ -33,7 +33,7 @@ class RedirectableUrlMatcherTest extends UrlMatcherTest
$coll->add('foo', new Route('/foo'));
$matcher = $this->getUrlMatcher($coll);
$matcher->expects($this->once())->method('redirect')->will($this->returnValue(array()));
$matcher->expects($this->once())->method('redirect')->will($this->returnValue([]));
$matcher->match('/foo/');
}
@@ -54,14 +54,14 @@ class RedirectableUrlMatcherTest extends UrlMatcherTest
public function testSchemeRedirectRedirectsToFirstScheme()
{
$coll = new RouteCollection();
$coll->add('foo', new Route('/foo', array(), array(), array(), '', array('FTP', 'HTTPS')));
$coll->add('foo', new Route('/foo', [], [], [], '', ['FTP', 'HTTPS']));
$matcher = $this->getUrlMatcher($coll);
$matcher
->expects($this->once())
->method('redirect')
->with('/foo', 'foo', 'ftp')
->will($this->returnValue(array('_route' => 'foo')))
->will($this->returnValue(['_route' => 'foo']))
;
$matcher->match('/foo');
}
@@ -69,7 +69,7 @@ class RedirectableUrlMatcherTest extends UrlMatcherTest
public function testNoSchemaRedirectIfOneOfMultipleSchemesMatches()
{
$coll = new RouteCollection();
$coll->add('foo', new Route('/foo', array(), array(), array(), '', array('https', 'http')));
$coll->add('foo', new Route('/foo', [], [], [], '', ['https', 'http']));
$matcher = $this->getUrlMatcher($coll);
$matcher
@@ -81,30 +81,30 @@ class RedirectableUrlMatcherTest extends UrlMatcherTest
public function testSchemeRedirectWithParams()
{
$coll = new RouteCollection();
$coll->add('foo', new Route('/foo/{bar}', array(), array(), array(), '', array('https')));
$coll->add('foo', new Route('/foo/{bar}', [], [], [], '', ['https']));
$matcher = $this->getUrlMatcher($coll);
$matcher
->expects($this->once())
->method('redirect')
->with('/foo/baz', 'foo', 'https')
->will($this->returnValue(array('redirect' => 'value')))
->will($this->returnValue(['redirect' => 'value']))
;
$this->assertEquals(array('_route' => 'foo', 'bar' => 'baz', 'redirect' => 'value'), $matcher->match('/foo/baz'));
$this->assertEquals(['_route' => 'foo', 'bar' => 'baz', 'redirect' => 'value'], $matcher->match('/foo/baz'));
}
public function testSchemeRedirectForRoot()
{
$coll = new RouteCollection();
$coll->add('foo', new Route('/', array(), array(), array(), '', array('https')));
$coll->add('foo', new Route('/', [], [], [], '', ['https']));
$matcher = $this->getUrlMatcher($coll);
$matcher
->expects($this->once())
->method('redirect')
->with('/', 'foo', 'https')
->will($this->returnValue(array('redirect' => 'value')));
$this->assertEquals(array('_route' => 'foo', 'redirect' => 'value'), $matcher->match('/'));
->will($this->returnValue(['redirect' => 'value']));
$this->assertEquals(['_route' => 'foo', 'redirect' => 'value'], $matcher->match('/'));
}
public function testSlashRedirectWithParams()
@@ -117,9 +117,9 @@ class RedirectableUrlMatcherTest extends UrlMatcherTest
->expects($this->once())
->method('redirect')
->with('/foo/baz/', 'foo', null)
->will($this->returnValue(array('redirect' => 'value')))
->will($this->returnValue(['redirect' => 'value']))
;
$this->assertEquals(array('_route' => 'foo', 'bar' => 'baz', 'redirect' => 'value'), $matcher->match('/foo/baz'));
$this->assertEquals(['_route' => 'foo', 'bar' => 'baz', 'redirect' => 'value'], $matcher->match('/foo/baz'));
}
public function testRedirectPreservesUrlEncoding()
@@ -128,17 +128,17 @@ class RedirectableUrlMatcherTest extends UrlMatcherTest
$coll->add('foo', new Route('/foo:bar/'));
$matcher = $this->getUrlMatcher($coll);
$matcher->expects($this->once())->method('redirect')->with('/foo%3Abar/')->willReturn(array());
$matcher->expects($this->once())->method('redirect')->with('/foo%3Abar/')->willReturn([]);
$matcher->match('/foo%3Abar');
}
public function testSchemeRequirement()
{
$coll = new RouteCollection();
$coll->add('foo', new Route('/foo', array(), array(), array(), '', array('https')));
$coll->add('foo', new Route('/foo', [], [], [], '', ['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'));
$matcher->expects($this->once())->method('redirect')->with('/foo', 'foo', 'https')->willReturn([]);
$this->assertSame(['_route' => 'foo'], $matcher->match('/foo'));
}
public function testFallbackPage()
@@ -148,47 +148,69 @@ class RedirectableUrlMatcherTest extends UrlMatcherTest
$coll->add('bar', new Route('/{name}'));
$matcher = $this->getUrlMatcher($coll);
$matcher->expects($this->once())->method('redirect')->with('/foo/', 'foo')->will($this->returnValue(array('_route' => 'foo')));
$this->assertSame(array('_route' => 'foo'), $matcher->match('/foo'));
$matcher->expects($this->once())->method('redirect')->with('/foo/', 'foo')->will($this->returnValue(['_route' => 'foo']));
$this->assertSame(['_route' => 'foo'], $matcher->match('/foo'));
$coll = new RouteCollection();
$coll->add('foo', new Route('/foo'));
$coll->add('bar', new Route('/{name}/'));
$matcher = $this->getUrlMatcher($coll);
$matcher->expects($this->once())->method('redirect')->with('/foo', 'foo')->will($this->returnValue(array('_route' => 'foo')));
$this->assertSame(array('_route' => 'foo'), $matcher->match('/foo/'));
$matcher->expects($this->once())->method('redirect')->with('/foo', 'foo')->will($this->returnValue(['_route' => 'foo']));
$this->assertSame(['_route' => 'foo'], $matcher->match('/foo/'));
}
public function testMissingTrailingSlashAndScheme()
{
$coll = new RouteCollection();
$coll->add('foo', (new Route('/foo/'))->setSchemes(array('https')));
$coll->add('foo', (new Route('/foo/'))->setSchemes(['https']));
$matcher = $this->getUrlMatcher($coll);
$matcher->expects($this->once())->method('redirect')->with('/foo/', 'foo', 'https')->will($this->returnValue(array()));
$matcher->expects($this->once())->method('redirect')->with('/foo/', 'foo', 'https')->will($this->returnValue([]));
$matcher->match('/foo');
}
public function testSlashAndVerbPrecedenceWithRedirection()
{
$coll = new RouteCollection();
$coll->add('a', new Route('/api/customers/{customerId}/contactpersons', array(), array(), array(), '', array(), array('post')));
$coll->add('b', new Route('/api/customers/{customerId}/contactpersons/', array(), array(), array(), '', array(), array('get')));
$coll->add('a', new Route('/api/customers/{customerId}/contactpersons', [], [], [], '', [], ['post']));
$coll->add('b', new Route('/api/customers/{customerId}/contactpersons/', [], [], [], '', [], ['get']));
$matcher = $this->getUrlMatcher($coll);
$expected = array(
$expected = [
'_route' => 'b',
'customerId' => '123',
);
];
$this->assertEquals($expected, $matcher->match('/api/customers/123/contactpersons/'));
$matcher->expects($this->once())->method('redirect')->with('/api/customers/123/contactpersons/')->willReturn(array());
$matcher->expects($this->once())->method('redirect')->with('/api/customers/123/contactpersons/')->willReturn([]);
$this->assertEquals($expected, $matcher->match('/api/customers/123/contactpersons'));
}
public function testNonGreedyTrailingRequirement()
{
$coll = new RouteCollection();
$coll->add('a', new Route('/{a}', [], ['a' => '\d+']));
$matcher = $this->getUrlMatcher($coll);
$matcher->expects($this->once())->method('redirect')->with('/123')->willReturn([]);
$this->assertEquals(['_route' => 'a', 'a' => '123'], $matcher->match('/123/'));
}
public function testTrailingRequirementWithDefault_A()
{
$coll = new RouteCollection();
$coll->add('a', new Route('/fr-fr/{a}', ['a' => 'aaa'], ['a' => '.+']));
$matcher = $this->getUrlMatcher($coll);
$matcher->expects($this->once())->method('redirect')->with('/fr-fr')->willReturn([]);
$this->assertEquals(['_route' => 'a', 'a' => 'aaa'], $matcher->match('/fr-fr/'));
}
protected function getUrlMatcher(RouteCollection $routes, RequestContext $context = null)
{
return $this->getMockForAbstractClass('Symfony\Component\Routing\Matcher\RedirectableUrlMatcher', array($routes, $context ?: new RequestContext()));
return $this->getMockForAbstractClass('Symfony\Component\Routing\Matcher\RedirectableUrlMatcher', [$routes, $context ?: new RequestContext()]);
}
}

View File

@@ -23,41 +23,41 @@ class TraceableUrlMatcherTest extends TestCase
public function test()
{
$coll = new RouteCollection();
$coll->add('foo', new Route('/foo', array(), array(), array(), '', array(), array('POST')));
$coll->add('bar', new Route('/bar/{id}', array(), array('id' => '\d+')));
$coll->add('bar1', new Route('/bar/{name}', array(), array('id' => '\w+'), array(), '', array(), array('POST')));
$coll->add('bar2', new Route('/foo', array(), array(), array(), 'baz'));
$coll->add('bar3', new Route('/foo1', array(), array(), array(), 'baz'));
$coll->add('bar4', new Route('/foo2', array(), array(), array(), 'baz', array(), array(), 'context.getMethod() == "GET"'));
$coll->add('foo', new Route('/foo', [], [], [], '', [], ['POST']));
$coll->add('bar', new Route('/bar/{id}', [], ['id' => '\d+']));
$coll->add('bar1', new Route('/bar/{name}', [], ['id' => '\w+'], [], '', [], ['POST']));
$coll->add('bar2', new Route('/foo', [], [], [], 'baz'));
$coll->add('bar3', new Route('/foo1', [], [], [], 'baz'));
$coll->add('bar4', new Route('/foo2', [], [], [], 'baz', [], [], 'context.getMethod() == "GET"'));
$context = new RequestContext();
$context->setHost('baz');
$matcher = new TraceableUrlMatcher($coll, $context);
$traces = $matcher->getTraces('/babar');
$this->assertSame(array(0, 0, 0, 0, 0, 0), $this->getLevels($traces));
$this->assertSame([0, 0, 0, 0, 0, 0], $this->getLevels($traces));
$traces = $matcher->getTraces('/foo');
$this->assertSame(array(1, 0, 0, 2), $this->getLevels($traces));
$this->assertSame([1, 0, 0, 2], $this->getLevels($traces));
$traces = $matcher->getTraces('/bar/12');
$this->assertSame(array(0, 2), $this->getLevels($traces));
$this->assertSame([0, 2], $this->getLevels($traces));
$traces = $matcher->getTraces('/bar/dd');
$this->assertSame(array(0, 1, 1, 0, 0, 0), $this->getLevels($traces));
$this->assertSame([0, 1, 1, 0, 0, 0], $this->getLevels($traces));
$traces = $matcher->getTraces('/foo1');
$this->assertSame(array(0, 0, 0, 0, 2), $this->getLevels($traces));
$this->assertSame([0, 0, 0, 0, 2], $this->getLevels($traces));
$context->setMethod('POST');
$traces = $matcher->getTraces('/foo');
$this->assertSame(array(2), $this->getLevels($traces));
$this->assertSame([2], $this->getLevels($traces));
$traces = $matcher->getTraces('/bar/dd');
$this->assertSame(array(0, 1, 2), $this->getLevels($traces));
$this->assertSame([0, 1, 2], $this->getLevels($traces));
$traces = $matcher->getTraces('/foo2');
$this->assertSame(array(0, 0, 0, 0, 0, 1), $this->getLevels($traces));
$this->assertSame([0, 0, 0, 0, 0, 1], $this->getLevels($traces));
}
public function testMatchRouteOnMultipleHosts()
@@ -65,17 +65,17 @@ class TraceableUrlMatcherTest extends TestCase
$routes = new RouteCollection();
$routes->add('first', new Route(
'/mypath/',
array('_controller' => 'MainBundle:Info:first'),
array(),
array(),
['_controller' => 'MainBundle:Info:first'],
[],
[],
'some.example.com'
));
$routes->add('second', new Route(
'/mypath/',
array('_controller' => 'MainBundle:Info:second'),
array(),
array(),
['_controller' => 'MainBundle:Info:second'],
[],
[],
'another.example.com'
));
@@ -86,14 +86,14 @@ class TraceableUrlMatcherTest extends TestCase
$traces = $matcher->getTraces('/mypath/');
$this->assertSame(
array(TraceableUrlMatcher::ROUTE_ALMOST_MATCHES, TraceableUrlMatcher::ROUTE_ALMOST_MATCHES),
[TraceableUrlMatcher::ROUTE_ALMOST_MATCHES, TraceableUrlMatcher::ROUTE_ALMOST_MATCHES],
$this->getLevels($traces)
);
}
public function getLevels($traces)
{
$levels = array();
$levels = [];
foreach ($traces as $trace) {
$levels[] = $trace['level'];
}
@@ -104,7 +104,7 @@ class TraceableUrlMatcherTest extends TestCase
public function testRoutesWithConditions()
{
$routes = new RouteCollection();
$routes->add('foo', new Route('/foo', array(), array(), array(), 'baz', array(), array(), "request.headers.get('User-Agent') matches '/firefox/i'"));
$routes->add('foo', new Route('/foo', [], [], [], 'baz', [], [], "request.headers.get('User-Agent') matches '/firefox/i'"));
$context = new RequestContext();
$context->setHost('baz');
@@ -115,7 +115,7 @@ class TraceableUrlMatcherTest extends TestCase
$traces = $matcher->getTracesForRequest($notMatchingRequest);
$this->assertEquals("Condition \"request.headers.get('User-Agent') matches '/firefox/i'\" does not evaluate to \"true\"", $traces[0]['log']);
$matchingRequest = Request::create('/foo', 'GET', array(), array(), array(), array('HTTP_USER_AGENT' => 'Firefox'));
$matchingRequest = Request::create('/foo', 'GET', [], [], [], ['HTTP_USER_AGENT' => 'Firefox']);
$traces = $matcher->getTracesForRequest($matchingRequest);
$this->assertEquals('Route matches!', $traces[0]['log']);
}

View File

@@ -33,7 +33,7 @@ class UrlMatcherTest extends TestCase
public function testMethodNotAllowed()
{
$coll = new RouteCollection();
$coll->add('foo', new Route('/foo', array(), array(), array(), '', array(), array('post')));
$coll->add('foo', new Route('/foo', [], [], [], '', [], ['post']));
$matcher = $this->getUrlMatcher($coll);
@@ -41,14 +41,14 @@ class UrlMatcherTest extends TestCase
$matcher->match('/foo');
$this->fail();
} catch (MethodNotAllowedException $e) {
$this->assertEquals(array('POST'), $e->getAllowedMethods());
$this->assertEquals(['POST'], $e->getAllowedMethods());
}
}
public function testMethodNotAllowedOnRoot()
{
$coll = new RouteCollection();
$coll->add('foo', new Route('/', array(), array(), array(), '', array(), array('GET')));
$coll->add('foo', new Route('/', [], [], [], '', [], ['GET']));
$matcher = $this->getUrlMatcher($coll, new RequestContext('', 'POST'));
@@ -56,14 +56,14 @@ class UrlMatcherTest extends TestCase
$matcher->match('/');
$this->fail();
} catch (MethodNotAllowedException $e) {
$this->assertEquals(array('GET'), $e->getAllowedMethods());
$this->assertEquals(['GET'], $e->getAllowedMethods());
}
}
public function testHeadAllowedWhenRequirementContainsGet()
{
$coll = new RouteCollection();
$coll->add('foo', new Route('/foo', array(), array(), array(), '', array(), array('get')));
$coll->add('foo', new Route('/foo', [], [], [], '', [], ['get']));
$matcher = $this->getUrlMatcher($coll, new RequestContext('', 'head'));
$this->assertInternalType('array', $matcher->match('/foo'));
@@ -72,8 +72,8 @@ class UrlMatcherTest extends TestCase
public function testMethodNotAllowedAggregatesAllowedMethods()
{
$coll = new RouteCollection();
$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')));
$coll->add('foo1', new Route('/foo', [], [], [], '', [], ['post']));
$coll->add('foo2', new Route('/foo', [], [], [], '', [], ['put', 'delete']));
$matcher = $this->getUrlMatcher($coll);
@@ -81,13 +81,12 @@ class UrlMatcherTest extends TestCase
$matcher->match('/foo');
$this->fail();
} catch (MethodNotAllowedException $e) {
$this->assertEquals(array('POST', 'PUT', 'DELETE'), $e->getAllowedMethods());
$this->assertEquals(['POST', 'PUT', 'DELETE'], $e->getAllowedMethods());
}
}
public function testMatch()
public function testPatternMatchAndParameterReturn()
{
// test the patterns are matched and parameters are returned
$collection = new RouteCollection();
$collection->add('foo', new Route('/foo/{bar}'));
$matcher = $this->getUrlMatcher($collection);
@@ -96,17 +95,24 @@ class UrlMatcherTest extends TestCase
$this->fail();
} catch (ResourceNotFoundException $e) {
}
$this->assertEquals(array('_route' => 'foo', 'bar' => 'baz'), $matcher->match('/foo/baz'));
$this->assertEquals(['_route' => 'foo', 'bar' => 'baz'], $matcher->match('/foo/baz'));
}
public function testDefaultsAreMerged()
{
// test that defaults are merged
$collection = new RouteCollection();
$collection->add('foo', new Route('/foo/{bar}', array('def' => 'test')));
$collection->add('foo', new Route('/foo/{bar}', ['def' => 'test']));
$matcher = $this->getUrlMatcher($collection);
$this->assertEquals(array('_route' => 'foo', 'bar' => 'baz', 'def' => 'test'), $matcher->match('/foo/baz'));
$this->assertEquals(['_route' => 'foo', 'bar' => 'baz', 'def' => 'test'], $matcher->match('/foo/baz'));
}
public function testMethodIsIgnoredIfNoMethodGiven()
{
// 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')));
$collection->add('foo', new Route('/foo', [], [], [], '', [], ['get', 'head']));
$matcher = $this->getUrlMatcher($collection);
$this->assertInternalType('array', $matcher->match('/foo'));
@@ -123,27 +129,31 @@ class UrlMatcherTest extends TestCase
$this->assertInternalType('array', $matcher->match('/foo'));
$matcher = $this->getUrlMatcher($collection, new RequestContext('', 'head'));
$this->assertInternalType('array', $matcher->match('/foo'));
}
// route with an optional variable as the first segment
public function testRouteWithOptionalVariableAsFirstSegment()
{
$collection = new RouteCollection();
$collection->add('bar', new Route('/{bar}/foo', array('bar' => 'bar'), array('bar' => 'foo|bar')));
$collection->add('bar', new Route('/{bar}/foo', ['bar' => 'bar'], ['bar' => 'foo|bar']));
$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'));
$this->assertEquals(['_route' => 'bar', 'bar' => 'bar'], $matcher->match('/bar/foo'));
$this->assertEquals(['_route' => 'bar', 'bar' => 'foo'], $matcher->match('/foo/foo'));
$collection = new RouteCollection();
$collection->add('bar', new Route('/{bar}', array('bar' => 'bar'), array('bar' => 'foo|bar')));
$collection->add('bar', new Route('/{bar}', ['bar' => 'bar'], ['bar' => 'foo|bar']));
$matcher = $this->getUrlMatcher($collection);
$this->assertEquals(array('_route' => 'bar', 'bar' => 'foo'), $matcher->match('/foo'));
$this->assertEquals(array('_route' => 'bar', 'bar' => 'bar'), $matcher->match('/'));
$this->assertEquals(['_route' => 'bar', 'bar' => 'foo'], $matcher->match('/foo'));
$this->assertEquals(['_route' => 'bar', 'bar' => 'bar'], $matcher->match('/'));
}
// route with only optional variables
public function testRouteWithOnlyOptionalVariables()
{
$collection = new RouteCollection();
$collection->add('bar', new Route('/{foo}/{bar}', array('foo' => 'foo', 'bar' => 'bar'), array()));
$collection->add('bar', new Route('/{foo}/{bar}', ['foo' => 'foo', 'bar' => 'bar'], []));
$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'));
$this->assertEquals(['_route' => 'bar', 'foo' => 'foo', 'bar' => 'bar'], $matcher->match('/'));
$this->assertEquals(['_route' => 'bar', 'foo' => 'a', 'bar' => 'bar'], $matcher->match('/a'));
$this->assertEquals(['_route' => 'bar', 'foo' => 'a', 'bar' => 'b'], $matcher->match('/a/b'));
}
public function testMatchWithPrefixes()
@@ -154,7 +164,7 @@ class UrlMatcherTest extends TestCase
$collection->addPrefix('/a');
$matcher = $this->getUrlMatcher($collection);
$this->assertEquals(array('_route' => 'foo', 'foo' => 'foo'), $matcher->match('/a/b/foo'));
$this->assertEquals(['_route' => 'foo', 'foo' => 'foo'], $matcher->match('/a/b/foo'));
}
public function testMatchWithDynamicPrefix()
@@ -165,7 +175,7 @@ class UrlMatcherTest extends TestCase
$collection->addPrefix('/{_locale}');
$matcher = $this->getUrlMatcher($collection);
$this->assertEquals(array('_locale' => 'fr', '_route' => 'foo', 'foo' => 'foo'), $matcher->match('/fr/b/foo'));
$this->assertEquals(['_locale' => 'fr', '_route' => 'foo', 'foo' => 'foo'], $matcher->match('/fr/b/foo'));
}
public function testMatchSpecialRouteName()
@@ -174,7 +184,7 @@ class UrlMatcherTest extends TestCase
$collection->add('$péß^a|', new Route('/bar'));
$matcher = $this->getUrlMatcher($collection);
$this->assertEquals(array('_route' => '$péß^a|'), $matcher->match('/bar'));
$this->assertEquals(['_route' => '$péß^a|'], $matcher->match('/bar'));
}
/**
@@ -193,20 +203,20 @@ class UrlMatcherTest extends TestCase
{
$collection = new RouteCollection();
$chars = '!"$%éà &\'()*+,./:;<=>@ABCDEFGHIJKLMNOPQRSTUVWXYZ\\[]^_`abcdefghijklmnopqrstuvwxyz{|}~-';
$collection->add('foo', new Route('/{foo}/bar', array(), array('foo' => '['.preg_quote($chars).']+'), array('utf8' => true)));
$collection->add('foo', new Route('/{foo}/bar', [], ['foo' => '['.preg_quote($chars).']+'], ['utf8' => true]));
$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'));
$this->assertEquals(['_route' => 'foo', 'foo' => $chars], $matcher->match('/'.rawurlencode($chars).'/bar'));
$this->assertEquals(['_route' => 'foo', 'foo' => $chars], $matcher->match('/'.strtr($chars, ['%' => '%25']).'/bar'));
}
public function testMatchWithDotMetacharacterInRequirements()
{
$collection = new RouteCollection();
$collection->add('foo', new Route('/{foo}/bar', array(), array('foo' => '.+')));
$collection->add('foo', new Route('/{foo}/bar', [], ['foo' => '.+']));
$matcher = $this->getUrlMatcher($collection);
$this->assertEquals(array('_route' => 'foo', 'foo' => "\n"), $matcher->match('/'.urlencode("\n").'/bar'), 'linefeed character is matched');
$this->assertEquals(['_route' => 'foo', 'foo' => "\n"], $matcher->match('/'.urlencode("\n").'/bar'), 'linefeed character is matched');
}
public function testMatchOverriddenRoute()
@@ -221,9 +231,9 @@ class UrlMatcherTest extends TestCase
$matcher = $this->getUrlMatcher($collection);
$this->assertEquals(array('_route' => 'foo'), $matcher->match('/foo1'));
$this->assertEquals(['_route' => 'foo'], $matcher->match('/foo1'));
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Routing\Exception\ResourceNotFoundException');
$this->assertEquals(array(), $matcher->match('/foo'));
$this->assertEquals([], $matcher->match('/foo'));
}
public function testMatchRegression()
@@ -233,7 +243,7 @@ class UrlMatcherTest extends TestCase
$coll->add('bar', new Route('/foo/bar/{foo}'));
$matcher = $this->getUrlMatcher($coll);
$this->assertEquals(array('foo' => 'bar', '_route' => 'bar'), $matcher->match('/foo/bar/bar'));
$this->assertEquals(['foo' => 'bar', '_route' => 'bar'], $matcher->match('/foo/bar/bar'));
$collection = new RouteCollection();
$collection->add('foo', new Route('/{bar}'));
@@ -260,36 +270,36 @@ class UrlMatcherTest extends TestCase
public function testDefaultRequirementForOptionalVariables()
{
$coll = new RouteCollection();
$coll->add('test', new Route('/{page}.{_format}', array('page' => 'index', '_format' => 'html')));
$coll->add('test', new Route('/{page}.{_format}', ['page' => 'index', '_format' => 'html']));
$matcher = $this->getUrlMatcher($coll);
$this->assertEquals(array('page' => 'my-page', '_format' => 'xml', '_route' => 'test'), $matcher->match('/my-page.xml'));
$this->assertEquals(['page' => 'my-page', '_format' => 'xml', '_route' => 'test'], $matcher->match('/my-page.xml'));
}
public function testMatchingIsEager()
{
$coll = new RouteCollection();
$coll->add('test', new Route('/{foo}-{bar}-', array(), array('foo' => '.+', 'bar' => '.+')));
$coll->add('test', new Route('/{foo}-{bar}-', [], ['foo' => '.+', 'bar' => '.+']));
$matcher = $this->getUrlMatcher($coll);
$this->assertEquals(array('foo' => 'text1-text2-text3', 'bar' => 'text4', '_route' => 'test'), $matcher->match('/text1-text2-text3-text4-'));
$this->assertEquals(['foo' => 'text1-text2-text3', 'bar' => 'text4', '_route' => 'test'], $matcher->match('/text1-text2-text3-text4-'));
}
public function testAdjacentVariables()
{
$coll = new RouteCollection();
$coll->add('test', new Route('/{w}{x}{y}{z}.{_format}', array('z' => 'default-z', '_format' => 'html'), array('y' => 'y|Y')));
$coll->add('test', new Route('/{w}{x}{y}{z}.{_format}', ['z' => 'default-z', '_format' => 'html'], ['y' => 'y|Y']));
$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.
$this->assertEquals(array('w' => 'wwwww', 'x' => 'x', 'y' => 'Y', 'z' => 'Z', '_format' => 'xml', '_route' => 'test'), $matcher->match('/wwwwwxYZ.xml'));
$this->assertEquals(['w' => 'wwwww', 'x' => 'x', 'y' => 'Y', 'z' => 'Z', '_format' => 'xml', '_route' => 'test'], $matcher->match('/wwwwwxYZ.xml'));
// As 'y' has custom requirement and can only be of value 'y|Y', it will leave 'ZZZ' to variable z.
// So with carefully chosen requirements adjacent variables, can be useful.
$this->assertEquals(array('w' => 'wwwww', 'x' => 'x', 'y' => 'y', 'z' => 'ZZZ', '_format' => 'html', '_route' => 'test'), $matcher->match('/wwwwwxyZZZ'));
$this->assertEquals(['w' => 'wwwww', 'x' => 'x', 'y' => 'y', 'z' => 'ZZZ', '_format' => 'html', '_route' => 'test'], $matcher->match('/wwwwwxyZZZ'));
// 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->assertEquals(['w' => 'wwwww', 'x' => 'x', 'y' => 'y', 'z' => 'default-z', '_format' => 'html', '_route' => 'test'], $matcher->match('/wwwwwxy'));
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('Symfony\Component\Routing\Exception\ResourceNotFoundException');
$matcher->match('/wxy.html');
@@ -298,11 +308,11 @@ class UrlMatcherTest extends TestCase
public function testOptionalVariableWithNoRealSeparator()
{
$coll = new RouteCollection();
$coll->add('test', new Route('/get{what}', array('what' => 'All')));
$coll->add('test', new Route('/get{what}', ['what' => 'All']));
$matcher = $this->getUrlMatcher($coll);
$this->assertEquals(array('what' => 'All', '_route' => 'test'), $matcher->match('/get'));
$this->assertEquals(array('what' => 'Sites', '_route' => 'test'), $matcher->match('/getSites'));
$this->assertEquals(['what' => 'All', '_route' => 'test'], $matcher->match('/get'));
$this->assertEquals(['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.
@@ -316,7 +326,7 @@ class UrlMatcherTest extends TestCase
$coll->add('test', new Route('/get{what}Suffix'));
$matcher = $this->getUrlMatcher($coll);
$this->assertEquals(array('what' => 'Sites', '_route' => 'test'), $matcher->match('/getSitesSuffix'));
$this->assertEquals(['what' => 'Sites', '_route' => 'test'], $matcher->match('/getSitesSuffix'));
}
public function testDefaultRequirementOfVariable()
@@ -325,7 +335,7 @@ class UrlMatcherTest extends TestCase
$coll->add('test', new Route('/{page}.{_format}'));
$matcher = $this->getUrlMatcher($coll);
$this->assertEquals(array('page' => 'index', '_format' => 'mobile.html', '_route' => 'test'), $matcher->match('/index.mobile.html'));
$this->assertEquals(['page' => 'index', '_format' => 'mobile.html', '_route' => 'test'], $matcher->match('/index.mobile.html'));
}
/**
@@ -346,7 +356,7 @@ class UrlMatcherTest extends TestCase
public function testDefaultRequirementOfVariableDisallowsNextSeparator()
{
$coll = new RouteCollection();
$coll->add('test', new Route('/{page}.{_format}', array(), array('_format' => 'html|xml')));
$coll->add('test', new Route('/{page}.{_format}', [], ['_format' => 'html|xml']));
$matcher = $this->getUrlMatcher($coll);
$matcher->match('/do.t.html');
@@ -410,7 +420,7 @@ class UrlMatcherTest extends TestCase
public function testSchemeRequirement()
{
$coll = new RouteCollection();
$coll->add('foo', new Route('/foo', array(), array(), array(), '', array('https')));
$coll->add('foo', new Route('/foo', [], [], [], '', ['https']));
$matcher = $this->getUrlMatcher($coll);
$matcher->match('/foo');
}
@@ -421,7 +431,7 @@ class UrlMatcherTest extends TestCase
public function testSchemeRequirementForNonSafeMethod()
{
$coll = new RouteCollection();
$coll->add('foo', new Route('/foo', array(), array(), array(), '', array('https')));
$coll->add('foo', new Route('/foo', [], [], [], '', ['https']));
$context = new RequestContext();
$context->setMethod('POST');
@@ -432,10 +442,10 @@ class UrlMatcherTest extends TestCase
public function testSamePathWithDifferentScheme()
{
$coll = new RouteCollection();
$coll->add('https_route', new Route('/', array(), array(), array(), '', array('https')));
$coll->add('http_route', new Route('/', array(), array(), array(), '', array('http')));
$coll->add('https_route', new Route('/', [], [], [], '', ['https']));
$coll->add('http_route', new Route('/', [], [], [], '', ['http']));
$matcher = $this->getUrlMatcher($coll);
$this->assertEquals(array('_route' => 'http_route'), $matcher->match('/'));
$this->assertEquals(['_route' => 'http_route'], $matcher->match('/'));
}
/**
@@ -461,7 +471,7 @@ class UrlMatcherTest extends TestCase
$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'));
$this->assertEquals(['bar' => 'bar', '_route' => 'foo'], $matcher->match('/foo/bar'));
}
public function testDecodeOnce()
@@ -470,7 +480,7 @@ class UrlMatcherTest extends TestCase
$coll->add('foo', new Route('/foo/{foo}'));
$matcher = $this->getUrlMatcher($coll);
$this->assertEquals(array('foo' => 'bar%23', '_route' => 'foo'), $matcher->match('/foo/bar%2523'));
$this->assertEquals(['foo' => 'bar%23', '_route' => 'foo'], $matcher->match('/foo/bar%2523'));
}
public function testCannotRelyOnPrefix()
@@ -486,30 +496,165 @@ class UrlMatcherTest extends TestCase
$coll->addCollection($subColl);
$matcher = $this->getUrlMatcher($coll);
$this->assertEquals(array('_route' => 'bar'), $matcher->match('/new'));
$this->assertEquals(['_route' => 'bar'], $matcher->match('/new'));
}
public function testWithHost()
{
$coll = new RouteCollection();
$coll->add('foo', new Route('/foo/{foo}', array(), array(), array(), '{locale}.example.com'));
$coll->add('foo', new Route('/foo/{foo}', [], [], [], '{locale}.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'));
$this->assertEquals(['foo' => 'bar', '_route' => 'foo', 'locale' => 'en'], $matcher->match('/foo/bar'));
}
public function testWithHostOnRouteCollection()
{
$coll = new RouteCollection();
$coll->add('foo', new Route('/foo/{foo}'));
$coll->add('bar', new Route('/bar/{foo}', array(), array(), array(), '{locale}.example.net'));
$coll->add('bar', new Route('/bar/{foo}', [], [], [], '{locale}.example.net'));
$coll->setHost('{locale}.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'));
$this->assertEquals(['foo' => 'bar', '_route' => 'foo', 'locale' => 'en'], $matcher->match('/foo/bar'));
$matcher = $this->getUrlMatcher($coll, new RequestContext('', 'GET', 'en.example.com'));
$this->assertEquals(array('foo' => 'bar', '_route' => 'bar', 'locale' => 'en'), $matcher->match('/bar/bar'));
$this->assertEquals(['foo' => 'bar', '_route' => 'bar', 'locale' => 'en'], $matcher->match('/bar/bar'));
}
public function testVariationInTrailingSlashWithHosts()
{
$coll = new RouteCollection();
$coll->add('foo', new Route('/foo/', [], [], [], 'foo.example.com'));
$coll->add('bar', new Route('/foo', [], [], [], 'bar.example.com'));
$matcher = $this->getUrlMatcher($coll, new RequestContext('', 'GET', 'foo.example.com'));
$this->assertEquals(['_route' => 'foo'], $matcher->match('/foo/'));
$matcher = $this->getUrlMatcher($coll, new RequestContext('', 'GET', 'bar.example.com'));
$this->assertEquals(['_route' => 'bar'], $matcher->match('/foo'));
}
public function testVariationInTrailingSlashWithHostsInReverse()
{
// The order should not matter
$coll = new RouteCollection();
$coll->add('bar', new Route('/foo', [], [], [], 'bar.example.com'));
$coll->add('foo', new Route('/foo/', [], [], [], 'foo.example.com'));
$matcher = $this->getUrlMatcher($coll, new RequestContext('', 'GET', 'foo.example.com'));
$this->assertEquals(['_route' => 'foo'], $matcher->match('/foo/'));
$matcher = $this->getUrlMatcher($coll, new RequestContext('', 'GET', 'bar.example.com'));
$this->assertEquals(['_route' => 'bar'], $matcher->match('/foo'));
}
public function testVariationInTrailingSlashWithHostsAndVariable()
{
$coll = new RouteCollection();
$coll->add('foo', new Route('/{foo}/', [], [], [], 'foo.example.com'));
$coll->add('bar', new Route('/{foo}', [], [], [], 'bar.example.com'));
$matcher = $this->getUrlMatcher($coll, new RequestContext('', 'GET', 'foo.example.com'));
$this->assertEquals(['foo' => 'bar', '_route' => 'foo'], $matcher->match('/bar/'));
$matcher = $this->getUrlMatcher($coll, new RequestContext('', 'GET', 'bar.example.com'));
$this->assertEquals(['foo' => 'bar', '_route' => 'bar'], $matcher->match('/bar'));
}
public function testVariationInTrailingSlashWithHostsAndVariableInReverse()
{
// The order should not matter
$coll = new RouteCollection();
$coll->add('bar', new Route('/{foo}', [], [], [], 'bar.example.com'));
$coll->add('foo', new Route('/{foo}/', [], [], [], 'foo.example.com'));
$matcher = $this->getUrlMatcher($coll, new RequestContext('', 'GET', 'foo.example.com'));
$this->assertEquals(['foo' => 'bar', '_route' => 'foo'], $matcher->match('/bar/'));
$matcher = $this->getUrlMatcher($coll, new RequestContext('', 'GET', 'bar.example.com'));
$this->assertEquals(['foo' => 'bar', '_route' => 'bar'], $matcher->match('/bar'));
}
public function testVariationInTrailingSlashWithMethods()
{
$coll = new RouteCollection();
$coll->add('foo', new Route('/foo/', [], [], [], '', [], ['POST']));
$coll->add('bar', new Route('/foo', [], [], [], '', [], ['GET']));
$matcher = $this->getUrlMatcher($coll, new RequestContext('', 'POST'));
$this->assertEquals(['_route' => 'foo'], $matcher->match('/foo/'));
$matcher = $this->getUrlMatcher($coll, new RequestContext('', 'GET'));
$this->assertEquals(['_route' => 'bar'], $matcher->match('/foo'));
}
public function testVariationInTrailingSlashWithMethodsInReverse()
{
// The order should not matter
$coll = new RouteCollection();
$coll->add('bar', new Route('/foo', [], [], [], '', [], ['GET']));
$coll->add('foo', new Route('/foo/', [], [], [], '', [], ['POST']));
$matcher = $this->getUrlMatcher($coll, new RequestContext('', 'POST'));
$this->assertEquals(['_route' => 'foo'], $matcher->match('/foo/'));
$matcher = $this->getUrlMatcher($coll, new RequestContext('', 'GET'));
$this->assertEquals(['_route' => 'bar'], $matcher->match('/foo'));
}
public function testVariableVariationInTrailingSlashWithMethods()
{
$coll = new RouteCollection();
$coll->add('foo', new Route('/{foo}/', [], [], [], '', [], ['POST']));
$coll->add('bar', new Route('/{foo}', [], [], [], '', [], ['GET']));
$matcher = $this->getUrlMatcher($coll, new RequestContext('', 'POST'));
$this->assertEquals(['foo' => 'bar', '_route' => 'foo'], $matcher->match('/bar/'));
$matcher = $this->getUrlMatcher($coll, new RequestContext('', 'GET'));
$this->assertEquals(['foo' => 'bar', '_route' => 'bar'], $matcher->match('/bar'));
}
public function testVariableVariationInTrailingSlashWithMethodsInReverse()
{
// The order should not matter
$coll = new RouteCollection();
$coll->add('bar', new Route('/{foo}', [], [], [], '', [], ['GET']));
$coll->add('foo', new Route('/{foo}/', [], [], [], '', [], ['POST']));
$matcher = $this->getUrlMatcher($coll, new RequestContext('', 'POST'));
$this->assertEquals(['foo' => 'bar', '_route' => 'foo'], $matcher->match('/bar/'));
$matcher = $this->getUrlMatcher($coll, new RequestContext('', 'GET'));
$this->assertEquals(['foo' => 'bar', '_route' => 'bar'], $matcher->match('/bar'));
}
public function testMixOfStaticAndVariableVariationInTrailingSlashWithHosts()
{
$coll = new RouteCollection();
$coll->add('foo', new Route('/foo/', [], [], [], 'foo.example.com'));
$coll->add('bar', new Route('/{foo}', [], [], [], 'bar.example.com'));
$matcher = $this->getUrlMatcher($coll, new RequestContext('', 'GET', 'foo.example.com'));
$this->assertEquals(['_route' => 'foo'], $matcher->match('/foo/'));
$matcher = $this->getUrlMatcher($coll, new RequestContext('', 'GET', 'bar.example.com'));
$this->assertEquals(['foo' => 'bar', '_route' => 'bar'], $matcher->match('/bar'));
}
public function testMixOfStaticAndVariableVariationInTrailingSlashWithMethods()
{
$coll = new RouteCollection();
$coll->add('foo', new Route('/foo/', [], [], [], '', [], ['POST']));
$coll->add('bar', new Route('/{foo}', [], [], [], '', [], ['GET']));
$matcher = $this->getUrlMatcher($coll, new RequestContext('', 'POST'));
$this->assertEquals(['_route' => 'foo'], $matcher->match('/foo/'));
$matcher = $this->getUrlMatcher($coll, new RequestContext('', 'GET'));
$this->assertEquals(['foo' => 'bar', '_route' => 'bar'], $matcher->match('/bar'));
$this->assertEquals(['foo' => 'foo', '_route' => 'bar'], $matcher->match('/foo'));
}
/**
@@ -518,7 +663,7 @@ class UrlMatcherTest extends TestCase
public function testWithOutHostHostDoesNotMatch()
{
$coll = new RouteCollection();
$coll->add('foo', new Route('/foo/{foo}', array(), array(), array(), '{locale}.example.com'));
$coll->add('foo', new Route('/foo/{foo}', [], [], [], '{locale}.example.com'));
$matcher = $this->getUrlMatcher($coll, new RequestContext('', 'GET', 'example.com'));
$matcher->match('/foo/bar');
@@ -530,7 +675,7 @@ class UrlMatcherTest extends TestCase
public function testPathIsCaseSensitive()
{
$coll = new RouteCollection();
$coll->add('foo', new Route('/locale', array(), array('locale' => 'EN|FR|DE')));
$coll->add('foo', new Route('/locale', [], ['locale' => 'EN|FR|DE']));
$matcher = $this->getUrlMatcher($coll);
$matcher->match('/en');
@@ -539,10 +684,10 @@ class UrlMatcherTest extends TestCase
public function testHostIsCaseInsensitive()
{
$coll = new RouteCollection();
$coll->add('foo', new Route('/', array(), array('locale' => 'EN|FR|DE'), array(), '{locale}.example.com'));
$coll->add('foo', new Route('/', [], ['locale' => 'EN|FR|DE'], [], '{locale}.example.com'));
$matcher = $this->getUrlMatcher($coll, new RequestContext('', 'GET', 'en.example.com'));
$this->assertEquals(array('_route' => 'foo', 'locale' => 'en'), $matcher->match('/'));
$this->assertEquals(['_route' => 'foo', 'locale' => 'en'], $matcher->match('/'));
}
/**
@@ -575,9 +720,9 @@ class UrlMatcherTest extends TestCase
$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'));
$this->assertEquals(['_route' => 'a'], $matcher->match('/p/a'));
$this->assertEquals(['_route' => 'baz', 'baz' => 'p'], $matcher->match('/p'));
$this->assertEquals(['_route' => 'buz'], $matcher->match('/prefix/buz'));
}
/**
@@ -586,7 +731,7 @@ class UrlMatcherTest extends TestCase
public function testSchemeAndMethodMismatch()
{
$coll = new RouteCollection();
$coll->add('foo', new Route('/', array(), array(), array(), null, array('https'), array('POST')));
$coll->add('foo', new Route('/', [], [], [], null, ['https'], ['POST']));
$matcher = $this->getUrlMatcher($coll);
$matcher->match('/');
@@ -600,54 +745,54 @@ class UrlMatcherTest extends TestCase
$coll->add('c', new Route('/a{a}'));
$coll->add('d', (new Route('/b{a}'))->setCondition('false'));
$coll->add('e', (new Route('/{b}{a}'))->setCondition('false'));
$coll->add('f', (new Route('/{b}{a}'))->setRequirements(array('b' => 'b')));
$coll->add('f', (new Route('/{b}{a}'))->setRequirements(['b' => 'b']));
$matcher = $this->getUrlMatcher($coll);
$this->assertEquals(array('_route' => 'c', 'a' => 'a'), $matcher->match('/aa'));
$this->assertEquals(array('_route' => 'f', 'b' => 'b', 'a' => 'a'), $matcher->match('/ba'));
$this->assertEquals(['_route' => 'c', 'a' => 'a'], $matcher->match('/aa'));
$this->assertEquals(['_route' => 'f', 'b' => 'b', 'a' => 'a'], $matcher->match('/ba'));
}
public function testUnicodeRoute()
{
$coll = new RouteCollection();
$coll->add('a', new Route('/{a}', array(), array('a' => '.'), array('utf8' => false)));
$coll->add('b', new Route('/{a}', array(), array('a' => '.'), array('utf8' => true)));
$coll->add('a', new Route('/{a}', [], ['a' => '.'], ['utf8' => false]));
$coll->add('b', new Route('/{a}', [], ['a' => '.'], ['utf8' => true]));
$matcher = $this->getUrlMatcher($coll);
$this->assertEquals(array('_route' => 'b', 'a' => 'é'), $matcher->match('/é'));
$this->assertEquals(['_route' => 'b', 'a' => 'é'], $matcher->match('/é'));
}
public function testRequirementWithCapturingGroup()
{
$coll = new RouteCollection();
$coll->add('a', new Route('/{a}/{b}', array(), array('a' => '(a|b)')));
$coll->add('a', new Route('/{a}/{b}', [], ['a' => '(a|b)']));
$matcher = $this->getUrlMatcher($coll);
$this->assertEquals(array('_route' => 'a', 'a' => 'a', 'b' => 'b'), $matcher->match('/a/b'));
$this->assertEquals(['_route' => 'a', 'a' => 'a', 'b' => 'b'], $matcher->match('/a/b'));
}
public function testDotAllWithCatchAll()
{
$coll = new RouteCollection();
$coll->add('a', new Route('/{id}.html', array(), array('id' => '.+')));
$coll->add('b', new Route('/{all}', array(), array('all' => '.+')));
$coll->add('a', new Route('/{id}.html', [], ['id' => '.+']));
$coll->add('b', new Route('/{all}', [], ['all' => '.+']));
$matcher = $this->getUrlMatcher($coll);
$this->assertEquals(array('_route' => 'a', 'id' => 'foo/bar'), $matcher->match('/foo/bar.html'));
$this->assertEquals(['_route' => 'a', 'id' => 'foo/bar'], $matcher->match('/foo/bar.html'));
}
public function testHostPattern()
{
$coll = new RouteCollection();
$coll->add('a', new Route('/{app}/{action}/{unused}', array(), array(), array(), '{host}'));
$coll->add('a', new Route('/{app}/{action}/{unused}', [], [], [], '{host}'));
$expected = array(
$expected = [
'_route' => 'a',
'app' => 'an_app',
'action' => 'an_action',
'unused' => 'unused',
'host' => 'foo',
);
];
$matcher = $this->getUrlMatcher($coll, new RequestContext('', 'GET', 'foo'));
$this->assertEquals($expected, $matcher->match('/an_app/an_action/unused'));
}
@@ -655,8 +800,8 @@ class UrlMatcherTest extends TestCase
public function testUtf8Prefix()
{
$coll = new RouteCollection();
$coll->add('a', new Route('/é{foo}', array(), array(), array('utf8' => true)));
$coll->add('b', new Route('/è{bar}', array(), array(), array('utf8' => true)));
$coll->add('a', new Route('/é{foo}', [], [], ['utf8' => true]));
$coll->add('b', new Route('/è{bar}', [], [], ['utf8' => true]));
$matcher = $this->getUrlMatcher($coll);
$this->assertEquals('a', $matcher->match('/éo')['_route']);
@@ -665,9 +810,9 @@ class UrlMatcherTest extends TestCase
public function testUtf8AndMethodMatching()
{
$coll = new RouteCollection();
$coll->add('a', new Route('/admin/api/list/{shortClassName}/{id}.{_format}', array(), array(), array('utf8' => true), '', array(), array('PUT')));
$coll->add('b', new Route('/admin/api/package.{_format}', array(), array(), array(), '', array(), array('POST')));
$coll->add('c', new Route('/admin/api/package.{_format}', array('_format' => 'json'), array(), array(), '', array(), array('GET')));
$coll->add('a', new Route('/admin/api/list/{shortClassName}/{id}.{_format}', [], [], ['utf8' => true], '', [], ['PUT']));
$coll->add('b', new Route('/admin/api/package.{_format}', [], [], [], '', [], ['POST']));
$coll->add('c', new Route('/admin/api/package.{_format}', ['_format' => 'json'], [], [], '', [], ['GET']));
$matcher = $this->getUrlMatcher($coll);
$this->assertEquals('c', $matcher->match('/admin/api/package.json')['_route']);
@@ -676,7 +821,7 @@ class UrlMatcherTest extends TestCase
public function testHostWithDot()
{
$coll = new RouteCollection();
$coll->add('a', new Route('/foo', array(), array(), array(), 'foo.example.com'));
$coll->add('a', new Route('/foo', [], [], [], 'foo.example.com'));
$coll->add('b', new Route('/bar/{baz}'));
$matcher = $this->getUrlMatcher($coll);
@@ -686,7 +831,7 @@ class UrlMatcherTest extends TestCase
public function testSlashVariant()
{
$coll = new RouteCollection();
$coll->add('a', new Route('/foo/{bar}', array(), array('bar' => '.*')));
$coll->add('a', new Route('/foo/{bar}', [], ['bar' => '.*']));
$matcher = $this->getUrlMatcher($coll);
$this->assertEquals('a', $matcher->match('/foo/')['_route']);
@@ -695,57 +840,103 @@ class UrlMatcherTest extends TestCase
public function testSlashVariant2()
{
$coll = new RouteCollection();
$coll->add('a', new Route('/foo/{bar}/', array(), array('bar' => '.*')));
$coll->add('a', new Route('/foo/{bar}/', [], ['bar' => '.*']));
$matcher = $this->getUrlMatcher($coll);
$this->assertEquals(array('_route' => 'a', 'bar' => 'bar'), $matcher->match('/foo/bar/'));
$this->assertEquals(['_route' => 'a', 'bar' => 'bar'], $matcher->match('/foo/bar/'));
}
public function testSlashWithVerb()
{
$coll = new RouteCollection();
$coll->add('a', new Route('/{foo}', array(), array(), array(), '', array(), array('put', 'delete')));
$coll->add('a', new Route('/{foo}', [], [], [], '', [], ['put', 'delete']));
$coll->add('b', new Route('/bar/'));
$matcher = $this->getUrlMatcher($coll);
$this->assertSame(array('_route' => 'b'), $matcher->match('/bar/'));
$this->assertSame(['_route' => 'b'], $matcher->match('/bar/'));
$coll = new RouteCollection();
$coll->add('a', new Route('/dav/{foo<.*>?}', array(), array(), array(), '', array(), array('GET', 'OPTIONS')));
$coll->add('a', new Route('/dav/{foo}', [], ['foo' => '.*'], [], '', [], ['GET', 'OPTIONS']));
$matcher = $this->getUrlMatcher($coll, new RequestContext('', 'OPTIONS'));
$expected = array(
$expected = [
'_route' => 'a',
'foo' => 'files/bar',
);
'foo' => 'files/bar/',
];
$this->assertEquals($expected, $matcher->match('/dav/files/bar/'));
}
public function testSlashAndVerbPrecedence()
{
$coll = new RouteCollection();
$coll->add('a', new Route('/api/customers/{customerId}/contactpersons/', array(), array(), array(), '', array(), array('post')));
$coll->add('b', new Route('/api/customers/{customerId}/contactpersons', array(), array(), array(), '', array(), array('get')));
$coll->add('a', new Route('/api/customers/{customerId}/contactpersons/', [], [], [], '', [], ['post']));
$coll->add('b', new Route('/api/customers/{customerId}/contactpersons', [], [], [], '', [], ['get']));
$matcher = $this->getUrlMatcher($coll);
$expected = array(
$expected = [
'_route' => 'b',
'customerId' => '123',
);
];
$this->assertEquals($expected, $matcher->match('/api/customers/123/contactpersons'));
$coll = new RouteCollection();
$coll->add('a', new Route('/api/customers/{customerId}/contactpersons/', array(), array(), array(), '', array(), array('get')));
$coll->add('b', new Route('/api/customers/{customerId}/contactpersons', array(), array(), array(), '', array(), array('post')));
$coll->add('a', new Route('/api/customers/{customerId}/contactpersons/', [], [], [], '', [], ['get']));
$coll->add('b', new Route('/api/customers/{customerId}/contactpersons', [], [], [], '', [], ['post']));
$matcher = $this->getUrlMatcher($coll, new RequestContext('', 'POST'));
$expected = array(
$expected = [
'_route' => 'b',
'customerId' => '123',
);
];
$this->assertEquals($expected, $matcher->match('/api/customers/123/contactpersons'));
}
public function testGreedyTrailingRequirement()
{
$coll = new RouteCollection();
$coll->add('a', new Route('/{a}', [], ['a' => '.+']));
$matcher = $this->getUrlMatcher($coll);
$this->assertEquals(['_route' => 'a', 'a' => 'foo'], $matcher->match('/foo'));
$this->assertEquals(['_route' => 'a', 'a' => 'foo/'], $matcher->match('/foo/'));
}
public function testTrailingRequirementWithDefault()
{
$coll = new RouteCollection();
$coll->add('a', new Route('/fr-fr/{a}', ['a' => 'aaa'], ['a' => '.+']));
$coll->add('b', new Route('/en-en/{b}', ['b' => 'bbb'], ['b' => '.*']));
$matcher = $this->getUrlMatcher($coll);
$this->assertEquals(['_route' => 'a', 'a' => 'aaa'], $matcher->match('/fr-fr'));
$this->assertEquals(['_route' => 'a', 'a' => 'AAA'], $matcher->match('/fr-fr/AAA'));
$this->assertEquals(['_route' => 'b', 'b' => 'bbb'], $matcher->match('/en-en'));
$this->assertEquals(['_route' => 'b', 'b' => 'BBB'], $matcher->match('/en-en/BBB'));
}
public function testTrailingRequirementWithDefault_A()
{
$coll = new RouteCollection();
$coll->add('a', new Route('/fr-fr/{a}', ['a' => 'aaa'], ['a' => '.+']));
$matcher = $this->getUrlMatcher($coll);
$this->expectException(ResourceNotFoundException::class);
$matcher->match('/fr-fr/');
}
public function testTrailingRequirementWithDefault_B()
{
$coll = new RouteCollection();
$coll->add('b', new Route('/en-en/{b}', ['b' => 'bbb'], ['b' => '.*']));
$matcher = $this->getUrlMatcher($coll);
$this->assertEquals(['_route' => 'b', 'b' => ''], $matcher->match('/en-en/'));
}
protected function getUrlMatcher(RouteCollection $routes, RequestContext $context = null)
{
return new UrlMatcher($routes, $context ?: new RequestContext());

View File

@@ -68,16 +68,16 @@ class RequestContextTest extends TestCase
public function testGetParameters()
{
$requestContext = new RequestContext();
$this->assertEquals(array(), $requestContext->getParameters());
$this->assertEquals([], $requestContext->getParameters());
$requestContext->setParameters(array('foo' => 'bar'));
$this->assertEquals(array('foo' => 'bar'), $requestContext->getParameters());
$requestContext->setParameters(['foo' => 'bar']);
$this->assertEquals(['foo' => 'bar'], $requestContext->getParameters());
}
public function testHasParameter()
{
$requestContext = new RequestContext();
$requestContext->setParameters(array('foo' => 'bar'));
$requestContext->setParameters(['foo' => 'bar']);
$this->assertTrue($requestContext->hasParameter('foo'));
$this->assertFalse($requestContext->hasParameter('baz'));
@@ -86,7 +86,7 @@ class RequestContextTest extends TestCase
public function testGetParameter()
{
$requestContext = new RequestContext();
$requestContext->setParameters(array('foo' => 'bar'));
$requestContext->setParameters(['foo' => 'bar']);
$this->assertEquals('bar', $requestContext->getParameter('foo'));
$this->assertNull($requestContext->getParameter('baz'));
@@ -154,7 +154,7 @@ class RequestContextTest extends TestCase
$this->assertSame($requestContext, $requestContext->setQueryString('foo=bar'));
$this->assertSame($requestContext, $requestContext->setHttpPort(80));
$this->assertSame($requestContext, $requestContext->setHttpsPort(443));
$this->assertSame($requestContext, $requestContext->setParameters(array()));
$this->assertSame($requestContext, $requestContext->setParameters([]));
$this->assertSame($requestContext, $requestContext->setParameter('foo', 'bar'));
}
}

View File

@@ -68,7 +68,7 @@ class RouteCollectionBuilderTest extends TestCase
public function testImportAddResources()
{
$routeCollectionBuilder = new RouteCollectionBuilder(new YamlFileLoader(new FileLocator(array(__DIR__.'/Fixtures/'))));
$routeCollectionBuilder = new RouteCollectionBuilder(new YamlFileLoader(new FileLocator([__DIR__.'/Fixtures/'])));
$routeCollectionBuilder->import('file_resource.yml');
$routeCollection = $routeCollectionBuilder->build();
@@ -131,13 +131,13 @@ class RouteCollectionBuilderTest extends TestCase
$this->assertCount(5, $actualCollection);
$actualRouteNames = array_keys($actualCollection->all());
$this->assertEquals(array(
$this->assertEquals([
'checkout_route',
'imported_route1',
'imported_route2',
'homepage',
'admin_dashboard',
), $actualRouteNames);
], $actualRouteNames);
// make sure the defaults were set
$checkoutRoute = $actualCollection->get('checkout_route');
@@ -154,18 +154,18 @@ class RouteCollectionBuilderTest extends TestCase
$collectionBuilder->add('/admin', 'AppBundle:Admin:dashboard', 'admin_dashboard');
// add an unnamed route
$collectionBuilder->add('/blogs', 'AppBundle:Blog:list')
->setMethods(array('GET'));
->setMethods(['GET']);
// integer route names are allowed - they don't confuse things
$collectionBuilder->add('/products', 'AppBundle:Product:list', 100);
$actualCollection = $collectionBuilder->build();
$actualRouteNames = array_keys($actualCollection->all());
$this->assertEquals(array(
$this->assertEquals([
'admin_dashboard',
'GET_blogs',
'100',
), $actualRouteNames);
], $actualRouteNames);
}
public function testFlushSetsDetailsOnChildrenRoutes()
@@ -183,8 +183,8 @@ class RouteCollectionBuilderTest extends TestCase
->setOption('fooBar', true)
->setHost('example.com')
->setCondition('request.isSecure()')
->setSchemes(array('https'))
->setMethods(array('POST'));
->setSchemes(['https'])
->setMethods(['POST']);
// a simple route, nothing added to it
$routes->add('/blogs/{id}', 'editAction', 'blog_edit');
@@ -201,8 +201,8 @@ class RouteCollectionBuilderTest extends TestCase
->setDefault('_locale', 'fr')
->setRequirement('_locale', 'fr|en')
->setOption('niceRoute', true)
->setSchemes(array('http'))
->setMethods(array('GET', 'POST'));
->setSchemes(['http'])
->setMethods(['GET', 'POST']);
$collection = $routes->build();
$actualListRoute = $collection->get('blog_list');
@@ -216,8 +216,8 @@ class RouteCollectionBuilderTest extends TestCase
$this->assertTrue($actualListRoute->getOption('fooBar'));
$this->assertEquals('example.com', $actualListRoute->getHost());
$this->assertEquals('request.isSecure()', $actualListRoute->getCondition());
$this->assertEquals(array('https'), $actualListRoute->getSchemes());
$this->assertEquals(array('POST'), $actualListRoute->getMethods());
$this->assertEquals(['https'], $actualListRoute->getSchemes());
$this->assertEquals(['POST'], $actualListRoute->getMethods());
// inherited from the main collection
$this->assertEquals('fr', $actualListRoute->getDefault('_locale'));
$this->assertEquals('fr|en', $actualListRoute->getRequirement('_locale'));
@@ -227,8 +227,8 @@ class RouteCollectionBuilderTest extends TestCase
// inherited from the collection
$this->assertEquals('symfony.com', $actualEditRoute->getHost());
$this->assertEquals('request.query.get("page")==1', $actualEditRoute->getCondition());
$this->assertEquals(array('http'), $actualEditRoute->getSchemes());
$this->assertEquals(array('GET', 'POST'), $actualEditRoute->getMethods());
$this->assertEquals(['http'], $actualEditRoute->getSchemes());
$this->assertEquals(['GET', 'POST'], $actualEditRoute->getMethods());
}
/**
@@ -250,16 +250,16 @@ class RouteCollectionBuilderTest extends TestCase
public function providePrefixTests()
{
$tests = array();
$tests = [];
// empty prefix is of course ok
$tests[] = array('', '/foo', '/foo');
$tests[] = ['', '/foo', '/foo'];
// normal prefix - does not matter if it's a wildcard
$tests[] = array('/{admin}', '/foo', '/{admin}/foo');
$tests[] = ['/{admin}', '/foo', '/{admin}/foo'];
// shows that a prefix will always be given the starting slash
$tests[] = array('0', '/foo', '/0/foo');
$tests[] = ['0', '/foo', '/0/foo'];
// spaces are ok, and double slahses at the end are cleaned
$tests[] = array('/ /', '/foo', '/ /foo');
$tests[] = ['/ /', '/foo', '/ /foo'];
return $tests;
}
@@ -323,10 +323,10 @@ class RouteCollectionBuilderTest extends TestCase
$accountRoutes = $routes->createBuilder();
// route 2
$accountRoutes->add('/dashboard', '')
->setMethods(array('GET'));
->setMethods(['GET']);
// route 3
$accountRoutes->add('/dashboard', '')
->setMethods(array('POST'));
->setMethods(['POST']);
$routes->mount('/admin', $adminRoutes);
$routes->mount('/account', $accountRoutes);
@@ -351,7 +351,7 @@ class RouteCollectionBuilderTest extends TestCase
$loader
->expects($this->any())
->method('load')
->will($this->returnValue(array($firstCollection, $secondCollection)));
->will($this->returnValue([$firstCollection, $secondCollection]));
$routeCollectionBuilder = new RouteCollectionBuilder($loader);
$routeCollectionBuilder->import('/directory/recurse/*', '/other/', 'glob');

View File

@@ -23,7 +23,7 @@ class RouteCollectionTest extends TestCase
$collection = new RouteCollection();
$route = new Route('/foo');
$collection->add('foo', $route);
$this->assertEquals(array('foo' => $route), $collection->all(), '->add() adds a route');
$this->assertEquals(['foo' => $route], $collection->all(), '->add() adds a route');
$this->assertEquals($route, $collection->get('foo'), '->get() returns a route by name');
$this->assertNull($collection->get('bar'), '->get() returns null if a route does not exist');
}
@@ -67,7 +67,7 @@ class RouteCollectionTest extends TestCase
$collection->add('last', $last = new Route('/last'));
$this->assertInstanceOf('\ArrayIterator', $collection->getIterator());
$this->assertSame(array('bar' => $bar, 'foo' => $foo, 'last' => $last), $collection->getIterator()->getArrayCopy());
$this->assertSame(['bar' => $bar, 'foo' => $foo, 'last' => $last], $collection->getIterator()->getArrayCopy());
}
public function testCount()
@@ -98,7 +98,7 @@ class RouteCollectionTest extends TestCase
$collection->addCollection($collection1);
$collection->add('last', $last = new Route('/last'));
$this->assertSame(array('bar' => $bar, 'foo' => $foo, 'grandchild' => $grandchild, 'last' => $last), $collection->all(),
$this->assertSame(['bar' => $bar, 'foo' => $foo, 'grandchild' => $grandchild, 'last' => $last], $collection->all(),
'->addCollection() imports routes of another collection, overrides if necessary and adds them at the end');
}
@@ -109,7 +109,7 @@ class RouteCollectionTest extends TestCase
$collection1 = new RouteCollection();
$collection1->addResource($foo1 = new FileResource(__DIR__.'/Fixtures/foo1.xml'));
$collection->addCollection($collection1);
$this->assertEquals(array($foo, $foo1), $collection->getResources(), '->addCollection() merges resources');
$this->assertEquals([$foo, $foo1], $collection->getResources(), '->addCollection() merges resources');
}
public function testAddDefaultsAndRequirementsAndOptions()
@@ -118,23 +118,23 @@ class RouteCollectionTest extends TestCase
$collection->add('foo', new Route('/{placeholder}'));
$collection1 = new RouteCollection();
$collection1->add('bar', new Route('/{placeholder}',
array('_controller' => 'fixed', 'placeholder' => 'default'), array('placeholder' => '.+'), array('option' => 'value'))
['_controller' => 'fixed', 'placeholder' => 'default'], ['placeholder' => '.+'], ['option' => 'value'])
);
$collection->addCollection($collection1);
$collection->addDefaults(array('placeholder' => 'new-default'));
$this->assertEquals(array('placeholder' => 'new-default'), $collection->get('foo')->getDefaults(), '->addDefaults() adds defaults to all routes');
$this->assertEquals(array('_controller' => 'fixed', 'placeholder' => 'new-default'), $collection->get('bar')->getDefaults(),
$collection->addDefaults(['placeholder' => 'new-default']);
$this->assertEquals(['placeholder' => 'new-default'], $collection->get('foo')->getDefaults(), '->addDefaults() adds defaults to all routes');
$this->assertEquals(['_controller' => 'fixed', 'placeholder' => 'new-default'], $collection->get('bar')->getDefaults(),
'->addDefaults() adds defaults to all routes and overwrites existing ones');
$collection->addRequirements(array('placeholder' => '\d+'));
$this->assertEquals(array('placeholder' => '\d+'), $collection->get('foo')->getRequirements(), '->addRequirements() adds requirements to all routes');
$this->assertEquals(array('placeholder' => '\d+'), $collection->get('bar')->getRequirements(),
$collection->addRequirements(['placeholder' => '\d+']);
$this->assertEquals(['placeholder' => '\d+'], $collection->get('foo')->getRequirements(), '->addRequirements() adds requirements to all routes');
$this->assertEquals(['placeholder' => '\d+'], $collection->get('bar')->getRequirements(),
'->addRequirements() adds requirements to all routes and overwrites existing ones');
$collection->addOptions(array('option' => 'new-value'));
$collection->addOptions(['option' => 'new-value']);
$this->assertEquals(
array('option' => 'new-value', 'compiler_class' => 'Symfony\\Component\\Routing\\RouteCompiler'),
['option' => 'new-value', 'compiler_class' => 'Symfony\\Component\\Routing\\RouteCompiler'],
$collection->get('bar')->getOptions(), '->addOptions() adds options to all routes and overwrites existing ones'
);
}
@@ -148,13 +148,13 @@ class RouteCollectionTest extends TestCase
$collection->addCollection($collection2);
$collection->addPrefix(' / ');
$this->assertSame('/foo', $collection->get('foo')->getPath(), '->addPrefix() trims the prefix and a single slash has no effect');
$collection->addPrefix('/{admin}', array('admin' => 'admin'), array('admin' => '\d+'));
$collection->addPrefix('/{admin}', ['admin' => 'admin'], ['admin' => '\d+']);
$this->assertEquals('/{admin}/foo', $collection->get('foo')->getPath(), '->addPrefix() adds a prefix to all routes');
$this->assertEquals('/{admin}/bar', $collection->get('bar')->getPath(), '->addPrefix() adds a prefix to all routes');
$this->assertEquals(array('admin' => 'admin'), $collection->get('foo')->getDefaults(), '->addPrefix() adds defaults to all routes');
$this->assertEquals(array('admin' => 'admin'), $collection->get('bar')->getDefaults(), '->addPrefix() adds defaults to all routes');
$this->assertEquals(array('admin' => '\d+'), $collection->get('foo')->getRequirements(), '->addPrefix() adds requirements to all routes');
$this->assertEquals(array('admin' => '\d+'), $collection->get('bar')->getRequirements(), '->addPrefix() adds requirements to all routes');
$this->assertEquals(['admin' => 'admin'], $collection->get('foo')->getDefaults(), '->addPrefix() adds defaults to all routes');
$this->assertEquals(['admin' => 'admin'], $collection->get('bar')->getDefaults(), '->addPrefix() adds defaults to all routes');
$this->assertEquals(['admin' => '\d+'], $collection->get('foo')->getRequirements(), '->addPrefix() adds requirements to all routes');
$this->assertEquals(['admin' => '\d+'], $collection->get('bar')->getRequirements(), '->addPrefix() adds requirements to all routes');
$collection->addPrefix('0');
$this->assertEquals('/0/{admin}/foo', $collection->get('foo')->getPath(), '->addPrefix() ensures a prefix must start with a slash and must not end with a slash');
$collection->addPrefix('/ /');
@@ -166,8 +166,8 @@ class RouteCollectionTest extends TestCase
{
$collection = new RouteCollection();
$collection->add('foo', $foo = new Route('/foo.{_format}'));
$collection->add('bar', $bar = new Route('/bar.{_format}', array(), array('_format' => 'json')));
$collection->addPrefix('/admin', array(), array('_format' => 'html'));
$collection->add('bar', $bar = new Route('/bar.{_format}', [], ['_format' => 'json']));
$collection->addPrefix('/admin', [], ['_format' => 'html']);
$this->assertEquals('html', $collection->get('foo')->getRequirement('_format'), '->addPrefix() overrides existing requirements');
$this->assertEquals('html', $collection->get('bar')->getRequirement('_format'), '->addPrefix() overrides existing requirements');
@@ -180,7 +180,7 @@ class RouteCollectionTest extends TestCase
$collection->addResource($bar = new FileResource(__DIR__.'/Fixtures/bar.xml'));
$collection->addResource(new FileResource(__DIR__.'/Fixtures/foo.xml'));
$this->assertEquals(array($foo, $bar), $collection->getResources(),
$this->assertEquals([$foo, $bar], $collection->getResources(),
'->addResource() adds a resource and getResources() only returns unique ones by comparing the string representation');
}
@@ -227,16 +227,16 @@ class RouteCollectionTest extends TestCase
$collection->add('last', $last = new Route('/last'));
$collection->remove('foo');
$this->assertSame(array('bar' => $bar, 'last' => $last), $collection->all(), '->remove() can remove a single route');
$collection->remove(array('bar', 'last'));
$this->assertSame(array(), $collection->all(), '->remove() accepts an array and can remove multiple routes at once');
$this->assertSame(['bar' => $bar, 'last' => $last], $collection->all(), '->remove() can remove a single route');
$collection->remove(['bar', 'last']);
$this->assertSame([], $collection->all(), '->remove() accepts an array and can remove multiple routes at once');
}
public function testSetHost()
{
$collection = new RouteCollection();
$routea = new Route('/a');
$routeb = new Route('/b', array(), array(), array(), '{locale}.example.net');
$routeb = new Route('/b', [], [], [], '{locale}.example.net');
$collection->add('a', $routea);
$collection->add('b', $routeb);
@@ -250,7 +250,7 @@ class RouteCollectionTest extends TestCase
{
$collection = new RouteCollection();
$routea = new Route('/a');
$routeb = new Route('/b', array(), array(), array(), '{locale}.example.net', array(), array(), 'context.getMethod() == "GET"');
$routeb = new Route('/b', [], [], [], '{locale}.example.net', [], [], 'context.getMethod() == "GET"');
$collection->add('a', $routea);
$collection->add('b', $routeb);
@@ -264,7 +264,7 @@ class RouteCollectionTest extends TestCase
{
$collection = new RouteCollection();
$collection->add('a', new Route('/a'));
$collection->add('b', new Route('/b', array('placeholder' => 'default'), array('placeholder' => '.+')));
$collection->add('b', new Route('/b', ['placeholder' => 'default'], ['placeholder' => '.+']));
$clonedCollection = clone $collection;
@@ -278,29 +278,29 @@ class RouteCollectionTest extends TestCase
public function testSetSchemes()
{
$collection = new RouteCollection();
$routea = new Route('/a', array(), array(), array(), '', 'http');
$routea = new Route('/a', [], [], [], '', 'http');
$routeb = new Route('/b');
$collection->add('a', $routea);
$collection->add('b', $routeb);
$collection->setSchemes(array('http', 'https'));
$collection->setSchemes(['http', 'https']);
$this->assertEquals(array('http', 'https'), $routea->getSchemes());
$this->assertEquals(array('http', 'https'), $routeb->getSchemes());
$this->assertEquals(['http', 'https'], $routea->getSchemes());
$this->assertEquals(['http', 'https'], $routeb->getSchemes());
}
public function testSetMethods()
{
$collection = new RouteCollection();
$routea = new Route('/a', array(), array(), array(), '', array(), array('GET', 'POST'));
$routea = new Route('/a', [], [], [], '', [], ['GET', 'POST']);
$routeb = new Route('/b');
$collection->add('a', $routea);
$collection->add('b', $routeb);
$collection->setMethods('PUT');
$this->assertEquals(array('PUT'), $routea->getMethods());
$this->assertEquals(array('PUT'), $routeb->getMethods());
$this->assertEquals(['PUT'], $routea->getMethods());
$this->assertEquals(['PUT'], $routeb->getMethods());
}
public function testAddNamePrefix()
@@ -321,9 +321,9 @@ class RouteCollectionTest extends TestCase
public function testAddNamePrefixCanonicalRouteName()
{
$collection = new RouteCollection();
$collection->add('foo', new Route('/foo', array('_canonical_route' => 'foo')));
$collection->add('bar', new Route('/bar', array('_canonical_route' => 'bar')));
$collection->add('api_foo', new Route('/api/foo', array('_canonical_route' => 'api_foo')));
$collection->add('foo', new Route('/foo', ['_canonical_route' => 'foo']));
$collection->add('bar', new Route('/bar', ['_canonical_route' => 'bar']));
$collection->add('api_foo', new Route('/api/foo', ['_canonical_route' => 'api_foo']));
$collection->addNamePrefix('api_');
$this->assertEquals('api_foo', $collection->get('api_foo')->getDefault('_canonical_route'));

View File

@@ -34,153 +34,153 @@ class RouteCompilerTest extends TestCase
public function provideCompileData()
{
return array(
array(
return [
[
'Static route',
array('/foo'),
'/foo', '#^/foo$#sD', array(), array(
array('text', '/foo'),
),
),
['/foo'],
'/foo', '#^/foo$#sD', [], [
['text', '/foo'],
],
],
array(
[
'Route with a variable',
array('/foo/{bar}'),
'/foo', '#^/foo/(?P<bar>[^/]++)$#sD', array('bar'), array(
array('variable', '/', '[^/]++', 'bar'),
array('text', '/foo'),
),
),
['/foo/{bar}'],
'/foo', '#^/foo/(?P<bar>[^/]++)$#sD', ['bar'], [
['variable', '/', '[^/]++', 'bar'],
['text', '/foo'],
],
],
array(
[
'Route with a variable that has a default value',
array('/foo/{bar}', array('bar' => 'bar')),
'/foo', '#^/foo(?:/(?P<bar>[^/]++))?$#sD', array('bar'), array(
array('variable', '/', '[^/]++', 'bar'),
array('text', '/foo'),
),
),
['/foo/{bar}', ['bar' => 'bar']],
'/foo', '#^/foo(?:/(?P<bar>[^/]++))?$#sD', ['bar'], [
['variable', '/', '[^/]++', 'bar'],
['text', '/foo'],
],
],
array(
[
'Route with several variables',
array('/foo/{bar}/{foobar}'),
'/foo', '#^/foo/(?P<bar>[^/]++)/(?P<foobar>[^/]++)$#sD', array('bar', 'foobar'), array(
array('variable', '/', '[^/]++', 'foobar'),
array('variable', '/', '[^/]++', 'bar'),
array('text', '/foo'),
),
),
['/foo/{bar}/{foobar}'],
'/foo', '#^/foo/(?P<bar>[^/]++)/(?P<foobar>[^/]++)$#sD', ['bar', 'foobar'], [
['variable', '/', '[^/]++', 'foobar'],
['variable', '/', '[^/]++', 'bar'],
['text', '/foo'],
],
],
array(
[
'Route with several variables that have default values',
array('/foo/{bar}/{foobar}', array('bar' => 'bar', 'foobar' => '')),
'/foo', '#^/foo(?:/(?P<bar>[^/]++)(?:/(?P<foobar>[^/]++))?)?$#sD', array('bar', 'foobar'), array(
array('variable', '/', '[^/]++', 'foobar'),
array('variable', '/', '[^/]++', 'bar'),
array('text', '/foo'),
),
),
['/foo/{bar}/{foobar}', ['bar' => 'bar', 'foobar' => '']],
'/foo', '#^/foo(?:/(?P<bar>[^/]++)(?:/(?P<foobar>[^/]++))?)?$#sD', ['bar', 'foobar'], [
['variable', '/', '[^/]++', 'foobar'],
['variable', '/', '[^/]++', 'bar'],
['text', '/foo'],
],
],
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>[^/]++)$#sD', array('bar', 'foobar'), array(
array('variable', '/', '[^/]++', 'foobar'),
array('variable', '/', '[^/]++', 'bar'),
array('text', '/foo'),
),
),
['/foo/{bar}/{foobar}', ['bar' => 'bar']],
'/foo', '#^/foo/(?P<bar>[^/]++)/(?P<foobar>[^/]++)$#sD', ['bar', 'foobar'], [
['variable', '/', '[^/]++', 'foobar'],
['variable', '/', '[^/]++', 'bar'],
['text', '/foo'],
],
],
array(
[
'Route with an optional variable as the first segment',
array('/{bar}', array('bar' => 'bar')),
'', '#^/(?P<bar>[^/]++)?$#sD', array('bar'), array(
array('variable', '/', '[^/]++', 'bar'),
),
),
['/{bar}', ['bar' => 'bar']],
'', '#^/(?P<bar>[^/]++)?$#sD', ['bar'], [
['variable', '/', '[^/]++', 'bar'],
],
],
array(
[
'Route with a requirement of 0',
array('/{bar}', array('bar' => null), array('bar' => '0')),
'', '#^/(?P<bar>0)?$#sD', array('bar'), array(
array('variable', '/', '0', 'bar'),
),
),
['/{bar}', ['bar' => null], ['bar' => '0']],
'', '#^/(?P<bar>0)?$#sD', ['bar'], [
['variable', '/', '0', 'bar'],
],
],
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))?$#sD', array('bar'), array(
array('variable', '/', '(?:foo|bar)', 'bar'),
),
),
['/{bar}', ['bar' => 'bar'], ['bar' => '(foo|bar)']],
'', '#^/(?P<bar>(?:foo|bar))?$#sD', ['bar'], [
['variable', '/', '(?:foo|bar)', 'bar'],
],
],
array(
[
'Route with only optional variables',
array('/{foo}/{bar}', array('foo' => 'foo', 'bar' => 'bar')),
'', '#^/(?P<foo>[^/]++)?(?:/(?P<bar>[^/]++))?$#sD', array('foo', 'bar'), array(
array('variable', '/', '[^/]++', 'bar'),
array('variable', '/', '[^/]++', 'foo'),
),
),
['/{foo}/{bar}', ['foo' => 'foo', 'bar' => 'bar']],
'', '#^/(?P<foo>[^/]++)?(?:/(?P<bar>[^/]++))?$#sD', ['foo', 'bar'], [
['variable', '/', '[^/]++', 'bar'],
['variable', '/', '[^/]++', 'foo'],
],
],
array(
[
'Route with a variable in last position',
array('/foo-{bar}'),
'/foo-', '#^/foo\-(?P<bar>[^/]++)$#sD', array('bar'), array(
array('variable', '-', '[^/]++', 'bar'),
array('text', '/foo'),
),
),
['/foo-{bar}'],
'/foo-', '#^/foo\-(?P<bar>[^/]++)$#sD', ['bar'], [
['variable', '-', '[^/]++', 'bar'],
['text', '/foo'],
],
],
array(
[
'Route with nested placeholders',
array('/{static{var}static}'),
'/{static', '#^/\{static(?P<var>[^/]+)static\}$#sD', array('var'), array(
array('text', 'static}'),
array('variable', '', '[^/]+', 'var'),
array('text', '/{static'),
),
),
['/{static{var}static}'],
'/{static', '#^/\{static(?P<var>[^/]+)static\}$#sD', ['var'], [
['text', 'static}'],
['variable', '', '[^/]+', 'var'],
['text', '/{static'],
],
],
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>[^/]++))?)?$#sD', array('w', 'x', 'y', 'z', '_format'), array(
array('variable', '.', '[^/]++', '_format'),
array('variable', '', '[^/\.]++', 'z'),
array('variable', '', '(?:y|Y)', 'y'),
array('variable', '', '[^/\.]+', 'x'),
array('variable', '/', '[^/\.]+', 'w'),
),
),
['/{w}{x}{y}{z}.{_format}', ['z' => 'default-z', '_format' => 'html'], ['y' => '(y|Y)']],
'', '#^/(?P<w>[^/\.]+)(?P<x>[^/\.]+)(?P<y>(?:y|Y))(?:(?P<z>[^/\.]++)(?:\.(?P<_format>[^/]++))?)?$#sD', ['w', 'x', 'y', 'z', '_format'], [
['variable', '.', '[^/]++', '_format'],
['variable', '', '[^/\.]++', 'z'],
['variable', '', '(?:y|Y)', 'y'],
['variable', '', '[^/\.]+', 'x'],
['variable', '/', '[^/\.]+', 'w'],
],
],
array(
[
'Route with a format',
array('/foo/{bar}.{_format}'),
'/foo', '#^/foo/(?P<bar>[^/\.]++)\.(?P<_format>[^/]++)$#sD', array('bar', '_format'), array(
array('variable', '.', '[^/]++', '_format'),
array('variable', '/', '[^/\.]++', 'bar'),
array('text', '/foo'),
),
),
['/foo/{bar}.{_format}'],
'/foo', '#^/foo/(?P<bar>[^/\.]++)\.(?P<_format>[^/]++)$#sD', ['bar', '_format'], [
['variable', '.', '[^/]++', '_format'],
['variable', '/', '[^/\.]++', 'bar'],
['text', '/foo'],
],
],
array(
[
'Static non UTF-8 route',
array("/fo\xE9"),
"/fo\xE9", "#^/fo\xE9$#sD", array(), array(
array('text', "/fo\xE9"),
),
),
["/fo\xE9"],
"/fo\xE9", "#^/fo\xE9$#sD", [], [
['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),
),
),
);
['/{bar}', ['bar' => null], ['bar' => '.'], ['utf8' => true]],
'', '#^/(?P<bar>.)?$#sDu', ['bar'], [
['variable', '/', '.', 'bar', true],
],
],
];
}
/**
@@ -201,45 +201,45 @@ class RouteCompilerTest extends TestCase
public function provideCompileImplicitUtf8Data()
{
return array(
array(
return [
[
'Static UTF-8 route',
array('/foé'),
'/foé', '#^/foé$#sDu', array(), array(
array('text', '/foé'),
),
['/foé'],
'/foé', '#^/foé$#sDu', [], [
['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),
),
['/{bar}', ['bar' => null], ['bar' => 'é']],
'', '#^/(?P<bar>é)?$#sDu', ['bar'], [
['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),
),
['/{bar}', ['bar' => null], ['bar' => '\pM']],
'', '#^/(?P<bar>\pM)?$#sDu', ['bar'], [
['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'),
),
['/foo/{bar}§{_format}', [], [], ['compiler_class' => Utf8RouteCompiler::class]],
'/foo', '#^/foo/(?P<bar>[^/§]++)§(?P<_format>[^/]++)$#sDu', ['bar', '_format'], [
['variable', '§', '[^/]++', '_format', true],
['variable', '/', '[^/§]++', 'bar', true],
['text', '/foo'],
],
'patterns',
),
);
],
];
}
/**
@@ -257,7 +257,7 @@ class RouteCompilerTest extends TestCase
*/
public function testRouteCharsetMismatch()
{
$route = new Route("/\xE9/{bar}", array(), array('bar' => '.'), array('utf8' => true));
$route = new Route("/\xE9/{bar}", [], ['bar' => '.'], ['utf8' => true]);
$compiled = $route->compile();
}
@@ -267,7 +267,7 @@ class RouteCompilerTest extends TestCase
*/
public function testRequirementCharsetMismatch()
{
$route = new Route('/foo/{bar}', array(), array('bar' => "\xE9"), array('utf8' => true));
$route = new Route('/foo/{bar}', [], ['bar' => "\xE9"], ['utf8' => true]);
$compiled = $route->compile();
}
@@ -294,11 +294,11 @@ class RouteCompilerTest extends TestCase
public function getVariableNamesStartingWithADigit()
{
return array(
array('09'),
array('123'),
array('1e2'),
);
return [
['09'],
['123'],
['1e2'],
];
}
/**
@@ -311,65 +311,65 @@ class RouteCompilerTest extends TestCase
$compiled = $route->compile();
$this->assertEquals($prefix, $compiled->getStaticPrefix(), $name.' (static prefix)');
$this->assertEquals($regex, str_replace(array("\n", ' '), '', $compiled->getRegex()), $name.' (regex)');
$this->assertEquals($regex, str_replace(["\n", ' '], '', $compiled->getRegex()), $name.' (regex)');
$this->assertEquals($variables, $compiled->getVariables(), $name.' (variables)');
$this->assertEquals($pathVariables, $compiled->getPathVariables(), $name.' (path variables)');
$this->assertEquals($tokens, $compiled->getTokens(), $name.' (tokens)');
$this->assertEquals($hostRegex, str_replace(array("\n", ' '), '', $compiled->getHostRegex()), $name.' (host regex)');
$this->assertEquals($hostRegex, str_replace(["\n", ' '], '', $compiled->getHostRegex()), $name.' (host regex)');
$this->assertEquals($hostVariables, $compiled->getHostVariables(), $name.' (host variables)');
$this->assertEquals($hostTokens, $compiled->getHostTokens(), $name.' (host tokens)');
}
public function provideCompileWithHostData()
{
return array(
array(
return [
[
'Route with host pattern',
array('/hello', array(), array(), array(), 'www.example.com'),
'/hello', '#^/hello$#sD', array(), array(), array(
array('text', '/hello'),
),
'#^www\.example\.com$#sDi', array(), array(
array('text', 'www.example.com'),
),
),
array(
['/hello', [], [], [], 'www.example.com'],
'/hello', '#^/hello$#sD', [], [], [
['text', '/hello'],
],
'#^www\.example\.com$#sDi', [], [
['text', 'www.example.com'],
],
],
[
'Route with host pattern and some variables',
array('/hello/{name}', array(), array(), array(), 'www.example.{tld}'),
'/hello', '#^/hello/(?P<name>[^/]++)$#sD', array('tld', 'name'), array('name'), array(
array('variable', '/', '[^/]++', 'name'),
array('text', '/hello'),
),
'#^www\.example\.(?P<tld>[^\.]++)$#sDi', array('tld'), array(
array('variable', '.', '[^\.]++', 'tld'),
array('text', 'www.example'),
),
),
array(
['/hello/{name}', [], [], [], 'www.example.{tld}'],
'/hello', '#^/hello/(?P<name>[^/]++)$#sD', ['tld', 'name'], ['name'], [
['variable', '/', '[^/]++', 'name'],
['text', '/hello'],
],
'#^www\.example\.(?P<tld>[^\.]++)$#sDi', ['tld'], [
['variable', '.', '[^\.]++', 'tld'],
['text', 'www.example'],
],
],
[
'Route with variable at beginning of host',
array('/hello', array(), array(), array(), '{locale}.example.{tld}'),
'/hello', '#^/hello$#sD', array('locale', 'tld'), array(), array(
array('text', '/hello'),
),
'#^(?P<locale>[^\.]++)\.example\.(?P<tld>[^\.]++)$#sDi', array('locale', 'tld'), array(
array('variable', '.', '[^\.]++', 'tld'),
array('text', '.example'),
array('variable', '', '[^\.]++', 'locale'),
),
),
array(
['/hello', [], [], [], '{locale}.example.{tld}'],
'/hello', '#^/hello$#sD', ['locale', 'tld'], [], [
['text', '/hello'],
],
'#^(?P<locale>[^\.]++)\.example\.(?P<tld>[^\.]++)$#sDi', ['locale', 'tld'], [
['variable', '.', '[^\.]++', 'tld'],
['text', '.example'],
['variable', '', '[^\.]++', 'locale'],
],
],
[
'Route with host variables that has a default value',
array('/hello', array('locale' => 'a', 'tld' => 'b'), array(), array(), '{locale}.example.{tld}'),
'/hello', '#^/hello$#sD', array('locale', 'tld'), array(), array(
array('text', '/hello'),
),
'#^(?P<locale>[^\.]++)\.example\.(?P<tld>[^\.]++)$#sDi', array('locale', 'tld'), array(
array('variable', '.', '[^\.]++', 'tld'),
array('text', '.example'),
array('variable', '', '[^\.]++', 'locale'),
),
),
);
['/hello', ['locale' => 'a', 'tld' => 'b'], [], [], '{locale}.example.{tld}'],
'/hello', '#^/hello$#sD', ['locale', 'tld'], [], [
['text', '/hello'],
],
'#^(?P<locale>[^\.]++)\.example\.(?P<tld>[^\.]++)$#sDi', ['locale', 'tld'], [
['variable', '.', '[^\.]++', 'tld'],
['text', '.example'],
['variable', '', '[^\.]++', 'locale'],
],
],
];
}
/**
@@ -386,19 +386,19 @@ class RouteCompilerTest extends TestCase
*/
public function testRemoveCapturingGroup($regex, $requirement)
{
$route = new Route('/{foo}', array(), array('foo' => $requirement));
$route = new Route('/{foo}', [], ['foo' => $requirement]);
$this->assertSame($regex, $route->compile()->getRegex());
}
public function provideRemoveCapturingGroup()
{
yield array('#^/(?P<foo>a(?:b|c)(?:d|e)f)$#sD', 'a(b|c)(d|e)f');
yield array('#^/(?P<foo>a\(b\)c)$#sD', 'a\(b\)c');
yield array('#^/(?P<foo>(?:b))$#sD', '(?:b)');
yield array('#^/(?P<foo>(?(b)b))$#sD', '(?(b)b)');
yield array('#^/(?P<foo>(*F))$#sD', '(*F)');
yield array('#^/(?P<foo>(?:(?:foo)))$#sD', '((foo))');
yield ['#^/(?P<foo>a(?:b|c)(?:d|e)f)$#sD', 'a(b|c)(d|e)f'];
yield ['#^/(?P<foo>a\(b\)c)$#sD', 'a\(b\)c'];
yield ['#^/(?P<foo>(?:b))$#sD', '(?:b)'];
yield ['#^/(?P<foo>(?(b)b))$#sD', '(?(b)b)'];
yield ['#^/(?P<foo>(*F))$#sD', '(*F)'];
yield ['#^/(?P<foo>(?:(?:foo)))$#sD', '((foo))'];
}
}

View File

@@ -18,21 +18,21 @@ class RouteTest extends TestCase
{
public function testConstructor()
{
$route = new Route('/{foo}', array('foo' => 'bar'), array('foo' => '\d+'), array('foo' => 'bar'), '{locale}.example.com');
$route = new Route('/{foo}', ['foo' => 'bar'], ['foo' => '\d+'], ['foo' => 'bar'], '{locale}.example.com');
$this->assertEquals('/{foo}', $route->getPath(), '__construct() takes a path as its first argument');
$this->assertEquals(array('foo' => 'bar'), $route->getDefaults(), '__construct() takes defaults as its second argument');
$this->assertEquals(array('foo' => '\d+'), $route->getRequirements(), '__construct() takes requirements as its third argument');
$this->assertEquals(['foo' => 'bar'], $route->getDefaults(), '__construct() takes defaults as its second argument');
$this->assertEquals(['foo' => '\d+'], $route->getRequirements(), '__construct() takes requirements as its third argument');
$this->assertEquals('bar', $route->getOption('foo'), '__construct() takes options as its fourth argument');
$this->assertEquals('{locale}.example.com', $route->getHost(), '__construct() takes a host pattern as its fifth argument');
$route = new Route('/', array(), array(), array(), '', array('Https'), array('POST', 'put'), 'context.getMethod() == "GET"');
$this->assertEquals(array('https'), $route->getSchemes(), '__construct() takes schemes as its sixth argument and lowercases it');
$this->assertEquals(array('POST', 'PUT'), $route->getMethods(), '__construct() takes methods as its seventh argument and uppercases it');
$route = new Route('/', [], [], [], '', ['Https'], ['POST', 'put'], 'context.getMethod() == "GET"');
$this->assertEquals(['https'], $route->getSchemes(), '__construct() takes schemes as its sixth argument and lowercases it');
$this->assertEquals(['POST', 'PUT'], $route->getMethods(), '__construct() takes methods as its seventh argument and uppercases it');
$this->assertEquals('context.getMethod() == "GET"', $route->getCondition(), '__construct() takes a condition as its eight argument');
$route = new Route('/', array(), array(), array(), '', 'Https', 'Post');
$this->assertEquals(array('https'), $route->getSchemes(), '__construct() takes a single scheme as its sixth argument');
$this->assertEquals(array('POST'), $route->getMethods(), '__construct() takes a single method as its seventh argument');
$route = new Route('/', [], [], [], '', 'Https', 'Post');
$this->assertEquals(['https'], $route->getSchemes(), '__construct() takes a single scheme as its sixth argument');
$this->assertEquals(['POST'], $route->getMethods(), '__construct() takes a single method as its seventh argument');
}
public function testPath()
@@ -52,16 +52,16 @@ class RouteTest extends TestCase
public function testOptions()
{
$route = new Route('/{foo}');
$route->setOptions(array('foo' => 'bar'));
$this->assertEquals(array_merge(array(
$route->setOptions(['foo' => 'bar']);
$this->assertEquals(array_merge([
'compiler_class' => 'Symfony\\Component\\Routing\\RouteCompiler',
), array('foo' => 'bar')), $route->getOptions(), '->setOptions() sets the options');
$this->assertEquals($route, $route->setOptions(array()), '->setOptions() implements a fluent interface');
], ['foo' => 'bar']), $route->getOptions(), '->setOptions() sets the options');
$this->assertEquals($route, $route->setOptions([]), '->setOptions() implements a fluent interface');
$route->setOptions(array('foo' => 'foo'));
$route->addOptions(array('bar' => 'bar'));
$this->assertEquals($route, $route->addOptions(array()), '->addOptions() implements a fluent interface');
$this->assertEquals(array('foo' => 'foo', 'bar' => 'bar', 'compiler_class' => 'Symfony\\Component\\Routing\\RouteCompiler'), $route->getOptions(), '->addDefaults() keep previous defaults');
$route->setOptions(['foo' => 'foo']);
$route->addOptions(['bar' => 'bar']);
$this->assertEquals($route, $route->addOptions([]), '->addOptions() implements a fluent interface');
$this->assertEquals(['foo' => 'foo', 'bar' => 'bar', 'compiler_class' => 'Symfony\\Component\\Routing\\RouteCompiler'], $route->getOptions(), '->addDefaults() keep previous defaults');
}
public function testOption()
@@ -76,9 +76,9 @@ class RouteTest extends TestCase
public function testDefaults()
{
$route = new Route('/{foo}');
$route->setDefaults(array('foo' => 'bar'));
$this->assertEquals(array('foo' => 'bar'), $route->getDefaults(), '->setDefaults() sets the defaults');
$this->assertEquals($route, $route->setDefaults(array()), '->setDefaults() implements a fluent interface');
$route->setDefaults(['foo' => 'bar']);
$this->assertEquals(['foo' => 'bar'], $route->getDefaults(), '->setDefaults() sets the defaults');
$this->assertEquals($route, $route->setDefaults([]), '->setDefaults() implements a fluent interface');
$route->setDefault('foo', 'bar');
$this->assertEquals('bar', $route->getDefault('foo'), '->setDefault() sets a default value');
@@ -90,27 +90,27 @@ class RouteTest extends TestCase
$route->setDefault('_controller', $closure = function () { return 'Hello'; });
$this->assertEquals($closure, $route->getDefault('_controller'), '->setDefault() sets a default value');
$route->setDefaults(array('foo' => 'foo'));
$route->addDefaults(array('bar' => 'bar'));
$this->assertEquals($route, $route->addDefaults(array()), '->addDefaults() implements a fluent interface');
$this->assertEquals(array('foo' => 'foo', 'bar' => 'bar'), $route->getDefaults(), '->addDefaults() keep previous defaults');
$route->setDefaults(['foo' => 'foo']);
$route->addDefaults(['bar' => 'bar']);
$this->assertEquals($route, $route->addDefaults([]), '->addDefaults() implements a fluent interface');
$this->assertEquals(['foo' => 'foo', 'bar' => 'bar'], $route->getDefaults(), '->addDefaults() keep previous defaults');
}
public function testRequirements()
{
$route = new Route('/{foo}');
$route->setRequirements(array('foo' => '\d+'));
$this->assertEquals(array('foo' => '\d+'), $route->getRequirements(), '->setRequirements() sets the requirements');
$route->setRequirements(['foo' => '\d+']);
$this->assertEquals(['foo' => '\d+'], $route->getRequirements(), '->setRequirements() sets the requirements');
$this->assertEquals('\d+', $route->getRequirement('foo'), '->getRequirement() returns a requirement');
$this->assertNull($route->getRequirement('bar'), '->getRequirement() returns null if a requirement is not defined');
$route->setRequirements(array('foo' => '^\d+$'));
$route->setRequirements(['foo' => '^\d+$']);
$this->assertEquals('\d+', $route->getRequirement('foo'), '->getRequirement() removes ^ and $ from the path');
$this->assertEquals($route, $route->setRequirements(array()), '->setRequirements() implements a fluent interface');
$this->assertEquals($route, $route->setRequirements([]), '->setRequirements() implements a fluent interface');
$route->setRequirements(array('foo' => '\d+'));
$route->addRequirements(array('bar' => '\d+'));
$this->assertEquals($route, $route->addRequirements(array()), '->addRequirements() implements a fluent interface');
$this->assertEquals(array('foo' => '\d+', 'bar' => '\d+'), $route->getRequirements(), '->addRequirement() keep previous requirements');
$route->setRequirements(['foo' => '\d+']);
$route->addRequirements(['bar' => '\d+']);
$this->assertEquals($route, $route->addRequirements([]), '->addRequirements() implements a fluent interface');
$this->assertEquals(['foo' => '\d+', 'bar' => '\d+'], $route->getRequirements(), '->addRequirement() keep previous requirements');
}
public function testRequirement()
@@ -134,13 +134,13 @@ class RouteTest extends TestCase
public function getInvalidRequirements()
{
return array(
array(''),
array(array()),
array('^$'),
array('^'),
array('$'),
);
return [
[''],
[[]],
['^$'],
['^'],
['$'],
];
}
public function testHost()
@@ -153,14 +153,14 @@ class RouteTest extends TestCase
public function testScheme()
{
$route = new Route('/');
$this->assertEquals(array(), $route->getSchemes(), 'schemes is initialized with array()');
$this->assertEquals([], $route->getSchemes(), 'schemes is initialized with []');
$this->assertFalse($route->hasScheme('http'));
$route->setSchemes('hTTp');
$this->assertEquals(array('http'), $route->getSchemes(), '->setSchemes() accepts a single scheme string and lowercases it');
$this->assertEquals(['http'], $route->getSchemes(), '->setSchemes() accepts a single scheme string and lowercases it');
$this->assertTrue($route->hasScheme('htTp'));
$this->assertFalse($route->hasScheme('httpS'));
$route->setSchemes(array('HttpS', 'hTTp'));
$this->assertEquals(array('https', 'http'), $route->getSchemes(), '->setSchemes() accepts an array of schemes and lowercases them');
$route->setSchemes(['HttpS', 'hTTp']);
$this->assertEquals(['https', 'http'], $route->getSchemes(), '->setSchemes() accepts an array of schemes and lowercases them');
$this->assertTrue($route->hasScheme('htTp'));
$this->assertTrue($route->hasScheme('httpS'));
}
@@ -168,11 +168,11 @@ class RouteTest extends TestCase
public function testMethod()
{
$route = new Route('/');
$this->assertEquals(array(), $route->getMethods(), 'methods is initialized with array()');
$this->assertEquals([], $route->getMethods(), 'methods is initialized with []');
$route->setMethods('gEt');
$this->assertEquals(array('GET'), $route->getMethods(), '->setMethods() accepts a single method string and uppercases it');
$route->setMethods(array('gEt', 'PosT'));
$this->assertEquals(array('GET', 'POST'), $route->getMethods(), '->setMethods() accepts an array of methods and uppercases them');
$this->assertEquals(['GET'], $route->getMethods(), '->setMethods() accepts a single method string and uppercases it');
$route->setMethods(['gEt', 'PosT']);
$this->assertEquals(['GET', 'POST'], $route->getMethods(), '->setMethods() accepts an array of methods and uppercases them');
}
public function testCondition()
@@ -194,7 +194,7 @@ class RouteTest extends TestCase
public function testSerialize()
{
$route = new Route('/prefix/{foo}', array('foo' => 'default'), array('foo' => '\d+'));
$route = new Route('/prefix/{foo}', ['foo' => 'default'], ['foo' => '\d+']);
$serialized = serialize($route);
$unserialized = unserialize($serialized);
@@ -208,11 +208,11 @@ class RouteTest extends TestCase
$this->assertEquals((new Route('/foo/{bar}'))->setDefault('bar', null), new Route('/foo/{bar?}'));
$this->assertEquals((new Route('/foo/{bar}'))->setDefault('bar', 'baz'), new Route('/foo/{bar?baz}'));
$this->assertEquals((new Route('/foo/{bar}'))->setDefault('bar', 'baz<buz>'), new Route('/foo/{bar?baz<buz>}'));
$this->assertEquals((new Route('/foo/{bar}'))->setDefault('bar', 'baz'), new Route('/foo/{bar?}', array('bar' => 'baz')));
$this->assertEquals((new Route('/foo/{bar}'))->setDefault('bar', 'baz'), new Route('/foo/{bar?}', ['bar' => 'baz']));
$this->assertEquals((new Route('/foo/{bar}'))->setRequirement('bar', '.*'), new Route('/foo/{bar<.*>}'));
$this->assertEquals((new Route('/foo/{bar}'))->setRequirement('bar', '>'), new Route('/foo/{bar<>>}'));
$this->assertEquals((new Route('/foo/{bar}'))->setRequirement('bar', '\d+'), new Route('/foo/{bar<.*>}', array(), array('bar' => '\d+')));
$this->assertEquals((new Route('/foo/{bar}'))->setRequirement('bar', '\d+'), new Route('/foo/{bar<.*>}', [], ['bar' => '\d+']));
$this->assertEquals((new Route('/foo/{bar}'))->setRequirement('bar', '[a-z]{2}'), new Route('/foo/{bar<[a-z]{2}>}'));
$this->assertEquals((new Route('/foo/{bar}'))->setDefault('bar', null)->setRequirement('bar', '.*'), new Route('/foo/{bar<.*>?}'));
@@ -225,7 +225,7 @@ class RouteTest extends TestCase
*/
public function testSerializeWhenCompiled()
{
$route = new Route('/prefix/{foo}', array('foo' => 'default'), array('foo' => '\d+'));
$route = new Route('/prefix/{foo}', ['foo' => 'default'], ['foo' => '\d+']);
$route->setHost('{locale}.example.net');
$route->compile();
@@ -242,7 +242,7 @@ class RouteTest extends TestCase
*/
public function testSerializeWhenCompiledWithClass()
{
$route = new Route('/', array(), array(), array('compiler_class' => '\Symfony\Component\Routing\Tests\Fixtures\CustomRouteCompiler'));
$route = new Route('/', [], [], ['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);
@@ -264,7 +264,7 @@ class RouteTest extends TestCase
$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+'));
$route = new Route('/prefix/{foo}', ['foo' => 'default'], ['foo' => '\d+']);
$route->setHost('{locale}.example.net');
$route->compile();

View File

@@ -30,11 +30,11 @@ class RouterTest extends TestCase
public function testSetOptionsWithSupportedOptions()
{
$this->router->setOptions(array(
$this->router->setOptions([
'cache_dir' => './cache',
'debug' => true,
'resource_type' => 'ResourceType',
));
]);
$this->assertSame('./cache', $this->router->getOption('cache_dir'));
$this->assertTrue($this->router->getOption('debug'));
@@ -47,12 +47,12 @@ class RouterTest extends TestCase
*/
public function testSetOptionsWithUnsupportedOptions()
{
$this->router->setOptions(array(
$this->router->setOptions([
'cache_dir' => './cache',
'option_foo' => true,
'option_bar' => 'baz',
'resource_type' => 'ResourceType',
));
]);
}
public function testSetOptionWithSupportedOption()
@@ -109,10 +109,10 @@ class RouterTest extends TestCase
public function provideMatcherOptionsPreventingCaching()
{
return array(
array('cache_dir'),
array('matcher_cache_class'),
);
return [
['cache_dir'],
['matcher_cache_class'],
];
}
/**
@@ -131,10 +131,10 @@ class RouterTest extends TestCase
public function provideGeneratorOptionsPreventingCaching()
{
return array(
array('cache_dir'),
array('generator_cache_class'),
);
return [
['cache_dir'],
['generator_cache_class'],
];
}
public function testMatchRequestWithUrlMatcherInterface()