1 | <?php |
||
16 | class ApiClientTest extends \PHPUnit_Framework_TestCase |
||
17 | { |
||
18 | const REGION = 'euw'; |
||
19 | const API_KEY = 'test'; |
||
20 | |||
21 | /** |
||
22 | * @covers LoLApi\ApiClient::getMatchListApi |
||
23 | * @covers LoLApi\ApiClient::getMatchApi |
||
24 | * @covers LoLApi\ApiClient::getSummonerApi |
||
25 | * @covers LoLApi\ApiClient::getChampionApi |
||
26 | * @covers LoLApi\ApiClient::getFeaturedGamesApi |
||
27 | * @covers LoLApi\ApiClient::getGameApi |
||
28 | * @covers LoLApi\ApiClient::getStatsApi |
||
29 | * @covers LoLApi\ApiClient::getCurrentGameApi |
||
30 | * @covers LoLApi\ApiClient::getStaticDataApi |
||
31 | * @covers LoLApi\ApiClient::getLeagueApi |
||
32 | * @covers LoLApi\ApiClient::getStatusApi |
||
33 | * @covers LoLApi\ApiClient::getChampionMasteryApi |
||
34 | */ |
||
35 | public function testApiGetters() |
||
36 | { |
||
37 | $apiClient = new ApiClient(ApiClient::REGION_EUW, 'test'); |
||
38 | |||
39 | $this->assertInstanceOf('LoLApi\Api\MatchListApi', $apiClient->getMatchListApi()); |
||
40 | $this->assertInstanceOf('LoLApi\Api\MatchApi', $apiClient->getMatchApi()); |
||
41 | $this->assertInstanceOf('LoLApi\Api\SummonerApi', $apiClient->getSummonerApi()); |
||
42 | $this->assertInstanceOf('LoLApi\Api\ChampionApi', $apiClient->getChampionApi()); |
||
43 | $this->assertInstanceOf('LoLApi\Api\FeaturedGamesApi', $apiClient->getFeaturedGamesApi()); |
||
44 | $this->assertInstanceOf('LoLApi\Api\GameApi', $apiClient->getGameApi()); |
||
45 | $this->assertInstanceOf('LoLApi\Api\StatsApi', $apiClient->getStatsApi()); |
||
46 | $this->assertInstanceOf('LoLApi\Api\CurrentGameApi', $apiClient->getCurrentGameApi()); |
||
47 | $this->assertInstanceOf('LoLApi\Api\MasteryApi', $apiClient->getMasteriesApi()); |
||
48 | $this->assertInstanceOf('LoLApi\Api\RuneApi', $apiClient->getRunesApi()); |
||
49 | $this->assertInstanceOf('LoLApi\Api\StaticDataApi', $apiClient->getStaticDataApi()); |
||
50 | $this->assertInstanceOf('LoLApi\Api\LeagueApi', $apiClient->getLeagueApi()); |
||
51 | $this->assertInstanceOf('LoLApi\Api\StatusApi', $apiClient->getStatusApi()); |
||
52 | $this->assertInstanceOf('LoLApi\Api\ChampionMasteryApi', $apiClient->getChampionMasteryApi()); |
||
53 | } |
||
54 | |||
55 | /** |
||
56 | * @covers LoLApi\ApiClient::getRegion |
||
57 | * @covers LoLApi\ApiClient::getApiKey |
||
58 | * @covers LoLApi\ApiClient::getHttpClient |
||
59 | * @covers LoLApi\ApiClient::getGlobalUrl |
||
60 | * @covers LoLApi\ApiClient::getStatusUrl |
||
61 | */ |
||
62 | public function testOtherGetters() |
||
63 | { |
||
64 | $apiClient = new ApiClient(ApiClient::REGION_EUW, 'test'); |
||
65 | |||
66 | $this->assertEquals(self::REGION, $apiClient->getRegion()); |
||
67 | $this->assertEquals(self::API_KEY, $apiClient->getApiKey()); |
||
68 | $this->assertInstanceOf('GuzzleHttp\Client', $apiClient->getHttpClient()); |
||
69 | $this->assertSame('https://global.api.riotgames.com', $apiClient->getGlobalUrl()); |
||
70 | $this->assertSame('http://status.leagueoflegends.com', $apiClient->getStatusUrl()); |
||
71 | } |
||
72 | |||
73 | /** |
||
74 | * @covers LoLApi\ApiClient::setCacheProvider |
||
75 | * @covers LoLApi\ApiClient::getCacheProvider |
||
76 | */ |
||
77 | public function testCacheProvider() |
||
78 | { |
||
79 | $apiClient = new ApiClient(ApiClient::REGION_EUW, 'test'); |
||
80 | |||
81 | $this->assertInstanceOf('Doctrine\Common\Cache\VoidCache', $apiClient->getCacheProvider()); |
||
82 | |||
83 | $apiClient->setCacheProvider(new ArrayCache()); |
||
84 | |||
85 | $this->assertInstanceOf('Doctrine\Common\Cache\ArrayCache', $apiClient->getCacheProvider()); |
||
86 | } |
||
87 | |||
88 | /** |
||
89 | * @covers LoLApi\ApiClient::cacheApiResult |
||
90 | */ |
||
91 | public function testCacheApiResult() |
||
92 | { |
||
93 | $apiResult = new ApiResult(); |
||
94 | $arrayCache = $this->getMockBuilder('Doctrine\Common\Cache\ArrayCache')->disableOriginalConstructor()->getMock(); |
||
95 | $arrayCache->expects($this->once())->method('save')->willReturn($this->equalTo($apiResult)); |
||
96 | |||
97 | $client = new ApiClient(ApiClient::REGION_EUW, 'test', $arrayCache); |
||
98 | |||
99 | $client->cacheApiResult($apiResult); |
||
100 | } |
||
101 | |||
102 | /** |
||
103 | * @covers LoLApi\ApiClient::getBaseUrlWithPlatformId |
||
104 | */ |
||
105 | public function testGetBaseUrlWithRegion() |
||
114 | |||
115 | /** |
||
116 | * @covers LoLApi\ApiClient::getBaseUrlWithPlatformId |
||
117 | */ |
||
118 | public function testGetBaseUrlWithPlatformId() |
||
127 | |||
128 | /** |
||
129 | * @covers LoLApi\ApiClient::__construct |
||
130 | * |
||
131 | * @expectedException \LoLApi\Exception\InvalidRegionException |
||
132 | */ |
||
133 | public function testInvalidRegion() |
||
137 | |||
138 | /** |
||
139 | * @covers LoLApi\ApiClient::__construct |
||
140 | */ |
||
141 | public function testConstructWithClient() |
||
148 | |||
149 | /** |
||
150 | * @covers LoLApi\ApiClient::__construct |
||
151 | */ |
||
152 | public function testConstruct() |
||
158 | } |
||
159 |