BaseApiTest::dataProvider()   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\Api;
4
5
use LoLApi\Tests\AbstractApiTest;
6
use Symfony\Component\Cache\Adapter\ArrayAdapter;
7
8
/**
9
 * Class BaseApiTest
10
 *
11
 * @package LoLApi\Tests\Api
12
 */
13
class BaseApiTest extends AbstractApiTest
14
{
15
    /**
16
     * @param string $api
17
     * @param string $method
18
     * @param array  $options
19
     *
20
     * @dataProvider dataProvider
21
     *
22
     * @covers       LoLApi\Api\BaseApi
23
     * @covers       LoLApi\Api\ChampionApi
24
     * @covers       LoLApi\Api\FeaturedGamesApi
25
     * @covers       LoLApi\Api\MatchApi
26
     * @covers       LoLApi\Api\MatchListApi
27
     * @covers       LoLApi\Api\SummonerApi
28
     * @covers       LoLApi\Api\TeamApi
29
     * @covers       LoLApi\Api\CurrentGameApi
30
     * @covers       LoLApi\Api\StatsApi
31
     * @covers       LoLApi\Api\StaticDataApi
32
     * @covers       LoLApi\Api\LeagueApi
33
     * @covers       LoLApi\Api\StatusApi
34
     * @covers       LoLApi\Api\ChampionMasteryApi
35
     */
36
    public function testAll($api, $method, array $options = [])
37
    {
38
        $api = $this->apiClient->{$api}();
39
40
        $this->assertSame(['success'], call_user_func_array([$api, $method], $options)->getResult());
41
    }
42
43
    /**
44
     * @covers LoLApi\Api\BaseApi::callApiUrl
45
     */
46
    public function testWithCachedResult()
47
    {
48
        $arrayCache = new ArrayAdapter();
49
50
        $item = $arrayCache->getItem('foo');
51
        $item->set('{}');
52
        $arrayCache->save($item);
53
54
        $fooItem = $arrayCache->getItem('foo');
55
        $this->assertTrue($fooItem->isHit());
56
        $this->assertEquals('{}', $fooItem->get());
57
58
        $apiClient = $this->getApiClient($arrayCache, $this->getSuccessfulHttpClient());
59
60
        $apiClient->getSpectatorApi()->getCurrentGameByPlatformIdAndSummonerId(5);
61
    }
62
63
    /**
64
     * @covers LoLApi\Api\BaseApi::callApiUrl
65
     *
66
     * @expectedException \LoLApi\Exception\ServiceRateLimitException
67
     */
68
    public function testWithRateLimitException()
69
    {
70
        $apiClient = $this->getApiClient(new ArrayAdapter(), $this->getRateLimitHttpClient());
71
72
        $apiClient->getSpectatorApi()->getCurrentGameByPlatformIdAndSummonerId(5);
73
    }
74
75
    /**
76
     * @return array
77
     */
78
    public function dataProvider()
79
    {
80
        return array_merge($this->getDataProvider1(), $this->getDataProvider2(), $this->getDataProvider3(), $this->getDataProvider4(), $this->getDataProvider5(), $this->getDataProvider6());
81
    }
82
83
    /**
84
     * @return array
85
     */
86
    protected function getDataProvider1()
87
    {
88
        return [
89
            [
90
                'getSpectatorApi',
91
                'getCurrentGameByPlatformIdAndSummonerId',
92
                [
93
                    5
94
                ]
95
            ],
96
        ];
97
    }
98
99
    /**
100
     * @return array
101
     */
102
    protected function getDataProvider2()
103
    {
104
        return [
105
            [
106
                'getMatchApi',
107
                'getMatchListByAccountId',
108
                [
109
                    5
110
                ]
111
            ],
112
            [
113
                'getChampionApi',
114
                'getAllChampions',
115
            ],
116
            [
117
                'getChampionApi',
118
                'getChampionById',
119
                [
120
                    5
121
                ]
122
            ],
123
            [
124
                'getFeaturedGamesApi',
125
                'getFeaturedGames'
126
            ],
127
            [
128
                'getMatchApi',
129
                'getMatchByMatchId',
130
                [
131
                    5
132
                ]
133
            ],
134
            [
135
                'getSummonerApi',
136
                'getSummonerBySummonerName',
137
                [
138
                    'test'
139
                ]
140
            ],
141
            [
142
                'getSummonerApi',
143
                'getSummonerBySummonerId',
144
                [
145
                    5
146
                ]
147
            ],
148
            [
149
                'getSummonerApi',
150
                'getSummonerByAccountId',
151
                [
152
                    5
153
                ]
154
            ],
155
        ];
156
    }
157
158
    /**
159
     * @return array
160
     */
161
    protected function getDataProvider3()
162
    {
163
        return [
164
            [
165
                'getStaticDataApi',
166
                'getChampions',
167
            ],
168
            [
169
                'getStaticDataApi',
170
                'getChampionById',
171
                [
172
                    5
173
                ]
174
            ],
175
            [
176
                'getStaticDataApi',
177
                'getChampionById',
178
                [
179
                    5
180
                ]
181
            ],
182
            [
183
                'getStaticDataApi',
184
                'getItems'
185
            ],
186
            [
187
                'getStaticDataApi',
188
                'getItemById',
189
                [
190
                    5
191
                ]
192
            ],
193
            [
194
                'getStaticDataApi',
195
                'getLanguageStrings'
196
            ],
197
            [
198
                'getStaticDataApi',
199
                'getLanguages'
200
            ],
201
            [
202
                'getStaticDataApi',
203
                'getMap'
204
            ]
205
        ];
206
    }
207
208
    /**
209
     * @return array
210
     */
211
    protected function getDataProvider4()
212
    {
213
        return [
214
            [
215
                'getStaticDataApi',
216
                'getMasteries'
217
            ],
218
            [
219
                'getStaticDataApi',
220
                'getMasteryById',
221
                [
222
                    5
223
                ]
224
            ],
225
            [
226
                'getStaticDataApi',
227
                'getRealms'
228
            ],
229
            [
230
                'getStaticDataApi',
231
                'getRunes'
232
            ],
233
            [
234
                'getStaticDataApi',
235
                'getRuneById',
236
                [
237
                    5,
238
                    'fr',
239
                    'v1.2'
240
                ]
241
            ],
242
            [
243
                'getStaticDataApi',
244
                'getVersions'
245
            ],
246
            [
247
                'getStaticDataApi',
248
                'getSummonerSpells'
249
            ],
250
            [
251
                'getStaticDataApi',
252
                'getSummonerSpellById',
253
                [
254
                    5
255
                ]
256
            ]
257
        ];
258
    }
259
260
    /**
261
     * @return array
262
     */
263
    protected function getDataProvider5()
264
    {
265
        return [
266
            [
267
                'getLeagueApi',
268
                'getLeaguePositionsBySummonerId',
269
                [
270
                    5
271
                ]
272
            ],
273
            [
274
                'getLeagueApi',
275
                'getChallengerLeagues',
276
                [
277
                    'RANKED_SOLO_5x5'
278
                ]
279
            ],
280
            [
281
                'getLeagueApi',
282
                'getMasterLeagues',
283
                [
284
                    'RANKED_SOLO_5x5'
285
                ]
286
            ]
287
        ];
288
    }
289
290
    /**
291
     * @return array
292
     */
293
    protected function getDataProvider6()
294
    {
295
        return [
296
            [
297
                'getStatusApi',
298
                'getShards'
299
            ],
300
            [
301
                'getChampionMasteryApi',
302
                'getChampionMastery',
303
                [
304
                    5,
305
                    5
306
                ]
307
            ],
308
            [
309
                'getChampionMasteryApi',
310
                'getChampionsMasteries',
311
                [
312
                    5
313
                ]
314
            ],
315
            [
316
                'getChampionMasteryApi',
317
                'getChampionsMasteriesScore',
318
                [
319
                    5
320
                ]
321
            ],
322
        ];
323
    }
324
}
325