Skip to content

Commit

Permalink
Adds error test and throws error in SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
typhonius committed Nov 24, 2017
1 parent ebccd0a commit 98ec81b
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 7 deletions.
9 changes: 2 additions & 7 deletions src/CloudApi/Connector.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,6 @@ public function __construct(GuzzleClient $client, $config)
]);
}

public function setConfig($config = [])
{
$this->config = $config;
}

/**
* @param string $verb
* @param string $path
Expand Down Expand Up @@ -92,6 +87,7 @@ public function makeRequest(string $verb, string $path, array $query = [], array
/**
* @param ResponseInterface $response
* @return mixed|StreamInterface
* @throws Exception
*/
public function processResponse(ResponseInterface $response)
{
Expand All @@ -105,8 +101,7 @@ public function processResponse(ResponseInterface $response)
if (property_exists($object, '_embedded') && property_exists($object->_embedded, 'items')) {
$return = $object->_embedded->items;
} elseif (property_exists($object, 'error')) {
$this->error = true;
$return = $object->message;
throw new \Exception($object->message);
} else {
$return = $object;
}
Expand Down
41 changes: 41 additions & 0 deletions tests/Endpoints/ErrorTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

class ErrorTest extends CloudApiTestCase
{

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

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

try {
/** @var AcquiaCloudApi\CloudApi\Client $client */
$client->applications();
} catch (Exception $e) {
$this->assertEquals($e->getMessage(), 'You do not have permission to view applications.');

return;
}

$this->fail();
}

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

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

try {
/** @var AcquiaCloudApi\CloudApi\Client $client */
$client->applications();
} catch (Exception $e) {
$this->assertEquals($e->getMessage(), 'The application you are trying to access does not exist, or you do not have permission to access it.');

return;
}

$this->fail();
}
}
4 changes: 4 additions & 0 deletions tests/Fixtures/Endpoints/error404.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"error": "not_found",
"message": "The application you are trying to access does not exist, or you do not have permission to access it."
}

0 comments on commit 98ec81b

Please sign in to comment.