Passed
Push — master ( 744134...9f7edb )
by Ax
01:44
created

SleeperLeagueTest::testUsers()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 11
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 16
rs 9.9
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 SleeperLeagueTest extends TestCase
10
{
11
12
  public function testLeague()
13
  {
14
    $data = file_get_contents(__DIR__ . '/data/league.json');
15
    $response = new GuzzleHttp\Psr7\Response(200, [], $data);
16
    $mock = new GuzzleHttp\Handler\MockHandler([ $response, $response ]);
17
18
    $client = new SleeperClient($mock);
19
20
    $league = (object) $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

20
    $league = (object) $client->/** @scrutinizer ignore-call */ leagues()->find('289646328504385536');
Loading history...
21
22
    $this->assertIsObject($league);
23
    $this->assertEquals('289646328504385536', $league->league_id);
24
    $this->assertEquals('Sleeper Friends League', $league->name);
25
    $this->assertEquals('2018', $league->season);
26
    $this->assertCount(15, $league->roster_positions);
27
    $this->assertIsArray($league->settings);
28
  }
29
30
  public function testLeagues()
31
  {
32
    $data = file_get_contents(__DIR__ . '/data/leagues.json');
33
    $response = new GuzzleHttp\Psr7\Response(200, [], $data);
34
    $mock = new GuzzleHttp\Handler\MockHandler([ $response, $response ]);
35
36
    $client = new SleeperClient($mock);
37
38
    $leagues = $client->leagues()->byUser('457511950237696', '2018');
39
    $league = (object) $leagues[0];
40
41
    $this->assertIsArray($leagues);
42
    $this->assertCount(2, $leagues);
43
    $this->assertEquals('337383787396628480', $league->league_id);
44
    $this->assertEquals('Dynasty Warriors', $league->name);
45
    $this->assertEquals('2018', $league->season);
46
    $this->assertCount(18, $league->roster_positions);
47
    $this->assertIsArray($league->settings);
48
  }
49
50
  public function testState()
51
  {
52
    $data = file_get_contents(__DIR__ . '/data/state.json');
53
    $response = new GuzzleHttp\Psr7\Response(200, [], $data);
54
    $mock = new GuzzleHttp\Handler\MockHandler([ $response, $response ]);
55
56
    $client = new SleeperClient($mock);
57
58
    $state = (object) $client->leagues()->state();
59
60
    $this->assertIsObject($state);
61
    $this->assertEquals(2, $state->week);
62
    $this->assertEquals('2021-09-09', $state->season_start_date);
63
    $this->assertEquals('2020', $state->previous_season);
64
    $this->assertEquals('2021', $state->season);
65
  }
66
67
  public function testUsers()
68
  {
69
    $data = file_get_contents(__DIR__ . '/data/users.json');
70
    $response = new GuzzleHttp\Psr7\Response(200, [], $data);
71
    $mock = new GuzzleHttp\Handler\MockHandler([ $response, $response ]);
72
73
    $client = new SleeperClient($mock);
74
75
    $users = $client->leagues()->users('289646328504385536');
76
    $user = (object) $users[0];
77
78
    $this->assertIsArray($users);
79
    $this->assertCount(14, $users);
80
    $this->assertEquals('457511950237696', $user->user_id);
81
    $this->assertTrue($user->is_owner);
82
    $this->assertEquals('2KSports', $user->display_name);
83
  }
84
85
}
86