|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace LoLApi\Tests; |
|
4
|
|
|
|
|
5
|
|
|
use Doctrine\Common\Cache\ArrayCache; |
|
6
|
|
|
use Doctrine\Common\Cache\VoidCache; |
|
7
|
|
|
use GuzzleHttp\Client; |
|
8
|
|
|
use LoLApi\ApiClient; |
|
9
|
|
|
use LoLApi\Result\ApiResult; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Class ApiClientTest |
|
13
|
|
|
* |
|
14
|
|
|
* @package LoLApi\Tests |
|
15
|
|
|
*/ |
|
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() |
|
106
|
|
|
{ |
|
107
|
|
|
$apiClient = new ApiClient(ApiClient::REGION_EUW, 'test'); |
|
108
|
|
|
$class = new \ReflectionClass('LoLApi\ApiClient'); |
|
109
|
|
|
$method = $class->getMethod('getBaseUrl'); |
|
110
|
|
|
$method->setAccessible(true); |
|
111
|
|
|
|
|
112
|
|
|
$this->assertEquals('https://euw.api.pvp.net', $method->invoke($apiClient, false)); |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
/** |
|
116
|
|
|
* @covers LoLApi\ApiClient::getBaseUrlWithPlatformId |
|
117
|
|
|
*/ |
|
118
|
|
|
public function testGetBaseUrlWithPlatformId() |
|
119
|
|
|
{ |
|
120
|
|
|
$apiClient = new ApiClient(ApiClient::REGION_EUW, 'test', null, null, true); |
|
121
|
|
|
$class = new \ReflectionClass('LoLApi\ApiClient'); |
|
122
|
|
|
$method = $class->getMethod('getBaseUrl'); |
|
123
|
|
|
$method->setAccessible(true); |
|
124
|
|
|
|
|
125
|
|
|
$this->assertEquals('https://euw1.api.riotgames.com', $method->invoke($apiClient, true)); |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
/** |
|
129
|
|
|
* @covers LoLApi\ApiClient::__construct |
|
130
|
|
|
* |
|
131
|
|
|
* @expectedException \LoLApi\Exception\InvalidRegionException |
|
132
|
|
|
*/ |
|
133
|
|
|
public function testInvalidRegion() |
|
134
|
|
|
{ |
|
135
|
|
|
new ApiClient('test', 'test'); |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
/** |
|
139
|
|
|
* @covers LoLApi\ApiClient::__construct |
|
140
|
|
|
*/ |
|
141
|
|
|
public function testConstructWithClient() |
|
142
|
|
|
{ |
|
143
|
|
|
$httpClient = new Client(); |
|
144
|
|
|
$apiClient = new ApiClient(ApiClient::REGION_EUW, 'test', new VoidCache(), $httpClient); |
|
145
|
|
|
|
|
146
|
|
|
$this->assertSame($httpClient, $apiClient->getHttpClient()); |
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
|
|
/** |
|
150
|
|
|
* @covers LoLApi\ApiClient::__construct |
|
151
|
|
|
*/ |
|
152
|
|
|
public function testConstruct() |
|
153
|
|
|
{ |
|
154
|
|
|
$apiClient = new ApiClient(ApiClient::REGION_EUW, 'test', new VoidCache()); |
|
155
|
|
|
|
|
156
|
|
|
$this->assertInstanceOf('GuzzleHttp\Client', $apiClient->getHttpClient()); |
|
157
|
|
|
} |
|
158
|
|
|
} |
|
159
|
|
|
|