8000 bug #15425 [Routing] Fix the retrieval of the default value for varia… · symfony/symfony@e5909be · GitHub
[go: up one dir, main page]

Skip to content

Commit e5909be

Browse files
committed
bug #15425 [Routing] Fix the retrieval of the default value for variadic arguments in the annotation loader (wdalmut, stof)
This PR was merged into the 2.3 branch. Discussion ---------- [Routing] Fix the retrieval of the default value for variadic arguments in the annotation loader | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #13690 | License | MIT | Doc PR | n/a This takes the test submitted in #13690 and implements the fix for this bug Commits ------- 73c5eff Fix the retrieval of the default value for variadic arguments 9b7d4c7 Annotated routes with a variadic parameter
2 parents 69171d4 + 73c5eff commit e5909be

File tree

4 files changed

+35
-1
lines changed

4 files changed

+35
-1
lines changed

src/Symfony/Component/Routing/Loader/AnnotationClassLoader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ protected function addRoute(RouteCollection $collection, $annot, $globals, \Refl
180180

181181
$defaults = array_replace($globals['defaults'], $annot->getDefaults());
182182
foreach ($method->getParameters() as $param) {
183-
if (!isset($defaults[$param->getName()]) && $param->isOptional()) {
183+
if (!isset($defaults[$param->getName()]) && $param->isDefaultValueAvailable()) {
184184
$defaults[$param->getName()] = $param->getDefaultValue();
185185
}
186186
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Routing\Tests\Fixtures\OtherAnnotatedClasses;
13+
14+
class VariadicClass
15+
{
16+
public function routeAction(...$params)
17+
{
18+
}
19+
}

src/Symfony/Component/Routing/Tests/Loader/AnnotationClassLoaderTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
class AnnotationClassLoaderTest extends AbstractAnnotationLoaderTest
1717
{
1818
protected $loader;
19+
private $reader;
1920

2021
protected function setUp()
2122
{

src/Symfony/Component/Routing/Tests/Loader/AnnotationFileLoaderTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Symfony\Component\Routing\Loader\AnnotationFileLoader;
1515
use Symfony\Component\Config\FileLocator;
16+
use Symfony\Component\Routing\Annotation\Route;
1617

1718
class AnnotationFileLoaderTest extends AbstractAnnotationLoaderTest
1819
{
@@ -34,6 +35,19 @@ public function testLoad()
3435
$this->loader->load(__DIR__.'/../Fixtures/AnnotatedClasses/FooClass.php');
3536
}
3637

38+
/**
39+
* @requires PHP 5.6
40+
*/
41+
public function testLoadVariadic()
42+
{
43+
$route = new Route(array('path' => '/path/to/{id}'));
44+
$this->reader->expects($this->once())->method('getClassAnnotation');
45+
$this->reader->expects($this->once())->method('getMethodAnnotations')
46+
->will($this->returnValue(array($route)));
47+
48+
$this->loader->load(__DIR__.'/../Fixtures/OtherAnnotatedClasses/VariadicClass.php');
49+
}
50+
3751
public function testSupports()
3852
{
3953
$fixture = __DIR__.'/../Fixtures/annotated.php';

0 commit comments

Comments
 (0)
0