1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use PHPUnit\Framework\TestCase; |
4
|
|
|
use SchoppAx\Sleeper\SleeperClient; |
5
|
|
|
use GuzzleHttp\Handler\MockHandler; |
6
|
|
|
use GuzzleHttp\Psr7\Response; |
7
|
|
|
use GuzzleHttp\Psr7\Request; |
8
|
|
|
|
9
|
|
|
class SleeperExceptionTest extends TestCase |
10
|
|
|
{ |
11
|
|
|
|
12
|
|
|
public function testBadMethodException() { |
13
|
|
|
$client = new SleeperClient(); |
14
|
|
|
|
15
|
|
|
$this->expectException(BadMethodCallException::class); |
16
|
|
|
|
17
|
|
|
$client->TestClass(); |
|
|
|
|
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
public function testSleeperHttpException() { |
21
|
|
|
$response = new GuzzleHttp\Psr7\Response(429, [], null); |
22
|
|
|
$mock = new GuzzleHttp\Handler\MockHandler([ $response, $response ]); |
23
|
|
|
|
24
|
|
|
$client = new SleeperClient($mock); |
25
|
|
|
|
26
|
|
|
$this->expectException(Exception::class); |
27
|
|
|
$this->expectExceptionMessage('Client error: `GET league/289646328504385536` resulted in a `429 Too Many Requests` response'); |
28
|
|
|
|
29
|
|
|
$client->leagues()->find('289646328504385536'); |
|
|
|
|
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function testSleeperHttpException2() { |
33
|
|
|
$response = new GuzzleHttp\Psr7\Response(302, [], null); |
34
|
|
|
$mock = new GuzzleHttp\Handler\MockHandler([ $response, $response ]); |
35
|
|
|
|
36
|
|
|
$client = new SleeperClient($mock); |
37
|
|
|
|
38
|
|
|
$this->expectException(Exception::class); |
39
|
|
|
$this->expectExceptionMessage('Client error: `GET league/289646328504385536` resulted in a 302 response'); |
40
|
|
|
|
41
|
|
|
$client->leagues()->find('289646328504385536'); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function testSleeperHttpException3() { |
45
|
|
|
$response = new GuzzleHttp\Psr7\Response(200, [], null); |
46
|
|
|
$mock = new GuzzleHttp\Handler\MockHandler([ $response, $response ]); |
47
|
|
|
|
48
|
|
|
$client = new SleeperClient($mock); |
49
|
|
|
|
50
|
|
|
$this->expectException(Exception::class); |
51
|
|
|
$this->expectExceptionMessage('Client error: `GET league/289646328504385536` resulted in a empty response body'); |
52
|
|
|
|
53
|
|
|
$client->leagues()->find('289646328504385536'); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
} |
57
|
|
|
|