Skip to content

Commit

Permalink
Adding more tests to methods missed previously.
Browse files Browse the repository at this point in the history
  • Loading branch information
typhonius committed Dec 8, 2019
1 parent 5a4e538 commit 600b93a
Show file tree
Hide file tree
Showing 15 changed files with 257 additions and 151 deletions.
6 changes: 3 additions & 3 deletions src/Connector/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public static function factory(ConnectorInterface $connector)
* @param string $path
* @param array $options
*
* @return StreamInterface
* @return object|array
*/
public function request(string $verb, string $path, array $options = [])
{
Expand Down Expand Up @@ -91,8 +91,8 @@ public function makeRequest(string $verb, string $path, array $options = [])
* Processes the returned response from the API.
*
* @param ResponseInterface $response
* @return StreamInterface
* @throws \Exception
* @return object|array
* @throws ApiErrorException
*/
public function processResponse(ResponseInterface $response)
{
Expand Down
4 changes: 2 additions & 2 deletions src/Connector/ClientInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ interface ClientInterface
* @param string $path
* @param array $options
*
* @return object|array|StreamInterface
* @return object|array
*/
public function request(string $verb, string $path, array $options = []);

Expand All @@ -37,7 +37,7 @@ public function makeRequest(string $verb, string $path, array $options = []);
* Processes the returned response from the API.
*
* @param ResponseInterface $response
* @return object|array|StreamInterface
* @return object|array
* @throws \Exception
*/
public function processResponse(ResponseInterface $response);
Expand Down
4 changes: 1 addition & 3 deletions src/Endpoints/Logs.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ public function getAll($environmentUuid)
*/
public function download($environmentUuid, $logType)
{
return new LogsResponse(
$this->client->request('get', "/environments/${environmentUuid}/logs/${logType}")
);
return $this->client->request('get', "/environments/${environmentUuid}/logs/${logType}");
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/Exception/ApiErrorException.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public function setError($object)
}
$this->message = $output;
} else {
$this->code = $object->error;
$this->message = $object->message;
}
}
Expand Down
42 changes: 0 additions & 42 deletions src/Response/TaskResponse.php

This file was deleted.

22 changes: 0 additions & 22 deletions src/Response/TasksResponse.php

This file was deleted.

53 changes: 16 additions & 37 deletions tests/Endpoints/DatabasesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ public function testGetApplicationDatabases()
$client = $this->getMockClient($response);

/** @var \AcquiaCloudApi\CloudApi\ClientInterface $client */
$application = new Databases($client);
$result = $application->getAll('185f07c7-9c4f-407b-8968-67892ebcb38a');
$databases = new Databases($client);
$result = $databases->getAll('185f07c7-9c4f-407b-8968-67892ebcb38a');

$this->assertInstanceOf('\ArrayObject', $result);
$this->assertInstanceOf('\AcquiaCloudApi\Response\DatabasesResponse', $result);
Expand All @@ -45,35 +45,14 @@ public function testGetApplicationDatabases()
}
}

// public function testGetEnvironmentDatabases()
// {
// $response = $this->getPsr7JsonResponseForFixture('Endpoints/getEnvironmentDatabases.json');
// $client = $this->getMockClient($response);

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

// $this->assertInstanceOf('\ArrayObject', $result);
// $this->assertInstanceOf('\AcquiaCloudApi\Response\DatabasesResponse', $result);

// foreach ($result as $record) {
// $this->assertInstanceOf('\AcquiaCloudApi\Response\DatabaseResponse', $record);

// foreach ($this->properties as $property) {
// $this->assertObjectHasAttribute($property, $record);
// }
// }
// }

public function testDatabaseCopy()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/copyDatabases.json');
$client = $this->getMockClient($response);

/** @var \AcquiaCloudApi\CloudApi\ClientInterface $client */
$environment = new Databases($client);
$result = $environment->copy(
$databases = new Databases($client);
$result = $databases->copy(
'24-a47ac10b-58cc-4372-a567-0e02b2c3d470',
'db_name',
'14-0c7e79ab-1c4a-424e-8446-76ae8be7e851'
Expand All @@ -90,8 +69,8 @@ public function testDatabaseCreate()
$client = $this->getMockClient($response);

/** @var \AcquiaCloudApi\CloudApi\ClientInterface $client */
$application = new Databases($client);
$result = $application->create('8ff6c046-ec64-4ce4-bea6-27845ec18600', 'db_name');
$databases = new Databases($client);
$result = $databases->create('8ff6c046-ec64-4ce4-bea6-27845ec18600', 'db_name');

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

Expand All @@ -104,8 +83,8 @@ public function testDatabaseDelete()
$client = $this->getMockClient($response);

/** @var \AcquiaCloudApi\CloudApi\ClientInterface $client */
$application = new Databases($client);
$result = $application->delete('8ff6c046-ec64-4ce4-bea6-27845ec18600', 'db_name');
$databases = new Databases($client);
$result = $databases->delete('8ff6c046-ec64-4ce4-bea6-27845ec18600', 'db_name');

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

Expand All @@ -118,8 +97,8 @@ public function testDatabaseBackup()
$client = $this->getMockClient($response);

/** @var \AcquiaCloudApi\CloudApi\ClientInterface $client */
$environment = new DatabaseBackups($client);
$result = $environment->create('185f07c7-9c4f-407b-8968-67892ebcb38a', 'db_name');
$databaseBackup = new DatabaseBackups($client);
$result = $databaseBackup->create('185f07c7-9c4f-407b-8968-67892ebcb38a', 'db_name');

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

Expand All @@ -132,8 +111,8 @@ public function testGetDatabaseBackups()
$client = $this->getMockClient($response);

/** @var \AcquiaCloudApi\CloudApi\ClientInterface $client */
$environment = new DatabaseBackups($client);
$result = $environment->getAll('185f07c7-9c4f-407b-8968-67892ebcb38a', 'db_name');
$databaseBackup = new DatabaseBackups($client);
$result = $databaseBackup->getAll('185f07c7-9c4f-407b-8968-67892ebcb38a', 'db_name');

$this->assertInstanceOf('\ArrayObject', $result);
$this->assertInstanceOf('\AcquiaCloudApi\Response\BackupsResponse', $result);
Expand All @@ -153,8 +132,8 @@ public function testGetDatabaseBackup()
$client = $this->getMockClient($response);

/** @var \AcquiaCloudApi\CloudApi\ClientInterface $client */
$environment = new DatabaseBackups($client);
$result = $environment->get('24-a47ac10b-58cc-4372-a567-0e02b2c3d470', 'db_name', 12);
$databaseBackup = new DatabaseBackups($client);
$result = $databaseBackup->get('24-a47ac10b-58cc-4372-a567-0e02b2c3d470', 'db_name', 12);

$this->assertNotInstanceOf('\AcquiaCloudApi\Response\BackupsResponse', $result);
$this->assertInstanceOf('\AcquiaCloudApi\Response\BackupResponse', $result);
Expand All @@ -170,8 +149,8 @@ public function testRestoreDatabaseBackup()
$client = $this->getMockClient($response);

/** @var \AcquiaCloudApi\CloudApi\ClientInterface $client */
$environment = new DatabaseBackups($client);
$result = $environment->restore('24-a47ac10b-58cc-4372-a567-0e02b2c3d470', 'db_name', 12);
$databaseBackup = new DatabaseBackups($client);
$result = $databaseBackup->restore('24-a47ac10b-58cc-4372-a567-0e02b2c3d470', 'db_name', 12);

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

Expand Down
4 changes: 2 additions & 2 deletions tests/Endpoints/FiltersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ public function testAddFilter()
'sort' => 'title',
'filter' => ['name=@"foobar"', 'type=@"baz"']
];
$object->addQuery('limit', '5');
$object->addQuery('offset', '1');
$object->addQuery('limit', 5);
$object->addQuery('offset', 1);
$property = $this->getPrivateProperty(get_class($object), 'query');
$this->assertEquals($property->getValue($object), $expectedValue);

Expand Down
91 changes: 91 additions & 0 deletions tests/Endpoints/LogsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?php

namespace AcquiaCloudApi\Tests\Endpoints;

use AcquiaCloudApi\Tests\CloudApiTestCase;
use AcquiaCloudApi\Endpoints\Logs;

class LogsTest extends CloudApiTestCase
{

public $properties = [
'type',
'label',
'flags',
'links'
];

public $logstreamProperties = [
'logstream',
'links'
];

public function testGetLogs()
{

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

/** @var \AcquiaCloudApi\CloudApi\ClientInterface $client */
$logs = new Logs($client);
$result = $logs->getAll('14-0c7e79ab-1c4a-424e-8446-76ae8be7e851');

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

foreach ($result as $record) {
$this->assertInstanceOf('\AcquiaCloudApi\Response\LogResponse', $record);

foreach ($this->properties as $property) {
$this->assertObjectHasAttribute($property, $record);
}
}
}

public function testLogSnapshot()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/createLogSnapshot.json');
$client = $this->getMockClient($response);

/** @var \AcquiaCloudApi\CloudApi\ClientInterface $client */
$logs = new Logs($client);
$result = $logs->snapshot('r47ac10b-58cc-4372-a567-0e02b2c3d470', 'php-error');

$this->assertInstanceOf('\AcquiaCloudApi\Response\OperationResponse', $result);
$this->assertEquals('The log file is being created.', $result->message);
}

public function testDownloadLog()
{
$response = $this->getPsr7GzipResponseForFixture('Endpoints/downloadLog.json');
$client = $this->getMockClient($response);

/** @var \AcquiaCloudApi\CloudApi\ClientInterface $client */
$logs = new Logs($client);
$result = $logs->download('8ff6c046-ec64-4ce4-bea6-27845ec18600', 'php-error');

$headers = $response->getHeader('Content-Type');
$this->assertEquals('application/gzip', reset($headers));

$this->assertNotInstanceOf('\ArrayObject', $result);
$this->assertInstanceOf('GuzzleHttp\Psr7\Stream', $result);
}


public function testGetLogstream()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getLogstream.json');

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

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

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

foreach ($this->logstreamProperties as $property) {
$this->assertObjectHasAttribute($property, $result);
}
}
}
32 changes: 0 additions & 32 deletions tests/Endpoints/LogstreamTest.php

This file was deleted.

Loading

0 comments on commit 600b93a

Please sign in to comment.