SchoppAx /
php-sleeper-api
| 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 SleeperPlayerTest extends TestCase |
||
| 10 | { |
||
| 11 | |||
| 12 | public function testPlayers() |
||
| 13 | { |
||
| 14 | $data = file_get_contents(__DIR__ . '/data/players.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 | $players = $client->players()->all(); |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 21 | $mThomas = (object) $players['3199']; |
||
| 22 | |||
| 23 | $this->assertIsArray($players); |
||
| 24 | $this->assertCount(4, $players); |
||
| 25 | $this->assertIsObject($mThomas); |
||
| 26 | $this->assertEquals('nfl', $mThomas->sport); |
||
| 27 | $this->assertEquals('Michael Thomas', $mThomas->full_name); |
||
| 28 | $this->assertEquals('PUP', $mThomas->injury_status); |
||
| 29 | $this->assertEquals('Inactive', $mThomas->status); |
||
| 30 | $this->assertEquals("6'3\"", $mThomas->height); |
||
| 31 | $this->assertEquals(28, $mThomas->age); |
||
| 32 | $this->assertEquals('212', $mThomas->weight); |
||
| 33 | $this->assertEquals(5, $mThomas->years_exp); |
||
| 34 | $this->assertEquals('NO', $mThomas->team); |
||
| 35 | $this->assertEquals('WR', $mThomas->position); |
||
| 36 | $this->assertEquals('3199', $mThomas->player_id); |
||
| 37 | } |
||
| 38 | |||
| 39 | public function testTrendingAdds() |
||
| 40 | { |
||
| 41 | $data = file_get_contents(__DIR__ . '/data/trending-add.json'); |
||
| 42 | $response = new GuzzleHttp\Psr7\Response(200, [], $data); |
||
| 43 | $mock = new GuzzleHttp\Handler\MockHandler([ $response, $response ]); |
||
| 44 | |||
| 45 | $client = new SleeperClient($mock); |
||
| 46 | |||
| 47 | $players = $client->players()->trending('add'); |
||
| 48 | $player = (object) $players['6']; |
||
| 49 | |||
| 50 | $this->assertIsArray($players); |
||
| 51 | $this->assertCount(25, $players); |
||
| 52 | $this->assertIsObject($player); |
||
| 53 | $this->assertEquals('1110', $player->player_id); |
||
| 54 | $this->assertEquals(53134, $player->count); |
||
| 55 | } |
||
| 56 | |||
| 57 | public function testTrendingDrops() |
||
| 58 | { |
||
| 59 | $data = file_get_contents(__DIR__ . '/data/trending-drop.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 | $players = $client->players()->trending('add'); |
||
| 66 | $player = (object) $players['24']; |
||
| 67 | |||
| 68 | $this->assertIsArray($players); |
||
| 69 | $this->assertCount(25, $players); |
||
| 70 | $this->assertIsObject($player); |
||
| 71 | $this->assertEquals('367', $player->player_id); |
||
| 72 | $this->assertEquals(15676, $player->count); |
||
| 73 | } |
||
| 74 | |||
| 75 | public function testTrendingTypeException() |
||
| 76 | { |
||
| 77 | $response = new GuzzleHttp\Psr7\Response(200, [], null); |
||
| 78 | $mock = new GuzzleHttp\Handler\MockHandler([ $response, $response ]); |
||
| 79 | |||
| 80 | $client = new SleeperClient($mock); |
||
| 81 | |||
| 82 | $this->expectException(InvalidArgumentException::class); |
||
| 83 | $this->expectExceptionMessage("trending function only accepts type 'add' or 'drop'. Input was: none"); |
||
| 84 | |||
| 85 | $client->players()->trending('none'); |
||
| 86 | } |
||
| 87 | |||
| 88 | public function testTrendingSportException() |
||
| 89 | { |
||
| 90 | $response = new GuzzleHttp\Psr7\Response(200, [], null); |
||
| 91 | $mock = new GuzzleHttp\Handler\MockHandler([ $response, $response ]); |
||
| 92 | |||
| 93 | $client = new SleeperClient($mock); |
||
| 94 | |||
| 95 | $this->expectException(InvalidArgumentException::class); |
||
| 96 | $this->expectExceptionMessage("trending function only accepts sports like nfl, nba, lcs. Input was: none"); |
||
| 97 | |||
| 98 | $client->players()->trending('add', 'none'); |
||
| 99 | } |
||
| 100 | |||
| 101 | public function testTrendingHourException() |
||
| 102 | { |
||
| 103 | $response = new GuzzleHttp\Psr7\Response(200, [], null); |
||
| 104 | $mock = new GuzzleHttp\Handler\MockHandler([ $response, $response ]); |
||
| 105 | |||
| 106 | $client = new SleeperClient($mock); |
||
| 107 | |||
| 108 | $this->expectException(InvalidArgumentException::class); |
||
| 109 | $this->expectExceptionMessage("trending function only accepts hours between 1 and 24. Input was: 26"); |
||
| 110 | |||
| 111 | $client->players()->trending('add', 'nfl', 26); |
||
| 112 | } |
||
| 113 | |||
| 114 | public function testTrendingLimitException() |
||
| 115 | { |
||
| 116 | $response = new GuzzleHttp\Psr7\Response(200, [], null); |
||
| 117 | $mock = new GuzzleHttp\Handler\MockHandler([ $response, $response ]); |
||
| 118 | |||
| 119 | $client = new SleeperClient($mock); |
||
| 120 | |||
| 121 | $this->expectException(InvalidArgumentException::class); |
||
| 122 | $this->expectExceptionMessage("trending function only accepts limits between 1 and 200. Input was: 0"); |
||
| 123 | |||
| 124 | $client->players()->trending('add', 'nfl', 24, 0); |
||
| 125 | } |
||
| 126 | |||
| 127 | } |
||
| 128 |