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::getTeamApi |
31
|
|
|
* @covers LoLApi\ApiClient::getStaticDataApi |
32
|
|
|
* @covers LoLApi\ApiClient::getLeagueApi |
33
|
|
|
* @covers LoLApi\ApiClient::getStatusApi |
34
|
|
|
* @covers LoLApi\ApiClient::getChampionMasteryApi |
35
|
|
|
*/ |
36
|
|
|
public function testApiGetters() |
37
|
|
|
{ |
38
|
|
|
$apiClient = new ApiClient(ApiClient::REGION_EUW, 'test'); |
39
|
|
|
|
40
|
|
|
$this->assertInstanceOf('LoLApi\Api\MatchListApi', $apiClient->getMatchListApi()); |
41
|
|
|
$this->assertInstanceOf('LoLApi\Api\MatchApi', $apiClient->getMatchApi()); |
42
|
|
|
$this->assertInstanceOf('LoLApi\Api\SummonerApi', $apiClient->getSummonerApi()); |
43
|
|
|
$this->assertInstanceOf('LoLApi\Api\ChampionApi', $apiClient->getChampionApi()); |
44
|
|
|
$this->assertInstanceOf('LoLApi\Api\FeaturedGamesApi', $apiClient->getFeaturedGamesApi()); |
45
|
|
|
$this->assertInstanceOf('LoLApi\Api\GameApi', $apiClient->getGameApi()); |
46
|
|
|
$this->assertInstanceOf('LoLApi\Api\StatsApi', $apiClient->getStatsApi()); |
47
|
|
|
$this->assertInstanceOf('LoLApi\Api\CurrentGameApi', $apiClient->getCurrentGameApi()); |
48
|
|
|
$this->assertInstanceOf('LoLApi\Api\MasteryApi', $apiClient->getMasteriesApi()); |
49
|
|
|
$this->assertInstanceOf('LoLApi\Api\RuneApi', $apiClient->getRunesApi()); |
50
|
|
|
$this->assertInstanceOf('LoLApi\Api\StaticDataApi', $apiClient->getStaticDataApi()); |
51
|
|
|
$this->assertInstanceOf('LoLApi\Api\LeagueApi', $apiClient->getLeagueApi()); |
52
|
|
|
$this->assertInstanceOf('LoLApi\Api\StatusApi', $apiClient->getStatusApi()); |
53
|
|
|
$this->assertInstanceOf('LoLApi\Api\ChampionMasteryApi', $apiClient->getChampionMasteryApi()); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @covers LoLApi\ApiClient::getRegion |
58
|
|
|
* @covers LoLApi\ApiClient::getApiKey |
59
|
|
|
* @covers LoLApi\ApiClient::getHttpClient |
60
|
|
|
* @covers LoLApi\ApiClient::getGlobalUrl |
61
|
|
|
* @covers LoLApi\ApiClient::getStatusUrl |
62
|
|
|
*/ |
63
|
|
|
public function testOtherGetters() |
64
|
|
|
{ |
65
|
|
|
$apiClient = new ApiClient(ApiClient::REGION_EUW, 'test'); |
66
|
|
|
|
67
|
|
|
$this->assertEquals(self::REGION, $apiClient->getRegion()); |
68
|
|
|
$this->assertEquals(self::API_KEY, $apiClient->getApiKey()); |
69
|
|
|
$this->assertInstanceOf('GuzzleHttp\Client', $apiClient->getHttpClient()); |
70
|
|
|
$this->assertSame('https://global.api.riotgames.com', $apiClient->getGlobalUrl()); |
71
|
|
|
$this->assertSame('http://status.leagueoflegends.com', $apiClient->getStatusUrl()); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @covers LoLApi\ApiClient::setCacheProvider |
76
|
|
|
* @covers LoLApi\ApiClient::getCacheProvider |
77
|
|
|
*/ |
78
|
|
|
public function testCacheProvider() |
79
|
|
|
{ |
80
|
|
|
$apiClient = new ApiClient(ApiClient::REGION_EUW, 'test'); |
81
|
|
|
|
82
|
|
|
$this->assertInstanceOf('Doctrine\Common\Cache\VoidCache', $apiClient->getCacheProvider()); |
83
|
|
|
|
84
|
|
|
$apiClient->setCacheProvider(new ArrayCache()); |
85
|
|
|
|
86
|
|
|
$this->assertInstanceOf('Doctrine\Common\Cache\ArrayCache', $apiClient->getCacheProvider()); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @covers LoLApi\ApiClient::cacheApiResult |
91
|
|
|
*/ |
92
|
|
|
public function testCacheApiResult() |
93
|
|
|
{ |
94
|
|
|
$apiResult = new ApiResult(); |
95
|
|
|
$arrayCache = $this->getMockBuilder('Doctrine\Common\Cache\ArrayCache')->disableOriginalConstructor()->getMock(); |
96
|
|
|
$arrayCache->expects($this->once())->method('save')->willReturn($this->equalTo($apiResult)); |
97
|
|
|
|
98
|
|
|
$client = new ApiClient(ApiClient::REGION_EUW, 'test', $arrayCache); |
99
|
|
|
|
100
|
|
|
$client->cacheApiResult($apiResult); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* @covers LoLApi\ApiClient::getBaseUrlWithPlatformId |
105
|
|
|
*/ |
106
|
|
|
public function testGetBaseUrlWithRegion() |
107
|
|
|
{ |
108
|
|
|
$apiClient = new ApiClient(ApiClient::REGION_EUW, 'test'); |
109
|
|
|
$class = new \ReflectionClass('LoLApi\ApiClient'); |
110
|
|
|
$method = $class->getMethod('getBaseUrl'); |
111
|
|
|
$method->setAccessible(true); |
112
|
|
|
|
113
|
|
|
$this->assertEquals('https://euw.api.pvp.net', $method->invoke($apiClient, false)); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* @covers LoLApi\ApiClient::getBaseUrlWithPlatformId |
118
|
|
|
*/ |
119
|
|
|
public function testGetBaseUrlWithPlatformId() |
120
|
|
|
{ |
121
|
|
|
$apiClient = new ApiClient(ApiClient::REGION_EUW, 'test', null, null, true); |
122
|
|
|
$class = new \ReflectionClass('LoLApi\ApiClient'); |
123
|
|
|
$method = $class->getMethod('getBaseUrl'); |
124
|
|
|
$method->setAccessible(true); |
125
|
|
|
|
126
|
|
|
$this->assertEquals('https://euw1.api.riotgames.com', $method->invoke($apiClient, true)); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* @covers LoLApi\ApiClient::__construct |
131
|
|
|
* |
132
|
|
|
* @expectedException \LoLApi\Exception\InvalidRegionException |
133
|
|
|
*/ |
134
|
|
|
public function testInvalidRegion() |
135
|
|
|
{ |
136
|
|
|
new ApiClient('test', 'test'); |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* @covers LoLApi\ApiClient::__construct |
141
|
|
|
*/ |
142
|
|
|
public function testConstructWithClient() |
143
|
|
|
{ |
144
|
|
|
$httpClient = new Client(); |
145
|
|
|
$apiClient = new ApiClient(ApiClient::REGION_EUW, 'test', new VoidCache(), $httpClient); |
146
|
|
|
|
147
|
|
|
$this->assertSame($httpClient, $apiClient->getHttpClient()); |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* @covers LoLApi\ApiClient::__construct |
152
|
|
|
*/ |
153
|
|
|
public function testConstruct() |
154
|
|
|
{ |
155
|
|
|
$apiClient = new ApiClient(ApiClient::REGION_EUW, 'test', new VoidCache()); |
156
|
|
|
|
157
|
|
|
$this->assertInstanceOf('GuzzleHttp\Client', $apiClient->getHttpClient()); |
158
|
|
|
} |
159
|
|
|
} |
160
|
|
|
|