Passed
Push — master ( cc57e4...8c3235 )
by Ax
07:11
created

SleeperLeagueTest   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 154
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 98
dl 0
loc 154
rs 10
c 2
b 0
f 0
wmc 8

8 Methods

Rating   Name   Duplication   Size   Complexity  
A testLeagues() 0 18 1
A testUsers() 0 16 1
A testState() 0 15 1
A testLeague() 0 16 1
A testRoster() 0 18 1
A testMatchup() 0 16 1
A testLosersBracket() 0 19 1
A testWinnersBracket() 0 19 1
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
  public function testMatchup()
86
  {
87
    $data = file_get_contents(__DIR__ . '/data/matchups.json');
88
    $response = new GuzzleHttp\Psr7\Response(200, [], $data);
89
    $mock = new GuzzleHttp\Handler\MockHandler([ $response, $response ]);
90
91
    $client = new SleeperClient($mock);
92
93
    $matchups = $client->leagues()->matchups('337383787396628480', '3');
94
    $matchup = (object) $matchups[0];
95
96
    $this->assertIsArray($matchups);
97
    $this->assertCount(12, $matchups);
98
    $this->assertEquals(108.9, $matchup->points);
99
    $this->assertIsArray($matchup->starters);
100
    $this->assertIsArray($matchup->players);
101
  }
102
103
  public function testRoster()
104
  {
105
    $data = file_get_contents(__DIR__ . '/data/rosters.json');
106
    $response = new GuzzleHttp\Psr7\Response(200, [], $data);
107
    $mock = new GuzzleHttp\Handler\MockHandler([ $response, $response ]);
108
109
    $client = new SleeperClient($mock);
110
111
    $rosters = $client->leagues()->rosters('337383787396628480');
112
    $roster = (object) $rosters[0];
113
114
    $this->assertIsArray($rosters);
115
    $this->assertCount(12, $rosters);
116
    $this->assertEquals('189140835533586432', $roster->owner_id);
117
    $this->assertEquals('289646328504385536', $roster->league_id);
118
    $this->assertIsArray($roster->settings);
119
    $this->assertEquals(7, $roster->settings['wins']);
120
    $this->assertEquals(6, $roster->settings['losses']);
121
  }
122
123
  public function testLosersBracket()
124
  {
125
    $data = file_get_contents(__DIR__ . '/data/playoff-bracket-loser.json');
126
    $response = new GuzzleHttp\Psr7\Response(200, [], $data);
127
    $mock = new GuzzleHttp\Handler\MockHandler([ $response, $response ]);
128
129
    $client = new SleeperClient($mock);
130
131
    $bracket = $client->leagues()->losersBracket('289646328504385536');
132
    $firstMatchup = (object) $bracket[0];
133
    $secondMatchup = (object) $bracket[2];
134
135
    $this->assertIsArray($bracket);
136
    $this->assertCount(7, $bracket);
137
    $this->assertEquals(7, $firstMatchup->w);
138
    $this->assertEquals(1, $firstMatchup->r);
139
    $this->assertEquals(1, $secondMatchup->t2_from['w']);
140
    $this->assertEquals(7, $secondMatchup->l);
141
    $this->assertEquals(11, $secondMatchup->w);
142
  }
143
144
  public function testWinnersBracket()
145
  {
146
    $data = file_get_contents(__DIR__ . '/data/playoff-bracket-winner.json');
147
    $response = new GuzzleHttp\Psr7\Response(200, [], $data);
148
    $mock = new GuzzleHttp\Handler\MockHandler([ $response, $response ]);
149
150
    $client = new SleeperClient($mock);
151
152
    $bracket = $client->leagues()->winnersBracket('289646328504385536');
153
    $firstMatchup = (object) $bracket[0];
154
    $secondMatchup = (object) $bracket[3];
155
156
    $this->assertIsArray($bracket);
157
    $this->assertCount(7, $bracket);
158
    $this->assertEquals(1, $firstMatchup->w);
159
    $this->assertEquals(5, $firstMatchup->t1);
160
    $this->assertEquals(2, $secondMatchup->t2_from['w']);
161
    $this->assertEquals(2, $secondMatchup->l);
162
    $this->assertEquals(3, $secondMatchup->w);
163
  }
164
165
}
166