[Routing] renamed pattern to path
This commit is contained in:
parent
b357cafd00
commit
508299400d
@ -20,7 +20,7 @@ namespace Symfony\Component\Routing\Annotation;
|
||||
*/
|
||||
class Route
|
||||
{
|
||||
private $pattern;
|
||||
private $path;
|
||||
private $name;
|
||||
private $requirements;
|
||||
private $options;
|
||||
@ -39,7 +39,7 @@ class Route
|
||||
$this->defaults = array();
|
||||
|
||||
if (isset($data['value'])) {
|
||||
$data['pattern'] = $data['value'];
|
||||
$data['path'] = $data['value'];
|
||||
unset($data['value']);
|
||||
}
|
||||
|
||||
@ -52,14 +52,30 @@ class Route
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Deprecated in 2.2, to be removed in 3.0. Use setPath instead.
|
||||
*/
|
||||
public function setPattern($pattern)
|
||||
{
|
||||
$this->pattern = $pattern;
|
||||
$this->path = $pattern;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Deprecated in 2.2, to be removed in 3.0. Use getPath instead.
|
||||
*/
|
||||
public function getPattern()
|
||||
{
|
||||
return $this->pattern;
|
||||
return $this->path;
|
||||
}
|
||||
|
||||
public function setPath($path)
|
||||
{
|
||||
$this->path = $path;
|
||||
}
|
||||
|
||||
public function getPath()
|
||||
{
|
||||
return $this->path;
|
||||
}
|
||||
|
||||
public function setHostname($pattern)
|
||||
|
@ -28,7 +28,7 @@ use Symfony\Component\Config\Loader\LoaderResolverInterface;
|
||||
* The @Route annotation can be set on the class (for global parameters),
|
||||
* and on each method.
|
||||
*
|
||||
* The @Route annotation main value is the route pattern. The annotation also
|
||||
* The @Route annotation main value is the route path. The annotation also
|
||||
* recognizes three parameters: requirements, options, and name. The name parameter
|
||||
* is mandatory. Here is an example of how you should be able to use it:
|
||||
*
|
||||
@ -108,7 +108,7 @@ abstract class AnnotationClassLoader implements LoaderInterface
|
||||
}
|
||||
|
||||
$globals = array(
|
||||
'pattern' => '',
|
||||
'path' => '',
|
||||
'requirements' => array(),
|
||||
'options' => array(),
|
||||
'defaults' => array(),
|
||||
@ -121,8 +121,11 @@ abstract class AnnotationClassLoader implements LoaderInterface
|
||||
}
|
||||
|
||||
if ($annot = $this->reader->getClassAnnotation($class, $this->routeAnnotationClass)) {
|
||||
if (null !== $annot->getPattern()) {
|
||||
$globals['pattern'] = $annot->getPattern();
|
||||
// for BC reasons
|
||||
if (null !== $annot->getPath()) {
|
||||
$globals['path'] = $annot->getPath();
|
||||
} elseif (null !== $annot->getPattern()) {
|
||||
$globals['path'] = $annot->getPattern();
|
||||
}
|
||||
|
||||
if (null !== $annot->getRequirements()) {
|
||||
@ -178,7 +181,7 @@ abstract class AnnotationClassLoader implements LoaderInterface
|
||||
$hostname = $globals['hostname'];
|
||||
}
|
||||
|
||||
$route = new Route($globals['pattern'].$annot->getPattern(), $defaults, $requirements, $options, $hostname);
|
||||
$route = new Route($globals['path'].$annot->getPath(), $defaults, $requirements, $options, $hostname);
|
||||
|
||||
$this->configureRoute($route, $class, $method, $annot);
|
||||
|
||||
|
@ -112,8 +112,17 @@ class XmlFileLoader extends FileLoader
|
||||
*/
|
||||
protected function parseRoute(RouteCollection $collection, \DOMElement $node, $path)
|
||||
{
|
||||
if ('' === ($id = $node->getAttribute('id')) || !$node->hasAttribute('pattern')) {
|
||||
throw new \InvalidArgumentException(sprintf('The <route> element in file "%s" must have an "id" and a "pattern" attribute.', $path));
|
||||
if ('' === ($id = $node->getAttribute('id')) || (!$node->hasAttribute('pattern') && !$node->hasAttribute('path'))) {
|
||||
throw new \InvalidArgumentException(sprintf('The <route> element in file "%s" must have an "id" and a "path" attribute.', $path));
|
||||
}
|
||||
|
||||
if ($node->hasAttribute('pattern')) {
|
||||
if ($node->hasAttribute('path')) {
|
||||
throw new \InvalidArgumentException(sprintf('The <route> element in file "%s" cannot define both a "path" and a "pattern" attribute. Use only "path".', $path));
|
||||
}
|
||||
|
||||
$node->setAttribute('path', $node->getAttribute('pattern'));
|
||||
$node->removeAttribute('pattern');
|
||||
}
|
||||
|
||||
$schemes = array_filter(explode(' ', $node->getAttribute('schemes')));
|
||||
@ -121,7 +130,7 @@ class XmlFileLoader extends FileLoader
|
||||
|
||||
list($defaults, $requirements, $options) = $this->parseConfigs($node, $path);
|
||||
|
||||
$route = new Route($node->getAttribute('pattern'), $defaults, $requirements, $options, $node->getAttribute('hostname'), $schemes, $methods);
|
||||
$route = new Route($node->getAttribute('path'), $defaults, $requirements, $options, $node->getAttribute('hostname'), $schemes, $methods);
|
||||
$collection->add($id, $route);
|
||||
}
|
||||
|
||||
|
@ -28,7 +28,7 @@ use Symfony\Component\Config\Loader\FileLoader;
|
||||
class YamlFileLoader extends FileLoader
|
||||
{
|
||||
private static $availableKeys = array(
|
||||
'resource', 'type', 'prefix', 'pattern', 'hostname', 'schemes', 'methods', 'defaults', 'requirements', 'options',
|
||||
'resource', 'type', 'prefix', 'pattern', 'path', 'hostname', 'schemes', 'methods', 'defaults', 'requirements', 'options',
|
||||
);
|
||||
|
||||
/**
|
||||
@ -63,6 +63,15 @@ class YamlFileLoader extends FileLoader
|
||||
}
|
||||
|
||||
foreach ($config as $name => $config) {
|
||||
if (isset($config['pattern'])) {
|
||||
if (isset($config['path'])) {
|
||||
throw new \InvalidArgumentException(sprintf('The file "%s" cannot define both a "path" and a "pattern" attribute. Use only "path".', $path));
|
||||
}
|
||||
|
||||
$config['path'] = $config['pattern'];
|
||||
unset($config['pattern']);
|
||||
}
|
||||
|
||||
$this->validate($config, $name, $path);
|
||||
|
||||
if (isset($config['resource'])) {
|
||||
@ -102,7 +111,7 @@ class YamlFileLoader extends FileLoader
|
||||
$schemes = isset($config['schemes']) ? $config['schemes'] : array();
|
||||
$methods = isset($config['methods']) ? $config['methods'] : array();
|
||||
|
||||
$route = new Route($config['pattern'], $defaults, $requirements, $options, $hostname, $schemes, $methods);
|
||||
$route = new Route($config['path'], $defaults, $requirements, $options, $hostname, $schemes, $methods);
|
||||
|
||||
$collection->add($name, $route);
|
||||
}
|
||||
@ -168,9 +177,9 @@ class YamlFileLoader extends FileLoader
|
||||
$path, $name, implode('", "', $extraKeys), implode('", "', self::$availableKeys)
|
||||
));
|
||||
}
|
||||
if (isset($config['resource']) && isset($config['pattern'])) {
|
||||
if (isset($config['resource']) && isset($config['path'])) {
|
||||
throw new \InvalidArgumentException(sprintf(
|
||||
'The routing file "%s" must not specify both the "resource" key and the "pattern" key for "%s". Choose between an import and a route definition.',
|
||||
'The routing file "%s" must not specify both the "resource" key and the "path" key for "%s". Choose between an import and a route definition.',
|
||||
$path, $name
|
||||
));
|
||||
}
|
||||
@ -180,9 +189,9 @@ class YamlFileLoader extends FileLoader
|
||||
$name, $path
|
||||
));
|
||||
}
|
||||
if (!isset($config['resource']) && !isset($config['pattern'])) {
|
||||
if (!isset($config['resource']) && !isset($config['path'])) {
|
||||
throw new \InvalidArgumentException(sprintf(
|
||||
'You must define a "pattern" for the route "%s" in file "%s".',
|
||||
'You must define a "path" for the route "%s" in file "%s".',
|
||||
$name, $path
|
||||
));
|
||||
}
|
||||
|
@ -46,7 +46,8 @@
|
||||
<xsd:group ref="configs" minOccurs="0" maxOccurs="unbounded" />
|
||||
|
||||
<xsd:attribute name="id" type="xsd:string" use="required" />
|
||||
<xsd:attribute name="pattern" type="xsd:string" use="required" />
|
||||
<xsd:attribute name="path" type="xsd:string" />
|
||||
<xsd:attribute name="pattern" type="xsd:string" />
|
||||
<xsd:attribute name="hostname" type="xsd:string" />
|
||||
<xsd:attribute name="schemes" type="stringlist" />
|
||||
<xsd:attribute name="methods" type="stringlist" />
|
||||
|
@ -48,16 +48,16 @@ class TraceableUrlMatcher extends UrlMatcher
|
||||
|
||||
if (!preg_match($compiledRoute->getRegex(), $pathinfo, $matches)) {
|
||||
// does it match without any requirements?
|
||||
$r = new Route($route->getPattern(), $route->getDefaults(), array(), $route->getOptions());
|
||||
$r = new Route($route->getPath(), $route->getDefaults(), array(), $route->getOptions());
|
||||
$cr = $r->compile();
|
||||
if (!preg_match($cr->getRegex(), $pathinfo)) {
|
||||
$this->addTrace(sprintf('Pattern "%s" does not match', $route->getPattern()), self::ROUTE_DOES_NOT_MATCH, $name, $route);
|
||||
$this->addTrace(sprintf('Path "%s" does not match', $route->getPath()), self::ROUTE_DOES_NOT_MATCH, $name, $route);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ($route->getRequirements() as $n => $regex) {
|
||||
$r = new Route($route->getPattern(), $route->getDefaults(), array($n => $regex), $route->getOptions());
|
||||
$r = new Route($route->getPath(), $route->getDefaults(), array($n => $regex), $route->getOptions());
|
||||
$cr = $r->compile();
|
||||
|
||||
if (in_array($n, $cr->getVariables()) && !preg_match($cr->getRegex(), $pathinfo)) {
|
||||
@ -104,10 +104,10 @@ class TraceableUrlMatcher extends UrlMatcher
|
||||
private function addTrace($log, $level = self::ROUTE_DOES_NOT_MATCH, $name = null, $route = null)
|
||||
{
|
||||
$this->traces[] = array(
|
||||
'log' => $log,
|
||||
'name' => $name,
|
||||
'level' => $level,
|
||||
'pattern' => null !== $route ? $route->getPattern() : null,
|
||||
'log' => $log,
|
||||
'name' => $name,
|
||||
'level' => $level,
|
||||
'path' => null !== $route ? $route->getPath() : null,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ class Route implements \Serializable
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $pattern = '/';
|
||||
private $path = '/';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
@ -70,7 +70,7 @@ class Route implements \Serializable
|
||||
*
|
||||
* * compiler_class: A class name able to compile this route instance (RouteCompiler by default)
|
||||
*
|
||||
* @param string $pattern The path pattern to match
|
||||
* @param string $path The path pattern to match
|
||||
* @param array $defaults An array of default parameter values
|
||||
* @param array $requirements An array of requirements for parameters (regexes)
|
||||
* @param array $options An array of options
|
||||
@ -80,9 +80,9 @@ class Route implements \Serializable
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function __construct($pattern, array $defaults = array(), array $requirements = array(), array $options = array(), $hostname = '', $schemes = array(), $methods = array())
|
||||
public function __construct($path, array $defaults = array(), array $requirements = array(), array $options = array(), $hostname = '', $schemes = array(), $methods = array())
|
||||
{
|
||||
$this->setPattern($pattern);
|
||||
$this->setPath($path);
|
||||
$this->setDefaults($defaults);
|
||||
$this->setRequirements($requirements);
|
||||
$this->setOptions($options);
|
||||
@ -100,7 +100,7 @@ class Route implements \Serializable
|
||||
public function serialize()
|
||||
{
|
||||
return serialize(array(
|
||||
'pattern' => $this->pattern,
|
||||
'path' => $this->path,
|
||||
'hostname' => $this->hostname,
|
||||
'defaults' => $this->defaults,
|
||||
'requirements' => $this->requirements,
|
||||
@ -113,7 +113,7 @@ class Route implements \Serializable
|
||||
public function unserialize($data)
|
||||
{
|
||||
$data = unserialize($data);
|
||||
$this->pattern = $data['pattern'];
|
||||
$this->path = $data['path'];
|
||||
$this->hostname = $data['hostname'];
|
||||
$this->defaults = $data['defaults'];
|
||||
$this->requirements = $data['requirements'];
|
||||
@ -126,10 +126,12 @@ class Route implements \Serializable
|
||||
* Returns the pattern for the path.
|
||||
*
|
||||
* @return string The pattern
|
||||
*
|
||||
* @deprecated Deprecated in 2.2, to be removed in 3.0. Use setPath instead.
|
||||
*/
|
||||
public function getPattern()
|
||||
{
|
||||
return $this->pattern;
|
||||
return $this->path;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -140,12 +142,38 @@ class Route implements \Serializable
|
||||
* @param string $pattern The pattern
|
||||
*
|
||||
* @return Route The current Route instance
|
||||
*
|
||||
* @deprecated Deprecated in 2.2, to be removed in 3.0. Use setPath instead.
|
||||
*/
|
||||
public function setPattern($pattern)
|
||||
{
|
||||
return $this->setPath($pattern);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the pattern for the path.
|
||||
*
|
||||
* @return string The path pattern
|
||||
*/
|
||||
public function getPath()
|
||||
{
|
||||
return $this->path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the pattern for the path.
|
||||
*
|
||||
* This method implements a fluent interface.
|
||||
*
|
||||
* @param string $path The path pattern
|
||||
*
|
||||
* @return Route The current Route instance
|
||||
*/
|
||||
public function setPath($path)
|
||||
{
|
||||
// A pattern must start with a slash and must not have multiple slashes at the beginning because the
|
||||
// generated path for this route would be confused with a network path, e.g. '//domain.com/path'.
|
||||
$this->pattern = '/' . ltrim(trim($pattern), '/');
|
||||
$this->path = '/' . ltrim(trim($path), '/');
|
||||
$this->compiled = null;
|
||||
|
||||
return $this;
|
||||
|
@ -235,7 +235,7 @@ class RouteCollection implements \IteratorAggregate, \Countable
|
||||
$options = func_num_args() > 3 ? func_get_arg(3) : array();
|
||||
|
||||
foreach ($this->routes as $route) {
|
||||
$route->setPattern('/' . $prefix . $route->getPattern());
|
||||
$route->setPath('/' . $prefix . $route->getPath());
|
||||
$route->addDefaults($defaults);
|
||||
$route->addRequirements($requirements);
|
||||
$route->addOptions($options);
|
||||
|
@ -56,9 +56,9 @@ class RouteCompiler implements RouteCompilerInterface
|
||||
$hostnameRegex = $result['regex'];
|
||||
}
|
||||
|
||||
$pattern = $route->getPattern();
|
||||
$path = $route->getPath();
|
||||
|
||||
$result = $this->compilePattern($route, $pattern, false);
|
||||
$result = $this->compilePattern($route, $path, false);
|
||||
|
||||
$staticPrefix = $result['staticPrefix'];
|
||||
|
||||
|
@ -36,6 +36,7 @@ class RouteTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
return array(
|
||||
array('value', '/Blog', 'getPattern'),
|
||||
array('value', '/Blog', 'getPath'),
|
||||
array('requirements', array('_method' => 'GET'), 'getRequirements'),
|
||||
array('options', array('compiler_class' => 'RouteCompiler'), 'getOptions'),
|
||||
array('name', 'blog_index', 'getName'),
|
||||
|
@ -89,7 +89,7 @@ class AnnotationClassLoaderTest extends AbstractAnnotationLoaderTest
|
||||
{
|
||||
$routeDatas = array_replace(array(
|
||||
'name' => 'route',
|
||||
'pattern' => '/',
|
||||
'path' => '/',
|
||||
'requirements' => array(),
|
||||
'options' => array(),
|
||||
'defaults' => array(),
|
||||
@ -103,7 +103,7 @@ class AnnotationClassLoaderTest extends AbstractAnnotationLoaderTest
|
||||
$routeCollection = $this->loader->load($className);
|
||||
$route = $routeCollection->get($routeDatas['name']);
|
||||
|
||||
$this->assertSame($routeDatas['pattern'], $route->getPattern(), '->load preserves pattern annotation');
|
||||
$this->assertSame($routeDatas['path'], $route->getPath(), '->load preserves path annotation');
|
||||
$this->assertSame($routeDatas['requirements'],$route->getRequirements(), '->load preserves requirements annotation');
|
||||
$this->assertCount(0, array_intersect($route->getOptions(), $routeDatas['options']), '->load preserves options annotation');
|
||||
$this->assertSame(array_replace($routeDatas['defaults'], $methodArgs), $route->getDefaults(), '->load preserves defaults annotation');
|
||||
|
@ -43,7 +43,7 @@ class PhpFileLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertEquals(1, count($routes), 'One route is loaded');
|
||||
$this->assertContainsOnly('Symfony\Component\Routing\Route', $routes);
|
||||
$route = $routes['blog_show'];
|
||||
$this->assertEquals('/blog/{slug}', $route->getPattern());
|
||||
$this->assertEquals('/blog/{slug}', $route->getPath());
|
||||
$this->assertEquals('MyBlogBundle:Blog:show', $route->getDefault('_controller'));
|
||||
$this->assertEquals('GET', $route->getRequirement('_method'));
|
||||
$this->assertEquals('{locale}.example.com', $route->getHostname());
|
||||
|
@ -44,7 +44,7 @@ class XmlFileLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertEquals(1, count($routes), 'One route is loaded');
|
||||
$this->assertContainsOnly('Symfony\Component\Routing\Route', $routes);
|
||||
$route = $routes['blog_show'];
|
||||
$this->assertEquals('/blog/{slug}', $route->getPattern());
|
||||
$this->assertEquals('/blog/{slug}', $route->getPath());
|
||||
$this->assertEquals('MyBundle:Blog:show', $route->getDefault('_controller'));
|
||||
$this->assertEquals('GET', $route->getRequirement('_method'));
|
||||
$this->assertEquals('\w+', $route->getRequirement('locale'));
|
||||
@ -59,7 +59,7 @@ class XmlFileLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
$this->assertCount(1, $routeCollection, 'One route is loaded');
|
||||
$route = $routeCollection->get('blog_show');
|
||||
$this->assertEquals('/blog/{slug}', $route->getPattern());
|
||||
$this->assertEquals('/blog/{slug}', $route->getPath());
|
||||
$this->assertEquals('MyBundle:Blog:show', $route->getDefault('_controller'));
|
||||
$this->assertEquals('\w+', $route->getRequirement('slug'));
|
||||
$this->assertEquals('en|fr|de', $route->getRequirement('_locale'));
|
||||
@ -75,7 +75,7 @@ class XmlFileLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
$this->assertEquals(1, count($routes), 'One route is loaded');
|
||||
$this->assertContainsOnly('Symfony\Component\Routing\Route', $routes);
|
||||
$this->assertEquals('/{foo}/blog/{slug}', $routes['blog_show']->getPattern());
|
||||
$this->assertEquals('/{foo}/blog/{slug}', $routes['blog_show']->getPath());
|
||||
$this->assertEquals('MyBundle:Blog:show', $routes['blog_show']->getDefault('_controller'));
|
||||
$this->assertEquals('123', $routes['blog_show']->getDefault('foo'));
|
||||
$this->assertEquals('\d+', $routes['blog_show']->getRequirement('foo'));
|
||||
|
@ -70,7 +70,7 @@ class YamlFileLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
$route = $routeCollection->get('#$péß^a|');
|
||||
|
||||
$this->assertInstanceOf('Symfony\Component\Routing\Route', $route);
|
||||
$this->assertSame('/true', $route->getPattern());
|
||||
$this->assertSame('/true', $route->getPath());
|
||||
}
|
||||
|
||||
public function testLoadWithPattern()
|
||||
@ -82,7 +82,7 @@ class YamlFileLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertEquals(1, count($routes), 'One route is loaded');
|
||||
$this->assertContainsOnly('Symfony\Component\Routing\Route', $routes);
|
||||
$route = $routes['blog_show'];
|
||||
$this->assertEquals('/blog/{slug}', $route->getPattern());
|
||||
$this->assertEquals('/blog/{slug}', $route->getPath());
|
||||
$this->assertEquals('MyBlogBundle:Blog:show', $route->getDefault('_controller'));
|
||||
$this->assertEquals('GET', $route->getRequirement('_method'));
|
||||
$this->assertEquals('\w+', $route->getRequirement('locale'));
|
||||
@ -98,7 +98,7 @@ class YamlFileLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
$this->assertEquals(1, count($routes), 'One route is loaded');
|
||||
$this->assertContainsOnly('Symfony\Component\Routing\Route', $routes);
|
||||
$this->assertEquals('/{foo}/blog/{slug}', $routes['blog_show']->getPattern());
|
||||
$this->assertEquals('/{foo}/blog/{slug}', $routes['blog_show']->getPath());
|
||||
$this->assertEquals('MyBlogBundle:Blog:show', $routes['blog_show']->getDefault('_controller'));
|
||||
$this->assertEquals('123', $routes['blog_show']->getDefault('foo'));
|
||||
$this->assertEquals('\d+', $routes['blog_show']->getRequirement('foo'));
|
||||
|
@ -105,7 +105,7 @@ EOF;
|
||||
$string .= sprintf("%s|-coll %s\n", $prefix, $route->getPrefix());
|
||||
$string .= $this->collectionToString($route, $prefix.'| ');
|
||||
} else {
|
||||
$string .= sprintf("%s|-route %s %s\n", $prefix, $route->getName(), $route->getRoute()->getPattern());
|
||||
$string .= sprintf("%s|-route %s %s\n", $prefix, $route->getName(), $route->getRoute()->getPath());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -33,7 +33,7 @@ class RouteCollectionTest extends \PHPUnit_Framework_TestCase
|
||||
$collection->add('foo', new Route('/foo'));
|
||||
$collection->add('foo', new Route('/foo1'));
|
||||
|
||||
$this->assertEquals('/foo1', $collection->get('foo')->getPattern());
|
||||
$this->assertEquals('/foo1', $collection->get('foo')->getPath());
|
||||
}
|
||||
|
||||
public function testDeepOverriddenRoute()
|
||||
@ -50,8 +50,8 @@ class RouteCollectionTest extends \PHPUnit_Framework_TestCase
|
||||
$collection1->addCollection($collection2);
|
||||
$collection->addCollection($collection1);
|
||||
|
||||
$this->assertEquals('/foo2', $collection1->get('foo')->getPattern());
|
||||
$this->assertEquals('/foo2', $collection->get('foo')->getPattern());
|
||||
$this->assertEquals('/foo2', $collection1->get('foo')->getPath());
|
||||
$this->assertEquals('/foo2', $collection->get('foo')->getPath());
|
||||
}
|
||||
|
||||
public function testIteratorWithOverriddenRoutes()
|
||||
@ -63,7 +63,7 @@ class RouteCollectionTest extends \PHPUnit_Framework_TestCase
|
||||
$collection1->add('foo', new Route('/foo1'));
|
||||
$collection->addCollection($collection1);
|
||||
|
||||
$this->assertEquals('/foo1', $this->getFirstNamedRoute($collection, 'foo')->getPattern());
|
||||
$this->assertEquals('/foo1', $this->getFirstNamedRoute($collection, 'foo')->getPath());
|
||||
}
|
||||
|
||||
public function testCount()
|
||||
@ -110,7 +110,7 @@ class RouteCollectionTest extends \PHPUnit_Framework_TestCase
|
||||
$collection1 = new RouteCollection();
|
||||
$collection1->add('foo', $foo1 = new Route('/foo1'));
|
||||
$collection->addCollection($collection1, '/{foo}', array('foo' => 'foo'), array('foo' => '\d+'), array('foo' => 'bar'));
|
||||
$this->assertEquals('/{foo}/foo1', $collection->get('foo')->getPattern(), '->addCollection() can add a prefix to all merged routes');
|
||||
$this->assertEquals('/{foo}/foo1', $collection->get('foo')->getPath(), '->addCollection() can add a prefix to all merged routes');
|
||||
$this->assertEquals(array('foo' => 'foo'), $collection->get('foo')->getDefaults(), '->addCollection() can add a prefix to all merged routes');
|
||||
$this->assertEquals(array('foo' => '\d+'), $collection->get('foo')->getRequirements(), '->addCollection() can add a prefix to all merged routes');
|
||||
$this->assertEquals(
|
||||
@ -137,8 +137,8 @@ class RouteCollectionTest extends \PHPUnit_Framework_TestCase
|
||||
$collection->addPrefix(' / ');
|
||||
$this->assertSame('', $collection->getPrefix(), '->addPrefix() trims the prefix and a single slash has no effect');
|
||||
$collection->addPrefix('/{admin}', array('admin' => 'admin'), array('admin' => '\d+'), array('foo' => 'bar'));
|
||||
$this->assertEquals('/{admin}/foo', $collection->get('foo')->getPattern(), '->addPrefix() adds a prefix to all routes');
|
||||
$this->assertEquals('/{admin}/bar', $collection->get('bar')->getPattern(), '->addPrefix() adds a prefix to all routes');
|
||||
$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');
|
||||
@ -155,8 +155,8 @@ class RouteCollectionTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertEquals('/0/{admin}', $collection->getPrefix(), '->addPrefix() ensures a prefix must start with a slash and must not end with a slash');
|
||||
$collection->addPrefix('/ /');
|
||||
$this->assertSame('/ /0/{admin}', $collection->getPrefix(), '->addPrefix() can handle spaces if desired');
|
||||
$this->assertSame('/ /0/{admin}/foo', $collection->get('foo')->getPattern(), 'the route pattern is in synch with the collection prefix');
|
||||
$this->assertSame('/ /0/{admin}/bar', $collection->get('bar')->getPattern(), 'the route pattern in a sub-collection is in synch with the collection prefix');
|
||||
$this->assertSame('/ /0/{admin}/foo', $collection->get('foo')->getPath(), 'the route path is in synch with the collection prefix');
|
||||
$this->assertSame('/ /0/{admin}/bar', $collection->get('bar')->getPath(), 'the route path in a sub-collection is in synch with the collection prefix');
|
||||
}
|
||||
|
||||
public function testAddPrefixOverridesDefaultsAndRequirements()
|
||||
|
@ -18,7 +18,7 @@ class RouteTest extends \PHPUnit_Framework_TestCase
|
||||
public function testConstructor()
|
||||
{
|
||||
$route = new Route('/{foo}', array('foo' => 'bar'), array('foo' => '\d+'), array('foo' => 'bar'), '{locale}.example.com');
|
||||
$this->assertEquals('/{foo}', $route->getPattern(), '__construct() takes a pattern as its first argument');
|
||||
$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('bar', $route->getOption('foo'), '__construct() takes options as its fourth argument');
|
||||
@ -33,18 +33,18 @@ class RouteTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertEquals(array('POST'), $route->getMethods(), '__construct() takes a single method as its seventh argument');
|
||||
}
|
||||
|
||||
public function testPattern()
|
||||
public function testPath()
|
||||
{
|
||||
$route = new Route('/{foo}');
|
||||
$route->setPattern('/{bar}');
|
||||
$this->assertEquals('/{bar}', $route->getPattern(), '->setPattern() sets the pattern');
|
||||
$route->setPattern('');
|
||||
$this->assertEquals('/', $route->getPattern(), '->setPattern() adds a / at the beginning of the pattern if needed');
|
||||
$route->setPattern('bar');
|
||||
$this->assertEquals('/bar', $route->getPattern(), '->setPattern() adds a / at the beginning of the pattern if needed');
|
||||
$this->assertEquals($route, $route->setPattern(''), '->setPattern() implements a fluent interface');
|
||||
$route->setPattern('//path');
|
||||
$this->assertEquals('/path', $route->getPattern(), '->setPattern() does not allow two slahes "//" at the beginning of the pattern as it would be confused with a network path when generating the path from the route');
|
||||
$route->setPath('/{bar}');
|
||||
$this->assertEquals('/{bar}', $route->getPath(), '->setPath() sets the path');
|
||||
$route->setPath('');
|
||||
$this->assertEquals('/', $route->getPath(), '->setPath() adds a / at the beginning of the path if needed');
|
||||
$route->setPath('bar');
|
||||
$this->assertEquals('/bar', $route->getPath(), '->setPath() adds a / at the beginning of the path if needed');
|
||||
$this->assertEquals($route, $route->setPath(''), '->setPath() implements a fluent interface');
|
||||
$route->setPath('//path');
|
||||
$this->assertEquals('/path', $route->getPath(), '->setPath() does not allow two slahes "//" at the beginning of the path as it would be confused with a network path when generating the path from the route');
|
||||
}
|
||||
|
||||
public function testOptions()
|
||||
@ -93,7 +93,7 @@ class RouteTest extends \PHPUnit_Framework_TestCase
|
||||
$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+$'));
|
||||
$this->assertEquals('\d+', $route->getRequirement('foo'), '->getRequirement() removes ^ and $ from the pattern');
|
||||
$this->assertEquals('\d+', $route->getRequirement('foo'), '->getRequirement() removes ^ and $ from the path');
|
||||
$this->assertEquals($route, $route->setRequirements(array()), '->setRequirements() implements a fluent interface');
|
||||
|
||||
$route->setRequirements(array('foo' => '\d+'));
|
||||
@ -106,7 +106,7 @@ class RouteTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
$route = new Route('/{foo}');
|
||||
$route->setRequirement('foo', '^\d+$');
|
||||
$this->assertEquals('\d+', $route->getRequirement('foo'), '->setRequirement() removes ^ and $ from the pattern');
|
||||
$this->assertEquals('\d+', $route->getRequirement('foo'), '->setRequirement() removes ^ and $ from the path');
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user