From 9b7d4c7613b5b7e351e32c6f60c08377388150d4 Mon Sep 17 00:00:00 2001 From: Walter Dal Mut Date: Sat, 14 Feb 2015 14:38:59 +0100 Subject: [PATCH 1/2] Annotated routes with a variadic parameter There are no variadic default values and that generate a fatal error. --- .../AnnotatedClasses/VariadicClass.php | 19 +++++++++++++++++++ .../Tests/Loader/AnnotationFileLoaderTest.php | 14 ++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 src/Symfony/Component/Routing/Tests/Fixtures/AnnotatedClasses/VariadicClass.php diff --git a/src/Symfony/Component/Routing/Tests/Fixtures/AnnotatedClasses/VariadicClass.php b/src/Symfony/Component/Routing/Tests/Fixtures/AnnotatedClasses/VariadicClass.php new file mode 100644 index 0000000000..f0fe7f095e --- /dev/null +++ b/src/Symfony/Component/Routing/Tests/Fixtures/AnnotatedClasses/VariadicClass.php @@ -0,0 +1,19 @@ + + * + * 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 VariadicClass +{ + public function routeAction(...$params) + { + } +} diff --git a/src/Symfony/Component/Routing/Tests/Loader/AnnotationFileLoaderTest.php b/src/Symfony/Component/Routing/Tests/Loader/AnnotationFileLoaderTest.php index f0a8a0e329..94b6d02981 100644 --- a/src/Symfony/Component/Routing/Tests/Loader/AnnotationFileLoaderTest.php +++ b/src/Symfony/Component/Routing/Tests/Loader/AnnotationFileLoaderTest.php @@ -13,6 +13,7 @@ namespace Symfony\Component\Routing\Tests\Loader; use Symfony\Component\Routing\Loader\AnnotationFileLoader; use Symfony\Component\Config\FileLocator; +use Symfony\Component\Routing\Annotation\Route; class AnnotationFileLoaderTest extends AbstractAnnotationLoaderTest { @@ -34,6 +35,19 @@ class AnnotationFileLoaderTest extends AbstractAnnotationLoaderTest $this->loader->load(__DIR__.'/../Fixtures/AnnotatedClasses/FooClass.php'); } + /** + * @requires PHP 5.6 + */ + public function testLoadVariadic() + { + $route = new Route(["path" => "/path/to/{id}"]); + $this->reader->expects($this->once())->method('getClassAnnotation'); + $this->reader->expects($this->once())->method('getMethodAnnotations') + ->will($this->returnValue([$route])); + + $this->loader->load(__DIR__.'/../Fixtures/AnnotatedClasses/VariadicClass.php'); + } + public function testSupports() { $fixture = __DIR__.'/../Fixtures/annotated.php'; From 73c5eff44d77d8970a4f472c81cfd197c9878dac Mon Sep 17 00:00:00 2001 From: Christophe Coevoet Date: Sat, 1 Aug 2015 21:33:42 +0200 Subject: [PATCH 2/2] Fix the retrieval of the default value for variadic arguments --- .../Component/Routing/Loader/AnnotationClassLoader.php | 2 +- .../VariadicClass.php | 2 +- .../Routing/Tests/Loader/AnnotationClassLoaderTest.php | 1 + .../Routing/Tests/Loader/AnnotationFileLoaderTest.php | 6 +++--- 4 files changed, 6 insertions(+), 5 deletions(-) rename src/Symfony/Component/Routing/Tests/Fixtures/{AnnotatedClasses => OtherAnnotatedClasses}/VariadicClass.php (81%) diff --git a/src/Symfony/Component/Routing/Loader/AnnotationClassLoader.php b/src/Symfony/Component/Routing/Loader/AnnotationClassLoader.php index e35f807b4c..11d8f34d5a 100644 --- a/src/Symfony/Component/Routing/Loader/AnnotationClassLoader.php +++ b/src/Symfony/Component/Routing/Loader/AnnotationClassLoader.php @@ -180,7 +180,7 @@ abstract class AnnotationClassLoader implements LoaderInterface $defaults = array_replace($globals['defaults'], $annot->getDefaults()); foreach ($method->getParameters() as $param) { - if (!isset($defaults[$param->getName()]) && $param->isOptional()) { + if (!isset($defaults[$param->getName()]) && $param->isDefaultValueAvailable()) { $defaults[$param->getName()] = $param->getDefaultValue(); } } diff --git a/src/Symfony/Component/Routing/Tests/Fixtures/AnnotatedClasses/VariadicClass.php b/src/Symfony/Component/Routing/Tests/Fixtures/OtherAnnotatedClasses/VariadicClass.php similarity index 81% rename from src/Symfony/Component/Routing/Tests/Fixtures/AnnotatedClasses/VariadicClass.php rename to src/Symfony/Component/Routing/Tests/Fixtures/OtherAnnotatedClasses/VariadicClass.php index f0fe7f095e..729c9b4d07 100644 --- a/src/Symfony/Component/Routing/Tests/Fixtures/AnnotatedClasses/VariadicClass.php +++ b/src/Symfony/Component/Routing/Tests/Fixtures/OtherAnnotatedClasses/VariadicClass.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Symfony\Component\Routing\Tests\Fixtures\AnnotatedClasses; +namespace Symfony\Component\Routing\Tests\Fixtures\OtherAnnotatedClasses; class VariadicClass { diff --git a/src/Symfony/Component/Routing/Tests/Loader/AnnotationClassLoaderTest.php b/src/Symfony/Component/Routing/Tests/Loader/AnnotationClassLoaderTest.php index 07efaf7778..67d07c3f5d 100644 --- a/src/Symfony/Component/Routing/Tests/Loader/AnnotationClassLoaderTest.php +++ b/src/Symfony/Component/Routing/Tests/Loader/AnnotationClassLoaderTest.php @@ -16,6 +16,7 @@ use Symfony\Component\Routing\Annotation\Route; class AnnotationClassLoaderTest extends AbstractAnnotationLoaderTest { protected $loader; + private $reader; protected function setUp() { diff --git a/src/Symfony/Component/Routing/Tests/Loader/AnnotationFileLoaderTest.php b/src/Symfony/Component/Routing/Tests/Loader/AnnotationFileLoaderTest.php index 94b6d02981..9a83994f9a 100644 --- a/src/Symfony/Component/Routing/Tests/Loader/AnnotationFileLoaderTest.php +++ b/src/Symfony/Component/Routing/Tests/Loader/AnnotationFileLoaderTest.php @@ -40,12 +40,12 @@ class AnnotationFileLoaderTest extends AbstractAnnotationLoaderTest */ public function testLoadVariadic() { - $route = new Route(["path" => "/path/to/{id}"]); + $route = new Route(array('path' => '/path/to/{id}')); $this->reader->expects($this->once())->method('getClassAnnotation'); $this->reader->expects($this->once())->method('getMethodAnnotations') - ->will($this->returnValue([$route])); + ->will($this->returnValue(array($route))); - $this->loader->load(__DIR__.'/../Fixtures/AnnotatedClasses/VariadicClass.php'); + $this->loader->load(__DIR__.'/../Fixtures/OtherAnnotatedClasses/VariadicClass.php'); } public function testSupports()