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

Commit 6db3cf6

Browse files
authored
Merge pull request #41 from grayloon/singular-custom-endpoints
Ability to use singular custom endpoints
2 parents ac54bc9 + 184edcd commit 6db3cf6

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/Api/Custom.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ public function __construct(string $endpoint, Magento $magento)
3535
public function __call($method, $args)
3636
{
3737
if (in_array($method, self::HTTP_METHODS)) {
38-
$args[0] = $this->endpoint.ltrim($args[0], '/');
38+
$args[0] = (isset($args[0]))
39+
? $this->endpoint.ltrim($args[0], '/')
40+
: rtrim($this->endpoint, '/');
3941
}
4042

4143
return call_user_func_array([$this, $method], $args);

tests/Api/CustomTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,17 @@ public function test_can_get_custom_endpoint()
1818
$this->assertTrue($customApi->ok());
1919
}
2020

21+
public function test_can_get_singular_custom_endpoint()
22+
{
23+
Http::fake([
24+
'*rest/all/V1/foo' => Http::response([], 200),
25+
]);
26+
27+
$customApi = MagentoFacade::api('foo')->get();
28+
29+
$this->assertTrue($customApi->ok());
30+
}
31+
2132
public function test_can_post_custom_endpoint()
2233
{
2334
Http::fake([

0 commit comments

Comments
 (0)