-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[Routing][DX] Add full route definition for invokable controller/class #21723
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Routing\Tests\Fixtures\AnnotatedClasses; | ||
|
||
class BazClass | ||
{ | ||
public function __invoke() | ||
{ | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -180,6 +180,73 @@ public function testClassRouteLoad() | |
$this->assertEquals(array_merge($classRouteData['methods'], $methodRouteData['methods']), $route->getMethods(), '->load merges class and method route methods'); | ||
} | ||
|
||
public function testInvokableClassRouteLoad() | ||
{ | ||
$classRouteData = array( | ||
'name' => 'route1', | ||
'path' => '/', | ||
'schemes' => array('https'), | ||
'methods' => array('GET'), | ||
); | ||
|
||
$this->reader | ||
->expects($this->exactly(2)) | ||
->method('getClassAnnotation') | ||
->will($this->returnValue($this->getAnnotatedRoute($classRouteData))) | ||
; | ||
$this->reader | ||
->expects($this->once()) | ||
->method('getMethodAnnotations') | ||
->will($this->returnValue(array())) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't you think a test case with an annotation on method would be great to avoid a potential regression? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, thanks! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Test added! |
||
; | ||
|
||
$routeCollection = $this->loader->load('Symfony\Component\Routing\Tests\Fixtures\AnnotatedClasses\BazClass'); | ||
$route = $routeCollection->get($classRouteData['name']); | ||
|
||
$this->assertSame($classRouteData['path'], $route->getPath(), '->load preserves class route path'); | ||
$this->assertEquals(array_merge($classRouteData['schemes'], $classRouteData['schemes']), $route->getSchemes(), '->load preserves class route schemes'); | ||
$this->assertEquals(array_merge($classRouteData['methods'], $classRouteData['methods']), $route->getMethods(), '->load preserves class route methods'); | ||
} | ||
|
||
public function testInvokableClassWithMethodRouteLoad() | ||
{ | ||
$classRouteData = array( | ||
'name' => 'route1', | ||
'path' => '/prefix', | ||
'schemes' => array('https'), | ||
'methods' => array('GET'), | ||
); | ||
|
||
$methodRouteData = array( | ||
'name' => 'route2', | ||
'path' => '/path', | ||
'schemes' => array('http'), | ||
'methods' => array('POST', 'PUT'), | ||
); | ||
|
||
$this->reader | ||
->expects($this->once()) | ||
->method('getClassAnnotation') | ||
->will($this->returnValue($this->getAnnotatedRoute($classRouteData))) | ||
; | ||
$this->reader | ||
->expects($this->once()) | ||
->method('getMethodAnnotations') | ||
->will($this->returnValue(array($this->getAnnotatedRoute($methodRouteData)))) | ||
; | ||
|
||
$routeCollection = $this->loader->load('Symfony\Component\Routing\Tests\Fixtures\AnnotatedClasses\BazClass'); | ||
$route = $routeCollection->get($classRouteData['name']); | ||
|
||
$this->assertNull($route, '->load ignores class route'); | ||
|
||
$route = $routeCollection->get($methodRouteData['name']); | ||
|
||
$this->assertSame($classRouteData['path'].$methodRouteData['path'], $route->getPath(), '->load concatenates class and method route path'); | ||
$this->assertEquals(array_merge($classRouteData['schemes'], $methodRouteData['schemes']), $route->getSchemes(), '->load merges class and method route schemes'); | ||
$this->assertEquals(array_merge($classRouteData['methods'], $methodRouteData['methods']), $route->getMethods(), '->load merges class and method route methods'); | ||
} | ||
|
||
private function getAnnotatedRoute($data) | ||
{ | ||
return new Route($data); | ||
|
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know this is useless but having related annotation here would be great for people that read tests.