Completed
Pull Request — master (#11)
by Tristan
03:13 queued 01:06
created

ApiClientTest::testInvalidRegion()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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