Passed
Push — master ( 1186c1...cc57e4 )
by Ax
01:41
created

SleeperExceptionTest::testSleeperHttpException3()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 1
eloc 6
c 1
b 1
f 0
nc 1
nop 0
dl 0
loc 10
rs 10
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();
0 ignored issues
show
Bug introduced by
The method TestClass() does not exist on SchoppAx\Sleeper\SleeperClient. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

17
    $client->/** @scrutinizer ignore-call */ 
18
             TestClass();
Loading history...
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');
0 ignored issues
show
Bug introduced by
The method leagues() does not exist on SchoppAx\Sleeper\SleeperClient. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

29
    $client->/** @scrutinizer ignore-call */ 
30
             leagues()->find('289646328504385536');
Loading history...
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