Skip to content

Commit

Permalink
Client test (#9)
Browse files Browse the repository at this point in the history
* [ClientTest] Added test for ClearQuery function.

* [ClientTest] Reversed changes in composer json.

* [ClientTest] Created connector class.

* [ClientTest] Finished testApplications.

* [ClientTest] Fixed application tests.

* [ClientTest] Fixed team test.

* [ClientTest] Fixed tasks test.

* [ClientTest] Fixed server test.

* [ClientTest] Fixed roles, permissions, organizations tests.

* [ClientTest] Fixed member test.

* [ClientTest] Fixed Insights test.

* [ClientTest] Fixed files test.

* [ClientTest] Fixed environment test.

* [ClientTest] Fixed filter tests.

* [ClientTest] Removed unused functions.
  • Loading branch information
rujiali authored and typhonius committed Nov 23, 2017
1 parent 23ffd3f commit ec6b87f
Show file tree
Hide file tree
Showing 14 changed files with 104 additions and 348 deletions.
173 changes: 53 additions & 120 deletions src/CloudApi/Client.php

Large diffs are not rendered by default.

57 changes: 19 additions & 38 deletions tests/CloudApiTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,53 +45,34 @@ protected function getPsr7JsonResponseForFixture($fixture, $statusCode = 200): P
* @param $response
* @return static
*/
protected function getMockClient($response)
protected function getMockClient($response = '')
{
$connector = $this
->getMockBuilder('AcquiaCloudApi\CloudApi\Connector')
->disableOriginalConstructor()
->setMethods(['makeRequest'])
->getMock();
$connector
->expects($this->atLeastOnce())
->method('makeRequest')
->willReturn($response);
$client = Client::factory(
[
'key' => 'd0697bfc-7f56-4942-9205-b5686bf5b3f5',
'secret' => 'D5UfO/4FfNBWn4+0cUwpLOoFzfP7Qqib4AoY+wYGsKE=',
],
if ($response) {
$connector = $this
->getMockBuilder('AcquiaCloudApi\CloudApi\Connector')
->disableOriginalConstructor()
->setMethods(['makeRequest'])
->getMock();
$connector
);

return $client;
}

// To be removed.
/**
protected function generateCloudApiResponse($fixture)
{
$response = $this->getPsr7JsonResponseForFixture($fixture);
$client = $this->getMockCloudApiClient();
$reflection = new \ReflectionClass(get_class($client));
$method = $reflection->getMethod('processResponse');
$method->setAccessible(true);
return $method->invokeArgs($client, [$response]);
}
**/
->expects($this->atLeastOnce())
->method('makeRequest')
->willReturn($response);
}
else {
$connector = $this
->getMockBuilder('AcquiaCloudApi\CloudApi\Connector')
->disableOriginalConstructor()
->getMock();
}

/**
protected function getMockCloudApiClient()
{
$client = Client::factory(
[
'key' => 'd0697bfc-7f56-4942-9205-b5686bf5b3f5',
'secret' => 'D5UfO/4FfNBWn4+0cUwpLOoFzfP7Qqib4AoY+wYGsKE=',
],
$connector);

return $client;
}
**/

}
5 changes: 1 addition & 4 deletions tests/Endpoints/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,8 @@ public function testClearQuery()
'secret' => 'D5UfO/4FfNBWn4+0cUwpLOoFzfP7Qqib4AoY+wYGsKE=',
],
$connector
);
);
$this->assertTrue(empty($client->getQuery()));
}

public function testApplications()
{
}
}
2 changes: 1 addition & 1 deletion tests/Endpoints/EnvironmentsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ class EnvironmentsTest extends CloudApiTestCase
public function testGetEnvironments()
{


$response = $this->getPsr7JsonResponseForFixture('Endpoints/getEnvironments.json');
$client = $this->getMockClient($response);

Expand All @@ -45,6 +44,7 @@ public function testGetEnvironments()
public function testGetEnvironment()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getEnvironment.json');

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

/** @var AcquiaCloudApi\CloudApi\Client $client */
Expand Down
15 changes: 2 additions & 13 deletions tests/Endpoints/FilesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,8 @@ class FilesTest extends CloudApiTestCase

public function testFilesCopy()
{
$response = $this->generateCloudApiResponse('Endpoints/copyFiles.json');

$message = new \AcquiaCloudApi\Response\OperationResponse($response);

$client = $this->getMockBuilder('\AcquiaCloudApi\CloudApi\Client')
->disableOriginalConstructor()
->setMethods(['copyFiles'])
->getMock();

$client->expects($this->once())
->method('copyFiles')
->with('8ff6c046-ec64-4ce4-bea6-27845ec18600', '14-0c7e79ab-1c4a-424e-8446-76ae8be7e851')
->will($this->returnValue($message));
$response = $this->getPsr7JsonResponseForFixture('Endpoints/copyFiles.json');
$client = $this->getMockClient($response);

/** @var AcquiaCloudApi\CloudApi\Client $client */
$result = $client->copyFiles('8ff6c046-ec64-4ce4-bea6-27845ec18600', '14-0c7e79ab-1c4a-424e-8446-76ae8be7e851');
Expand Down
2 changes: 1 addition & 1 deletion tests/Endpoints/FiltersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public function testAddFilter()
{

/** @var AcquiaCloudApi\CloudApi\Client $object */
$object = $this->getMockCloudApiClient();
$object = $this->getMockClient();

$expectedValue = ['filter' => 'name=@"foobar"'];
$object->addQuery('filter', 'name=@"foobar"');
Expand Down
14 changes: 2 additions & 12 deletions tests/Endpoints/InsightsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,8 @@ class InsightsTest extends CloudApiTestCase
public function testGetInsights()
{

$response = $this->generateCloudApiResponse('Endpoints/getInsights.json');
$insights = new \AcquiaCloudApi\Response\InsightsResponse($response);


$client = $this->getMockBuilder('\AcquiaCloudApi\CloudApi\Client')
->disableOriginalConstructor()
->setMethods(['applicationInsights'])
->getMock();
$client->expects($this->once())
->method('applicationInsights')
->with('8ff6c046-ec64-4ce4-bea6-27845ec18600')
->will($this->returnValue($insights));
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getInsights.json');
$client = $this->getMockClient($response);

/** @var AcquiaCloudApi\CloudApi\Client $client */
$result = $client->applicationInsights('8ff6c046-ec64-4ce4-bea6-27845ec18600');
Expand Down
28 changes: 4 additions & 24 deletions tests/Endpoints/MembersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,8 @@ class MembersTest extends CloudApiTestCase
public function testGetOrganizationMembers()
{

$response = $this->generateCloudApiResponse('Endpoints/getOrganizationMembers.json');
$members = new \AcquiaCloudApi\Response\MembersResponse($response);

$client = $this->getMockBuilder('\AcquiaCloudApi\CloudApi\Client')
->disableOriginalConstructor()
->setMethods(['members'])
->getMock();

$client->expects($this->once())
->method('members')
->with('14-0c7e79ab-1c4a-424e-8446-76ae8be7e851')
->will($this->returnValue($members));
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getOrganizationMembers.json');
$client = $this->getMockClient($response);

/** @var AcquiaCloudApi\CloudApi\Client $client */
$result = $client->members('14-0c7e79ab-1c4a-424e-8446-76ae8be7e851');
Expand All @@ -62,18 +52,8 @@ public function testGetOrganizationMembers()
public function testGetOrganizationInvitees()
{

$response = $this->generateCloudApiResponse('Endpoints/getOrganizationInvitees.json');
$invitations = new \AcquiaCloudApi\Response\InvitationsResponse($response);

$client = $this->getMockBuilder('\AcquiaCloudApi\CloudApi\Client')
->disableOriginalConstructor()
->setMethods(['invitees'])
->getMock();

$client->expects($this->once())
->method('invitees')
->with('14-0c7e79ab-1c4a-424e-8446-76ae8be7e851')
->will($this->returnValue($invitations));
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getOrganizationInvitees.json');
$client = $this->getMockClient($response);

/** @var AcquiaCloudApi\CloudApi\Client $client */
$result = $client->invitees('14-0c7e79ab-1c4a-424e-8446-76ae8be7e851');
Expand Down
13 changes: 2 additions & 11 deletions tests/Endpoints/OrganizationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,8 @@ class OrganizationsTest extends CloudApiTestCase
public function testGetOrganizations()
{

$response = $this->generateCloudApiResponse('Endpoints/getOrganizations.json');
$organizations = new \AcquiaCloudApi\Response\OrganizationsResponse($response);


$client = $this->getMockBuilder('\AcquiaCloudApi\CloudApi\Client')
->disableOriginalConstructor()
->setMethods(['organizations'])
->getMock();
$client->expects($this->once())
->method('organizations')
->will($this->returnValue($organizations));
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getOrganizations.json');
$client = $this->getMockClient($response);

/** @var AcquiaCloudApi\CloudApi\Client $client */
$result = $client->organizations();
Expand Down
13 changes: 2 additions & 11 deletions tests/Endpoints/PermissionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,8 @@ class PermissionsTest extends CloudApiTestCase
public function testGetAllPermissions()
{

$response = (array) $this->generateCloudApiResponse('Endpoints/getPermissions.json');
$branches = new \AcquiaCloudApi\Response\PermissionsResponse($response);


$client = $this->getMockBuilder('\AcquiaCloudApi\CloudApi\Client')
->disableOriginalConstructor()
->setMethods(['permissions'])
->getMock();
$client->expects($this->once())
->method('permissions')
->will($this->returnValue($branches));
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getPermissions.json');
$client = $this->getMockClient($response);

/** @var AcquiaCloudApi\CloudApi\Client $client */
$result = $client->permissions();
Expand Down
56 changes: 8 additions & 48 deletions tests/Endpoints/RolesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,8 @@ class RolesTest extends CloudApiTestCase
public function testGetRoles()
{

$response = $this->generateCloudApiResponse('Endpoints/getOrganizationRoles.json');
$roles = new \AcquiaCloudApi\Response\RolesResponse($response);

$client = $this->getMockBuilder('\AcquiaCloudApi\CloudApi\Client')
->disableOriginalConstructor()
->setMethods(['organizationRoles'])
->getMock();

$client->expects($this->once())
->method('organizationRoles')
->with('8ff6c046-ec64-4ce4-bea6-27845ec18600')
->will($this->returnValue($roles));
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getOrganizationRoles.json');
$client = $this->getMockClient($response);

/** @var AcquiaCloudApi\CloudApi\Client $client */
$result = $client->organizationRoles('8ff6c046-ec64-4ce4-bea6-27845ec18600');
Expand All @@ -45,18 +35,8 @@ public function testGetRoles()
public function testCreateRole()
{

$response = $this->generateCloudApiResponse('Endpoints/addRole.json');
$task = new \AcquiaCloudApi\Response\OperationResponse($response);

$client = $this->getMockBuilder('\AcquiaCloudApi\CloudApi\Client')
->disableOriginalConstructor()
->setMethods(['createRole'])
->getMock();

$client->expects($this->once())
->method('createRole')
->with('8ff6c046-ec64-4ce4-bea6-27845ec18600')
->will($this->returnValue($task));
$response = $this->getPsr7JsonResponseForFixture('Endpoints/addRole.json');
$client = $this->getMockClient($response);

/** @var AcquiaCloudApi\CloudApi\Client $client */
$result = $client->createRole(
Expand All @@ -73,18 +53,8 @@ public function testCreateRole()
public function testDeleteRole()
{

$response = $this->generateCloudApiResponse('Endpoints/deleteRole.json');
$task = new \AcquiaCloudApi\Response\OperationResponse($response);

$client = $this->getMockBuilder('\AcquiaCloudApi\CloudApi\Client')
->disableOriginalConstructor()
->setMethods(['deleteRole'])
->getMock();

$client->expects($this->once())
->method('deleteRole')
->with('r47ac10b-58cc-4372-a567-0e02b2c3d470')
->will($this->returnValue($task));
$response = $this->getPsr7JsonResponseForFixture('Endpoints/deleteRole.json');
$client = $this->getMockClient($response);

/** @var AcquiaCloudApi\CloudApi\Client $client */
$result = $client->deleteRole('r47ac10b-58cc-4372-a567-0e02b2c3d470');
Expand All @@ -96,18 +66,8 @@ public function testDeleteRole()
public function testUpdateRole()
{

$response = $this->generateCloudApiResponse('Endpoints/updateRole.json');
$task = new \AcquiaCloudApi\Response\OperationResponse($response);

$client = $this->getMockBuilder('\AcquiaCloudApi\CloudApi\Client')
->disableOriginalConstructor()
->setMethods(['updateRolePermissions'])
->getMock();

$client->expects($this->once())
->method('updateRolePermissions')
->with('r47ac10b-58cc-4372-a567-0e02b2c3d470', ['pull from prod'])
->will($this->returnValue($task));
$response = $this->getPsr7JsonResponseForFixture('Endpoints/updateRole.json');
$client = $this->getMockClient($response);

/** @var AcquiaCloudApi\CloudApi\Client $client */
$result = $client->updateRolePermissions('r47ac10b-58cc-4372-a567-0e02b2c3d470', ['pull from prod']);
Expand Down
14 changes: 2 additions & 12 deletions tests/Endpoints/ServersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,8 @@ class ServersTest extends CloudApiTestCase
public function testGetServers()
{

$response = $this->generateCloudApiResponse('Endpoints/getServers.json');
$servers = new \AcquiaCloudApi\Response\ServersResponse($response);


$client = $this->getMockBuilder('\AcquiaCloudApi\CloudApi\Client')
->disableOriginalConstructor()
->setMethods(['servers'])
->getMock();
$client->expects($this->once())
->method('servers')
->with('14-0c7e79ab-1c4a-424e-8446-76ae8be7e851')
->will($this->returnValue($servers));
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getServers.json');
$client = $this->getMockClient($response);

/** @var AcquiaCloudApi\CloudApi\Client $client */
$result = $client->servers('14-0c7e79ab-1c4a-424e-8446-76ae8be7e851');
Expand Down

0 comments on commit ec6b87f

Please sign in to comment.