Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

merged branch fabpot/pattern-fix (PR #6998)

This PR was merged into the 2.2 branch.

Commits
-------

73aa7d1 replaced usage of the deprecated pattern routing key (replaced with path)

Discussion
----------

replaced usage of the deprecated pattern routing key (replaced with path)

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | n/a
| License       | MIT
| Doc PR        | n/a

---------------------------------------------------------------------------

by lsmith77 at 2013-02-07T13:35:54Z

do we have tests to cover the BC behavior?

---------------------------------------------------------------------------

by fabpot at 2013-02-07T16:30:31Z

I've just added some tests for the legacy way.
  • Loading branch information...
commit ee515991aba18a6b3f8ddc02c144f9ed6555c44f 2 parents 46972c7 + 5342c0d
@fabpot fabpot authored
View
2  Tests/Fixtures/nonesense_resource_plus_path.yml
@@ -1,3 +1,3 @@
blog_show:
resource: validpattern.yml
- pattern: /test
+ path: /test
View
2  Tests/Fixtures/nonesense_type_without_resource.yml
@@ -1,3 +1,3 @@
blog_show:
- pattern: /blog/{slug}
+ path: /blog/{slug}
type: custom
View
2  Tests/Fixtures/special_route_name.yml
@@ -1,2 +1,2 @@
"#$péß^a|":
- pattern: "true"
+ path: "true"
View
11 Tests/Fixtures/validpattern.php
@@ -6,9 +6,18 @@
$collection->add('blog_show', new Route(
'/blog/{slug}',
array('_controller' => 'MyBlogBundle:Blog:show'),
- array('_method' => 'GET', 'locale' => '\w+'),
+ array('_method' => 'GET', 'locale' => '\w+', '_scheme' => 'https'),
array('compiler_class' => 'RouteCompiler'),
'{locale}.example.com'
));
+$collection->add('blog_show_legacy', new Route(
+ '/blog/{slug}',
+ array('_controller' => 'MyBlogBundle:Blog:show'),
+ array('locale' => '\w+'),
+ array('compiler_class' => 'RouteCompiler'),
+ '{locale}.example.com',
+ array('https'),
+ array('GET')
+));
return $collection;
View
9 Tests/Fixtures/validpattern.xml
@@ -4,9 +4,16 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd">
- <route id="blog_show" pattern="/blog/{slug}" host="{locale}.example.com">
+ <route id="blog_show" path="/blog/{slug}" host="{locale}.example.com" methods="GET" schemes="https">
+ <default key="_controller">MyBundle:Blog:show</default>
+ <requirement key="locale">\w+</requirement>
+ <option key="compiler_class">RouteCompiler</option>
+ </route>
+
+ <route id="blog_show_legacy" pattern="/blog/{slug}" host="{locale}.example.com">
<default key="_controller">MyBundle:Blog:show</default>
<requirement key="_method">GET</requirement>
+ <requirement key="_scheme">https</requirement>
<requirement key="locale">\w+</requirement>
<option key="compiler_class">RouteCompiler</option>
</route>
View
14 Tests/Fixtures/validpattern.yml
@@ -1,7 +1,17 @@
blog_show:
+ path: /blog/{slug}
+ defaults: { _controller: MyBlogBundle:Blog:show }
+ host: "{locale}.example.com"
+ requirements: { 'locale': '\w+' }
+ methods: ['GET']
+ schemes: ['https']
+ options:
+ compiler_class: RouteCompiler
+
+blog_show_legacy:
pattern: /blog/{slug}
defaults: { _controller: MyBlogBundle:Blog:show }
- host : "{locale}.example.com"
- requirements: { '_method': 'GET', 'locale': '\w+' }
+ host: "{locale}.example.com"
+ requirements: { '_method': 'GET', 'locale': '\w+', _scheme: 'https' }
options:
compiler_class: RouteCompiler
View
17 Tests/Loader/PhpFileLoaderTest.php
@@ -40,13 +40,16 @@ public function testLoadWithRoute()
$routeCollection = $loader->load('validpattern.php');
$routes = $routeCollection->all();
- $this->assertEquals(1, count($routes), 'One route is loaded');
+ $this->assertCount(2, $routes, 'Two routes are loaded');
$this->assertContainsOnly('Symfony\Component\Routing\Route', $routes);
- $route = $routes['blog_show'];
- $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->getHost());
- $this->assertEquals('RouteCompiler', $route->getOption('compiler_class'));
+
+ foreach ($routes as $route) {
+ $this->assertEquals('/blog/{slug}', $route->getPath());
+ $this->assertEquals('MyBlogBundle:Blog:show', $route->getDefault('_controller'));
+ $this->assertEquals('GET', $route->getRequirement('_method'));
+ $this->assertEquals('https', $route->getRequirement('_scheme'));
+ $this->assertEquals('{locale}.example.com', $route->getHost());
+ $this->assertEquals('RouteCompiler', $route->getOption('compiler_class'));
+ }
}
}
View
23 Tests/Loader/XmlFileLoaderTest.php
@@ -41,12 +41,13 @@ public function testLoadWithRoute()
$routeCollection = $loader->load('validpattern.xml');
$routes = $routeCollection->all();
- $this->assertEquals(1, count($routes), 'One route is loaded');
+ $this->assertCount(2, $routes, 'Two routes are loaded');
$this->assertContainsOnly('Symfony\Component\Routing\Route', $routes);
$route = $routes['blog_show'];
$this->assertEquals('/blog/{slug}', $route->getPath());
$this->assertEquals('MyBundle:Blog:show', $route->getDefault('_controller'));
$this->assertEquals('GET', $route->getRequirement('_method'));
+ $this->assertEquals('https', $route->getRequirement('_scheme'));
$this->assertEquals('\w+', $route->getRequirement('locale'));
$this->assertEquals('{locale}.example.com', $route->getHost());
$this->assertEquals('RouteCompiler', $route->getOption('compiler_class'));
@@ -57,7 +58,8 @@ public function testLoadWithNamespacePrefix()
$loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
$routeCollection = $loader->load('namespaceprefix.xml');
- $this->assertCount(1, $routeCollection, 'One route is loaded');
+ $this->assertCount(1, $routeCollection->all(), 'One route is loaded');
+
$route = $routeCollection->get('blog_show');
$this->assertEquals('/blog/{slug}', $route->getPath());
$this->assertEquals('MyBundle:Blog:show', $route->getDefault('_controller'));
@@ -73,14 +75,17 @@ public function testLoadWithImport()
$routeCollection = $loader->load('validresource.xml');
$routes = $routeCollection->all();
- $this->assertEquals(1, count($routes), 'One route is loaded');
+ $this->assertCount(2, $routes, 'Two routes are loaded');
$this->assertContainsOnly('Symfony\Component\Routing\Route', $routes);
- $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'));
- $this->assertEquals('bar', $routes['blog_show']->getOption('foo'));
- $this->assertEquals('{locale}.example.com', $routes['blog_show']->getHost());
+
+ foreach ($routes as $route) {
+ $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'));
+ $this->assertEquals('bar', $routes['blog_show']->getOption('foo'));
+ $this->assertEquals('{locale}.example.com', $routes['blog_show']->getHost());
+ }
}
/**
View
21 Tests/Loader/YamlFileLoaderTest.php
@@ -79,15 +79,18 @@ public function testLoadWithPattern()
$routeCollection = $loader->load('validpattern.yml');
$routes = $routeCollection->all();
- $this->assertEquals(1, count($routes), 'One route is loaded');
+ $this->assertCount(2, $routes, 'Two routes are loaded');
$this->assertContainsOnly('Symfony\Component\Routing\Route', $routes);
- $route = $routes['blog_show'];
- $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'));
- $this->assertEquals('{locale}.example.com', $route->getHost());
- $this->assertEquals('RouteCompiler', $route->getOption('compiler_class'));
+
+ foreach ($routes as $route) {
+ $this->assertEquals('/blog/{slug}', $route->getPath());
+ $this->assertEquals('MyBlogBundle:Blog:show', $route->getDefault('_controller'));
+ $this->assertEquals('GET', $route->getRequirement('_method'));
+ $this->assertEquals('https', $route->getRequirement('_scheme'));
+ $this->assertEquals('\w+', $route->getRequirement('locale'));
+ $this->assertEquals('{locale}.example.com', $route->getHost());
+ $this->assertEquals('RouteCompiler', $route->getOption('compiler_class'));
+ }
}
public function testLoadWithResource()
@@ -96,7 +99,7 @@ public function testLoadWithResource()
$routeCollection = $loader->load('validresource.yml');
$routes = $routeCollection->all();
- $this->assertEquals(1, count($routes), 'One route is loaded');
+ $this->assertCount(2, $routes, 'Two routes are loaded');
$this->assertContainsOnly('Symfony\Component\Routing\Route', $routes);
$this->assertEquals('/{foo}/blog/{slug}', $routes['blog_show']->getPath());
$this->assertEquals('MyBlogBundle:Blog:show', $routes['blog_show']->getDefault('_controller'));
Please sign in to comment.
Something went wrong with that request. Please try again.