1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace LoLApi\Tests\Handler; |
4
|
|
|
|
5
|
|
|
use GuzzleHttp\Exception\ClientException; |
6
|
|
|
use GuzzleHttp\Psr7\Request; |
7
|
|
|
use GuzzleHttp\Psr7\Response; |
8
|
|
|
use LoLApi\Handler\ClientExceptionHandler; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class ClientExceptionHandlerTest |
12
|
|
|
* |
13
|
|
|
* @package LoLApi\Tests\Handler |
14
|
|
|
*/ |
15
|
|
|
class ClientExceptionHandlerTest extends \PHPUnit_Framework_TestCase |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* @param ClientException $clientException |
19
|
|
|
* |
20
|
|
|
* @covers LoLApi\Handler\ClientExceptionHandler::handleClientException |
21
|
|
|
* |
22
|
|
|
* @dataProvider getClientException |
23
|
|
|
*/ |
24
|
|
|
public function testHandleClientExceptionWithoutRateLimit(ClientException $clientException) |
25
|
|
|
{ |
26
|
|
|
$this->assertSame($clientException, (new ClientExceptionHandler())->handleClientException($clientException)); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @param string $headerRateLimit |
31
|
|
|
* @param string $exceptionNamespace |
32
|
|
|
* |
33
|
|
|
* @covers LoLApi\Handler\ClientExceptionHandler::handleClientException |
34
|
|
|
* @covers LoLApi\Handler\ClientExceptionHandler::handleRateLimitException |
35
|
|
|
* |
36
|
|
|
* @dataProvider dataProvider |
37
|
|
|
*/ |
38
|
|
|
public function testHandleClientExceptionWithRateLimit($headerRateLimit, $exceptionNamespace) |
39
|
|
|
{ |
40
|
|
|
$response = new Response( |
41
|
|
|
429, |
42
|
|
|
[ |
43
|
|
|
ClientExceptionHandler::HEADER_RATE_LIMIT_TYPE => $headerRateLimit, |
44
|
|
|
ClientExceptionHandler::HEADER_RETRY_AFTER => 10 |
45
|
|
|
] |
46
|
|
|
); |
47
|
|
|
|
48
|
|
|
$clientException = new ClientException('test', new Request('GET', 'test'), $response); |
49
|
|
|
$clientExceptionHandler = new ClientExceptionHandler(); |
50
|
|
|
|
51
|
|
|
$this->assertInstanceOf($exceptionNamespace, $clientExceptionHandler->handleClientException($clientException)); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @return array |
56
|
|
|
*/ |
57
|
|
|
public function dataProvider() |
58
|
|
|
{ |
59
|
|
|
return [ |
60
|
|
|
[ |
61
|
|
|
ClientExceptionHandler::RATE_LIMIT_TYPE_USER, |
62
|
|
|
'LoLApi\Exception\UserRateLimitException' |
63
|
|
|
], |
64
|
|
|
[ |
65
|
|
|
ClientExceptionHandler::RATE_LIMIT_TYPE_SERVICE, |
66
|
|
|
'LoLApi\Exception\ServiceRateLimitException' |
67
|
|
|
] |
68
|
|
|
]; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @return array |
73
|
|
|
*/ |
74
|
|
|
public function getClientException() |
75
|
|
|
{ |
76
|
|
|
return [ |
77
|
|
|
[ |
78
|
|
|
new ClientException('exception', new Request('POST', 'data'), new Response(400)) |
79
|
|
|
] |
80
|
|
|
]; |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|