mirror of
https://github.com/elyby/mojang-api.git
synced 2024-12-24 01:00:12 +05:30
57 lines
1.8 KiB
PHP
57 lines
1.8 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace Ely\Mojang\Test\Middleware;
|
|
|
|
use Ely\Mojang\Exception;
|
|
use Ely\Mojang\Middleware\ResponseConverterMiddleware;
|
|
use GuzzleHttp\Handler\MockHandler;
|
|
use GuzzleHttp\Psr7\Request;
|
|
use GuzzleHttp\Psr7\Response;
|
|
use PHPUnit\Framework\TestCase;
|
|
use Psr\Http\Message\RequestInterface;
|
|
use Psr\Http\Message\ResponseInterface;
|
|
|
|
class ResponseConverterMiddlewareTest extends TestCase {
|
|
|
|
/**
|
|
* @param ResponseInterface $response
|
|
* @dataProvider getResponses
|
|
*/
|
|
public function testInvoke(RequestInterface $request, ResponseInterface $response, string $expectedException) {
|
|
$this->expectException($expectedException);
|
|
$handler = new MockHandler([$response]);
|
|
$middleware = new ResponseConverterMiddleware($handler);
|
|
$middleware($request, [])->wait();
|
|
}
|
|
|
|
public function getResponses(): iterable {
|
|
yield [
|
|
new Request('GET', 'http://localhost'),
|
|
new Response(204, [], ''),
|
|
Exception\NoContentException::class,
|
|
];
|
|
|
|
yield [
|
|
new Request('GET', 'http://localhost'),
|
|
new Response(
|
|
403,
|
|
['Content-Type' => 'application/json'],
|
|
'{"error":"ForbiddenOperationException","errorMessage":"Invalid token"}'
|
|
),
|
|
Exception\ForbiddenException::class,
|
|
];
|
|
|
|
yield [
|
|
new Request('GET', 'http://localhost'),
|
|
new Response(
|
|
429,
|
|
['Content-Type' => 'application/json'],
|
|
'{"error":"TooManyRequestsException","errorMessage":"The client has sent too many requests within a certain amount of time"}'
|
|
),
|
|
Exception\TooManyRequestsException::class,
|
|
];
|
|
}
|
|
|
|
}
|