|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* (c) Christian Gripp <[email protected]> |
|
5
|
|
|
* |
|
6
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
7
|
|
|
* file that was distributed with this source code. |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
namespace Core23\LastFm\Tests\Service; |
|
11
|
|
|
|
|
12
|
|
|
use Core23\LastFm\Connection\ConnectionInterface; |
|
13
|
|
|
use Core23\LastFm\Service\GeoService; |
|
14
|
|
|
use PHPUnit\Framework\TestCase; |
|
15
|
|
|
|
|
16
|
|
|
class GeoServiceTest extends TestCase |
|
17
|
|
|
{ |
|
18
|
|
|
private $connection; |
|
19
|
|
|
|
|
20
|
|
|
protected function setUp() |
|
21
|
|
|
{ |
|
22
|
|
|
$this->connection = $this->prophesize(ConnectionInterface::class); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
public function testItIsInstantiable(): void |
|
26
|
|
|
{ |
|
27
|
|
|
$service = new GeoService($this->connection->reveal()); |
|
28
|
|
|
|
|
29
|
|
|
$this->assertNotNull($service); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public function testGetTopArtists(): void |
|
33
|
|
|
{ |
|
34
|
|
|
$rawResponse = <<<'EOD' |
|
35
|
|
|
a:1:{s:10:"topartists";a:2:{s:6:"artist";a:1:{i:0;a:6:{s:4:"name";s:8:"Coldplay";s:9:"listeners";s:7:"5381410";s:4:"mbid";s:36:"cc197bad-dc9c-440d-a5b5-d52ba2e14234";s:3:"url";s:34:"https://www.last.fm/music/Coldplay";s:10:"streamable";s:1:"0";s:5:"image";a:5:{i:0;a:2:{s:5:"#text";s:78:"https://lastfm-img2.akamaized.net/i/u/34s/5bdb5d4c53504627c62f9e30f48e9063.png";s:4:"size";s:5:"small";}i:1;a:2:{s:5:"#text";s:78:"https://lastfm-img2.akamaized.net/i/u/64s/5bdb5d4c53504627c62f9e30f48e9063.png";s:4:"size";s:6:"medium";}i:2;a:2:{s:5:"#text";s:79:"https://lastfm-img2.akamaized.net/i/u/174s/5bdb5d4c53504627c62f9e30f48e9063.png";s:4:"size";s:5:"large";}i:3;a:2:{s:5:"#text";s:82:"https://lastfm-img2.akamaized.net/i/u/300x300/5bdb5d4c53504627c62f9e30f48e9063.png";s:4:"size";s:10:"extralarge";}i:4;a:2:{s:5:"#text";s:82:"https://lastfm-img2.akamaized.net/i/u/300x300/5bdb5d4c53504627c62f9e30f48e9063.png";s:4:"size";s:4:"mega";}}}}s:5:"@attr";a:5:{s:7:"country";s:7:"Germany";s:4:"page";s:1:"1";s:7:"perPage";s:1:"1";s:10:"totalPages";s:7:"1125116";s:5:"total";s:7:"1125116";}}} |
|
36
|
|
|
EOD; |
|
37
|
|
|
|
|
38
|
|
|
$this->connection->unsignedCall('geo.getTopArtists', [ |
|
39
|
|
|
'country' => 'France', |
|
40
|
|
|
'limit' => 50, |
|
41
|
|
|
'page' => 1, |
|
42
|
|
|
], 'GET') |
|
43
|
|
|
->willReturn(unserialize($rawResponse)) |
|
44
|
|
|
; |
|
45
|
|
|
|
|
46
|
|
|
$service = new GeoService($this->connection->reveal()); |
|
47
|
|
|
$result = $service->getTopArtists('France'); |
|
48
|
|
|
|
|
49
|
|
|
$this->assertCount(1, $result); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
public function testGetTopTracks(): void |
|
53
|
|
|
{ |
|
54
|
|
|
$rawResponse = <<<'EOD' |
|
55
|
|
|
a:1:{s:6:"tracks";a:2:{s:5:"track";a:1:{i:0;a:9:{s:4:"name";s:23:"Smells Like Teen Spirit";s:8:"duration";s:3:"301";s:9:"listeners";s:7:"2065226";s:4:"mbid";s:36:"0ebe2d92-a11d-4b2b-9922-806383074ed7";s:3:"url";s:59:"https://www.last.fm/music/Nirvana/_/Smells+Like+Teen+Spirit";s:10:"streamable";a:2:{s:5:"#text";s:1:"0";s:9:"fulltrack";s:1:"0";}s:6:"artist";a:3:{s:4:"name";s:7:"Nirvana";s:4:"mbid";s:36:"9282c8b4-ca0b-4c6b-b7e3-4f7762dfc4d6";s:3:"url";s:33:"https://www.last.fm/music/Nirvana";}s:5:"image";a:4:{i:0;a:2:{s:5:"#text";s:78:"https://lastfm-img2.akamaized.net/i/u/34s/5e5d836721e245d59946d38acb6d81d8.png";s:4:"size";s:5:"small";}i:1;a:2:{s:5:"#text";s:78:"https://lastfm-img2.akamaized.net/i/u/64s/5e5d836721e245d59946d38acb6d81d8.png";s:4:"size";s:6:"medium";}i:2;a:2:{s:5:"#text";s:79:"https://lastfm-img2.akamaized.net/i/u/174s/5e5d836721e245d59946d38acb6d81d8.png";s:4:"size";s:5:"large";}i:3;a:2:{s:5:"#text";s:82:"https://lastfm-img2.akamaized.net/i/u/300x300/5e5d836721e245d59946d38acb6d81d8.png";s:4:"size";s:10:"extralarge";}}s:5:"@attr";a:1:{s:4:"rank";s:1:"0";}}}s:5:"@attr";a:5:{s:7:"country";s:7:"Germany";s:4:"page";s:1:"1";s:7:"perPage";s:1:"1";s:10:"totalPages";s:8:"10183259";s:5:"total";s:8:"10183259";}}} |
|
56
|
|
|
EOD; |
|
57
|
|
|
|
|
58
|
|
|
$this->connection->unsignedCall('geo.getTopTracks', [ |
|
59
|
|
|
'country' => 'France', |
|
60
|
|
|
'location' => null, |
|
61
|
|
|
'limit' => 50, |
|
62
|
|
|
'page' => 1, |
|
63
|
|
|
], 'GET') |
|
64
|
|
|
->willReturn(unserialize($rawResponse)) |
|
65
|
|
|
; |
|
66
|
|
|
|
|
67
|
|
|
$service = new GeoService($this->connection->reveal()); |
|
68
|
|
|
$result = $service->getTopTracks('France'); |
|
69
|
|
|
|
|
70
|
|
|
$this->assertCount(1, $result); |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|