From 499886deab9466d63cee14243d3d1562dc37390d Mon Sep 17 00:00:00 2001 From: Zarko Stankovic Date: Tue, 27 Feb 2018 15:42:40 +0100 Subject: [PATCH] Fix #1239: FosRestDescriber properly configures Parameter#pattern property. Minor bugfix that configures `Parameter#pattern` property instead of `Parameter#format`. Tests provided that prove this implementation works as expected. --- RouteDescriber/FosRestDescriber.php | 2 +- Tests/Functional/Controller/ApiController.php | 2 +- Tests/Functional/FunctionalTest.php | 4 ++++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/RouteDescriber/FosRestDescriber.php b/RouteDescriber/FosRestDescriber.php index 1a4615f..fef4b18 100644 --- a/RouteDescriber/FosRestDescriber.php +++ b/RouteDescriber/FosRestDescriber.php @@ -54,7 +54,7 @@ final class FosRestDescriber implements RouteDescriberInterface $normalizedRequirements = $this->normalizeRequirements($annotation->requirements); if (null !== $normalizedRequirements) { - $parameter->setFormat($normalizedRequirements); + $parameter->setPattern($normalizedRequirements); } } } diff --git a/Tests/Functional/Controller/ApiController.php b/Tests/Functional/Controller/ApiController.php index db401ee..8ec78ba 100644 --- a/Tests/Functional/Controller/ApiController.php +++ b/Tests/Functional/Controller/ApiController.php @@ -108,7 +108,7 @@ class ApiController /** * @Route("/fosrest.{_format}", methods={"POST"}) * @QueryParam(name="foo") - * @RequestParam(name="bar") + * @RequestParam(name="bar", requirements="\d+") */ public function fosrestAction() { diff --git a/Tests/Functional/FunctionalTest.php b/Tests/Functional/FunctionalTest.php index 38ff95e..2069ed3 100644 --- a/Tests/Functional/FunctionalTest.php +++ b/Tests/Functional/FunctionalTest.php @@ -125,6 +125,10 @@ class FunctionalTest extends WebTestCase $this->assertTrue($parameters->has('foo', 'query')); $this->assertTrue($parameters->has('bar', 'formData')); + $barParameter = $parameters->get('bar', 'formData'); + $this->assertNotNull($barParameter->getPattern()); + $this->assertEquals('\d+', $barParameter->getPattern()); + // The _format path attribute should be removed $this->assertFalse($parameters->has('_format', 'path')); }