소스 검색

Update tests

shalvah 6 년 전
부모
커밋
1418ed9189

+ 14 - 5
tests/Fixtures/TestController.php

@@ -26,7 +26,7 @@ class TestController extends Controller
      * @bodyParam user_id int required The id of the user.
      * @bodyParam room_id string The id of the room.
      */
-    public function withBodyParameters(TestRequest $request)
+    public function withBodyParameters()
     {
         return '';
     }
@@ -36,7 +36,7 @@ class TestController extends Controller
         return $request->headers->all();
     }
 
-    public function fetchRouteResponse()
+    public function shouldFetchRouteResponse()
     {
         $fixture = new \stdClass();
         $fixture->id = 1;
@@ -54,7 +54,12 @@ class TestController extends Controller
         ];
     }
 
-    public function utf8()
+    /**
+     * @response {
+     *   "result": "Лорем ипсум долор сит амет"
+     * }
+     */
+    public function withUtf8ResponseTag()
     {
         return ['result' => 'Лорем ипсум долор сит амет'];
     }
@@ -68,8 +73,12 @@ class TestController extends Controller
 
     /**
      * @response {
-     *  "data": []
-     *}
+     *   "id": 4,
+     *   "name": "banana",
+     *   "color": "red",
+     *   "weight": "1 kg",
+     *   "delicious": true
+     * }
      */
     public function withResponseTag()
     {

+ 16 - 0
tests/Fixtures/TestResourceController.php

@@ -10,6 +10,10 @@ class TestResourceController extends Controller
     /**
      * Display a listing of the resource.
      *
+     * @response {
+     *   "index_resource": true
+     * }
+     *
      * @return \Illuminate\Http\Response
      */
     public function index()
@@ -22,6 +26,10 @@ class TestResourceController extends Controller
     /**
      * Show the form for creating a new resource.
      *
+     * @response {
+     *   "create_resource": true
+     * }
+     *
      * @return \Illuminate\Http\Response
      */
     public function create()
@@ -48,6 +56,10 @@ class TestResourceController extends Controller
     /**
      * Display the specified resource.
      *
+     * @response {
+     *   "show_resource": true
+     * }
+     *
      * @param  int  $id
      *
      * @return \Illuminate\Http\Response
@@ -62,6 +74,10 @@ class TestResourceController extends Controller
     /**
      * Show the form for editing the specified resource.
      *
+     * @response {
+     *   "edit_resource": true
+     * }
+     *
      * @param  int  $id
      *
      * @return \Illuminate\Http\Response

+ 1 - 1
tests/Fixtures/collection.json

@@ -1 +1 @@
-{"variables":[],"info":{"name":"","_postman_id":"","description":"","schema":"https:\/\/schema.getpostman.com\/json\/collection\/v2.0.0\/collection.json"},"item":[{"name":"general","description":"","item":[{"name":"Example title.","request":{"url":"http:\/\/localhost\/api\/test","method":"GET","body":{"mode":"formdata","formdata":[]},"description":"This will be the long description.\nIt can also be multiple lines long.","response":[]}},{"name":"http:\/\/localhost\/api\/fetch","request":{"url":"http:\/\/localhost\/api\/fetch","method":"POST","body":{"mode":"formdata","formdata":[]},"description":"","response":[]}}]}]}
+{"variables":[],"info":{"name":"","_postman_id":"","description":"","schema":"https:\/\/schema.getpostman.com\/json\/collection\/v2.0.0\/collection.json"},"item":[{"name":"general","description":"","item":[{"name":"Example title.","request":{"url":"http:\/\/localhost\/api\/test","method":"GET","body":{"mode":"formdata","formdata":[]},"description":"This will be the long description.\nIt can also be multiple lines long.","response":[]}},{"name":"http:\/\/localhost\/api\/responseTag","request":{"url":"http:\/\/localhost\/api\/responseTag","method":"POST","body":{"mode":"formdata","formdata":[]},"description":"","response":[]}}]}]}

+ 12 - 12
tests/Fixtures/index.md

@@ -41,7 +41,7 @@ var settings = {
     "url": "http://localhost/api/test",
     "method": "GET",
     "headers": {
-        "accept": "application/json"
+        "accept": "application/json",
     }
 }
 
@@ -62,13 +62,13 @@ null
 
 <!-- END_0bef4e738c9d6720ad43b062015d1078 -->
 
-<!-- START_960a1b2b0f0f4dde8ce993307397f9c4 -->
-## api/fetch
+<!-- START_39a6bfda1d6a0c4a5447f51b62557456 -->
+## api/responseTag
 
 > Example request:
 
 ```bash
-curl -X GET -G "http://localhost/api/fetch" \
+curl -X GET -G "http://localhost/api/responseTag" \
     -H "Accept: application/json"
 ```
 
@@ -76,10 +76,10 @@ curl -X GET -G "http://localhost/api/fetch" \
 var settings = {
     "async": true,
     "crossDomain": true,
-    "url": "http://localhost/api/fetch",
+    "url": "http://localhost/api/responseTag",
     "method": "GET",
     "headers": {
-        "accept": "application/json"
+        "accept": "application/json",
     }
 }
 
@@ -92,18 +92,18 @@ $.ajax(settings).done(function (response) {
 
 ```json
 {
-    "id": 1,
-    "name": "Banana",
-    "color": "Red",
-    "weight": "300 grams",
+    "id": 4,
+    "name": "banana",
+    "color": "red",
+    "weight": "1 kg",
     "delicious": true
 }
 ```
 
 ### HTTP Request
-`GET api/fetch`
+`GET api/responseTag`
 
 
-<!-- END_960a1b2b0f0f4dde8ce993307397f9c4 -->
+<!-- END_39a6bfda1d6a0c4a5447f51b62557456 -->
 
 

+ 6 - 6
tests/Fixtures/partial_resource_index.md

@@ -21,7 +21,7 @@ Welcome to the generated API reference.
 <!-- END_INFO -->
 
 #general
-<!-- START_2b6e5a4b188cb183c7e59558cce36cb6 -->
+<!-- START_fc1e4f6a697e3c48257de845299b71d5 -->
 ## Display a listing of the resource.
 
 > Example request:
@@ -38,7 +38,7 @@ var settings = {
     "url": "http://localhost/api/users",
     "method": "GET",
     "headers": {
-        "accept": "application/json"
+        "accept": "application/json",
     }
 }
 
@@ -59,9 +59,9 @@ $.ajax(settings).done(function (response) {
 `GET api/users`
 
 
-<!-- END_2b6e5a4b188cb183c7e59558cce36cb6 -->
+<!-- END_fc1e4f6a697e3c48257de845299b71d5 -->
 
-<!-- START_7f66c974d24032cb19061d55d801f62b -->
+<!-- START_5dac10bb34c7618b018b0230d4a51648 -->
 ## Show the form for creating a new resource.
 
 > Example request:
@@ -78,7 +78,7 @@ var settings = {
     "url": "http://localhost/api/users/create",
     "method": "GET",
     "headers": {
-        "accept": "application/json"
+        "accept": "application/json",
     }
 }
 
@@ -99,6 +99,6 @@ $.ajax(settings).done(function (response) {
 `GET api/users/create`
 
 
-<!-- END_7f66c974d24032cb19061d55d801f62b -->
+<!-- END_5dac10bb34c7618b018b0230d4a51648 -->
 
 

+ 23 - 23
tests/Fixtures/resource_index.md

@@ -21,7 +21,7 @@ Welcome to the generated API reference.
 <!-- END_INFO -->
 
 #general
-<!-- START_2b6e5a4b188cb183c7e59558cce36cb6 -->
+<!-- START_fc1e4f6a697e3c48257de845299b71d5 -->
 ## Display a listing of the resource.
 
 > Example request:
@@ -38,7 +38,7 @@ var settings = {
     "url": "http://localhost/api/users",
     "method": "GET",
     "headers": {
-        "accept": "application/json"
+        "accept": "application/json",
     }
 }
 
@@ -59,9 +59,9 @@ $.ajax(settings).done(function (response) {
 `GET api/users`
 
 
-<!-- END_2b6e5a4b188cb183c7e59558cce36cb6 -->
+<!-- END_fc1e4f6a697e3c48257de845299b71d5 -->
 
-<!-- START_7f66c974d24032cb19061d55d801f62b -->
+<!-- START_5dac10bb34c7618b018b0230d4a51648 -->
 ## Show the form for creating a new resource.
 
 > Example request:
@@ -78,7 +78,7 @@ var settings = {
     "url": "http://localhost/api/users/create",
     "method": "GET",
     "headers": {
-        "accept": "application/json"
+        "accept": "application/json",
     }
 }
 
@@ -99,9 +99,9 @@ $.ajax(settings).done(function (response) {
 `GET api/users/create`
 
 
-<!-- END_7f66c974d24032cb19061d55d801f62b -->
+<!-- END_5dac10bb34c7618b018b0230d4a51648 -->
 
-<!-- START_f0654d3f2fc63c11f5723f233cc53c83 -->
+<!-- START_12e37982cc5398c7100e59625ebb5514 -->
 ## Store a newly created resource in storage.
 
 > Example request:
@@ -118,7 +118,7 @@ var settings = {
     "url": "http://localhost/api/users",
     "method": "POST",
     "headers": {
-        "accept": "application/json"
+        "accept": "application/json",
     }
 }
 
@@ -132,9 +132,9 @@ $.ajax(settings).done(function (response) {
 `POST api/users`
 
 
-<!-- END_f0654d3f2fc63c11f5723f233cc53c83 -->
+<!-- END_12e37982cc5398c7100e59625ebb5514 -->
 
-<!-- START_ceec0e0b1d13d731ad96603d26bccc2f -->
+<!-- START_8653614346cb0e3d444d164579a0a0a2 -->
 ## Display the specified resource.
 
 > Example request:
@@ -151,7 +151,7 @@ var settings = {
     "url": "http://localhost/api/users/{user}",
     "method": "GET",
     "headers": {
-        "accept": "application/json"
+        "accept": "application/json",
     }
 }
 
@@ -164,7 +164,7 @@ $.ajax(settings).done(function (response) {
 
 ```json
 {
-    "show_resource": "1"
+    "show_resource": true
 }
 ```
 
@@ -172,9 +172,9 @@ $.ajax(settings).done(function (response) {
 `GET api/users/{user}`
 
 
-<!-- END_ceec0e0b1d13d731ad96603d26bccc2f -->
+<!-- END_8653614346cb0e3d444d164579a0a0a2 -->
 
-<!-- START_f4aa12af19ba08e1448d7eafc9f55e67 -->
+<!-- START_11ae28146a4d70ba9a0af9b65d290ad5 -->
 ## Show the form for editing the specified resource.
 
 > Example request:
@@ -191,7 +191,7 @@ var settings = {
     "url": "http://localhost/api/users/{user}/edit",
     "method": "GET",
     "headers": {
-        "accept": "application/json"
+        "accept": "application/json",
     }
 }
 
@@ -204,7 +204,7 @@ $.ajax(settings).done(function (response) {
 
 ```json
 {
-    "edit_resource": "1"
+    "edit_resource": true
 }
 ```
 
@@ -212,9 +212,9 @@ $.ajax(settings).done(function (response) {
 `GET api/users/{user}/edit`
 
 
-<!-- END_f4aa12af19ba08e1448d7eafc9f55e67 -->
+<!-- END_11ae28146a4d70ba9a0af9b65d290ad5 -->
 
-<!-- START_a4a2abed1e8e8cad5e6a3282812fe3f3 -->
+<!-- START_48a3115be98493a3c866eb0e23347262 -->
 ## Update the specified resource in storage.
 
 > Example request:
@@ -231,7 +231,7 @@ var settings = {
     "url": "http://localhost/api/users/{user}",
     "method": "PUT",
     "headers": {
-        "accept": "application/json"
+        "accept": "application/json",
     }
 }
 
@@ -247,9 +247,9 @@ $.ajax(settings).done(function (response) {
 `PATCH api/users/{user}`
 
 
-<!-- END_a4a2abed1e8e8cad5e6a3282812fe3f3 -->
+<!-- END_48a3115be98493a3c866eb0e23347262 -->
 
-<!-- START_4bb7fb4a7501d3cb1ed21acfc3b205a9 -->
+<!-- START_d2db7a9fe3abd141d5adbc367a88e969 -->
 ## Remove the specified resource from storage.
 
 > Example request:
@@ -266,7 +266,7 @@ var settings = {
     "url": "http://localhost/api/users/{user}",
     "method": "DELETE",
     "headers": {
-        "accept": "application/json"
+        "accept": "application/json",
     }
 }
 
@@ -280,6 +280,6 @@ $.ajax(settings).done(function (response) {
 `DELETE api/users/{user}`
 
 
-<!-- END_4bb7fb4a7501d3cb1ed21acfc3b205a9 -->
+<!-- END_d2db7a9fe3abd141d5adbc367a88e969 -->
 
 

+ 22 - 26
tests/GenerateDocumentationTest.php

@@ -27,7 +27,7 @@ class GenerateDocumentationTest extends TestCase
     public function tearDown()
     {
         // delete the generated docs - compatible cross-platform
-        $dir = __DIR__ . '/../public/docs';/*
+        $dir = __DIR__ . '/../public/docs';
         if (is_dir($dir)) {
             $files = new RecursiveIteratorIterator(
                 new RecursiveDirectoryIterator($dir, RecursiveDirectoryIterator::SKIP_DOTS),
@@ -39,7 +39,7 @@ class GenerateDocumentationTest extends TestCase
                 $todo($fileinfo->getRealPath());
             }
             rmdir($dir);
-        }*/
+        }
     }
 
     /**
@@ -61,7 +61,7 @@ class GenerateDocumentationTest extends TestCase
         RouteFacade::get('/api/closure', function () {
             return 'hi';
         });
-        RouteFacade::get('/api/test', TestController::class . '@parseMethodDescription');
+        RouteFacade::get('/api/test', TestController::class . '@withEndpointDescription');
 
         config(['apidoc.routes.0.match.prefixes' => ['api/*']]);
         $output = $this->artisan('apidoc:generate');
@@ -78,7 +78,7 @@ class GenerateDocumentationTest extends TestCase
             $api->get('/closure', function () {
                 return 'foo';
             });
-            $api->get('/test', DingoTestController::class . '@parseMethodDescription');
+            $api->get('/test', TestController::class . '@withEndpointDescription');
         });
 
         config(['apidoc.router' => 'dingo']);
@@ -94,7 +94,7 @@ class GenerateDocumentationTest extends TestCase
     public function can_skip_single_routes()
     {
         RouteFacade::get('/api/skip', TestController::class . '@skip');
-        RouteFacade::get('/api/test', TestController::class . '@parseMethodDescription');
+        RouteFacade::get('/api/test', TestController::class . '@withEndpointDescription');
 
         config(['apidoc.routes.0.match.prefixes' => ['api/*']]);
         $output = $this->artisan('apidoc:generate');
@@ -157,8 +157,8 @@ class GenerateDocumentationTest extends TestCase
     /** @test */
     public function generated_markdown_file_is_correct()
     {
-        RouteFacade::get('/api/test', TestController::class . '@parseMethodDescription');
-        RouteFacade::get('/api/fetch', TestController::class . '@fetchRouteResponse');
+        RouteFacade::get('/api/test', TestController::class . '@withEndpointDescription');
+        RouteFacade::get('/api/responseTag', TestController::class . '@withResponseTag');
 
         config(['apidoc.routes.0.match.prefixes' => ['api/*']]);
         $this->artisan('apidoc:generate');
@@ -173,8 +173,8 @@ class GenerateDocumentationTest extends TestCase
     /** @test */
     public function can_prepend_and_append_data_to_generated_markdown()
     {
-        RouteFacade::get('/api/test', TestController::class . '@parseMethodDescription');
-        RouteFacade::get('/api/fetch', TestController::class . '@fetchRouteResponse');
+        RouteFacade::get('/api/test', TestController::class . '@withEndpointDescription');
+        RouteFacade::get('/api/responseTag', TestController::class . '@withResponseTag');
 
         config(['apidoc.routes.0.match.prefixes' => ['api/*']]);
         $this->artisan('apidoc:generate');
@@ -187,15 +187,15 @@ class GenerateDocumentationTest extends TestCase
         $this->artisan('apidoc:generate');
 
         $generatedMarkdown = __DIR__ . '/../public/docs/source/index.md';
-        $this->assertContainsRaw($this->getFileContents($prependMarkdown), $this->getFileContents($generatedMarkdown));
-        $this->assertContainsRaw($this->getFileContents($appendMarkdown), $this->getFileContents($generatedMarkdown));
+        $this->assertContainsIgnoringWhitespace($this->getFileContents($prependMarkdown), $this->getFileContents($generatedMarkdown));
+        $this->assertContainsIgnoringWhitespace($this->getFileContents($appendMarkdown), $this->getFileContents($generatedMarkdown));
     }
 
     /** @test */
     public function generated_postman_collection_file_is_correct()
     {
-        RouteFacade::get('/api/test', TestController::class . '@parseMethodDescription');
-        RouteFacade::post('/api/fetch', TestController::class . '@fetchRouteResponse');
+        RouteFacade::get('/api/test', TestController::class . '@withEndpointDescription');
+        RouteFacade::post('/api/responseTag', TestController::class . '@withResponseTag');
 
         config(['apidoc.routes.0.match.prefixes' => ['api/*']]);
         $this->artisan('apidoc:generate');
@@ -212,26 +212,22 @@ class GenerateDocumentationTest extends TestCase
         RouteFacade::get('/api/headers', TestController::class . '@checkCustomHeaders');
 
         config(['apidoc.routes.0.match.prefixes' => ['api/*']]);
-        config(['apidoc.routes.0.apply.requests.headers' => [
-            'Authorization' => 'customAuthToken',
-            'Custom-Header' => 'NotSoCustom',
-            ]
+        config([
+            'apidoc.routes.0.apply.headers' => [
+                'Authorization' => 'customAuthToken',
+                'Custom-Header' => 'NotSoCustom',
+            ],
         ]);
         $this->artisan('apidoc:generate');
 
         $generatedMarkdown = $this->getFileContents(__DIR__ . '/../public/docs/source/index.md');
-        $this->assertContainsRaw('"authorization": [
-        "customAuthToken"
-    ],
-    "custom-header": [
-        "NotSoCustom"
-    ]', $generatedMarkdown);
+        $this->assertContainsIgnoringWhitespace('"Authorization": "customAuthToken","Custom-Header":"NotSoCustom"', $generatedMarkdown);
     }
 
     /** @test */
-    public function generates_utf8_responses()
+    public function can_parse_utf8_response()
     {
-        RouteFacade::get('/api/utf8', TestController::class . '@utf8');
+        RouteFacade::get('/api/utf8', TestController::class . '@withUtf8ResponseTag');
 
         config(['apidoc.routes.0.prefixes' => ['api/*'],]);
         $this->artisan('apidoc:generate');
@@ -278,7 +274,7 @@ class GenerateDocumentationTest extends TestCase
      * @param $needle
      * @param $haystack
      */
-    private function assertContainsRaw($needle, $haystack)
+    private function assertContainsIgnoringWhitespace($needle, $haystack)
     {
         $haystack = preg_replace('/\s/', '', $haystack);
         $needle = preg_replace('/\s/', '', $needle);

+ 7 - 1
tests/Unit/GeneratorTestCase.php

@@ -93,7 +93,13 @@ abstract class GeneratorTestCase extends TestCase
         $this->assertTrue(is_array($parsed));
         $this->assertArrayHasKey('showresponse', $parsed);
         $this->assertTrue($parsed['showresponse']);
-        $this->assertJsonStringEqualsJsonString($parsed['response'], '{ "data": []}');
+        $this->assertJsonStringEqualsJsonString(json_encode([
+            'id' => 4,
+            'name' => 'banana',
+            'color' => 'red',
+            'weight' => '1 kg',
+            'delicious' => true,
+        ]), $parsed['response']);
     }
 
     /** @test */