remove unused ApiException
This commit is contained in:
parent
19f5fca18a
commit
a50567fd0c
@ -17,7 +17,6 @@ namespace D3\LinkmobilityClient\Tests;
|
|||||||
|
|
||||||
use Assert\InvalidArgumentException;
|
use Assert\InvalidArgumentException;
|
||||||
use D3\LinkmobilityClient\Client;
|
use D3\LinkmobilityClient\Client;
|
||||||
use D3\LinkmobilityClient\Exceptions\ApiException;
|
|
||||||
use D3\LinkmobilityClient\LoggerHandler;
|
use D3\LinkmobilityClient\LoggerHandler;
|
||||||
use D3\LinkmobilityClient\Request\RequestInterface;
|
use D3\LinkmobilityClient\Request\RequestInterface;
|
||||||
use D3\LinkmobilityClient\Response\Response;
|
use D3\LinkmobilityClient\Response\Response;
|
||||||
@ -27,11 +26,9 @@ use D3\LinkmobilityClient\Url\Url;
|
|||||||
use D3\LinkmobilityClient\Url\UrlInterface;
|
use D3\LinkmobilityClient\Url\UrlInterface;
|
||||||
use GuzzleHttp\Client as GuzzleClient;
|
use GuzzleHttp\Client as GuzzleClient;
|
||||||
use GuzzleHttp\ClientInterface;
|
use GuzzleHttp\ClientInterface;
|
||||||
|
use GuzzleHttp\Psr7\Response as GuzzleResponse;
|
||||||
use PHPUnit\Framework\MockObject\MockObject;
|
use PHPUnit\Framework\MockObject\MockObject;
|
||||||
use Psr\Http\Message\ResponseInterface as MessageResponseInterface;
|
|
||||||
use Psr\Http\Message\StreamInterface;
|
use Psr\Http\Message\StreamInterface;
|
||||||
use Psr\Log\AbstractLogger;
|
|
||||||
use Psr\Log\LoggerInterface;
|
|
||||||
use ReflectionException;
|
use ReflectionException;
|
||||||
|
|
||||||
class ClientTest extends ApiTestCase
|
class ClientTest extends ApiTestCase
|
||||||
@ -195,41 +192,20 @@ class ClientTest extends ApiTestCase
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
* @param $okStatus
|
|
||||||
* @return void
|
* @return void
|
||||||
* @throws ReflectionException
|
* @throws ReflectionException
|
||||||
* @dataProvider rawRequestDataProvider
|
|
||||||
* @covers \D3\LinkmobilityClient\Client::rawRequest
|
* @covers \D3\LinkmobilityClient\Client::rawRequest
|
||||||
*/
|
*/
|
||||||
public function testRawRequest($okStatus, $logInvocationCount)
|
public function testRawRequest()
|
||||||
{
|
{
|
||||||
$statusCode = $okStatus ? '200' : '301';
|
|
||||||
|
|
||||||
/** @var StreamInterface|MockObject $streamMock */
|
/** @var StreamInterface|MockObject $streamMock */
|
||||||
$streamMock = $this->getMockBuilder(StreamInterface::class)
|
$streamMock = $this->getMockBuilder(StreamInterface::class)
|
||||||
->getMock();
|
->getMock();
|
||||||
|
|
||||||
/** @var MessageResponseInterface|MockObject $responseMock */
|
/** @var GuzzleResponse|MockObject $responseMock */
|
||||||
$responseMock = $this->getMockBuilder(MessageResponseInterface::class)
|
$responseMock = $this->getMockBuilder( GuzzleResponse::class)
|
||||||
->onlyMethods([
|
|
||||||
'getStatusCode',
|
|
||||||
'getBody',
|
|
||||||
'withStatus',
|
|
||||||
'getReasonPhrase',
|
|
||||||
'getProtocolVersion',
|
|
||||||
'withProtocolVersion',
|
|
||||||
'getHeaders',
|
|
||||||
'hasHeader',
|
|
||||||
'getHeader',
|
|
||||||
'getHeaderLine',
|
|
||||||
'withHeader',
|
|
||||||
'withAddedHeader',
|
|
||||||
'withoutHeader',
|
|
||||||
'withBody',
|
|
||||||
])
|
|
||||||
->disableOriginalConstructor()
|
->disableOriginalConstructor()
|
||||||
->getMock();
|
->getMock();
|
||||||
$responseMock->expects($this->atLeastOnce())->method('getStatusCode')->willReturn($statusCode);
|
|
||||||
$responseMock->expects($this->atLeastOnce())
|
$responseMock->expects($this->atLeastOnce())
|
||||||
->method('getBody')->willReturn($streamMock);
|
->method('getBody')->willReturn($streamMock);
|
||||||
|
|
||||||
@ -239,17 +215,6 @@ class ClientTest extends ApiTestCase
|
|||||||
->getMock();
|
->getMock();
|
||||||
$requestClientMock->expects($this->once())->method('request')->willReturn($responseMock);
|
$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 */
|
/** @var Client|MockObject $clientMock */
|
||||||
$clientMock = $this->getMockBuilder(Client::class)
|
$clientMock = $this->getMockBuilder(Client::class)
|
||||||
->disableOriginalConstructor()
|
->disableOriginalConstructor()
|
||||||
@ -257,30 +222,14 @@ class ClientTest extends ApiTestCase
|
|||||||
'getLoggerHandler',
|
'getLoggerHandler',
|
||||||
])
|
])
|
||||||
->getMock();
|
->getMock();
|
||||||
$clientMock->expects($logInvocationCount)
|
|
||||||
->method('getLoggerHandler')->willReturn($loggerHandlerMock);
|
|
||||||
$this->setValue($clientMock, 'requestClient', $requestClientMock);
|
$this->setValue($clientMock, 'requestClient', $requestClientMock);
|
||||||
|
|
||||||
if (false === $okStatus) {
|
|
||||||
$this->expectException(ApiException::class);
|
|
||||||
}
|
|
||||||
$this->assertSame(
|
$this->assertSame(
|
||||||
$responseMock,
|
$responseMock,
|
||||||
$this->callMethod($clientMock, 'rawRequest', ['myUrl'])
|
$this->callMethod($clientMock, 'rawRequest', ['myUrl'])
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function rawRequestDataProvider(): array
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
'OK status' => [true, $this->never()],
|
|
||||||
'NOK status' => [false, $this->once()],
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
* @return void
|
* @return void
|
||||||
|
@ -15,8 +15,6 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace D3\LinkmobilityClient;
|
namespace D3\LinkmobilityClient;
|
||||||
|
|
||||||
use D3\LinkmobilityClient\Exceptions\ApiException;
|
|
||||||
use D3\LinkmobilityClient\Exceptions\ExceptionMessages;
|
|
||||||
use D3\LinkmobilityClient\Request\RequestInterface;
|
use D3\LinkmobilityClient\Request\RequestInterface;
|
||||||
use D3\LinkmobilityClient\Url\Url;
|
use D3\LinkmobilityClient\Url\Url;
|
||||||
use D3\LinkmobilityClient\Url\UrlInterface;
|
use D3\LinkmobilityClient\Url\UrlInterface;
|
||||||
@ -65,7 +63,6 @@ class Client
|
|||||||
* @param RequestInterface $request
|
* @param RequestInterface $request
|
||||||
*
|
*
|
||||||
* @return Response\ResponseInterface
|
* @return Response\ResponseInterface
|
||||||
* @throws ApiException
|
|
||||||
* @throws GuzzleException
|
* @throws GuzzleException
|
||||||
* @throws InvalidArgumentException
|
* @throws InvalidArgumentException
|
||||||
*/
|
*/
|
||||||
@ -84,26 +81,13 @@ class Client
|
|||||||
* @param array $options
|
* @param array $options
|
||||||
*
|
*
|
||||||
* @return ResponseInterface
|
* @return ResponseInterface
|
||||||
* @throws ApiException
|
|
||||||
* @throws GuzzleException
|
* @throws GuzzleException
|
||||||
*/
|
*/
|
||||||
protected function rawRequest($url, string $method = RequestInterface::METHOD_GET, array $options = []): ResponseInterface
|
protected function rawRequest($url, string $method = RequestInterface::METHOD_GET, array $options = []): ResponseInterface
|
||||||
{
|
{
|
||||||
$options['headers']['Authorization'] = 'Bearer '.$this->accessToken;
|
$options['headers']['Authorization'] = 'Bearer '.$this->accessToken;
|
||||||
|
|
||||||
$response = $this->requestClient->request(
|
$response = $this->requestClient->request($method, $url, $options);
|
||||||
$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->getBody()->rewind();
|
$response->getBody()->rewind();
|
||||||
|
|
||||||
return $response;
|
return $response;
|
||||||
|
@ -1,20 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/**
|
|
||||||
* For the full copyright and license information, please view the LICENSE
|
|
||||||
* file that was distributed with this source code.
|
|
||||||
*
|
|
||||||
* https://www.d3data.de
|
|
||||||
*
|
|
||||||
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
|
|
||||||
* @author D3 Data Development - Daniel Seifert <support@shopmodule.com>
|
|
||||||
* @link https://www.oxidmodule.com
|
|
||||||
*/
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace D3\LinkmobilityClient\Exceptions;
|
|
||||||
|
|
||||||
class ApiException extends LinkmobilityException
|
|
||||||
{
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user