diff --git a/Tests/ClientTest.php b/Tests/ClientTest.php index 20f093d..66d5b94 100644 --- a/Tests/ClientTest.php +++ b/Tests/ClientTest.php @@ -17,7 +17,6 @@ namespace D3\LinkmobilityClient\Tests; use Assert\InvalidArgumentException; use D3\LinkmobilityClient\Client; -use D3\LinkmobilityClient\Exceptions\ApiException; use D3\LinkmobilityClient\LoggerHandler; use D3\LinkmobilityClient\Request\RequestInterface; use D3\LinkmobilityClient\Response\Response; @@ -27,11 +26,9 @@ use D3\LinkmobilityClient\Url\Url; use D3\LinkmobilityClient\Url\UrlInterface; use GuzzleHttp\Client as GuzzleClient; use GuzzleHttp\ClientInterface; +use GuzzleHttp\Psr7\Response as GuzzleResponse; use PHPUnit\Framework\MockObject\MockObject; -use Psr\Http\Message\ResponseInterface as MessageResponseInterface; use Psr\Http\Message\StreamInterface; -use Psr\Log\AbstractLogger; -use Psr\Log\LoggerInterface; use ReflectionException; class ClientTest extends ApiTestCase @@ -195,41 +192,20 @@ class ClientTest extends ApiTestCase /** * @test - * @param $okStatus * @return void * @throws ReflectionException - * @dataProvider rawRequestDataProvider * @covers \D3\LinkmobilityClient\Client::rawRequest */ - public function testRawRequest($okStatus, $logInvocationCount) + public function testRawRequest() { - $statusCode = $okStatus ? '200' : '301'; - /** @var StreamInterface|MockObject $streamMock */ $streamMock = $this->getMockBuilder(StreamInterface::class) ->getMock(); - /** @var MessageResponseInterface|MockObject $responseMock */ - $responseMock = $this->getMockBuilder(MessageResponseInterface::class) - ->onlyMethods([ - 'getStatusCode', - 'getBody', - 'withStatus', - 'getReasonPhrase', - 'getProtocolVersion', - 'withProtocolVersion', - 'getHeaders', - 'hasHeader', - 'getHeader', - 'getHeaderLine', - 'withHeader', - 'withAddedHeader', - 'withoutHeader', - 'withBody', - ]) + /** @var GuzzleResponse|MockObject $responseMock */ + $responseMock = $this->getMockBuilder( GuzzleResponse::class) ->disableOriginalConstructor() ->getMock(); - $responseMock->expects($this->atLeastOnce())->method('getStatusCode')->willReturn($statusCode); $responseMock->expects($this->atLeastOnce()) ->method('getBody')->willReturn($streamMock); @@ -239,17 +215,6 @@ class ClientTest extends ApiTestCase ->getMock(); $requestClientMock->expects($this->once())->method('request')->willReturn($responseMock); - /** @var LoggerInterface|MockObject $loggerMock */ - $loggerMock = $this->getMockBuilder(AbstractLogger::class) - ->onlyMethods(['debug', 'error', 'log']) - ->getMock(); - - /** @var LoggerHandler|MockObject $loggerHandlerMock */ - $loggerHandlerMock = $this->getMockBuilder(LoggerHandler::class) - ->onlyMethods(['getLogger']) - ->getMock(); - $loggerHandlerMock->method('getLogger')->willReturn($loggerMock); - /** @var Client|MockObject $clientMock */ $clientMock = $this->getMockBuilder(Client::class) ->disableOriginalConstructor() @@ -257,30 +222,14 @@ class ClientTest extends ApiTestCase 'getLoggerHandler', ]) ->getMock(); - $clientMock->expects($logInvocationCount) - ->method('getLoggerHandler')->willReturn($loggerHandlerMock); $this->setValue($clientMock, 'requestClient', $requestClientMock); - if (false === $okStatus) { - $this->expectException(ApiException::class); - } $this->assertSame( $responseMock, $this->callMethod($clientMock, 'rawRequest', ['myUrl']) ); } - /** - * @return array - */ - public function rawRequestDataProvider(): array - { - return [ - 'OK status' => [true, $this->never()], - 'NOK status' => [false, $this->once()], - ]; - } - /** * @test * @return void diff --git a/src/Client.php b/src/Client.php index b05aaa7..73a8831 100644 --- a/src/Client.php +++ b/src/Client.php @@ -15,8 +15,6 @@ declare(strict_types=1); namespace D3\LinkmobilityClient; -use D3\LinkmobilityClient\Exceptions\ApiException; -use D3\LinkmobilityClient\Exceptions\ExceptionMessages; use D3\LinkmobilityClient\Request\RequestInterface; use D3\LinkmobilityClient\Url\Url; use D3\LinkmobilityClient\Url\UrlInterface; @@ -65,7 +63,6 @@ class Client * @param RequestInterface $request * * @return Response\ResponseInterface - * @throws ApiException * @throws GuzzleException * @throws InvalidArgumentException */ @@ -84,26 +81,13 @@ class Client * @param array $options * * @return ResponseInterface - * @throws ApiException * @throws GuzzleException */ protected function rawRequest($url, string $method = RequestInterface::METHOD_GET, array $options = []): ResponseInterface { $options['headers']['Authorization'] = 'Bearer '.$this->accessToken; - $response = $this->requestClient->request( - $method, - $url, - $options - ); - - if ($response->getStatusCode() != 200) { - $message = sprintf(ExceptionMessages::NOK_REQUEST_RETURN, $url, $response->getStatusCode()); - $response->getBody()->rewind(); - $this->getLoggerHandler()->getLogger()->error('linkmobility error: '.$message, [$response->getBody()->getContents()]); - throw new ApiException($message); - } - + $response = $this->requestClient->request($method, $url, $options); $response->getBody()->rewind(); return $response; diff --git a/src/Exceptions/ApiException.php b/src/Exceptions/ApiException.php deleted file mode 100644 index 62fff17..0000000 --- a/src/Exceptions/ApiException.php +++ /dev/null @@ -1,20 +0,0 @@ - - * @link https://www.oxidmodule.com - */ - -declare(strict_types=1); - -namespace D3\LinkmobilityClient\Exceptions; - -class ApiException extends LinkmobilityException -{ -}