Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
minor #21379 [Routing] Fix BC break in AnnotationClassLoader defaults…
… attributes handling (chalasr) This PR was merged into the 2.7 branch. Discussion ---------- [Routing] Fix BC break in AnnotationClassLoader defaults attributes handling | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | 77289b9#commitcomment-20572462 | License | MIT | Doc PR | n/a This fixes a BC break introduced in #21333. Instead of removing the automatic request attributes creation, we keep it but only for attributes that are mandatory (i.e. present in the route path). Thanks to @iltar for the idea. Commits ------- 1d298f0 [Routing] Fix BC break in AnnotationClassLoader defaults attributes handling
- Loading branch information
Showing
8 changed files
with
126 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/Symfony/Bundle/FrameworkBundle/Tests/Functional/AnnotatedControllerTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?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\Bundle\FrameworkBundle\Tests\Functional; | ||
|
||
class AnnotatedControllerTest extends WebTestCase | ||
{ | ||
/** | ||
* @dataProvider getRoutes | ||
*/ | ||
public function testAnnotatedController($path, $expectedValue) | ||
{ | ||
$client = $this->createClient(array('test_case' => 'AnnotatedController', 'root_config' => 'config.yml')); | ||
$client->request('GET', '/annotated'.$path); | ||
|
||
$this->assertSame(200, $client->getResponse()->getStatusCode()); | ||
$this->assertSame($expectedValue, $client->getResponse()->getContent()); | ||
} | ||
|
||
public function getRoutes() | ||
{ | ||
return array( | ||
array('/null_request', 'Symfony\Component\HttpFoundation\Request'), | ||
array('/null_argument', ''), | ||
array('/null_argument_with_route_param', ''), | ||
array('/null_argument_with_route_param/value', 'value'), | ||
array('/argument_with_route_param_and_default', 'value'), | ||
array('/argument_with_route_param_and_default/custom', 'custom'), | ||
); | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
...dle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/Controller/AnnotatedController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?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\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\Controller; | ||
|
||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\Routing\Annotation\Route; | ||
|
||
class AnnotatedController | ||
{ | ||
/** | ||
* @Route("/null_request", name="null_request") | ||
*/ | ||
public function requestDefaultNullAction(Request $request = null) | ||
{ | ||
return new Response($request ? get_class($request) : null); | ||
} | ||
|
||
/** | ||
* @Route("/null_argument", name="null_argument") | ||
*/ | ||
public function argumentDefaultNullWithoutRouteParamAction($value = null) | ||
{ | ||
return new Response($value); | ||
} | ||
|
||
/** | ||
* @Route("/null_argument_with_route_param/{value}", name="null_argument_with_route_param") | ||
*/ | ||
public function argumentDefaultNullWithRouteParamAction($value = null) | ||
{ | ||
return new Response($value); | ||
} | ||
|
||
/** | ||
* @Route("/argument_with_route_param_and_default/{value}", defaults={"value": "value"}, name="argument_with_route_param_and_default") | ||
*/ | ||
public function argumentWithoutDefaultWithRouteParamAndDefaultAction($value) | ||
{ | ||
return new Response($value); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/AnnotatedController/bundles.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?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. | ||
*/ | ||
|
||
use Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\TestBundle; | ||
use Symfony\Bundle\FrameworkBundle\FrameworkBundle; | ||
use Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle; | ||
|
||
return array( | ||
new FrameworkBundle(), | ||
new TestBundle(), | ||
new SensioFrameworkExtraBundle(), | ||
); |
2 changes: 2 additions & 0 deletions
2
src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/AnnotatedController/config.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
imports: | ||
- { resource: ../config/default.yml } |
4 changes: 4 additions & 0 deletions
4
src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/AnnotatedController/routing.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
annotated_controller: | ||
prefix: /annotated | ||
resource: "@TestBundle/Controller/AnnotatedController.php" | ||
type: annotation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters