@nathanjdunn
use NathanDunn\Chargebee\Client;
$client = new Client('nathandunn-test', 'test_bv6UzHREYaCNJQLqzdNzILQ0450o2dyS');
$sub = $client->subscription()->list();
// Response
array(1) {
'list' =>
array(1) {
[0] =>
array(2) {
'subscription' =>
array(22) {
...
}
'customer' =>
array(21) {
...
}
}
}
}use NathanDunn\Chargebee\HttpClient\Builder;
use Http\Mock\Client as MockClient;
use NathanDunn\Chargebee\Client;
$builder = new Builder(
'test_bv6UzHREYaCNJQLqzdNzILQ0450o2dyS', new MockClient
);
$client = new Client(
'nathandunn-test', 'test_bv6UzHREYaCNJQLqzdNzILQ0450o2dyS', $builder
);
$sub = $client->subscription()->list();// Builder.php
/**
* @return HttpMethodsClient
*/
public function getHttpClient(): HttpMethodsClient
{
$this->httpMethodsClient = new HttpMethodsClient(
new PluginClient($this->httpClient, [new ErrorPlugin]),
$this->requestFactory
);
return $this->httpMethodsClient;
}// Builder.php
/**
* @return AuthenticationPlugin
*/
protected function getAuthenticationPlugin(): AuthenticationPlugin
{
$authentication = new BasicAuth($this->key, null);
return new AuthenticationPlugin($authentication);
}// Builder.php
/**
* @return HttpMethodsClient
*/
public function getHttpClient(): HttpMethodsClient
{
$authenticator = $this->getAuthenticationPlugin();
$this->httpMethodsClient = new HttpMethodsClient(
new PluginClient($this->httpClient, [$authenticator]),
$this->requestFactory
);
return $this->httpMethodsClient;
}// tests/Unit/Api/Addons/AddonTest.php
/** @test */
public function should_list_addons()
{
$expected = $this->getContent(
sprintf('%s/data/responses/addon_list.json', __DIR__)
);
$addon = $this->getApiMock();
$addon->expects($this->once())
->method('get')
->with('https://123456789.chargebee.com/api/v2/addons', [])
->will($this->returnValue($expected));
$this->assertEquals($expected, $addon->list());
}// Unit/Api/TestCase.php
protected function getApiMock(array $methods = [])
{
$httpClient = $this->getMockBuilder(HttpClient::class)
->setMethods(['sendRequest'])
->getMock();
$httpClient
->expects($this->any())
->method('sendRequest');
$builder = new Builder(self::$key, $httpClient);
$client = new Client(self::$site, self::$key, $builder);
return $this->getMockBuilder(Addon::class)
->setMethods(['get', 'post'])
->setConstructorArgs([$client])
->getMock();
}