Skip to content

Commit 07b7a54

Browse files
committed
Adjusting existing tests for new format and fixing encoding issue
1 parent c8f345c commit 07b7a54

9 files changed

+202
-33
lines changed

src/Writing/PostmanCollectionWriter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ protected function makeUrlData($route)
131131
'query' => $queryParams->union($route['queryParameters'])->map(function ($parameter, $key) {
132132
return [
133133
'key' => $key,
134-
'value' => $parameter['value'],
134+
'value' => urlencode($parameter['value']),
135135
'description' => $parameter['description'],
136136
// Default query params to disabled if they aren't required and have empty values
137137
'disabled' => ! $parameter['required'] && empty($parameter['value']),
@@ -149,7 +149,7 @@ protected function makeUrlData($route)
149149
return [
150150
'id' => $key,
151151
'key' => $key,
152-
'value' => $parameter['value'],
152+
'value' => urlencode($parameter['value']),
153153
'description' => $parameter['description'],
154154
];
155155
})->values()->toArray();

tests/Fixtures/collection.json

Lines changed: 119 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@
1414
{
1515
"name": "Example title.",
1616
"request": {
17-
"url": "http:\/\/localhost\/api\/withDescription",
17+
"url": {
18+
"protocol": "http",
19+
"host": "localhost",
20+
"path": "api\/withDescription",
21+
"query": []
22+
},
1823
"method": "GET",
1924
"header": [
2025
{
@@ -43,9 +48,14 @@
4348
}
4449
},
4550
{
46-
"name": "http:\/\/localhost\/api\/withResponseTag",
51+
"name": "api\/withResponseTag",
4752
"request": {
48-
"url": "http:\/\/localhost\/api\/withResponseTag",
53+
"url": {
54+
"protocol": "http",
55+
"host": "localhost",
56+
"path": "api\/withResponseTag",
57+
"query": []
58+
},
4959
"method": "GET",
5060
"header": [
5161
{
@@ -76,7 +86,12 @@
7686
{
7787
"name": "Endpoint with body parameters.",
7888
"request": {
79-
"url": "http:\/\/localhost\/api\/withBodyParameters",
89+
"url": {
90+
"protocol": "http",
91+
"host": "localhost",
92+
"path": "api\/withBodyParameters",
93+
"query": []
94+
},
8095
"method": "POST",
8196
"header": [
8297
{
@@ -105,9 +120,45 @@
105120
}
106121
},
107122
{
108-
"name": "http:\/\/localhost\/api\/withQueryParameters",
123+
"name": "api\/withQueryParameters",
109124
"request": {
110-
"url": "http:\/\/localhost\/api\/withQueryParameters?location_id=consequatur&user_id=me&page=4&filters=consequatur&url_encoded=%2B+%5B%5D%26%3D",
125+
"url": {
126+
"protocol": "http",
127+
"host": "localhost",
128+
"path": "api\/withQueryParameters",
129+
"query": [
130+
{
131+
"key": "location_id",
132+
"value": "consequatur",
133+
"description": "The id of the location.",
134+
"disabled": false
135+
},
136+
{
137+
"key": "user_id",
138+
"value": "me",
139+
"description": "The id of the user.",
140+
"disabled": false
141+
},
142+
{
143+
"key": "page",
144+
"value": "4",
145+
"description": "The page number.",
146+
"disabled": false
147+
},
148+
{
149+
"key": "filters",
150+
"value": "consequatur",
151+
"description": "The filters.",
152+
"disabled": false
153+
},
154+
{
155+
"key": "url_encoded",
156+
"value": "%2B+%5B%5D%26%3D",
157+
"description": "Used for testing that URL parameters will be URL-encoded where needed.",
158+
"disabled": false
159+
}
160+
]
161+
},
111162
"method": "GET",
112163
"header": [
113164
{
@@ -136,9 +187,14 @@
136187
}
137188
},
138189
{
139-
"name": "http:\/\/localhost\/api\/withAuthTag",
190+
"name": "api\/withAuthTag",
140191
"request": {
141-
"url": "http:\/\/localhost\/api\/withAuthTag",
192+
"url": {
193+
"protocol": "http",
194+
"host": "localhost",
195+
"path": "api\/withAuthTag",
196+
"query": []
197+
},
142198
"method": "GET",
143199
"header": [
144200
{
@@ -167,9 +223,14 @@
167223
}
168224
},
169225
{
170-
"name": "http:\/\/localhost\/api\/withEloquentApiResource",
226+
"name": "api\/withEloquentApiResource",
171227
"request": {
172-
"url": "http:\/\/localhost\/api\/withEloquentApiResource",
228+
"url": {
229+
"protocol": "http",
230+
"host": "localhost",
231+
"path": "api\/withEloquentApiResource",
232+
"query": []
233+
},
173234
"method": "GET",
174235
"header": [
175236
{
@@ -198,9 +259,14 @@
198259
}
199260
},
200261
{
201-
"name": "http:\/\/localhost\/api\/withMultipleResponseTagsAndStatusCode",
262+
"name": "api\/withMultipleResponseTagsAndStatusCode",
202263
"request": {
203-
"url": "http:\/\/localhost\/api\/withMultipleResponseTagsAndStatusCode",
264+
"url": {
265+
"protocol": "http",
266+
"host": "localhost",
267+
"path": "api\/withMultipleResponseTagsAndStatusCode",
268+
"query": []
269+
},
204270
"method": "POST",
205271
"header": [
206272
{
@@ -235,9 +301,14 @@
235301
"description": "",
236302
"item": [
237303
{
238-
"name": "http:\/\/localhost\/api\/withEloquentApiResourceCollectionClass",
304+
"name": "api\/withEloquentApiResourceCollectionClass",
239305
"request": {
240-
"url": "http:\/\/localhost\/api\/withEloquentApiResourceCollectionClass",
306+
"url": {
307+
"protocol": "http",
308+
"host": "localhost",
309+
"path": "api\/withEloquentApiResourceCollectionClass",
310+
"query": []
311+
},
241312
"method": "GET",
242313
"header": [
243314
{
@@ -266,9 +337,41 @@
266337
}
267338
},
268339
{
269-
"name": "http:\/\/localhost\/api\/echoesUrlParameters\/{param}-{param2}\/{param3?}",
340+
"name": "api\/echoesUrlParameters\/{param}-{param2}\/{param3?}",
270341
"request": {
271-
"url": "http:\/\/localhost\/api\/echoesUrlParameters\/{param}-{param2}\/{param3?}?something=consequatur",
342+
"url": {
343+
"protocol": "http",
344+
"host": "localhost",
345+
"path": "api\/echoesUrlParameters\/{param}-{param2}\/:param3",
346+
"query": [
347+
{
348+
"key": "param4",
349+
"value": "",
350+
"description": "",
351+
"disabled": true
352+
},
353+
{
354+
"key": "something",
355+
"value": "consequatur",
356+
"description": "",
357+
"disabled": false
358+
}
359+
],
360+
"variable": [
361+
{
362+
"id": "param",
363+
"key": "param",
364+
"value": "4",
365+
"description": ""
366+
},
367+
{
368+
"id": "param2",
369+
"key": "param2",
370+
"value": "consequatur",
371+
"description": ""
372+
}
373+
]
374+
},
272375
"method": "GET",
273376
"header": [
274377
{

tests/Fixtures/collection_custom_url.json

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@
1414
{
1515
"name": "Example title.",
1616
"request": {
17-
"url": "http:\/\/yourapp.app\/api\/test",
17+
"url": {
18+
"protocol": "http",
19+
"host": "yourapp.app",
20+
"path": "api/test",
21+
"query": []
22+
},
1823
"method": "GET",
1924
"header": [
2025
{
@@ -35,9 +40,14 @@
3540
}
3641
},
3742
{
38-
"name": "http:\/\/yourapp.app\/api\/responseTag",
43+
"name": "api\/responseTag",
3944
"request": {
40-
"url": "http:\/\/yourapp.app\/api\/responseTag",
45+
"url": {
46+
"protocol": "http",
47+
"host": "yourapp.app",
48+
"path": "api/responseTag",
49+
"query": []
50+
},
4151
"method": "POST",
4252
"header": [
4353
{

tests/Fixtures/collection_with_body_parameters.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@
1414
{
1515
"name": "Endpoint with body parameters.",
1616
"request": {
17-
"url": "http:\/\/localhost\/api\/withBodyParameters",
17+
"url": {
18+
"protocol": "http",
19+
"host": "localhost",
20+
"path": "api\/withBodyParameters",
21+
"query": []
22+
},
1823
"method": "GET",
1924
"header": [
2025
{

tests/Fixtures/collection_with_custom_headers.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,14 @@
1212
"description": "",
1313
"item": [
1414
{
15-
"name": "http:\/\/localhost\/api\/headers",
15+
"name": "api\/headers",
1616
"request": {
17-
"url": "http:\/\/localhost\/api\/headers",
17+
"url": {
18+
"protocol": "http",
19+
"host": "localhost",
20+
"path": "api/headers",
21+
"query": []
22+
},
1823
"method": "GET",
1924
"header": [
2025
{

tests/Fixtures/collection_with_query_parameters.json

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,45 @@
1212
"description": "",
1313
"item": [
1414
{
15-
"name": "http:\/\/localhost\/api\/withQueryParameters",
15+
"name": "api\/withQueryParameters",
1616
"request": {
17-
"url": "http:\/\/localhost\/api\/withQueryParameters?location_id=consequatur&user_id=me&page=4&filters=consequatur&url_encoded=%2B+%5B%5D%26%3D",
17+
"url": {
18+
"protocol": "http",
19+
"host": "localhost",
20+
"path": "api\/withQueryParameters",
21+
"query": [
22+
{
23+
"key": "location_id",
24+
"value": "consequatur",
25+
"description": "The id of the location.",
26+
"disabled": false
27+
},
28+
{
29+
"key": "user_id",
30+
"value": "me",
31+
"description": "The id of the user.",
32+
"disabled": false
33+
},
34+
{
35+
"key": "page",
36+
"value": "4",
37+
"description": "The page number.",
38+
"disabled": false
39+
},
40+
{
41+
"key": "filters",
42+
"value": "consequatur",
43+
"description": "The filters.",
44+
"disabled": false
45+
},
46+
{
47+
"key": "url_encoded",
48+
"value": "%2B+%5B%5D%26%3D",
49+
"description": "Used for testing that URL parameters will be URL-encoded where needed.",
50+
"disabled": false
51+
}
52+
]
53+
},
1854
"method": "GET",
1955
"header": [
2056
{

tests/Fixtures/collection_with_secure_url.json

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@
1414
{
1515
"name": "Example title.",
1616
"request": {
17-
"url": "https:\/\/yourapp.app\/api\/test",
17+
"url": {
18+
"protocol": "https",
19+
"host": "yourapp.app",
20+
"path": "api/test",
21+
"query": []
22+
},
1823
"method": "GET",
1924
"header": [
2025
{
@@ -35,9 +40,14 @@
3540
}
3641
},
3742
{
38-
"name": "https:\/\/yourapp.app\/api\/responseTag",
43+
"name": "api\/responseTag",
3944
"request": {
40-
"url": "https:\/\/yourapp.app\/api\/responseTag",
45+
"url": {
46+
"protocol": "https",
47+
"host": "yourapp.app",
48+
"path": "api/responseTag",
49+
"query": []
50+
},
4151
"method": "POST",
4252
"header": [
4353
{

tests/GenerateDocumentationTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,8 +275,8 @@ public function generated_postman_collection_domain_is_correct()
275275
$this->artisan('apidoc:generate');
276276

277277
$generatedCollection = json_decode(file_get_contents(__DIR__.'/../public/docs/collection.json'));
278-
$endpointUrl = $generatedCollection->item[0]->item[0]->request->url;
279-
$this->assertTrue(Str::startsWith($endpointUrl, $domain));
278+
$endpointUrl = $generatedCollection->item[0]->item[0]->request->url->host;
279+
$this->assertTrue(Str::startsWith($endpointUrl, 'somedomain.test'));
280280
}
281281

282282
/** @test */

tests/Unit/PostmanCollectionWriterTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ public function testQueryParametersAreDocumented()
173173
$this->assertCount(1, $variableData);
174174
$this->assertSame([
175175
'key' => 'limit',
176-
'value' => 5,
176+
'value' => '5',
177177
'description' => 'A fake limit for my fake endpoint',
178178
'disabled' => false,
179179
], $variableData[0]);
@@ -198,7 +198,7 @@ public function testUrlParametersAreResolvedAsQueryParametersIfMissingFromPath()
198198
$this->assertCount(1, $variableData);
199199
$this->assertSame([
200200
'key' => 'limit',
201-
'value' => 5,
201+
'value' => '5',
202202
'description' => 'A fake limit for my fake endpoint',
203203
'disabled' => false,
204204
], $variableData[0]);

0 commit comments

Comments
 (0)