Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit dfa59cb

Browse files
committed
Add CustomTest; update docs
1 parent b7f313c commit dfa59cb

File tree

2 files changed

+51
-4
lines changed

2 files changed

+51
-4
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -228,19 +228,19 @@ $magento->api('products')->show($sku);
228228
Magento modules can have their own API endpoints.
229229
For 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
```
238238
To 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>

tests/Api/CustomTest.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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+
}

0 commit comments

Comments
 (0)