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.
This commit is contained in:
Zarko Stankovic 2018-02-27 15:42:40 +01:00
parent 981a2b6293
commit 499886deab
3 changed files with 6 additions and 2 deletions

View File

@ -54,7 +54,7 @@ final class FosRestDescriber implements RouteDescriberInterface
$normalizedRequirements = $this->normalizeRequirements($annotation->requirements); $normalizedRequirements = $this->normalizeRequirements($annotation->requirements);
if (null !== $normalizedRequirements) { if (null !== $normalizedRequirements) {
$parameter->setFormat($normalizedRequirements); $parameter->setPattern($normalizedRequirements);
} }
} }
} }

View File

@ -108,7 +108,7 @@ class ApiController
/** /**
* @Route("/fosrest.{_format}", methods={"POST"}) * @Route("/fosrest.{_format}", methods={"POST"})
* @QueryParam(name="foo") * @QueryParam(name="foo")
* @RequestParam(name="bar") * @RequestParam(name="bar", requirements="\d+")
*/ */
public function fosrestAction() public function fosrestAction()
{ {

View File

@ -125,6 +125,10 @@ class FunctionalTest extends WebTestCase
$this->assertTrue($parameters->has('foo', 'query')); $this->assertTrue($parameters->has('foo', 'query'));
$this->assertTrue($parameters->has('bar', 'formData')); $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 // The _format path attribute should be removed
$this->assertFalse($parameters->has('_format', 'path')); $this->assertFalse($parameters->has('_format', 'path'));
} }