-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial commit with basic Subscription models (#193)
Co-authored-by: Dane Powell <[email protected]>
- Loading branch information
1 parent
a4d3597
commit 48ca8aa
Showing
7 changed files
with
486 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
|
||
namespace AcquiaCloudApi\Endpoints; | ||
|
||
use AcquiaCloudApi\Response\OperationResponse; | ||
use AcquiaCloudApi\Response\SubscriptionResponse; | ||
use AcquiaCloudApi\Response\SubscriptionsResponse; | ||
|
||
class Subscriptions extends CloudApiBase implements CloudApiInterface | ||
{ | ||
/** | ||
* Shows all Subscriptions. | ||
* | ||
* @return SubscriptionsResponse<SubscriptionResponse> | ||
*/ | ||
public function getAll(): SubscriptionsResponse | ||
{ | ||
return new SubscriptionsResponse($this->client->request('get', '/subscriptions')); | ||
} | ||
|
||
/** | ||
* Shows information about an subscription. | ||
* | ||
* @param string $subscriptionUuid | ||
* @return SubscriptionResponse | ||
*/ | ||
public function get($subscriptionUuid): SubscriptionResponse | ||
{ | ||
return new SubscriptionResponse( | ||
$this->client->request( | ||
'get', | ||
"/subscriptions/${subscriptionUuid}" | ||
) | ||
); | ||
} | ||
|
||
/** | ||
* Renames an subscription. | ||
* | ||
* @param string $subscriptionUuid | ||
* @param string $name | ||
* @return OperationResponse | ||
*/ | ||
public function rename($subscriptionUuid, $name): OperationResponse | ||
{ | ||
|
||
$options = [ | ||
'json' => [ | ||
'name' => $name, | ||
], | ||
]; | ||
|
||
return new OperationResponse( | ||
$this->client->request( | ||
'put', | ||
"/subscriptions/${subscriptionUuid}", | ||
$options | ||
) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
<?php | ||
|
||
namespace AcquiaCloudApi\Response; | ||
|
||
class SubscriptionResponse | ||
{ | ||
/** | ||
* @var int $id | ||
*/ | ||
public $id; | ||
|
||
/** | ||
* @var string $uuid | ||
*/ | ||
public $uuid; | ||
|
||
/** | ||
* @var string $name | ||
*/ | ||
public $name; | ||
|
||
/** | ||
* @var string $start_at | ||
*/ | ||
public $start_at; | ||
|
||
/** | ||
* @var string $expire_at | ||
*/ | ||
public $expire_at; | ||
|
||
/** | ||
* @var object $product | ||
*/ | ||
public $product; | ||
|
||
/** | ||
* @var int $applications_total | ||
*/ | ||
public $applications_total; | ||
|
||
/** | ||
* @var int $applications_used | ||
*/ | ||
public $applications_used; | ||
|
||
/** | ||
* @var int $advisory_hours_total | ||
*/ | ||
public $advisory_hours_total; | ||
|
||
/** | ||
* @var int $advisory_hours_used | ||
*/ | ||
public $advisory_hours_used; | ||
|
||
/** | ||
* @var object $organization | ||
*/ | ||
public $organization; | ||
|
||
/** | ||
* @var object $flags | ||
*/ | ||
public $flags; | ||
|
||
/** | ||
* @var object $links | ||
*/ | ||
public $links; | ||
|
||
/** | ||
* @param object $subscription | ||
*/ | ||
public function __construct($subscription) | ||
{ | ||
$this->id = $subscription->id; | ||
$this->uuid = $subscription->uuid; | ||
$this->name = $subscription->name; | ||
$this->start_at = $subscription->start_at; | ||
$this->expire_at = $subscription->expire_at; | ||
$this->product = $subscription->product; | ||
$this->applications_total = $subscription->applications_total; | ||
$this->applications_used = $subscription->applications_used; | ||
$this->advisory_hours_total = $subscription->advisory_hours_total; | ||
$this->advisory_hours_used = $subscription->advisory_hours_used; | ||
$this->organization = $subscription->organization; | ||
$this->flags = $subscription->flags; | ||
$this->links = $subscription->_links; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
namespace AcquiaCloudApi\Response; | ||
|
||
/** | ||
* @template TValue | ||
* @template-extends \ArrayObject<int,TValue> | ||
*/ | ||
class SubscriptionsResponse extends \ArrayObject | ||
{ | ||
|
||
/** | ||
* @param array<object> $subscriptions | ||
*/ | ||
public function __construct($subscriptions) | ||
{ | ||
parent::__construct( | ||
array_map( | ||
function ($subscription) { | ||
return new SubscriptionResponse($subscription); | ||
}, | ||
$subscriptions | ||
), | ||
self::ARRAY_AS_PROPS | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
<?php | ||
|
||
namespace AcquiaCloudApi\Tests\Endpoints; | ||
|
||
use AcquiaCloudApi\Tests\CloudApiTestCase; | ||
use AcquiaCloudApi\Endpoints\Subscriptions; | ||
|
||
class SubscriptionsTest extends CloudApiTestCase | ||
{ | ||
/** | ||
* @var mixed[] $properties | ||
*/ | ||
protected $properties = [ | ||
'uuid', | ||
'name', | ||
'start_at', | ||
'expire_at', | ||
'product', | ||
'applications_total', | ||
'applications_used', | ||
'advisory_hours_total', | ||
'advisory_hours_used', | ||
'organization', | ||
'flags', | ||
'links' | ||
]; | ||
|
||
public function testGetSubscriptions(): void | ||
{ | ||
$response = $this->getPsr7JsonResponseForFixture('Endpoints/Subscriptions/getAllSubscriptions.json'); | ||
$client = $this->getMockClient($response); | ||
|
||
/** @var \AcquiaCloudApi\Connector\ClientInterface $client */ | ||
$subscription = new Subscriptions($client); | ||
$result = $subscription->getAll(); | ||
|
||
$this->assertInstanceOf('\ArrayObject', $result); | ||
$this->assertInstanceOf('\AcquiaCloudApi\Response\SubscriptionsResponse', $result); | ||
$this->assertNotEmpty($result); | ||
|
||
foreach ($result as $record) { | ||
$this->assertInstanceOf('\AcquiaCloudApi\Response\SubscriptionResponse', $record); | ||
|
||
foreach ($this->properties as $property) { | ||
$this->assertObjectHasAttribute($property, $record); | ||
} | ||
} | ||
} | ||
|
||
public function testGetSubscription(): void | ||
{ | ||
$response = $this->getPsr7JsonResponseForFixture('Endpoints/Subscriptions/getSubscription.json'); | ||
$client = $this->getMockClient($response); | ||
|
||
/** @var \AcquiaCloudApi\Connector\ClientInterface $client */ | ||
$subscription = new Subscriptions($client); | ||
$result = $subscription->get('8533debb-ae4e-427b-aa34-731719b4201a'); | ||
|
||
$this->assertNotInstanceOf('\AcquiaCloudApi\Response\SubscriptionsResponse', $result); | ||
$this->assertInstanceOf('\AcquiaCloudApi\Response\SubscriptionResponse', $result); | ||
|
||
foreach ($this->properties as $property) { | ||
$this->assertObjectHasAttribute($property, $result); | ||
} | ||
} | ||
|
||
public function testRenameSubscription(): void | ||
{ | ||
$response = $this->getPsr7JsonResponseForFixture('Endpoints/Subscriptions/renameSubscription.json'); | ||
$client = $this->getMockClient($response); | ||
|
||
/** @var \AcquiaCloudApi\Connector\ClientInterface $client */ | ||
$subscription = new Subscriptions($client); | ||
$result = $subscription->rename('8533debb-ae4e-427b-aa34-731719b4201a', "My subscription's new name"); | ||
|
||
$requestOptions = [ | ||
'json' => [ | ||
'name' => "My subscription's new name", | ||
], | ||
]; | ||
|
||
$this->assertEquals($requestOptions, $this->getRequestOptions($client)); | ||
$this->assertInstanceOf('\AcquiaCloudApi\Response\OperationResponse', $result); | ||
$this->assertEquals('Subscription updated.', $result->message); | ||
} | ||
} |
Oops, something went wrong.