Skip to content

Commit

Permalink
Add NotImplemented exception (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
brpauwels committed May 30, 2024
1 parent 308d349 commit a594ddd
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/Exception/NotImplemented.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

declare(strict_types=1);

namespace MaxImmo\ExternalParties\Exception;

class NotImplemented extends ApiClientException
{
}
13 changes: 13 additions & 0 deletions src/JsonResponseEvaluator.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use MaxImmo\ExternalParties\Exception\BadRequest;
use MaxImmo\ExternalParties\Exception\InvalidJson;
use MaxImmo\ExternalParties\Exception\NotFound;
use MaxImmo\ExternalParties\Exception\NotImplemented;
use MaxImmo\ExternalParties\Exception\ServiceUnavailable;
use MaxImmo\ExternalParties\Exception\TooManyRequests;
use MaxImmo\ExternalParties\Exception\Unauthorized;
Expand All @@ -28,6 +29,7 @@ class JsonResponseEvaluator implements ResponseEvaluator
* @throws ServiceUnavailable
* @throws TooManyRequests
* @throws Unauthorized
* @throws NotImplemented
* @throws UnexpectedResponse
*/
public function evaluateResponse(ResponseInterface $response): mixed
Expand All @@ -51,6 +53,9 @@ public function evaluateResponse(ResponseInterface $response): mixed
case StatusCode::TOO_MANY_REQUESTS:
$this->handleResponseTooManyRequests($response);
break;
case StatusCode::NOT_IMPLEMENTED:
$this->handleResponseNotImplemented($response);
break;
case StatusCode::SERVICE_UNAVAILABLE:
$this->handleResponseServiceUnavailable($response);
break;
Expand Down Expand Up @@ -108,6 +113,14 @@ protected function handleResponseTooManyRequests(ResponseInterface $response): v
throw new TooManyRequests($response->getBody()->getContents());
}

/**
* @throws NotImplemented
*/
protected function handleResponseNotImplemented(ResponseInterface $response): void
{
throw new NotImplemented($response->getBody()->getContents());
}

/**
* @throws ServiceUnavailable
*/
Expand Down
9 changes: 9 additions & 0 deletions tests/JsonResponseEvaluatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use MaxImmo\ExternalParties\Exception\BadRequest;
use MaxImmo\ExternalParties\Exception\NotFound;
use MaxImmo\ExternalParties\Exception\NotImplemented;
use MaxImmo\ExternalParties\Exception\ServiceUnavailable;
use MaxImmo\ExternalParties\Exception\TooManyRequests;
use MaxImmo\ExternalParties\Exception\Unauthorized;
Expand Down Expand Up @@ -71,6 +72,14 @@ public function testEvaluateResponseShouldThrowTooManyRequestsExceptionOnTooMany
$this->evaluator->evaluateResponse($this->response);
}

public function testEvaluateResponseShouldThrowNotImplementedExceptionOnNotImplemented(): void
{
$this->body->expects($this->any())->method('getContents')->willReturn('Not Implemented');
$this->expectException(NotImplemented::class);
$this->response->expects($this->any())->method('getStatusCode')->willReturn(StatusCode::NOT_IMPLEMENTED);
$this->evaluator->evaluateResponse($this->response);
}

public function testEvaluateResponseShouldThrowTooManyRequestsExceptionOnServiceUnavailable(): void
{
$this->body->expects($this->any())->method('getContents')->willReturn('Service Unavailable');
Expand Down

0 comments on commit a594ddd

Please sign in to comment.