Browse Source

Fix tests

shalvah 4 years ago
parent
commit
53ff1073f3

+ 4 - 0
src/Tools/Utils.php

@@ -58,6 +58,10 @@ class Utils
             return $boundUri;
         }
 
+        foreach ($urlParameters as $parameterName => $example) {
+            $uri = preg_replace('#\{' . $parameterName . '\??}#', $example, $uri);
+        }
+
         // Remove unbound optional parameters with nothing
         $uri = preg_replace('#{([^/]+\?)}#', '', $uri);
         // Replace any unbound non-optional parameters with '1'

+ 1 - 7
src/Writing/PostmanCollectionWriter.php

@@ -188,12 +188,6 @@ class PostmanCollectionWriter
 
     protected function generateUrlObject($route)
     {
-        // URL Parameters are collected by the `UrlParameters` strategies, but only make sense if they're in the route
-        // definition. Filter out any URL parameters that don't appear in the URL.
-        $urlParams = collect($route['urlParameters'])->filter(function ($_, $key) use ($route) {
-            return Str::contains($route['uri'], '{' . $key . '}');
-        });
-
         $base = [
             'protocol' => Str::startsWith($this->baseUrl, 'https') ? 'https' : 'http',
             'host' => '{{baseUrl}}',
@@ -245,8 +239,8 @@ class PostmanCollectionWriter
             $base['protocol'], $base['host'], $base['path'], $queryString ? "?{$queryString}" : null
         );
 
-        // If there aren't any url parameters described then return what we've got
         /** @var $urlParams Collection */
+        $urlParams = collect($route['urlParameters']);
         if ($urlParams->isEmpty()) {
             return $base;
         }

+ 1 - 1
tests/Fixtures/TestController.php

@@ -242,7 +242,7 @@ class TestController extends Controller
      * @group Other😎
      *
      * @urlParam param required Example: 4
-     * @urlParam param2
+     * @urlParam param2 required
      * @urlParam param4 No-example.
      *
      * @queryParam something

+ 15 - 3
tests/Fixtures/collection.json

@@ -196,12 +196,12 @@
             "description": "",
             "item": [
                 {
-                    "name": "api\/echoesUrlParameters\/{param}-{param2}\/{param3?}",
+                    "name": "api\/echoesUrlParameters\/{param}\/{param2}\/{param3?}\/{param4?}",
                     "request": {
                         "url": {
                             "protocol": "http",
                             "host": "{{baseUrl}}",
-                            "path": "api\/echoesUrlParameters\/:param-:param2\/:param3",
+                            "path": "api\/echoesUrlParameters\/:param\/:param2\/:param3\/:param4",
                             "query": [
                                 {
                                     "key": "something",
@@ -210,7 +210,7 @@
                                     "disabled": false
                                 }
                             ],
-                            "raw": "http:\/\/{{baseUrl}}\/api\/echoesUrlParameters\/:param-:param2\/:param3?something=consequatur",
+                            "raw": "http:\/\/{{baseUrl}}\/api\/echoesUrlParameters\/:param\/:param2\/:param3\/:param4?something=consequatur",
                             "variable": [
                                 {
                                     "id": "param",
@@ -223,6 +223,18 @@
                                     "key": "param2",
                                     "value": "consequatur",
                                     "description": ""
+                                },
+                                {
+                                    "id": "param3",
+                                    "key": "param3",
+                                    "value": "consequatur",
+                                    "description": ""
+                                },
+                                {
+                                    "id": "param4",
+                                    "key": "param4",
+                                    "value": null,
+                                    "description": ""
                                 }
                             ]
                         },

+ 2 - 8
tests/Fixtures/openapi.yaml

@@ -219,17 +219,11 @@ paths:
             -
                 in: path
                 name: param2
-                description: 'Optional parameter.'
+                description: ''
                 required: true
                 schema:
                     type: string
-                examples:
-                    omitted:
-                        summary: 'When the value is omitted'
-                        value: ''
-                    present:
-                        summary: 'When the value is present'
-                        value: consequatur
+                example: consequatur
             -
                 in: path
                 name: param3

+ 1 - 1
tests/GenerateDocumentationTest.php

@@ -230,7 +230,7 @@ class GenerateDocumentationTest extends TestCase
         RouteFacade::post('/api/withBodyParameters', [TestController::class, 'withBodyParameters']);
         RouteFacade::get('/api/withQueryParameters', [TestController::class, 'withQueryParameters']);
         RouteFacade::get('/api/withAuthTag', [TestController::class, 'withAuthenticatedTag']);
-        RouteFacade::get('/api/echoesUrlParameters/{param}-{param2}/{param3?}', [TestController::class, 'echoesUrlParameters']);
+        RouteFacade::get('/api/echoesUrlParameters/{param}/{param2}/{param3?}/{param4?}', [TestController::class, 'echoesUrlParameters']);
         // We want to have the same values for params each time
         config(['scribe.faker_seed' => 1234]);
         config(['scribe.title' => 'GREAT API!']);

+ 4 - 4
tests/Unit/PostmanCollectionWriterTest.php

@@ -135,14 +135,14 @@ class PostmanCollectionWriterTest extends TestCase
             'disabled' => false,
         ], $variableData[0]);
         $this->assertEquals([
-            'key' => 'filters[0]',
-            'value' => 34,
+            'key' => urlencode('filters[0]'),
+            'value' => '34',
             'description' => 'Filters',
             'disabled' => false,
         ], $variableData[1]);
         $this->assertEquals([
-            'key' => 'filters[1]',
-            'value' => 12,
+            'key' => urlencode('filters[1]'),
+            'value' => '12',
             'description' => 'Filters',
             'disabled' => false,
         ], $variableData[2]);