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 SleeperDraftTest extends TestCase |
10
|
|
|
{ |
11
|
|
|
|
12
|
|
|
public function testUser() |
13
|
|
|
{ |
14
|
|
|
$data = file_get_contents(__DIR__ . '/data/draft.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
|
|
|
$draft = (object) $client->drafts()->byUser('457511950237696', '2018'); |
|
|
|
|
21
|
|
|
|
22
|
|
|
$this->assertIsObject($draft); |
23
|
|
|
$this->assertEquals('289646328504385536', $draft->league_id); |
24
|
|
|
$this->assertIsArray($draft->metadata); |
25
|
|
|
$this->assertEquals('Sleeper Friends League', $draft->metadata['name']); |
26
|
|
|
$this->assertEquals('2018', $draft->season); |
27
|
|
|
$this->assertEquals('snake', $draft->type); |
28
|
|
|
$this->assertCount(12, $draft->settings); |
29
|
|
|
$this->assertEquals(12, $draft->settings['teams']); |
30
|
|
|
$this->assertEquals('289646328508579840', $draft->draft_id); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function testLeague() |
34
|
|
|
{ |
35
|
|
|
$data = file_get_contents(__DIR__ . '/data/league-drafts.json'); |
36
|
|
|
$response = new GuzzleHttp\Psr7\Response(200, [], $data); |
37
|
|
|
$mock = new GuzzleHttp\Handler\MockHandler([ $response, $response ]); |
38
|
|
|
|
39
|
|
|
$client = new SleeperClient($mock); |
40
|
|
|
|
41
|
|
|
$drafts = $client->drafts()->byLeague('289646328504385536'); |
42
|
|
|
$draft = (object) $drafts[0]; |
43
|
|
|
|
44
|
|
|
$this->assertIsArray($drafts); |
45
|
|
|
$this->assertCount(1, $drafts); |
46
|
|
|
$this->assertIsObject($draft); |
47
|
|
|
$this->assertEquals('289646328504385536', $draft->league_id); |
48
|
|
|
$this->assertIsArray($draft->metadata); |
49
|
|
|
$this->assertEquals('Sleeper Friends League', $draft->metadata['name']); |
50
|
|
|
$this->assertEquals('2018', $draft->season); |
51
|
|
|
$this->assertEquals('snake', $draft->type); |
52
|
|
|
$this->assertCount(12, $draft->settings); |
53
|
|
|
$this->assertEquals(12, $draft->settings['teams']); |
54
|
|
|
$this->assertEquals('289646328508579840', $draft->draft_id); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function testDraft() |
58
|
|
|
{ |
59
|
|
|
$data = file_get_contents(__DIR__ . '/data/draft.json'); |
60
|
|
|
$response = new GuzzleHttp\Psr7\Response(200, [], $data); |
61
|
|
|
$mock = new GuzzleHttp\Handler\MockHandler([ $response, $response ]); |
62
|
|
|
|
63
|
|
|
$client = new SleeperClient($mock); |
64
|
|
|
|
65
|
|
|
$draft = (object) $client->drafts()->find('289646328508579840'); |
66
|
|
|
|
67
|
|
|
$this->assertIsObject($draft); |
68
|
|
|
$this->assertEquals('289646328504385536', $draft->league_id); |
69
|
|
|
$this->assertIsArray($draft->metadata); |
70
|
|
|
$this->assertEquals('Sleeper Friends League', $draft->metadata['name']); |
71
|
|
|
$this->assertEquals('2018', $draft->season); |
72
|
|
|
$this->assertEquals('snake', $draft->type); |
73
|
|
|
$this->assertCount(12, $draft->settings); |
74
|
|
|
$this->assertEquals(12, $draft->settings['teams']); |
75
|
|
|
$this->assertEquals('289646328508579840', $draft->draft_id); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
public function testPick() |
79
|
|
|
{ |
80
|
|
|
$data = file_get_contents(__DIR__ . '/data/draft-picks.json'); |
81
|
|
|
$response = new GuzzleHttp\Psr7\Response(200, [], $data); |
82
|
|
|
$mock = new GuzzleHttp\Handler\MockHandler([ $response, $response ]); |
83
|
|
|
|
84
|
|
|
$client = new SleeperClient($mock); |
85
|
|
|
|
86
|
|
|
$picks = $client->drafts()->picks('289646328508579840'); |
87
|
|
|
$pick = (object) $picks[3]; |
88
|
|
|
|
89
|
|
|
$this->assertIsArray($picks); |
90
|
|
|
$this->assertCount(180, $picks); |
91
|
|
|
$this->assertIsObject($pick); |
92
|
|
|
$this->assertEquals(1, $pick->round); |
93
|
|
|
$this->assertEquals(12, $pick->roster_id); |
94
|
|
|
$this->assertIsArray($pick->metadata); |
95
|
|
|
$this->assertEquals('Ezekiel', $pick->metadata['first_name']); |
96
|
|
|
$this->assertEquals('Elliott', $pick->metadata['last_name']); |
97
|
|
|
$this->assertEquals('3164', $pick->player_id); |
98
|
|
|
$this->assertEquals(4, $pick->draft_slot); |
99
|
|
|
$this->assertEquals('3975968863961088', $pick->picked_by); |
100
|
|
|
$this->assertEquals('289646328508579840', $pick->draft_id); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
public function testTrade() |
104
|
|
|
{ |
105
|
|
|
$data = file_get_contents(__DIR__ . '/data/traded-picks.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
|
|
|
$trades = $client->drafts()->tradedPicks('289646328508579840'); |
112
|
|
|
|
113
|
|
|
$this->assertIsArray($trades); |
114
|
|
|
$this->assertCount(0, $trades); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
} |
118
|
|
|
|