ApiClientTest::testInvalidRegion()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace LoLApi\Tests;
4
5
use GuzzleHttp\Client;
6
use LoLApi\ApiClient;
7
use LoLApi\Result\ApiResult;
8
use Symfony\Component\Cache\Adapter\ArrayAdapter;
9
use Symfony\Component\Cache\Adapter\NullAdapter;
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::getSpectatorApi
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\SpectatorApi', $apiClient->getSpectatorApi());
40
        $this->assertInstanceOf('LoLApi\Api\MasteryApi', $apiClient->getMasteriesApi());
41
        $this->assertInstanceOf('LoLApi\Api\RuneApi', $apiClient->getRunesApi());
42
        $this->assertInstanceOf('LoLApi\Api\StaticDataApi', $apiClient->getStaticDataApi());
43
        $this->assertInstanceOf('LoLApi\Api\LeagueApi', $apiClient->getLeagueApi());
44
        $this->assertInstanceOf('LoLApi\Api\StatusApi', $apiClient->getStatusApi());
45
        $this->assertInstanceOf('LoLApi\Api\ChampionMasteryApi', $apiClient->getChampionMasteryApi());
46
    }
47
48
    /**
49
     * @covers LoLApi\ApiClient::getRegion
50
     * @covers LoLApi\ApiClient::getApiKey
51
     * @covers LoLApi\ApiClient::getHttpClient
52
     * @covers LoLApi\ApiClient::getGlobalUrl
53
     */
54
    public function testOtherGetters()
55
    {
56
        $apiClient = new ApiClient(ApiClient::REGION_EUW, 'test');
57
58
        $this->assertEquals(self::REGION, $apiClient->getRegion());
59
        $this->assertEquals(self::API_KEY, $apiClient->getApiKey());
60
        $this->assertInstanceOf('GuzzleHttp\Client', $apiClient->getHttpClient());
61
    }
62
63
    /**
64
     * @covers LoLApi\ApiClient::setCacheProvider
65
     * @covers LoLApi\ApiClient::getCacheProvider
66
     */
67
    public function testCacheProvider()
68
    {
69
        $apiClient = new ApiClient(ApiClient::REGION_EUW, 'test');
70
71
        $apiClient->setCacheProvider(new NullAdapter());
72
        $this->assertInstanceOf(NullAdapter::class, $apiClient->getCacheProvider());
73
74
        $apiClient->setCacheProvider(new ArrayAdapter());
75
        $this->assertInstanceOf(ArrayAdapter::class, $apiClient->getCacheProvider());
76
    }
77
78
    /**
79
     * @covers LoLApi\ApiClient::cacheApiResult
80
     */
81
    public function testCacheApiResult()
82
    {
83
        $apiResult  = new ApiResult();
84
        $arrayCache = new ArrayAdapter();
85
86
        $client = new ApiClient(ApiClient::REGION_EUW, 'test', $arrayCache);
87
88
        $client->cacheApiResult($apiResult);
89
    }
90
91
    /**
92
     * @covers LoLApi\ApiClient::getBaseUrlWithPlatformId
93
     */
94
    public function testGetBaseUrlWithPlatformId()
95
    {
96
        $apiClient = new ApiClient(ApiClient::REGION_EUW, 'test', null, null);
97
        $class     = new \ReflectionClass('LoLApi\ApiClient');
98
        $method    = $class->getMethod('getBaseUrl');
99
        $method->setAccessible(true);
100
101
        $this->assertEquals('https://euw1.api.riotgames.com', $method->invoke($apiClient, true));
102
    }
103
104
    /**
105
     * @covers LoLApi\ApiClient::__construct
106
     *
107
     * @expectedException \LoLApi\Exception\InvalidRegionException
108
     */
109
    public function testInvalidRegion()
110
    {
111
        new ApiClient('test', 'test');
112
    }
113
114
    /**
115
     * @covers LoLApi\ApiClient::__construct
116
     */
117
    public function testConstructWithClient()
118
    {
119
        $httpClient = new Client();
120
        $apiClient  = new ApiClient(ApiClient::REGION_EUW, 'test', new NullAdapter(), $httpClient);
121
122
        $this->assertSame($httpClient, $apiClient->getHttpClient());
123
    }
124
125
    /**
126
     * @covers LoLApi\ApiClient::__construct
127
     */
128
    public function testConstruct()
129
    {
130
        $apiClient = new ApiClient(ApiClient::REGION_EUW, 'test', new NullAdapter());
131
132
        $this->assertInstanceOf('GuzzleHttp\Client', $apiClient->getHttpClient());
133
    }
134
}
135