Browse Source

Try to make tests faster

shalvah 4 years ago
parent
commit
22d960facf

+ 0 - 110
tests/Fixtures/collection-overridden.json

@@ -1,110 +0,0 @@
-{
-    "variable": [],
-    "info": {
-        "name": "Custom API",
-        "_postman_id": "",
-        "description": "",
-        "schema": "https:\/\/schema.getpostman.com\/json\/collection\/v2.1.0\/collection.json",
-        "version": "3.9.9"
-    },
-    "item": [
-        {
-            "name": "Group A",
-            "description": "",
-            "item": [
-                {
-                    "name": "Example title.",
-                    "request": {
-                        "url": {
-                            "protocol": "http",
-                            "host": "localhost",
-                            "path": "api\/withDescription",
-                            "query": [],
-                            "raw": "http:\/\/localhost\/api\/withDescription"
-                        },
-                        "method": "GET",
-                        "header": [
-                            {
-                                "key": "Content-Type",
-                                "value": "application\/json"
-                            },
-                            {
-                                "key": "Accept",
-                                "value": "application\/json"
-                            }
-                        ],
-                        "body": null,
-                        "description": "This will be the long description.\nIt can also be multiple lines long.",
-                        "auth": {
-                            "type": "noauth"
-                        }
-                    },
-                    "response": []
-                },
-                {
-                    "name": "api\/withQueryParameters",
-                    "request": {
-                        "url": {
-                            "protocol": "http",
-                            "host": "localhost",
-                            "path": "api\/withQueryParameters",
-                            "query": [
-                                {
-                                    "key": "location_id",
-                                    "value": "consequatur",
-                                    "description": "The id of the location.",
-                                    "disabled": false
-                                },
-                                {
-                                    "key": "user_id",
-                                    "value": "me",
-                                    "description": "The id of the user.",
-                                    "disabled": false
-                                },
-                                {
-                                    "key": "page",
-                                    "value": "4",
-                                    "description": "The page number.",
-                                    "disabled": false
-                                },
-                                {
-                                    "key": "filters",
-                                    "value": "consequatur",
-                                    "description": "The filters.",
-                                    "disabled": false
-                                },
-                                {
-                                    "key": "url_encoded",
-                                    "value": "%2B+%5B%5D%26%3D",
-                                    "description": "Used for testing that URL parameters will be URL-encoded where needed.",
-                                    "disabled": false
-                                }
-                            ],
-                            "raw": "http:\/\/localhost\/api\/withQueryParameters?location_id=consequatur&user_id=me&page=4&filters=consequatur&url_encoded=%2B+%5B%5D%26%3D"
-                        },
-                        "method": "GET",
-                        "header": [
-                            {
-                                "key": "Content-Type",
-                                "value": "application\/json"
-                            },
-                            {
-                                "key": "Accept",
-                                "value": "application\/json"
-                            }
-                        ],
-                        "body": null,
-                        "description": "",
-                        "auth": {
-                            "type": "noauth"
-                        }
-                    },
-                    "response": []
-                }
-            ]
-        }
-    ],
-    "auth": {
-        "type": "noauth"
-    }
-}

+ 2 - 1
tests/Fixtures/collection.json

@@ -4,7 +4,8 @@
         "name": "GREAT API!",
         "_postman_id": "",
         "description": "",
-        "schema": "https:\/\/schema.getpostman.com\/json\/collection\/v2.1.0\/collection.json"
+        "schema": "https:\/\/schema.getpostman.com\/json\/collection\/v2.1.0\/collection.json",
+        "version": "3.9.9"
     },
     "item": [
         {

+ 0 - 75
tests/Fixtures/openapi-overridden.yaml

@@ -1,75 +0,0 @@
-openapi: 3.0.3
-info:
-    title: null
-    description: ''
-    version: 3.9.9
-servers:
-    -
-        url: 'http://okay.dev'
-paths:
-    /api/withDescription:
-        get:
-            summary: 'Example title.'
-            description: "This will be the long description.\nIt can also be multiple lines long."
-            parameters:
-                -
-                    in: header
-                    name: Content-Type
-                    description: ''
-                    example: application/json
-                    schema:
-                        type: string
-                -
-                    in: header
-                    name: Accept
-                    description: ''
-                    example: application/json
-                    schema:
-                        type: string
-            responses: {  }
-            tags:
-                - 'Group A'
-            security: []
-    /api/withResponseTag:
-        get:
-            summary: ''
-            description: ''
-            parameters:
-                -
-                    in: header
-                    name: Content-Type
-                    description: ''
-                    example: application/json
-                    schema:
-                        type: string
-                -
-                    in: header
-                    name: Accept
-                    description: ''
-                    example: application/json
-                    schema:
-                        type: string
-            responses:
-                200:
-                    description: '200'
-                    content:
-                        application/json:
-                            schema:
-                                type: object
-                                example:
-                                    id: 4
-                                    name: banana
-                                    color: red
-                                    weight: '1 kg'
-                                    delicious: true
-                                    responseTag: true
-                                properties:
-                                    id: { type: integer, example: 4 }
-                                    name: { type: string, example: banana }
-                                    color: { type: string, example: red }
-                                    weight: { type: string, example: '1 kg' }
-                                    delicious: { type: boolean, example: true }
-                                    responseTag: { type: boolean, example: true }
-            tags:
-                - 'Group A'
-            security: []

+ 1 - 1
tests/Fixtures/openapi.yaml

@@ -2,7 +2,7 @@ openapi: 3.0.3
 info:
     title: null
     description: ''
-    version: 1.0.0
+    version: 3.9.9
 servers:
     -
         url: 'http://localhost'

+ 6 - 43
tests/GenerateDocumentationTest.php

@@ -239,6 +239,9 @@ class GenerateDocumentationTest extends TestCase
         config(['scribe.faker_seed' => 1234]);
         config(['scribe.title' => 'GREAT API!']);
         config(['scribe.routes.0.match.prefixes' => ['api/*']]);
+        config(['scribe.postman.overrides' => [
+            'info.version' => '3.9.9',
+        ]]);
         config([
             'scribe.routes.0.apply.headers' => [
                 'Custom-Header' => 'NotSoCustom',
@@ -254,28 +257,6 @@ class GenerateDocumentationTest extends TestCase
         $this->assertEquals($fixtureCollection, $generatedCollection);
     }
 
-    /** @test */
-    public function can_override_fields_in_generated_postman_collection_file()
-    {
-        RouteFacade::get('/api/withDescription', [TestController::class, 'withEndpointDescription']);
-        RouteFacade::get('/api/withQueryParameters', TestController::class . '@withQueryParameters');
-
-        config(['scribe.faker_seed' => 1234]);
-        config(['scribe.postman.enabled' => true]);
-        config(['scribe.postman.overrides' => [
-            'info.version' => '3.9.9',
-            'info.name' => 'Custom API',
-        ]]);
-        config(['scribe.routes.0.match.prefixes' => ['api/*']]);
-
-        $this->artisan('scribe:generate');
-
-        $generatedCollection = json_decode(file_get_contents(__DIR__ . '/../public/docs/collection.json'), true);
-        $generatedCollection['info']['_postman_id'] = '';
-        $fixtureCollection = json_decode(file_get_contents(__DIR__ . '/Fixtures/collection-overridden.json'), true);
-        $this->assertEquals($fixtureCollection, $generatedCollection);
-    }
-
     /** @test */
     public function generated_openapi_spec_file_is_correct()
     {
@@ -289,6 +270,9 @@ class GenerateDocumentationTest extends TestCase
         // We want to have the same values for params each time
         config(['scribe.faker_seed' => 1234]);
         config(['scribe.openapi.enabled' => true]);
+        config(['scribe.openapi.overrides' => [
+            'info.version' => '3.9.9',
+        ]]);
         config(['scribe.routes.0.match.prefixes' => ['api/*']]);
         config([
             'scribe.routes.0.apply.headers' => [
@@ -303,27 +287,6 @@ class GenerateDocumentationTest extends TestCase
         $this->assertEquals($fixtureCollection, $generatedCollection);
     }
 
-    /** @test */
-    public function can_override_fields_in_generated_openapi_spec_file()
-    {
-        RouteFacade::get('/api/withDescription', [TestController::class, 'withEndpointDescription']);
-        RouteFacade::get('/api/withResponseTag', TestController::class . '@withResponseTag');
-
-        config(['scribe.faker_seed' => 1234]);
-        config(['scribe.openapi.enabled' => true]);
-        config(['scribe.openapi.overrides' => [
-            'info.version' => '3.9.9',
-            'servers.0.url' => 'http://okay.dev',
-        ]]);
-        config(['scribe.routes.0.match.prefixes' => ['api/*']]);
-
-        $this->artisan('scribe:generate');
-
-        $generatedCollection = json_decode(file_get_contents(__DIR__ . '/../public/docs/openapi.yaml'), true);
-        $fixtureCollection = json_decode(file_get_contents(__DIR__ . '/Fixtures/openapi-overridden.yaml'), true);
-        $this->assertEquals($fixtureCollection, $generatedCollection);
-    }
-
     /** @test */
     public function can_append_custom_http_headers()
     {