Skip to content

Commit

Permalink
Added test for server error with no response body.
Browse files Browse the repository at this point in the history
  • Loading branch information
denpamusic committed Jan 21, 2017
1 parent 8e86ab3 commit 42ae7d5
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 15 deletions.
1 change: 1 addition & 0 deletions src/Denpa/Bitcoin/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ public function request($method, $params = []) {
throw new ClientException($message, $code);
}
}
throw new ClientException('Error Communicating with Server', 500);
}

$response = json_decode((string)$response->getBody(), true);
Expand Down
46 changes: 31 additions & 15 deletions tests/Denpa/Bitcoin/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ class ClientTest extends TestCase {
'message' => 'No information available about transaction'
];

/**
* @dataProvider urlProvider
*/
/**
* @dataProvider urlProvider
*/
public function testUrlParser($url, $scheme, $host, $port, $user, $pass) {
$bitcoind = new Client(['url' => $url]);

Expand Down Expand Up @@ -81,6 +81,7 @@ public function testInstance() {
new Response(200, [], $blockHeaderJson),
new Response(200, [], $rawTransactionErrorJson),
new Response(500, [], $rawTransactionErrorJson),
new Response(500),
];

$bitcoind = new Client(['handler' => MockHandler::createWithMiddleware($queue)]);
Expand All @@ -90,9 +91,9 @@ public function testInstance() {
return $bitcoind;
}

/**
* @depends testInstance
*/
/**
* @depends testInstance
*/
public function testRequest(Client $bitcoind) {
$response = $bitcoind->request('getblockheader', '000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f');

Expand All @@ -101,9 +102,9 @@ public function testRequest(Client $bitcoind) {
return $bitcoind;
}

/**
* @depends testRequest
*/
/**
* @depends testRequest
*/
public function testMagic(Client $bitcoind) {
$response = $bitcoind->getBlockHeader('000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f');

Expand All @@ -112,9 +113,9 @@ public function testMagic(Client $bitcoind) {
return $bitcoind;
}

/**
* @depends testMagic
*/
/**
* @depends testMagic
*/
public function testClientException(Client $bitcoind) {
try {
$response = $bitcoind->getRawTransaction('4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b');
Expand All @@ -127,9 +128,9 @@ public function testClientException(Client $bitcoind) {
return $bitcoind;
}

/**
* @depends testClientException
*/
/**
* @depends testClientException
*/
public function testClientExceptionWithServerErrorCode(Client $bitcoind) {
try {
$response = $bitcoind->getRawTransaction('4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b');
Expand All @@ -141,6 +142,21 @@ public function testClientExceptionWithServerErrorCode(Client $bitcoind) {

return $bitcoind;
}

/**
* @depends testClientExceptionWithServerErrorCode
*/
public function testClientExceptionWithNoResponseBody(Client $bitcoind) {
try {
$response = $bitcoind->getRawTransaction('4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b');
$this->expectException(ClientException::class);
} catch(ClientException $e) {
$this->assertEquals('Error Communicating with Server', $e->getMessage());
$this->assertEquals(500, $e->getCode());
}

return $bitcoind;
}
}

?>

0 comments on commit 42ae7d5

Please sign in to comment.