Skip to content

Commit b164263

Browse files
committed
Add tests on output, config and bindings
1 parent 622fb2f commit b164263

File tree

8 files changed

+303
-163
lines changed

8 files changed

+303
-163
lines changed

TODO.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
- Add tests for bindings and bindings prefixes
2-
- Add tests for config overrides
3-
- Add tests on output (deterministic)
1+
- Replace filesystem manipulation with lib
2+
3+
Major
44
- Bring `bindings` outside of `response_calls`
55
- Should `routes.*.apply.response_calls.headers` be replaced by `routes.*.apply.headers`?

resources/views/partials/route.blade.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
@foreach($settings['languages'] as $language)
1515
@include("apidoc::partials.example-requests.$language")
1616

17+
1718
@endforeach
1819

1920
@if(in_array('GET',$route['methods']) || (isset($route['showresponse']) && $route['showresponse']))

src/Tools/Utils.php

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
use Illuminate\Support\Str;
66
use Illuminate\Routing\Route;
7+
use League\Flysystem\Adapter\Local;
8+
use League\Flysystem\Filesystem;
9+
use RecursiveDirectoryIterator;
10+
use RecursiveIteratorIterator;
711

812
class Utils
913
{
@@ -45,7 +49,7 @@ public static function getRouteActionUses(array $action)
4549
*
4650
* @return mixed
4751
*/
48-
protected static function replaceUrlParameterBindings(string $uri, array $bindings)
52+
public static function replaceUrlParameterBindings(string $uri, array $bindings)
4953
{
5054
foreach ($bindings as $path => $binding) {
5155
// So we can support partial bindings like
@@ -63,4 +67,23 @@ protected static function replaceUrlParameterBindings(string $uri, array $bindin
6367

6468
return $uri;
6569
}
70+
71+
public static function deleteDirectoryAndContents($dir)
72+
{
73+
if (is_dir($dir)) {
74+
$files = new RecursiveIteratorIterator(
75+
new RecursiveDirectoryIterator($dir, RecursiveDirectoryIterator::SKIP_DOTS),
76+
RecursiveIteratorIterator::CHILD_FIRST
77+
);
78+
79+
foreach ($files as $fileinfo) {
80+
$todo = ($fileinfo->isDir() ? 'rmdir' : 'unlink');
81+
$todo($fileinfo->getRealPath());
82+
}
83+
rmdir($dir);
84+
}
85+
/*
86+
$adapter = new Local(__DIR__.'../../');
87+
$filesystem = new Filesystem($adapter);*/
88+
}
6689
}

tests/Fixtures/TestController.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,20 @@ public function shouldFetchRouteResponse()
112112
];
113113
}
114114

115+
public function echoesConfig()
116+
{
117+
return [
118+
'app.env' => config('app.env')
119+
];
120+
}
121+
122+
public function echoesUrlPathParameters($param)
123+
{
124+
return [
125+
'param' => $param
126+
];
127+
}
128+
115129
public function shouldFetchRouteResponseWithEchoedSettings($id)
116130
{
117131
return [

tests/Fixtures/index.md

Lines changed: 90 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -20,26 +20,27 @@ Welcome to the generated API reference.
2020

2121
<!-- END_INFO -->
2222

23-
#general
23+
#Group A
2424
<!-- START_264ee15c728df32e7ca6eedce5e42dcb -->
2525
## Example title.
26-
26+
2727
This will be the long description.
2828
It can also be multiple lines long.
2929

3030
> Example request:
3131
3232
```bash
3333
curl -X GET -G "http://localhost/api/withDescription" \
34-
-H "Accept: application/json" \
3534
-H "Authorization: customAuthToken" \
36-
-H "Custom-Header: NotSoCustom"
35+
-H "Custom-Header: NotSoCustom"
3736
```
3837

3938
```javascript
40-
const url = new URL("http://localhost/api/users");
39+
const url = new URL("http://localhost/api/withDescription");
4140

4241
let headers = {
42+
"Authorization": "customAuthToken",
43+
"Custom-Header": "NotSoCustom",
4344
"Accept": "application/json",
4445
"Content-Type": "application/json",
4546
}
@@ -52,7 +53,8 @@ fetch(url, {
5253
.then(json => console.log(json));
5354
```
5455

55-
> Example response:
56+
57+
> Example response (200):
5658
5759
```json
5860
null
@@ -66,35 +68,34 @@ null
6668

6769
<!-- START_9cedd363be06f5512f9e844b100fcc9d -->
6870
## api/withResponseTag
69-
7071
> Example request:
7172
7273
```bash
7374
curl -X GET -G "http://localhost/api/withResponseTag" \
74-
-H "Accept: application/json" \
7575
-H "Authorization: customAuthToken" \
76-
-H "Custom-Header: NotSoCustom"
76+
-H "Custom-Header: NotSoCustom"
7777
```
7878

7979
```javascript
80-
var settings = {
81-
"async": true,
82-
"crossDomain": true,
83-
"url": "http://localhost/api/withResponseTag",
84-
"method": "GET",
85-
"headers": {
86-
"accept": "application/json",
87-
"Authorization": "customAuthToken",
88-
"Custom-Header": "NotSoCustom",
89-
}
80+
const url = new URL("http://localhost/api/withResponseTag");
81+
82+
let headers = {
83+
"Authorization": "customAuthToken",
84+
"Custom-Header": "NotSoCustom",
85+
"Accept": "application/json",
86+
"Content-Type": "application/json",
9087
}
9188

92-
$.ajax(settings).done(function (response) {
93-
console.log(response);
94-
});
89+
fetch(url, {
90+
method: "GET",
91+
headers: headers,
92+
})
93+
.then(response => response.json())
94+
.then(json => console.log(json));
9595
```
9696

97-
> Example response:
97+
98+
> Example response (200):
9899
99100
```json
100101
{
@@ -114,49 +115,61 @@ $.ajax(settings).done(function (response) {
114115

115116
<!-- START_a25cb3b490fa579d7d77b386bbb7ec03 -->
116117
## api/withBodyParameters
117-
118118
> Example request:
119119
120120
```bash
121121
curl -X GET -G "http://localhost/api/withBodyParameters" \
122-
-H "Accept: application/json" \
123122
-H "Authorization: customAuthToken" \
124-
-H "Custom-Header: NotSoCustom" \
125-
-d "user_id"=20 \
126-
-d "room_id"=6DZyNcBgezdjdAIs \
127-
-d "forever"= \
128-
-d "another_one"=2153.4 \
129-
-d "yet_another_param"={} \
130-
-d "even_more_param"=[]
123+
-H "Custom-Header: NotSoCustom" \
124+
-H "Content-Type: application/json" \
125+
-d '{"user_id":9,"room_id":"consequatur","forever":false,"another_one":11613.31890586,"yet_another_param":{},"even_more_param":[],"book":{"name":"consequatur","author_id":17,"pages_count":17},"ids":[17],"users":[{"first_name":"John","last_name":"Doe"}]}'
126+
131127
```
132128

133129
```javascript
134-
var settings = {
135-
"async": true,
136-
"crossDomain": true,
137-
"url": "http://localhost/api/withBodyParameters",
138-
"method": "GET",
139-
"data": {
140-
"user_id": 20,
141-
"room_id": "6DZyNcBgezdjdAIs",
142-
"forever": false,
143-
"another_one": 2153.4,
144-
"yet_another_param": "{}",
145-
"even_more_param": "[]"
130+
const url = new URL("http://localhost/api/withBodyParameters");
131+
132+
let headers = {
133+
"Authorization": "customAuthToken",
134+
"Custom-Header": "NotSoCustom",
135+
"Content-Type": "application/json",
136+
"Accept": "application/json",
137+
}
138+
139+
let body = {
140+
"user_id": 9,
141+
"room_id": "consequatur",
142+
"forever": false,
143+
"another_one": 11613.31890586,
144+
"yet_another_param": {},
145+
"even_more_param": [],
146+
"book": {
147+
"name": "consequatur",
148+
"author_id": 17,
149+
"pages_count": 17
146150
},
147-
"headers": {
148-
"accept": "application/json",
149-
"Authorization": "customAuthToken",
150-
"Custom-Header": "NotSoCustom",
151-
}
151+
"ids": [
152+
17
153+
],
154+
"users": [
155+
{
156+
"first_name": "John",
157+
"last_name": "Doe"
158+
}
159+
]
152160
}
153161

154-
$.ajax(settings).done(function (response) {
155-
console.log(response);
156-
});
162+
fetch(url, {
163+
method: "GET",
164+
headers: headers,
165+
body: body
166+
})
167+
.then(response => response.json())
168+
.then(json => console.log(json));
157169
```
158170

159-
> Example response:
171+
172+
> Example response (200):
160173
161174
```json
162175
null
@@ -165,7 +178,7 @@ null
165178
### HTTP Request
166179
`GET api/withBodyParameters`
167180

168-
#### Parameters
181+
#### Body Parameters
169182

170183
Parameter | Type | Status | Description
171184
--------- | ------- | ------- | ------- | -----------
@@ -175,49 +188,46 @@ Parameter | Type | Status | Description
175188
another_one | number | optional | Just need something here.
176189
yet_another_param | object | required |
177190
even_more_param | array | optional |
191+
book.name | string | optional |
192+
book.author_id | integer | optional |
193+
book[pages_count] | integer | optional |
194+
ids.* | integer | optional |
195+
users.*.first_name | string | optional | The first name of the user.
196+
users.*.last_name | string | optional | The last name of the user.
178197

179198
<!-- END_a25cb3b490fa579d7d77b386bbb7ec03 -->
180199

181200
<!-- START_5c08cc4d72b6e5830f6814c64086e197 -->
182201
## api/withAuthTag
183-
<small style="
184-
padding: 1px 9px 2px;
185-
font-weight: bold;
186-
white-space: nowrap;
187-
color: #ffffff;
188-
-webkit-border-radius: 9px;
189-
-moz-border-radius: 9px;
190-
border-radius: 9px;
191-
background-color: #3a87ad;">Requires authentication</small>
192-
202+
<br><small style="padding: 1px 9px 2px;font-weight: bold;white-space: nowrap;color: #ffffff;-webkit-border-radius: 9px;-moz-border-radius: 9px;border-radius: 9px;background-color: #3a87ad;">Requires authentication</small>
193203
> Example request:
194204
195205
```bash
196206
curl -X GET -G "http://localhost/api/withAuthTag" \
197-
-H "Accept: application/json" \
198207
-H "Authorization: customAuthToken" \
199-
-H "Custom-Header: NotSoCustom"
208+
-H "Custom-Header: NotSoCustom"
200209
```
201210

202211
```javascript
203-
var settings = {
204-
"async": true,
205-
"crossDomain": true,
206-
"url": "http://localhost/api/withAuthTag",
207-
"method": "GET",
208-
"headers": {
209-
"accept": "application/json",
210-
"Authorization": "customAuthToken",
211-
"Custom-Header": "NotSoCustom",
212-
}
212+
const url = new URL("http://localhost/api/withAuthTag");
213+
214+
let headers = {
215+
"Authorization": "customAuthToken",
216+
"Custom-Header": "NotSoCustom",
217+
"Accept": "application/json",
218+
"Content-Type": "application/json",
213219
}
214220

215-
$.ajax(settings).done(function (response) {
216-
console.log(response);
217-
});
221+
fetch(url, {
222+
method: "GET",
223+
headers: headers,
224+
})
225+
.then(response => response.json())
226+
.then(json => console.log(json));
218227
```
219228

220-
> Example response:
229+
230+
> Example response (200):
221231
222232
```json
223233
null

0 commit comments

Comments
 (0)