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