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
|
|
|
} |
86
|
|
|
|