Просмотр исходного кода

Added test to see if route responses get fetched correctly (#43)

Marcel Pociot 9 лет назад
Родитель
Сommit
a73f21aecc
3 измененных файлов с 62 добавлено и 0 удалено
  1. 18 0
      tests/Fixtures/TestController.php
  2. 43 0
      tests/Fixtures/index.md
  3. 1 0
      tests/GenerateDocumentationTest.php

+ 18 - 0
tests/Fixtures/TestController.php

@@ -25,4 +25,22 @@ class TestController extends Controller
     {
         return '';
     }
+
+    public function fetchRouteResponse()
+    {
+        $fixture = new \stdClass();
+        $fixture->id = 1;
+        $fixture->name = 'banana';
+        $fixture->color = 'red';
+        $fixture->weight = 300;
+        $fixture->delicious = 1;
+
+        return [
+            'id'        => (int) $fixture->id,
+            'name'      => ucfirst($fixture->name),
+            'color'     => ucfirst($fixture->color),
+            'weight'    => $fixture->weight . ' grams',
+            'delicious' => (bool) $fixture->delicious,
+        ];
+    }
 }

+ 43 - 0
tests/Fixtures/index.md

@@ -59,3 +59,46 @@ null
 `HEAD api/test`
 
 
+## api/fetch
+
+> Example request:
+
+```bash
+curl "http://localhost/api/fetch" \
+-H "Accept: application/json"
+```
+
+```javascript
+var settings = {
+    "async": true,
+    "crossDomain": true,
+    "url": "http://localhost/api/fetch",
+    "method": "GET",
+        "headers": {
+    "accept": "application/json"
+    }
+}
+
+$.ajax(settings).done(function (response) {
+console.log(response);
+});
+```
+
+> Example response:
+
+```json
+{
+    "id": 1,
+    "name": "Banana",
+    "color": "Red",
+    "weight": "300 grams",
+    "delicious": true
+}
+```
+
+### HTTP Request
+`GET api/fetch`
+
+`HEAD api/fetch`
+
+

+ 1 - 0
tests/GenerateDocumentationTest.php

@@ -60,6 +60,7 @@ class GenerateDocumentationTest extends TestCase
     public function testGeneratedMarkdownFileIsCorrect()
     {
         RouteFacade::get('/api/test', TestController::class.'@parseMethodDescription');
+        RouteFacade::get('/api/fetch', TestController::class.'@fetchRouteResponse');
 
         $output = $this->artisan('api:generate', [
             '--routePrefix' => 'api/*',