Skip to content

Commit

Permalink
Augments responses with additional information.
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Malone authored and typhonius committed Dec 3, 2019
1 parent 563db16 commit 61eceb3
Show file tree
Hide file tree
Showing 20 changed files with 200 additions and 47 deletions.
4 changes: 4 additions & 0 deletions src/Response/OperationResponse.php
Expand Up @@ -10,6 +10,7 @@ class OperationResponse
{

public $message;
public $links;

/**
* ApplicationResponse constructor.
Expand All @@ -18,5 +19,8 @@ class OperationResponse
public function __construct($operation)
{
$this->message = $operation->message;
if (isset($operation->_links)) {
$this->links = $operation->_links;
}
}
}
14 changes: 14 additions & 0 deletions tests/CloudApiTestCase.php
Expand Up @@ -11,6 +11,20 @@
*/
abstract class CloudApiTestCase extends TestCase
{

/**
* Tests that Response classes have correct parameters.
*
* @param
* @throws AssertionFailedError
*
*/
public function assertOperationResponse($operationResponse)
{
$this->assertNotEmpty($operationResponse->links);
$this->assertNotEmpty($operationResponse->links->notification);
$this->assertNotEmpty($operationResponse->links->notification->href);
}
/**
* Returns a PSR7 Stream for a given fixture.
*
Expand Down
8 changes: 4 additions & 4 deletions tests/Endpoints/CodeTest.php
Expand Up @@ -41,8 +41,8 @@ public function testCodeSwitch()
$result = $client->switchCode('8ff6c046-ec64-4ce4-bea6-27845ec18600', 'my-feature-branch');

$this->assertInstanceOf('\AcquiaCloudApi\Response\OperationResponse', $result);

$this->assertEquals('The code is being switched.', $result->message);
$this->assertOperationResponse($result);
$this->assertEquals('Switching code.', $result->message);
}

public function testCodeDeploy()
Expand All @@ -54,7 +54,7 @@ public function testCodeDeploy()
$result = $client->deployCode('8ff6c046-ec64-4ce4-bea6-27845ec18600', 'f9ef59eb-13ee-4050-8120-5524d8ce9821', 'Commit message');

$this->assertInstanceOf('\AcquiaCloudApi\Response\OperationResponse', $result);

$this->assertEquals('The code is being deployed.', $result->message);
$this->assertOperationResponse($result);
$this->assertEquals('Deploying code.', $result->message);
}
}
4 changes: 2 additions & 2 deletions tests/Endpoints/CronsTest.php
Expand Up @@ -68,7 +68,7 @@ public function testCronAdd()
$result = $client->createCron('14-0c7e79ab-1c4a-424e-8446-76ae8be7e851', '/usr/local/bin/drush cc all', '*/30 * * * *', 'My New Cron');

$this->assertInstanceOf('\AcquiaCloudApi\Response\OperationResponse', $result);

$this->assertOperationResponse($result);
$this->assertEquals('Creating a new cron.', $result->message);
}

Expand All @@ -81,7 +81,7 @@ public function testCronDelete()
$result = $client->deleteCron('14-0c7e79ab-1c4a-424e-8446-76ae8be7e851', 14);

$this->assertInstanceOf('\AcquiaCloudApi\Response\OperationResponse', $result);

$this->assertOperationResponse($result);
$this->assertEquals('Deleting cron.', $result->message);
}

Expand Down
14 changes: 7 additions & 7 deletions tests/Endpoints/DatabasesTest.php
Expand Up @@ -71,8 +71,8 @@ public function testDatabaseCopy()
$result = $client->databaseCopy('24-a47ac10b-58cc-4372-a567-0e02b2c3d470', 'db_name', '14-0c7e79ab-1c4a-424e-8446-76ae8be7e851');

$this->assertInstanceOf('\AcquiaCloudApi\Response\OperationResponse', $result);

$this->assertEquals('The database is queued for copying.', $result->message);
$this->assertOperationResponse($result);
$this->assertEquals('The database is being copied', $result->message);
}

public function testDatabaseCreate()
Expand All @@ -84,7 +84,7 @@ public function testDatabaseCreate()
$result = $client->databaseCreate('8ff6c046-ec64-4ce4-bea6-27845ec18600', 'db_name');

$this->assertInstanceOf('\AcquiaCloudApi\Response\OperationResponse', $result);

$this->assertOperationResponse($result);
$this->assertEquals('The database is being created.', $result->message);
}

Expand All @@ -110,8 +110,8 @@ public function testDatabaseBackup()
$result = $client->createDatabaseBackup('185f07c7-9c4f-407b-8968-67892ebcb38a', 'db_name');

$this->assertInstanceOf('\AcquiaCloudApi\Response\OperationResponse', $result);

$this->assertEquals('The database is being backed up.', $result->message);
$this->assertOperationResponse($result);
$this->assertEquals('Creating the backup.', $result->message);
}

public function testGetDatabaseBackups()
Expand Down Expand Up @@ -159,7 +159,7 @@ public function testRestoreDatabaseBackup()
$result = $client->restoreDatabaseBackup('24-a47ac10b-58cc-4372-a567-0e02b2c3d470', 'db_name', 12);

$this->assertInstanceOf('\AcquiaCloudApi\Response\OperationResponse', $result);

$this->assertEquals('The backup is being restored.', $result->message);
$this->assertOperationResponse($result);
$this->assertEquals('Restoring the database backup.', $result->message);
}
}
12 changes: 6 additions & 6 deletions tests/Endpoints/DomainsTest.php
Expand Up @@ -56,11 +56,11 @@ public function testDomainAdd()
$client = $this->getMockClient($response);

/** @var \AcquiaCloudApi\CloudApi\ClientInterface $client */
$result = $client->createDomain('14-0c7e79ab-1c4a-424e-8446-76ae8be7e851', 'new-domain.com');
$result = $client->createDomain('14-0c7e79ab-1c4a-424e-8446-76ae8be7e851', 'example.com');

$this->assertInstanceOf('\AcquiaCloudApi\Response\OperationResponse', $result);

$this->assertEquals("The domain 'new-domain.com' is being added.", $result->message);
$this->assertOperationResponse($result);
$this->assertEquals("Adding domain example.com", $result->message);
}

public function testDomainDelete()
Expand All @@ -69,10 +69,10 @@ public function testDomainDelete()
$client = $this->getMockClient($response);

/** @var \AcquiaCloudApi\CloudApi\ClientInterface $client */
$result = $client->deleteDomain('14-0c7e79ab-1c4a-424e-8446-76ae8be7e851', 'deleted-domain.com');
$result = $client->deleteDomain('14-0c7e79ab-1c4a-424e-8446-76ae8be7e851', 'example.com');

$this->assertInstanceOf('\AcquiaCloudApi\Response\OperationResponse', $result);

$this->assertEquals("Removing the domain deleted-domain.com", $result->message);
$this->assertOperationResponse($result);
$this->assertEquals("Removing the domain example.com", $result->message);
}
}
5 changes: 3 additions & 2 deletions tests/Endpoints/FilesTest.php
Expand Up @@ -12,9 +12,10 @@ public function testFilesCopy()
$response = $this->getPsr7JsonResponseForFixture('Endpoints/copyFiles.json');
$client = $this->getMockClient($response);

/** @var \AcquiaCloudApi\CloudApi\ClientInterface $client */
/** @var \AcquiaCloudApi\CloudApi\ClientInterface $client */
$result = $client->copyFiles('8ff6c046-ec64-4ce4-bea6-27845ec18600', '14-0c7e79ab-1c4a-424e-8446-76ae8be7e851');
$this->assertInstanceOf('\AcquiaCloudApi\Response\OperationResponse', $result);
$this->assertEquals('The files have been queued for copying.', $result->message);
$this->assertOperationResponse($result);
$this->assertEquals('Copying files.', $result->message);
}
}
15 changes: 13 additions & 2 deletions tests/Fixtures/Endpoints/addCron.json
@@ -1,3 +1,14 @@
{
"message": "Creating a new cron."
}
"message": "Creating a new cron.",
"_links": {
"self": {
"href": "https://cloud.acquia.com/api/environments/286-f027502b-ed6c-448e-97e8-4a0def7d25e1/crons"
},
"parent": {
"href": "https://cloud.acquia.com/api/environments/286-f027502b-ed6c-448e-97e8-4a0def7d25e1"
},
"notification": {
"href": "https://cloud.acquia.com/api/notifications/01fde3bb-b65f-4629-b761-9072a35e8e50"
}
}
}
15 changes: 13 additions & 2 deletions tests/Fixtures/Endpoints/addDomain.json
@@ -1,3 +1,14 @@
{
"message": "The domain 'new-domain.com' is being added."
}
"message": "Adding domain example.com",
"_links": {
"self": {
"href": "https://cloud.acquia.com/api/environments/642-99d416c4-88b5-48c0-ae8e-4719007d7b8d/domains"
},
"notification": {
"href": "https://cloud.acquia.com/api/notifications/737a97a4-4c02-47e4-9924-d008de1aa7e5"
},
"parent": {
"href": "https://cloud.acquia.com/api/environments/642-99d416c4-88b5-48c0-ae8e-4719007d7b8d"
}
}
}
15 changes: 13 additions & 2 deletions tests/Fixtures/Endpoints/backupDatabases.json
@@ -1,3 +1,14 @@
{
"message": "The database is being backed up."
}
"message": "Creating the backup.",
"_links": {
"self": {
"href": "https://cloud.acquia.com/api/environments/12-d314739e-296f-11e9-b210-d663bd873d93/databases/my_db/backups/"
},
"notification": {
"href": "https://cloud.acquia.com/api/notifications/42b56cff-0b55-4bdf-a949-1fd0fca61c6c"
},
"parent": {
"href": "https://cloud.acquia.com/api/environments/12-d314739e-296f-11e9-b210-d663bd873d93/databases/my_db/"
}
}
}
15 changes: 13 additions & 2 deletions tests/Fixtures/Endpoints/copyDatabases.json
@@ -1,3 +1,14 @@
{
"message": "The database is queued for copying."
}
"message": "The database is being copied",
"_links": {
"self": {
"href": "https://cloud.acquia.com/api/environments/24-8fc7d3c6-2a53-11e9-b210-d663bd873d93/databases"
},
"notification": {
"href": "https://cloud.acquia.com/api/notifications/a49eeebb-0929-444a-972c-07b94ce93ab9"
},
"parent": {
"href": "https://cloud.acquia.com/api/environments/24-8fc7d3c6-2a53-11e9-b210-d663bd873d93"
}
}
}
15 changes: 13 additions & 2 deletions tests/Fixtures/Endpoints/copyFiles.json
@@ -1,3 +1,14 @@
{
"message": "The files have been queued for copying."
}
"message": "Copying files.",
"_links": {
"self": {
"href": "https://cloud.acquia.com/api/environments/12-482e4650-1b74-44db-8d4e-e86a3b1ed908/files"
},
"notification": {
"href": "https://cloud.acquia.com/api/notifications/d53fccec-5c1b-4ad4-b431-5cd39ad2b453"
},
"parent": {
"href": "https://cloud.acquia.com/api/environments/12-482e4650-1b74-44db-8d4e-e86a3b1ed908/files"
}
}
}
15 changes: 13 additions & 2 deletions tests/Fixtures/Endpoints/createDatabases.json
@@ -1,3 +1,14 @@
{
"message": "The database is being created."
}
"message": "The database is being created.",
"_links": {
"self": {
"href": "https://cloud.acquia.com/api/applications/f027502b-ed6c-448e-97e8-4a0def7d25e1/databases"
},
"notification": {
"href": "https://cloud.acquia.com/api/notifications/6992a41d-a953-4ded-ae99-41d2f4d62f69"
},
"parent": {
"href": "https://cloud.acquia.com/api/applications/f027502b-ed6c-448e-97e8-4a0def7d25e1"
}
}
}
15 changes: 13 additions & 2 deletions tests/Fixtures/Endpoints/deleteCron.json
@@ -1,3 +1,14 @@
{
"message": "Deleting cron."
}
"message": "Deleting cron.",
"_links": {
"self": {
"href": "https://cloud.acquia.com/api/environments/286-f027502b-ed6c-448e-97e8-4a0def7d25e1/crons/1891"
},
"parent": {
"href": "https://cloud.acquia.com/api/environments/286-f027502b-ed6c-448e-97e8-4a0def7d25e1/crons"
},
"notification": {
"href": "https://cloud.acquia.com/api/notifications/767cee8d-05f6-4761-a3dc-755957dfc9e6"
}
}
}
15 changes: 13 additions & 2 deletions tests/Fixtures/Endpoints/deleteDomain.json
@@ -1,3 +1,14 @@
{
"message": "Removing the domain deleted-domain.com"
}
"message": "Removing the domain example.com",
"_links": {
"self": {
"href": "https://cloud.acquia.com/api/environments/286-f027502b-ed6c-448e-97e8-4a0def7d25e1/domains/example.com"
},
"notification": {
"href": "https://cloud.acquia.com/api/notifications/67b7f08f-2dff-4c86-a8a0-35c4196880a3"
},
"parent": {
"href": "https://cloud.acquia.com/api/environments/286-f027502b-ed6c-448e-97e8-4a0def7d25e1/domains"
}
}
}
15 changes: 13 additions & 2 deletions tests/Fixtures/Endpoints/deployCode.json
@@ -1,3 +1,14 @@
{
"message": "The code is being deployed."
}
"message": "Deploying code.",
"_links": {
"self": {
"href": "https://cloud.acquia.com/api/environments/24-8fc7d3c6-2a53-11e9-b210-d663bd873d93/code"
},
"notification": {
"href": "https://cloud.acquia.com/api/notifications/a49eeebb-0929-444a-972c-07b94ce93ab9"
},
"parent": {
"href": "https://cloud.acquia.com/api/environments/24-8fc7d3c6-2a53-11e9-b210-d663bd873d93"
}
}
}
12 changes: 10 additions & 2 deletions tests/Fixtures/Endpoints/purgeVarnish.json
@@ -1,3 +1,11 @@
{
"message": "Varnish is being cleared for the selected domains."
}
"message": "Varnish is being cleared for the selected domains.",
"_links": {
"self": {
"href": "/environments/12-d314739e-296f-11e9-b210-d663bd873d93/domains/example.com/actions/clear-varnish"
},
"notification": {
"href": "https://cloud.acquia.com/api/notifications/42b56cff-0b55-4bdf-a949-1fd0fca61c6c"
}
}
}
15 changes: 13 additions & 2 deletions tests/Fixtures/Endpoints/renameApplication.json
@@ -1,3 +1,14 @@
{
"message": "Application renamed."
}
"message": "Application renamed.",
"_links": {
"self": {
"href": "https://cloud.acquia.com/api/applications/db1d0e46-6799-4208-9786-c7e64150a7c7"
},
"parent": {
"href": "https://cloud.acquia.com/api/applications"
},
"notification": {
"href": "https://cloud.acquia.com/api/notifications/27698331-bcf9-48e9-9f12-931ac88f446f"
}
}
}
12 changes: 10 additions & 2 deletions tests/Fixtures/Endpoints/restoreDatabaseBackup.json
@@ -1,3 +1,11 @@
{
"message": "The backup is being restored."
}
"message": "Restoring the database backup.",
"_links": {
"self": {
"href": "https://cloud.acquia.com/api/environments/286-f027502b-ed6c-448e-97e8-4a0def7d25e1/databases/test_database_1/backups/4189098/actions/restore"
},
"notification": {
"href": "https://cloud.acquia.com/api/notifications/f295cd91-c3c0-422c-a1ab-e91fe972041a"
}
}
}
12 changes: 10 additions & 2 deletions tests/Fixtures/Endpoints/switchCode.json
@@ -1,3 +1,11 @@
{
"message": "The code is being switched."
}
"message": "Switching code.",
"_links": {
"self": {
"href": "https://cloud.acquia.com/api/environments/861-ddccebef-eb2f-48ce-a92f-e0a16a3a0b53/code/actions/switch"
},
"notification": {
"href": "https://cloud.acquia.com/api/notifications/bfd9a39b-a85e-4de3-8a70-042d1c7e607a"
}
}
}

0 comments on commit 61eceb3

Please sign in to comment.