@ashraam You’re just instantiate the client in your constructor. You use mocks to mock dependencies. So re-factor your API class to receive a Guzzle client as a parameter and then you can pass a mock instead:
use Guzzle\ClientInterface;
class MyApi
{
protected $client;
public function __construct(ClientInterface $client)
{
$this->client = $client;
}
}
Now your API class receives a Guzzle client. It doesn’t care if it’s a real one or a mocked one. You can pass a mock one in your tests:
$client = Mockery::mock(ClientInterface::class);
$api = new MyApi($client);
This is also where you would the service provider to also instantiate your MyApi class with a Guzzle client properly configured with your token:
$this->app->singleton(MyApi::class, function () {
$client = new Client([
'base_uri' => 'https://url.com/api/v2',
'headers' => [
'Accept' => 'application/json',
'Authorization' => sprintf('Bearer %s', $this->app['config']['services.myapi.token']),
'Content-Type' => 'application/json',
],
]);
return new MyApi($client);
});