SleeperDraftTest::testUser()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 14
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 19
rs 9.7998
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');
0 ignored issues
show
Bug introduced by
The method drafts() 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
    $draft = (object) $client->/** @scrutinizer ignore-call */ drafts()->byUser('457511950237696', '2018');
Loading history...
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 testUserSeasonException()
34
  {
35
    $response = new GuzzleHttp\Psr7\Response(200, [], null);
36
    $mock = new GuzzleHttp\Handler\MockHandler([ $response, $response ]);
37
38
    $client = new SleeperClient($mock);
39
40
    $this->expectException(InvalidArgumentException::class);
41
    $this->expectExceptionMessage("byUser function only accepts seasons since 2015 and sport type 'nfl'. Inputs were: 1988, nfl");
42
43
    $client->drafts()->byUser('457511950237696', 1988);
44
  }
45
46
  public function testUserSportException()
47
  {
48
    $response = new GuzzleHttp\Psr7\Response(200, [], null);
49
    $mock = new GuzzleHttp\Handler\MockHandler([ $response, $response ]);
50
51
    $client = new SleeperClient($mock);
52
53
    $this->expectException(InvalidArgumentException::class);
54
    $this->expectExceptionMessage("byUser function only accepts seasons since 2015 and sport type 'nfl'. Inputs were: 2018, none");
55
56
    $client->drafts()->byUser('457511950237696', 2018, 'none');
57
  }
58
59
  public function testLeague()
60
  {
61
    $data = file_get_contents(__DIR__ . '/data/league-drafts.json');
62
    $response = new GuzzleHttp\Psr7\Response(200, [], $data);
63
    $mock = new GuzzleHttp\Handler\MockHandler([ $response, $response ]);
64
65
    $client = new SleeperClient($mock);
66
67
    $drafts = $client->drafts()->byLeague('289646328504385536');
68
    $draft = (object) $drafts[0];
69
70
    $this->assertIsArray($drafts);
71
    $this->assertCount(1, $drafts);
72
    $this->assertIsObject($draft);
73
    $this->assertEquals('289646328504385536', $draft->league_id);
74
    $this->assertIsArray($draft->metadata);
75
    $this->assertEquals('Sleeper Friends League', $draft->metadata['name']);
76
    $this->assertEquals('2018', $draft->season);
77
    $this->assertEquals('snake', $draft->type);
78
    $this->assertCount(12, $draft->settings);
79
    $this->assertEquals(12, $draft->settings['teams']);
80
    $this->assertEquals('289646328508579840', $draft->draft_id);
81
  }
82
83
  public function testDraft()
84
  {
85
    $data = file_get_contents(__DIR__ . '/data/draft.json');
86
    $response = new GuzzleHttp\Psr7\Response(200, [], $data);
87
    $mock = new GuzzleHttp\Handler\MockHandler([ $response, $response ]);
88
89
    $client = new SleeperClient($mock);
90
91
    $draft = (object) $client->drafts()->find('289646328508579840');
92
93
    $this->assertIsObject($draft);
94
    $this->assertEquals('289646328504385536', $draft->league_id);
95
    $this->assertIsArray($draft->metadata);
96
    $this->assertEquals('Sleeper Friends League', $draft->metadata['name']);
97
    $this->assertEquals('2018', $draft->season);
98
    $this->assertEquals('snake', $draft->type);
99
    $this->assertCount(12, $draft->settings);
100
    $this->assertEquals(12, $draft->settings['teams']);
101
    $this->assertEquals('289646328508579840', $draft->draft_id);
102
  }
103
104
  public function testPick()
105
  {
106
    $data = file_get_contents(__DIR__ . '/data/draft-picks.json');
107
    $response = new GuzzleHttp\Psr7\Response(200, [], $data);
108
    $mock = new GuzzleHttp\Handler\MockHandler([ $response, $response ]);
109
110
    $client = new SleeperClient($mock);
111
112
    $picks = $client->drafts()->picks('289646328508579840');
113
    $pick = (object) $picks[3];
114
115
    $this->assertIsArray($picks);
116
    $this->assertCount(180, $picks);
117
    $this->assertIsObject($pick);
118
    $this->assertEquals(1, $pick->round);
119
    $this->assertEquals(12, $pick->roster_id);
120
    $this->assertIsArray($pick->metadata);
121
    $this->assertEquals('Ezekiel', $pick->metadata['first_name']);
122
    $this->assertEquals('Elliott', $pick->metadata['last_name']);
123
    $this->assertEquals('3164', $pick->player_id);
124
    $this->assertEquals(4, $pick->draft_slot);
125
    $this->assertEquals('3975968863961088', $pick->picked_by);
126
    $this->assertEquals('289646328508579840', $pick->draft_id);
127
  }
128
129
  public function testTrade()
130
  {
131
    $data = file_get_contents(__DIR__ . '/data/draft-traded-picks.json');
132
    $response = new GuzzleHttp\Psr7\Response(200, [], $data);
133
    $mock = new GuzzleHttp\Handler\MockHandler([ $response, $response ]);
134
135
    $client = new SleeperClient($mock);
136
137
    $trades = $client->drafts()->tradedPicks('289646328508579840');
138
139
    $this->assertIsArray($trades);
140
    $this->assertCount(0, $trades);
141
  }
142
143
}
144