From 184edcd462a67c4596ea7fbeee8e797748cb3ca2 Mon Sep 17 00:00:00 2001 From: ahinkle Date: Tue, 27 Oct 2020 16:53:16 -0500 Subject: [PATCH] Fix: singular custom endpoints --- src/Api/Custom.php | 4 +++- tests/Api/CustomTest.php | 11 +++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/Api/Custom.php b/src/Api/Custom.php index 7be4cab..76b2acc 100644 --- a/src/Api/Custom.php +++ b/src/Api/Custom.php @@ -35,7 +35,9 @@ public function __construct(string $endpoint, Magento $magento) public function __call($method, $args) { if (in_array($method, self::HTTP_METHODS)) { - $args[0] = $this->endpoint.ltrim($args[0], '/'); + $args[0] = (isset($args[0])) + ? $this->endpoint.ltrim($args[0], '/') + : rtrim($this->endpoint, '/'); } return call_user_func_array([$this, $method], $args); diff --git a/tests/Api/CustomTest.php b/tests/Api/CustomTest.php index 4aed363..9279b1e 100644 --- a/tests/Api/CustomTest.php +++ b/tests/Api/CustomTest.php @@ -18,6 +18,17 @@ public function test_can_get_custom_endpoint() $this->assertTrue($customApi->ok()); } + public function test_can_get_singular_custom_endpoint() + { + Http::fake([ + '*rest/all/V1/foo' => Http::response([], 200), + ]); + + $customApi = MagentoFacade::api('foo')->get(); + + $this->assertTrue($customApi->ok()); + } + public function test_can_post_custom_endpoint() { Http::fake([