Fix the retrieval of the default value for variadic arguments

This commit is contained in:
Christophe Coevoet 2015-08-01 21:33:42 +02:00
parent 9b7d4c7613
commit 73c5eff44d
4 changed files with 6 additions and 5 deletions

View File

@ -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();
}
}

View File

@ -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
{

View File

@ -16,6 +16,7 @@ use Symfony\Component\Routing\Annotation\Route;
class AnnotationClassLoaderTest extends AbstractAnnotationLoaderTest
{
protected $loader;
private $reader;
protected function setUp()
{

View File

@ -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()