Skip to content

Commit 04f4b89

Browse files
committed
Add Api\Exception
1 parent 7295a19 commit 04f4b89

2 files changed

Lines changed: 51 additions & 0 deletions

File tree

src/Exception.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
namespace TraderInteractive\Api;
4+
5+
class Exception extends \Exception
6+
{
7+
/**
8+
* @var Response
9+
*/
10+
private $response;
11+
12+
public function __construct(string $message, Response $response)
13+
{
14+
parent::__construct($message);
15+
$this->response = $response;
16+
}
17+
18+
public function getResponse() : Response
19+
{
20+
return $this->response;
21+
}
22+
}

tests/ExceptionTest.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace TraderInteractive\Api;
4+
5+
use GuzzleHttp\Psr7;
6+
use PHPUnit\Framework\TestCase;
7+
8+
/**
9+
* Defines unit tests for the Exception class
10+
*
11+
* @coversDefaultClass \TraderInteractive\Api\Exception
12+
* @covers ::__construct
13+
*/
14+
final class ExceptionTest extends TestCase
15+
{
16+
/**
17+
* @test
18+
* @covers ::getResponse
19+
*/
20+
public function getResponseReturnsResponse()
21+
{
22+
$httpCode = 200;
23+
$body = ['doesnt' => 'matter'];
24+
$headers = ['Content-Type' => ['text/json']];
25+
$response = new Response($httpCode, $headers, $body);
26+
$exception = new Exception('the error message', $response);
27+
$this->assertSame($response, $exception->getResponse());
28+
}
29+
}

0 commit comments

Comments
 (0)