|
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'); |
|
|
|
|
|
|
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
|
|
|
} |
|
124
|
|
|
|