Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/Omniphx/Forrest/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use GuzzleHttp\ClientInterface;
use GuzzleHttp\Exception\GuzzleException;
use GuzzleHttp\Exception\RequestException;
use Illuminate\Support\Traits\Macroable;
use Omniphx\Forrest\Exceptions\InvalidLoginCreditialsException;
use Omniphx\Forrest\Exceptions\SalesforceException;
use Omniphx\Forrest\Exceptions\TokenExpiredException;
Expand Down Expand Up @@ -53,6 +54,10 @@
*/
abstract class Client implements AuthenticationInterface
{
use Macroable {
__call as macroable__call;
}

/**
* HTTP request client.
*
Expand Down Expand Up @@ -718,6 +723,10 @@ public function hasToken()
*/
public function __call($name, $arguments)
{
if ($this->hasMacro($name)) {
return $this->macroable__call($name, $arguments);
}

$url = $this->instanceURLRepo->get();
$url .= $this->resourceRepo->get($name);
$url .= $this->appendURL($arguments);
Expand Down
1 change: 1 addition & 0 deletions src/Omniphx/Forrest/Providers/Laravel/Facades/Forrest.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
* @method static ResponseInterface getAttachmentBody(string $id)
* @method static ResponseInterface getContentVersionBody(string $id)
* @method static \Omniphx\Forrest\Interfaces\RedirectInterface callback()
* @method static void macro(string $name, object|callable $macro)
*/
class Forrest extends Facade
{
Expand Down
22 changes: 22 additions & 0 deletions tests/Unit/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,28 @@ public function testDynamicResourceCallsAppendStringPaths(): void
$this->assertSame(['theme' => 'mobile'], $client->theme('mobile'));
}

public function testMacroable(): void
{
$client = $this->makeClient();

$client->macro('test', function () {
return 'macro test';
});

$this->assertSame('macro test', $client->test());
}

public function testStaticMacroable(): void
{
$client = $this->makeClient();

$client->macro('test', function () {
return 'macro test';
});

$this->assertSame('macro test', $client::test());
}

private function makeClient(?ClientInterface $http = null, ?EventInterface $event = null, ?RepositoryInterface $tokenRepo = null): InspectableClient
{
$http = $http ?: $this->createMock(ClientInterface::class);
Expand Down