From 1256275185572c40d4671a5d90d9e6bc4152cc77 Mon Sep 17 00:00:00 2001 From: Denys Pasishnyi Date: Mon, 13 Jun 2016 00:30:40 +0200 Subject: [PATCH] #502 Test for the improvement --- Tests/Extractor/Handler/FosRestHandlerTest.php | 18 ++++++++++++++++++ Tests/Fixtures/Controller/TestController.php | 8 ++++++++ Tests/Fixtures/app/config/routing.yml | 5 +++++ 3 files changed, 31 insertions(+) diff --git a/Tests/Extractor/Handler/FosRestHandlerTest.php b/Tests/Extractor/Handler/FosRestHandlerTest.php index 3fcac87..616bb2e 100644 --- a/Tests/Extractor/Handler/FosRestHandlerTest.php +++ b/Tests/Extractor/Handler/FosRestHandlerTest.php @@ -203,4 +203,22 @@ class FosRestHandlerTest extends WebTestCase $this->assertArrayHasKey('requirement', $filters['param1']); $this->assertEquals('NotNull, NotBlank', $filters['param1']['requirement']); } + + public function testWithRequirementParamNotSet() + { + $container = $this->getContainer(); + $extractor = $container->get('nelmio_api_doc.extractor.api_doc_extractor'); + $annotation = $extractor->get('Nelmio\ApiDocBundle\Tests\Fixtures\Controller\TestController::zActionWithRequirementParamNotSet', 'test_route_31'); + + $this->assertNotNull($annotation); + + $filters = $annotation->getFilters(); + $this->assertCount(1, $filters); + $this->assertArrayHasKey('param1', $filters); + $filter = $filters['param1']; + + $this->assertArrayNotHasKey('requirement', $filter); + $this->assertArrayHasKey('description', $filter); + $this->assertEquals($filter['description'], 'Param1 description.'); + } } diff --git a/Tests/Fixtures/Controller/TestController.php b/Tests/Fixtures/Controller/TestController.php index 9bc4fd9..f4e4b16 100644 --- a/Tests/Fixtures/Controller/TestController.php +++ b/Tests/Fixtures/Controller/TestController.php @@ -414,4 +414,12 @@ class TestController public function routeWithQueryParamPlainArrayRequirementsAction() { } + + /** + * @ApiDoc() + * @QueryParam(name="param1", description="Param1 description.") + */ + public function zActionWithRequirementParamNotSet() + { + } } diff --git a/Tests/Fixtures/app/config/routing.yml b/Tests/Fixtures/app/config/routing.yml index 9cba5f6..338640b 100644 --- a/Tests/Fixtures/app/config/routing.yml +++ b/Tests/Fixtures/app/config/routing.yml @@ -248,3 +248,8 @@ test_route_30: path: /z-query-param-plain-array-requirements methods: [GET] defaults: { _controller: NelmioApiDocTestBundle:Test:routeWithQueryParamPlainArrayRequirementsAction } + +test_route_31: + path: /z-query-requirement-param-not-set + methods: [GET] + defaults: { _controller: NelmioApiDocTestBundle:Test:zActionWithRequirementParamNotSet }