Skip to content

Commit

Permalink
Adds CDE endpoints.
Browse files Browse the repository at this point in the history
  • Loading branch information
typhonius committed Dec 24, 2019
1 parent ca311f4 commit a6e2f07
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 0 deletions.
44 changes: 44 additions & 0 deletions src/Endpoints/Environments.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,4 +195,48 @@ public function disableProductionMode($environmentUuid)
)
);
}

/**
* Add a new continuous delivery environment to an application.
*
* @param string $applicationUuid
* @param string $label
* @param string $branch
* @param array $databases
* @return OperationResponse
*/
public function create($applicationUuid, $label, $branch, array $databases)
{
$options = [
'form_params' => [
'label' => $label,
'branch' => $branch,
'databases' => $databases,
],
];

return new OperationResponse(
$this->client->request(
'post',
"/applications/${applicationUuid}/environments",
$options
)
);
}

/**
* Deletes a CD environment.
*
* @param string $environmentUuid
* @return OperationResponse
*/
public function delete($environmentUuid)
{
return new OperationResponse(
$this->client->request(
'delete',
"/environments/${environmentUuid}"
)
);
}
}
38 changes: 38 additions & 0 deletions tests/Endpoints/EnvironmentsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,42 @@ public function testRenameEnvironment()

$this->assertEquals('Changing environment label.', $result->message);
}

public function testCreateCDEnvironment()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/Environments/createCDEnvironment.json');

$client = $this->getMockClient($response);

/** @var \AcquiaCloudApi\CloudApi\ClientInterface $client */
$environment = new Environments($client);
$result = $environment->create(
'24-a47ac10b-58cc-4372-a567-0e02b2c3d470',
'CD label',
'my-feature-branch',
[
"database1",
"database2"
]
);

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

$this->assertEquals('Adding an environment.', $result->message);
}

public function testDeleteCDEnvironment()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/Environments/deleteCDEnvironment.json');

$client = $this->getMockClient($response);

/** @var \AcquiaCloudApi\CloudApi\ClientInterface $client */
$environment = new Environments($client);
$result = $environment->delete('24-a47ac10b-58cc-4372-a567-0e02b2c3d470');

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

$this->assertEquals('The environment is being deleted.', $result->message);
}
}
14 changes: 14 additions & 0 deletions tests/Fixtures/Endpoints/Environments/createCDEnvironment.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"message": "Adding an environment.",
"_links": {
"self": {
"href": "https://cloud.acquia.com/api/applications/896f142a-2c14-45ff-9b1f-41bcb2b5de8d/environments"
},
"notification": {
"href": "https://cloud.acquia.com/api/notifications/23d9184d-40b8-4f21-a3d5-416aef9bcd39"
},
"parent": {
"href": "https://cloud.acquia.com/api/applications/896f142a-2c14-45ff-9b1f-41bcb2b5de8d/environments"
}
}
}
11 changes: 11 additions & 0 deletions tests/Fixtures/Endpoints/Environments/deleteCDEnvironment.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"message": "The environment is being deleted.",
"_links": {
"self": {
"href": "https://cloud.acquia.com/api/environments/123-f027502b-ed6c-448e-97e8-4a0def7d25e1"
},
"notification": {
"href": "https://cloud.acquia.com/api/notifications/6992a41d-a953-4ded-ae99-41d2f4d62f69"
}
}
}

0 comments on commit a6e2f07

Please sign in to comment.