This repository was archived by the owner on Jan 23, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +51
-4
lines changed Expand file tree Collapse file tree 2 files changed +51
-4
lines changed Original file line number Diff line number Diff line change @@ -228,19 +228,19 @@ $magento->api('products')->show($sku);
228228Magento modules can have their own API endpoints.
229229For example:
230230``` xml
231- <route method =" POST" url =" /V1/custom/save" >
231+ <route method =" POST" url =" /V1/my- custom-endpoint /save" >
232232 ...
233233</route >
234- <route method =" GET" url =" /V1/custom/get/:id" >
234+ <route method =" GET" url =" /V1/my- custom-endpoint /get/:id" >
235235 ...
236236</route >
237237```
238238To use these you can directly use get/post methods:
239239``` php
240- $magento->api('custom')->post('save', [...]);
240+ $magento->api('my- custom-endpoint ')->post('save', [...]);
241241```
242242``` php
243- $magento->api('custom')->get('get/1');
243+ $magento->api('my- custom-endpoint ')->get('get/1');
244244```
245245
246246<a id =" schema " ></a >
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Grayloon \Magento \Tests ;
4+
5+ use Grayloon \Magento \Magento ;
6+ use Illuminate \Support \Facades \Http ;
7+
8+ class CustomTest extends TestCase
9+ {
10+ public function test_can_get_custom_endpoint ()
11+ {
12+ Http::fake ([
13+ '*rest/all/V1/foo/bar ' => Http::response ([], 200 ),
14+ ]);
15+
16+ $ magento = new Magento ();
17+ $ customApi = $ magento ->api ('/foo ' )->get ('bar ' );
18+
19+ $ this ->assertTrue ($ customApi ->ok ());
20+ }
21+
22+ public function test_can_post_custom_endpoint ()
23+ {
24+ Http::fake ([
25+ '*rest/all/V1/foo/bar ' => Http::response ([], 200 ),
26+ ]);
27+
28+ $ magento = new Magento ();
29+ $ customApi = $ magento ->api ('/foo ' )->post ('bar ' );
30+
31+ $ this ->assertTrue ($ customApi ->ok ());
32+ }
33+
34+ public function test_custom_post_endpoint_passes_params ()
35+ {
36+ Http::fake ([
37+ '*rest/all/V1/foo/bar ' => Http::response ([], 200 , ['baz ' => 'test ' ]),
38+ ]);
39+
40+ $ magento = new Magento ();
41+ $ customApi = $ magento ->api ('/foo ' )->post ('bar ' , [
42+ 'baz ' => 'test ' ,
43+ ]);
44+
45+ $ this ->assertTrue ($ customApi ->ok ());
46+ }
47+ }
You can’t perform that action at this time.
0 commit comments