[Routing] added some unit tests for the YAML loader
This commit is contained in:
parent
92f9c1561b
commit
3dfca47bcd
@ -57,7 +57,7 @@ use Symfony\Component\Config\Loader\LoaderResolverInterface;
|
|||||||
abstract class AnnotationClassLoader implements LoaderInterface
|
abstract class AnnotationClassLoader implements LoaderInterface
|
||||||
{
|
{
|
||||||
protected $reader;
|
protected $reader;
|
||||||
protected $routeAnnotationClass = 'Symfony\\Component\\Routing\\Annotation\\Route';
|
protected $routeAnnotationClass = 'Symfony\\Component\\Routing\\Annotation\\Route';
|
||||||
protected $defaultRouteIndex;
|
protected $defaultRouteIndex;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -97,11 +97,11 @@ abstract class AnnotationClassLoader implements LoaderInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
$globals = array(
|
$globals = array(
|
||||||
'pattern' => '',
|
'pattern' => '',
|
||||||
'requirements' => array(),
|
'requirements' => array(),
|
||||||
'options' => array(),
|
'options' => array(),
|
||||||
'defaults' => array(),
|
'defaults' => array(),
|
||||||
'hostname_pattern' => null,
|
'hostname_pattern' => null,
|
||||||
);
|
);
|
||||||
|
|
||||||
$class = new \ReflectionClass($class);
|
$class = new \ReflectionClass($class);
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
blog_show:
|
blog_show:
|
||||||
pattern: /blog/{slug}
|
pattern: /blog/{slug}
|
||||||
defaults: { _controller: MyBlogBundle:Blog:show }
|
defaults: { _controller: MyBlogBundle:Blog:show }
|
||||||
|
hostname_pattern: "{locale}.example.com"
|
||||||
|
requirements: { 'foo': '\d+' }
|
||||||
options:
|
options:
|
||||||
compiler_class: RouteCompiler
|
compiler_class: RouteCompiler
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
blog_show:
|
blog_show:
|
||||||
resource: validpattern.yml
|
resource: validpattern.yml
|
||||||
prefix: /{foo}
|
prefix: /{foo}
|
||||||
defaults: { 'foo': 'foo' }
|
defaults: { 'foo': 'foo' }
|
||||||
requirements: { 'foo': '\d+' }
|
requirements: { 'foo': '\d+' }
|
||||||
options: { 'foo': 'bar' }
|
options: { 'foo': 'bar' }
|
||||||
|
hostname_pattern: "{locale}.example.com"
|
||||||
|
@ -88,6 +88,10 @@ class YamlFileLoaderTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals(1, count($routes), 'One route is loaded');
|
$this->assertEquals(1, count($routes), 'One route is loaded');
|
||||||
$this->assertContainsOnly('Symfony\Component\Routing\Route', $routes);
|
$this->assertContainsOnly('Symfony\Component\Routing\Route', $routes);
|
||||||
$route = $routes['blog_show'];
|
$route = $routes['blog_show'];
|
||||||
|
$this->assertEquals('/blog/{slug}', $route->getPattern());
|
||||||
|
$this->assertEquals('MyBlogBundle:Blog:show', $route->getDefault('_controller'));
|
||||||
|
$this->assertEquals('\d+', $route->getRequirement('foo'));
|
||||||
|
$this->assertEquals('{locale}.example.com', $route->getHostnamePattern());
|
||||||
$this->assertEquals('RouteCompiler', $route->getOption('compiler_class'));
|
$this->assertEquals('RouteCompiler', $route->getOption('compiler_class'));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -99,9 +103,12 @@ class YamlFileLoaderTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
$this->assertEquals(1, count($routes), 'One route is loaded');
|
$this->assertEquals(1, count($routes), 'One route is loaded');
|
||||||
$this->assertContainsOnly('Symfony\Component\Routing\Route', $routes);
|
$this->assertContainsOnly('Symfony\Component\Routing\Route', $routes);
|
||||||
|
$this->assertEquals('/{foo}/blog/{slug}', $routes['blog_show']->getPattern());
|
||||||
|
$this->assertEquals('MyBlogBundle:Blog:show', $routes['blog_show']->getDefault('_controller'));
|
||||||
$this->assertEquals('foo', $routes['blog_show']->getDefault('foo'));
|
$this->assertEquals('foo', $routes['blog_show']->getDefault('foo'));
|
||||||
$this->assertEquals('\d+', $routes['blog_show']->getRequirement('foo'));
|
$this->assertEquals('\d+', $routes['blog_show']->getRequirement('foo'));
|
||||||
$this->assertEquals('bar', $routes['blog_show']->getOption('foo'));
|
$this->assertEquals('bar', $routes['blog_show']->getOption('foo'));
|
||||||
|
$this->assertEquals('{locale}.example.com', $routes['blog_show']->getHostnamePattern());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user