1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Bowerphp\Test\Repository; |
4
|
|
|
|
5
|
|
|
use Bowerphp\Repository\GithubRepository; |
6
|
|
|
use Bowerphp\Repository\RepositoryInterface; |
7
|
|
|
use Bowerphp\Test\BowerphpTestCase; |
8
|
|
|
use Mockery; |
9
|
|
|
use ReflectionClass; |
10
|
|
|
|
11
|
|
|
class GithubRepositoryTest extends BowerphpTestCase |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @var RepositoryInterface |
15
|
|
|
*/ |
16
|
|
|
protected $repository; |
17
|
|
|
|
18
|
|
|
protected $guzzle; |
19
|
|
|
|
20
|
|
|
protected function setUp() |
21
|
|
|
{ |
22
|
|
|
parent::setUp(); |
23
|
|
|
|
24
|
|
|
$this->guzzle = Mockery::mock('Guzzle\Http\ClientInterface'); |
25
|
|
|
$this->httpClient->shouldReceive('getHttpClient')->andReturn($this->guzzle); |
|
|
|
|
26
|
|
|
$this->guzzle->shouldReceive('setHeaders'); |
27
|
|
|
|
28
|
|
|
$this->repository = new GithubRepository(); |
29
|
|
|
$this->repository->setUrl('https://raw.githubusercontent.com/components/jquery')->setHttpClient($this->httpClient); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function testGetBower() |
33
|
|
|
{ |
34
|
|
|
$repo = Mockery::mock('Github\Api\Repo'); |
35
|
|
|
$contents = Mockery::mock('Github\Api\Repository\Contents'); |
36
|
|
|
|
37
|
|
|
$bowerJson = '{"name": "jquery", "version": "2.0.3", "main": "jquery.js"}'; |
38
|
|
|
|
39
|
|
|
$this->httpClient |
40
|
|
|
->shouldReceive('api')->with('repo')->andReturn($repo) |
41
|
|
|
; |
42
|
|
|
|
43
|
|
|
$repo |
|
|
|
|
44
|
|
|
->shouldReceive('contents')->andReturn($contents) |
45
|
|
|
; |
46
|
|
|
|
47
|
|
|
$contents |
48
|
|
|
->shouldReceive('exists')->with('components', 'jquery', 'bower.json', 'master')->andReturn(true) |
49
|
|
|
->shouldReceive('download')->with('components', 'jquery', 'bower.json', 'master')->andReturn($bowerJson) |
50
|
|
|
; |
51
|
|
|
|
52
|
|
|
$this->assertEquals($bowerJson, $this->repository->getBower()); |
53
|
|
|
$this->assertEquals($bowerJson, $this->repository->getBower('master', false, 'https://raw.githubusercontent.com/components/jquery')); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function testGetBowerWithByteMarkOrder() |
57
|
|
|
{ |
58
|
|
|
$repo = Mockery::mock('Github\Api\Repo'); |
59
|
|
|
$contents = Mockery::mock('Github\Api\Repository\Contents'); |
60
|
|
|
|
61
|
|
|
$bowerJson = '{"name": "jquery", "version": "2.0.3", "main": "jquery.js"}'; |
62
|
|
|
$bowerJsonWithBOM = "\xef\xbb\xbf" . $bowerJson; |
63
|
|
|
|
64
|
|
|
$this->httpClient |
65
|
|
|
->shouldReceive('api')->with('repo')->andReturn($repo) |
66
|
|
|
; |
67
|
|
|
|
68
|
|
|
$repo |
|
|
|
|
69
|
|
|
->shouldReceive('contents')->andReturn($contents) |
70
|
|
|
; |
71
|
|
|
|
72
|
|
|
$contents |
73
|
|
|
->shouldReceive('exists')->with('components', 'jquery', 'bower.json', 'master')->andReturn(true) |
74
|
|
|
->shouldReceive('download')->with('components', 'jquery', 'bower.json', 'master')->andReturn($bowerJsonWithBOM) |
75
|
|
|
; |
76
|
|
|
|
77
|
|
|
$this->assertEquals($bowerJson, $this->repository->getBower()); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
public function testGetBowerWithoutBowerJsonButWithPackageJson() |
81
|
|
|
{ |
82
|
|
|
$this->markTestIncomplete('TODO to be fixed, second expectation on "exists" does not work'); |
83
|
|
|
|
84
|
|
|
$repo = Mockery::mock('Github\Api\Repo'); |
85
|
|
|
$contents = Mockery::mock('Github\Api\Repository\Contents'); |
86
|
|
|
|
87
|
|
|
$bowerJson = '{"name": "jquery", "version": "2.0.3", "main": "jquery.js"}'; |
88
|
|
|
$expectedJson = '{ |
89
|
|
|
"name": "jquery", |
90
|
|
|
"version": "2.0.3", |
91
|
|
|
"main": "jquery.js" |
92
|
|
|
}'; |
93
|
|
|
|
94
|
|
|
$this->httpClient |
95
|
|
|
->shouldReceive('api')->with('repo')->andReturn($repo) |
96
|
|
|
; |
97
|
|
|
|
98
|
|
|
$repo |
|
|
|
|
99
|
|
|
->shouldReceive('contents')->andReturn($contents) |
100
|
|
|
; |
101
|
|
|
|
102
|
|
|
$contents |
103
|
|
|
->shouldReceive('exists')->with('components', 'jquery', 'bower.json', 'master')->andReturn(false)->ordered() |
104
|
|
|
->shouldReceive('exists')->with('components', 'jquery', 'package.json', 'master')->andReturn(true)->ordered() |
105
|
|
|
->shouldReceive('download')->with('components', 'jquery', 'package.json', 'master')->andReturn($bowerJson) |
106
|
|
|
; |
107
|
|
|
|
108
|
|
|
$this->assertEquals($expectedJson, $this->repository->getBower()); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @expectedException \RuntimeException |
113
|
|
|
*/ |
114
|
|
|
public function testGetBowerWithoutBowerJsonNorPackageJson() |
115
|
|
|
{ |
116
|
|
|
$repo = Mockery::mock('Github\Api\Repo'); |
117
|
|
|
$contents = Mockery::mock('Github\Api\Repository\Contents'); |
118
|
|
|
|
119
|
|
|
$this->httpClient |
120
|
|
|
->shouldReceive('api')->with('repo')->andReturn($repo) |
121
|
|
|
; |
122
|
|
|
|
123
|
|
|
$repo |
|
|
|
|
124
|
|
|
->shouldReceive('contents')->andReturn($contents) |
125
|
|
|
; |
126
|
|
|
|
127
|
|
|
$contents |
128
|
|
|
->shouldReceive('exists')->with('components', 'jquery', 'bower.json', 'master')->andReturn(false) |
129
|
|
|
->shouldReceive('exists')->with('components', 'jquery', 'package.json', 'master')->andReturn(false) |
130
|
|
|
->shouldReceive('download')->with('components', 'jquery', 'package.json', 'master')->andThrow(new \RuntimeException()) |
131
|
|
|
; |
132
|
|
|
|
133
|
|
|
$this->repository->getBower(); |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* See issue https://github.com/Bee-Lab/bowerphp/issues/33 |
138
|
|
|
* For some strange reason, Modernizr has package.json ONLY in master :-| |
139
|
|
|
*/ |
140
|
|
|
public function testGetBowerWithPackageJsonOnlyInMaster() |
141
|
|
|
{ |
142
|
|
|
$repo = Mockery::mock('Github\Api\Repo'); |
143
|
|
|
$contents = Mockery::mock('Github\Api\Repository\Contents'); |
144
|
|
|
|
145
|
|
|
$originalJson = '{"name": "jquery", "version": "2.0.3", "main": "jquery.js", "dependencies": {"foo": "bar"}}'; |
146
|
|
|
$expectedJson = '{ |
147
|
|
|
"name": "jquery", |
148
|
|
|
"version": "2.0.3", |
149
|
|
|
"main": "jquery.js" |
150
|
|
|
}'; |
151
|
|
|
|
152
|
|
|
$this->httpClient |
153
|
|
|
->shouldReceive('api')->with('repo')->andReturn($repo) |
154
|
|
|
; |
155
|
|
|
|
156
|
|
|
$repo |
|
|
|
|
157
|
|
|
->shouldReceive('contents')->andReturn($contents) |
158
|
|
|
; |
159
|
|
|
|
160
|
|
|
$contents |
161
|
|
|
->shouldReceive('exists')->with('components', 'jquery', 'bower.json', 'v2.7.2')->andReturn(false)->ordered() |
162
|
|
|
->shouldReceive('exists')->with('components', 'jquery', 'package.json', 'v2.7.2')->andReturn(false)->ordered() |
163
|
|
|
->shouldReceive('exists')->with('components', 'jquery', 'bower.json', 'master')->andReturn(false)->ordered() |
164
|
|
|
->shouldReceive('exists')->with('components', 'jquery', 'package.json', 'master')->andReturn(true)->ordered() |
165
|
|
|
->shouldReceive('download')->with('components', 'jquery', 'package.json', 'master')->andReturn($originalJson) |
166
|
|
|
; |
167
|
|
|
|
168
|
|
|
$this->assertEquals($expectedJson, $this->repository->getBower()); |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
public function testGetBowerWithHomepage() |
172
|
|
|
{ |
173
|
|
|
$repo = Mockery::mock('Github\Api\Repo'); |
174
|
|
|
$contents = Mockery::mock('Github\Api\Repository\Contents'); |
175
|
|
|
|
176
|
|
|
$bower1 = ['name' => 'jquery', 'version' => '2.0.3', 'main' => 'jquery.js']; |
177
|
|
|
$bower2 = ['name' => 'jquery', 'version' => '2.0.3', 'main' => 'jquery.js', 'homepage' => 'https://raw.githubusercontent.com/components/jquery']; |
178
|
|
|
|
179
|
|
|
$this->httpClient |
180
|
|
|
->shouldReceive('api')->with('repo')->andReturn($repo) |
181
|
|
|
; |
182
|
|
|
|
183
|
|
|
$repo |
|
|
|
|
184
|
|
|
->shouldReceive('contents')->andReturn($contents) |
185
|
|
|
; |
186
|
|
|
|
187
|
|
|
$contents |
188
|
|
|
->shouldReceive('exists')->with('components', 'jquery', 'bower.json', 'master')->andReturn(true) |
189
|
|
|
->shouldReceive('download')->with('components', 'jquery', 'bower.json', 'master')->andReturn(json_encode($bower1)) |
190
|
|
|
; |
191
|
|
|
|
192
|
|
|
$this->assertEquals($bower2, json_decode($this->repository->getBower('master', true), true)); |
193
|
|
|
$this->assertEquals($bower2, json_decode($this->repository->getBower('master', true, 'https://raw.githubusercontent.com/components/jquery'), true)); |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
public function testFindPackage() |
197
|
|
|
{ |
198
|
|
|
$tagsJson = '[{"name": "2.0.3", "zipball_url": "https://api.github.com/repos/components/jquery/zipball/2.0.3", "tarball_url": ""}, {"name": "2.0.2", "zipball_url": "", "tarball_url": ""}]'; |
199
|
|
|
$this->mockTagsRequest($tagsJson); |
200
|
|
|
|
201
|
|
|
$tag = $this->repository->findPackage(); |
202
|
|
|
$this->assertEquals('2.0.3', $tag); |
203
|
|
|
} |
204
|
|
|
|
205
|
|
|
public function testFindPackageWithoutTags() |
206
|
|
|
{ |
207
|
|
|
$this->mockTagsRequest('[ ]'); |
208
|
|
|
|
209
|
|
|
$tag = $this->repository->findPackage(); |
210
|
|
|
$this->assertEquals('master', $tag); |
211
|
|
|
} |
212
|
|
|
|
213
|
|
|
/** |
214
|
|
|
* "version with v" = something like "v1.2.3" instead of "1.2.3" |
215
|
|
|
*/ |
216
|
|
|
public function testFindPackageWithVersionWithV() |
217
|
|
|
{ |
218
|
|
|
$tagsJson = '[{"name": "v2.0.3", "zipball_url": "", "tarball_url": ""}, {"name": "v2.0.2", "zipball_url": "", "tarball_url": ""}]'; |
219
|
|
|
$this->mockTagsRequest($tagsJson); |
220
|
|
|
|
221
|
|
|
$tag = $this->repository->findPackage('v2.0.2'); |
222
|
|
|
$this->assertEquals('v2.0.2', $tag); |
223
|
|
|
} |
224
|
|
|
|
225
|
|
|
public function testLatestPackage() |
226
|
|
|
{ |
227
|
|
|
$tagsJson = '[{"name": "v2.0.3", "zipball_url": "", "tarball_url": ""}, {"name": "v2.0.2", "zipball_url": "", "tarball_url": ""}]'; |
228
|
|
|
$this->mockTagsRequest($tagsJson); |
229
|
|
|
|
230
|
|
|
$tag = $this->repository->findPackage('latest'); |
231
|
|
|
$this->assertEquals('v2.0.3', $tag); |
232
|
|
|
} |
233
|
|
|
|
234
|
|
|
/** |
235
|
|
|
* "version with ~" = something like "~1.2.3" |
236
|
|
|
*/ |
237
|
|
|
public function testFindPackageWithVersionWithTilde() |
238
|
|
|
{ |
239
|
|
|
$response = '[{"name": "2.1.4", "zipball_url": "", "tarball_url": ""}, ' |
240
|
|
|
. '{"name": "2.0.5", "zipball_url": "", "tarball_url": ""}, ' |
241
|
|
|
. '{"name": "2.0.4", "zipball_url": "", "tarball_url": ""}, ' |
242
|
|
|
. '{"name": "2.0.3-beta3", "zipball_url": "", "tarball_url": ""}, ' |
243
|
|
|
. '{"name": "2.0.3b1", "zipball_url": "", "tarball_url": ""}, ' |
244
|
|
|
. '{"name": "2.0.3", "zipball_url": "", "tarball_url": ""}]'; |
245
|
|
|
$this->mockTagsRequest($response); |
246
|
|
|
|
247
|
|
|
$tag = $this->repository->findPackage('~2.0.3'); |
248
|
|
|
$this->assertEquals('2.0.5', $tag); |
249
|
|
|
|
250
|
|
|
$tag = $this->repository->findPackage('~2.0'); |
251
|
|
|
$this->assertEquals('2.0.5', $tag); |
252
|
|
|
|
253
|
|
|
$tag = $this->repository->findPackage('~2.1'); |
254
|
|
|
$this->assertEquals('2.1.4', $tag); |
255
|
|
|
} |
256
|
|
|
|
257
|
|
|
/** |
258
|
|
|
* >1.2.3 AND <2.3.4 |
259
|
|
|
*/ |
260
|
|
|
public function testFindPackageWithVersionWithCompund() |
261
|
|
|
{ |
262
|
|
|
$response = '[{"name": "2.1.4", "zipball_url": "", "tarball_url": ""}, ' |
263
|
|
|
. '{"name": "2.0.5", "zipball_url": "", "tarball_url": ""}, ' |
264
|
|
|
. '{"name": "2.0.4", "zipball_url": "", "tarball_url": ""}, ' |
265
|
|
|
. '{"name": "2.0.3-beta3", "zipball_url": "", "tarball_url": ""}, ' |
266
|
|
|
. '{"name": "2.0.3b1", "zipball_url": "", "tarball_url": ""}, ' |
267
|
|
|
. '{"name": "2.0.3", "zipball_url": "", "tarball_url": ""}]'; |
268
|
|
|
$this->mockTagsRequest($response); |
269
|
|
|
|
270
|
|
|
$tag = $this->repository->findPackage('>=2.0.3 <2.0.4'); |
271
|
|
|
$this->assertEquals('2.0.3', $tag); |
272
|
|
|
|
273
|
|
|
$tag = $this->repository->findPackage('>2.0 <2.1.5'); |
274
|
|
|
$this->assertEquals('2.1.4', $tag); |
275
|
|
|
|
276
|
|
|
$tag = $this->repository->findPackage('>2.0.3 <=2.0.4'); |
277
|
|
|
$this->assertEquals('2.0.4', $tag); |
278
|
|
|
} |
279
|
|
|
|
280
|
|
|
/** |
281
|
|
|
* "version with any wildcard" = something like "1.2.x" or "1.2.X" or "1.2.*" |
282
|
|
|
*/ |
283
|
|
|
public function testFindPackageWithVersionWithWildcard() |
284
|
|
|
{ |
285
|
|
|
$response = '[{"name": "2.1.4", "zipball_url": "", "tarball_url": ""}, ' |
286
|
|
|
. '{"name": "2.0.5", "zipball_url": "", "tarball_url": ""}, ' |
287
|
|
|
. '{"name": "2.0.4", "zipball_url": "", "tarball_url": ""}, ' |
288
|
|
|
. '{"name": "2.0.3-beta3", "zipball_url": "", "tarball_url": ""}, ' |
289
|
|
|
. '{"name": "2.0.3b1", "zipball_url": "", "tarball_url": ""}, ' |
290
|
|
|
. '{"name": "2.0.3", "zipball_url": "", "tarball_url": ""},' |
291
|
|
|
. '{"name": "2.0.2", "zipball_url": "", "tarball_url": ""},' |
292
|
|
|
. '{"name": "2.0.1", "zipball_url": "", "tarball_url": ""},' |
293
|
|
|
. '{"name": "2.0.0", "zipball_url": "", "tarball_url": ""}]' |
294
|
|
|
; |
295
|
|
|
$this->mockTagsRequest($response); |
296
|
|
|
|
297
|
|
|
$wildcards = [ |
298
|
|
|
'x', |
299
|
|
|
'X', |
300
|
|
|
'*', |
301
|
|
|
]; |
302
|
|
|
|
303
|
|
|
foreach ($wildcards as $wildcard) { |
304
|
|
|
$tag = $this->repository->findPackage('2.0.' . $wildcard); |
305
|
|
|
$this->assertEquals('2.0.5', $tag); |
306
|
|
|
|
307
|
|
|
$tag = $this->repository->findPackage('2.x.' . $wildcard); |
308
|
|
|
$this->assertEquals('2.1.4', $tag); |
309
|
|
|
} |
310
|
|
|
} |
311
|
|
|
|
312
|
|
|
/** |
313
|
|
|
* Add non-allowed characters, e.g., jquery's wonderful 1.8.3+1 |
314
|
|
|
*/ |
315
|
|
|
public function testFindPackageWithVersionWithJunk() |
316
|
|
|
{ |
317
|
|
|
$response = '[{"name": "2.1.4", "zipball_url": "", "tarball_url": ""}, ' |
318
|
|
|
. '{"name": "2.0.5", "zipball_url": "", "tarball_url": ""}, ' |
319
|
|
|
. '{"name": "2.0.4", "zipball_url": "", "tarball_url": ""}, ' |
320
|
|
|
. '{"name": "2.0.3+1", "zipball_url": "", "tarball_url": ""}, ' |
321
|
|
|
. '{"name": "2.0.3+3", "zipball_url": "", "tarball_url": ""}, ' |
322
|
|
|
. '{"name": "2.0.3", "zipball_url": "", "tarball_url": ""},' |
323
|
|
|
. '{"name": "2.0.2", "zipball_url": "", "tarball_url": ""},' |
324
|
|
|
. '{"name": "2.0.1", "zipball_url": "", "tarball_url": ""},' |
325
|
|
|
. '{"name": "2.0.0", "zipball_url": "", "tarball_url": ""}]' |
326
|
|
|
; |
327
|
|
|
$this->mockTagsRequest($response); |
328
|
|
|
|
329
|
|
|
$tag = $this->repository->findPackage('2.0.*'); |
330
|
|
|
$this->assertEquals('2.0.5', $tag); |
331
|
|
|
|
332
|
|
|
$tag = $this->repository->findPackage('2.0.3'); |
333
|
|
|
$this->assertEquals('2.0.3', $tag); |
334
|
|
|
} |
335
|
|
|
|
336
|
|
|
/** |
337
|
|
|
* @expectedException \RuntimeException |
338
|
|
|
*/ |
339
|
|
|
public function testFindPackageVersionNotFound() |
340
|
|
|
{ |
341
|
|
|
$tagsJson = '[{"name": "2.0.3", "zipball_url": "https://api.github.com/repos/components/jquery/zipball/2.0.3", "tarball_url": ""}, {"name": "2.0.2", "zipball_url": "", "tarball_url": ""}]'; |
342
|
|
|
$this->mockTagsRequest($tagsJson); |
343
|
|
|
|
344
|
|
|
$tag = $this->repository->findPackage('3'); |
345
|
|
|
} |
346
|
|
|
|
347
|
|
|
public function testGetRelease() |
348
|
|
|
{ |
349
|
|
|
$repo = Mockery::mock('Github\Api\Repo'); |
350
|
|
|
$contents = Mockery::mock('Github\Api\Repository\Contents'); |
351
|
|
|
|
352
|
|
|
$this->setTag($this->repository, (['name' => 'foo'])); |
|
|
|
|
353
|
|
|
|
354
|
|
|
$this->httpClient |
355
|
|
|
->shouldReceive('api')->with('repo')->andReturn($repo) |
356
|
|
|
; |
357
|
|
|
|
358
|
|
|
$repo |
|
|
|
|
359
|
|
|
->shouldReceive('contents')->andReturn($contents) |
360
|
|
|
; |
361
|
|
|
|
362
|
|
|
$contents |
363
|
|
|
->shouldReceive('archive')->with('components', 'jquery', 'zipball', 'foo')->andReturn('...') |
364
|
|
|
; |
365
|
|
|
|
366
|
|
|
$this->repository->getRelease(); |
367
|
|
|
} |
368
|
|
|
|
369
|
|
|
public function testGetUrl() |
370
|
|
|
{ |
371
|
|
|
$this->assertEquals('https://raw.githubusercontent.com/components/jquery', $this->repository->getUrl()); |
372
|
|
|
$this->repository->setUrl('git://github.com/components/jquery-ui.git', false); |
373
|
|
|
$this->assertEquals('https://github.com/components/jquery-ui', $this->repository->getUrl()); |
374
|
|
|
} |
375
|
|
|
|
376
|
|
|
public function testClearUrl() |
377
|
|
|
{ |
378
|
|
|
$clearGitURL = $this->getMethod('Bowerphp\Repository\GithubRepository', 'clearGitURL'); |
379
|
|
|
$this->assertEquals('components/jquery', $clearGitURL->invokeArgs($this->repository, ['git://github.com/components/jquery.git'])); |
380
|
|
|
$this->assertEquals('components/jqueryui', $clearGitURL->invokeArgs($this->repository, ['git://github.com/components/jqueryui'])); |
381
|
|
|
$this->assertEquals('MAXakaWIZARD/jquery.appear', $clearGitURL->invokeArgs($this->repository, ['[email protected]:MAXakaWIZARD/jquery.appear.git'])); |
382
|
|
|
$this->assertEquals('components/jqueryui', $clearGitURL->invokeArgs($this->repository, ['https://github.com/components/jqueryui.git'])); |
383
|
|
|
$this->assertEquals('components/jqueryui', $clearGitURL->invokeArgs($this->repository, ['https://github.com/components/jqueryui'])); |
384
|
|
|
$this->assertEquals('components/jqueryui/master/jquery-ui.min.js', $clearGitURL->invokeArgs($this->repository, ['https://raw.githubusercontent.com/components/jqueryui/master/jquery-ui.min.js'])); |
385
|
|
|
} |
386
|
|
|
|
387
|
|
|
public function testGetTags() |
388
|
|
|
{ |
389
|
|
|
$tagJson = '[{"name": "2.0.3", "zipball_url": "https://api.github.com/repos/components/jquery/zipball/2.0.3"}, |
390
|
|
|
{"name": "2.0.3+1", "zipball_url": "https://api.github.com/repos/components/jquery/zipball/2.0.3+1"}, |
391
|
|
|
{"name": "2.0.2", "zipball_url": "https://api.github.com/repos/components/jquery/zipball/2.0.2"}]'; |
392
|
|
|
$this->mockTagsRequest($tagJson); |
393
|
|
|
|
394
|
|
|
$this->assertEquals(['2.0.2', '2.0.3'], $this->repository->getTags()); |
395
|
|
|
} |
396
|
|
|
|
397
|
|
|
public function testGetTagsWithoutTags() |
398
|
|
|
{ |
399
|
|
|
$this->mockTagsRequest('[ ]'); |
400
|
|
|
|
401
|
|
|
$this->assertEquals([], $this->repository->getTags()); |
402
|
|
|
} |
403
|
|
|
|
404
|
|
|
/** |
405
|
|
|
* Set value for protected property $tag |
406
|
|
|
* |
407
|
|
|
* @param GithubRepository $repository |
408
|
|
|
* @param array $value |
409
|
|
|
*/ |
410
|
|
|
protected function setTag(GithubRepository $repository, array $value) |
411
|
|
|
{ |
412
|
|
|
$class = new ReflectionClass('Bowerphp\Repository\GithubRepository'); |
413
|
|
|
$tag = $class->getProperty('tag'); |
414
|
|
|
$tag->setAccessible(true); |
415
|
|
|
$tag->setValue($repository, $value); |
416
|
|
|
} |
417
|
|
|
|
418
|
|
|
/** |
419
|
|
|
* @param string $responseJson |
420
|
|
|
*/ |
421
|
|
|
private function mockTagsRequest($responseJson) |
422
|
|
|
{ |
423
|
|
|
$response = Mockery::mock('Guzzle\Http\Message\Response'); |
424
|
|
|
$repo = Mockery::mock('Github\Api\Repo'); |
425
|
|
|
|
426
|
|
|
$repo |
427
|
|
|
->shouldReceive('setPerPage') |
428
|
|
|
->shouldReceive('getPerPage')->andReturn(30) |
429
|
|
|
->shouldReceive('tags')->with('components', 'jquery')->andReturn(json_decode($responseJson, true)) |
430
|
|
|
; |
431
|
|
|
$this->httpClient |
432
|
|
|
->shouldReceive('api')->with('repo')->andReturn($repo) |
433
|
|
|
; |
434
|
|
|
$this->guzzle |
|
|
|
|
435
|
|
|
->shouldReceive('getLastResponse')->andReturn($response) |
436
|
|
|
; |
437
|
|
|
$response |
438
|
|
|
->shouldReceive('getLastHeader') |
439
|
|
|
->shouldReceive('getHeader') |
440
|
|
|
; |
441
|
|
|
} |
442
|
|
|
} |
443
|
|
|
|
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: