Browse Source

Add tests for excluding query and body params
- Test that a valid result is returned
- Test that all query params are ignored
- Test for non-existence of specific body param

Marnu Lombard 5 years ago
parent
commit
e31dfdf1f1
2 changed files with 32 additions and 0 deletions
  1. 10 0
      tests/Fixtures/TestController.php
  2. 22 0
      tests/Unit/GeneratorTestCase.php

+ 10 - 0
tests/Fixtures/TestController.php

@@ -82,6 +82,16 @@ class TestController extends Controller
         return '';
     }
 
+    /**
+     * @bodyParam included string required Exists in examples. Example: 'Here'
+     * @bodyParam  excluded_body_param int Does not exist in examples. No-example
+     * @queryParam excluded_query_param Does not exist in examples. No-example
+     */
+    public function withExcludedExamples()
+    {
+        return '';
+    }
+
     /**
      * @authenticated
      */

+ 22 - 0
tests/Unit/GeneratorTestCase.php

@@ -210,6 +210,28 @@ abstract class GeneratorTestCase extends TestCase
         ], $queryParameters);
     }
 
+    /** @test */
+    public function it_ignores_excluded_params()
+    {
+        $route = $this->createRoute('GET', '/api/test', 'withExcludedExamples');
+        $parsed = $this->generator->processRoute($route);
+        $bodyParameters = $parsed['bodyParameters'];
+        $queryParameters = $parsed['queryParameters'];
+
+        $this->assertArraySubset([
+            'included' => [
+                'required' => true,
+                'type' => 'string',
+                'description' => 'Exists in examples.',
+            ],
+        ], $bodyParameters);
+
+        $this->assertArrayNotHasKey('excluded_body_param', $bodyParameters);
+
+        $this->assertEmpty($queryParameters);
+
+    }
+
     /** @test */
     public function can_parse_route_group()
     {