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\SetlistFm\Tests\Service; |
11
|
|
|
|
12
|
|
|
use Core23\SetlistFm\Builder\ArtistSearchBuilder; |
13
|
|
|
use Core23\SetlistFm\Connection\ConnectionInterface; |
14
|
|
|
use Core23\SetlistFm\Service\ArtistService; |
15
|
|
|
use PHPUnit\Framework\TestCase; |
16
|
|
|
|
17
|
|
|
class ArtistServiceTest extends TestCase |
18
|
|
|
{ |
19
|
|
|
private $connection; |
20
|
|
|
|
21
|
|
|
protected function setUp() |
22
|
|
|
{ |
23
|
|
|
$this->connection = $this->prophesize(ConnectionInterface::class); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
public function testItIsInstantiable(): void |
27
|
|
|
{ |
28
|
|
|
$service = new ArtistService($this->connection->reveal()); |
29
|
|
|
|
30
|
|
|
$this->assertNotNull($service); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function testGetArtist(): void |
34
|
|
|
{ |
35
|
|
|
$rawResponse = <<<'EOD' |
36
|
|
|
{ |
37
|
|
|
"mbid" : "b10bbbfc-cf9e-42e0-be17-e2c3e1d2600d", |
38
|
|
|
"tmid" : 735610, |
39
|
|
|
"name" : "The Beatles", |
40
|
|
|
"sortName" : "Beatles, The", |
41
|
|
|
"disambiguation" : "John, Paul, George and Ringo", |
42
|
|
|
"url" : "https://www.setlist.fm/setlists/the-beatles-23d6a88b.html" |
43
|
|
|
} |
44
|
|
|
EOD; |
45
|
|
|
|
46
|
|
|
$this->connection->call('artist/b10bbbfc-cf9e-42e0-be17-e2c3e1d2600d') |
47
|
|
|
->willReturn(json_decode($rawResponse, true)) |
48
|
|
|
; |
49
|
|
|
|
50
|
|
|
$service = new ArtistService($this->connection->reveal()); |
51
|
|
|
$result = $service->getArtist('b10bbbfc-cf9e-42e0-be17-e2c3e1d2600d'); |
52
|
|
|
|
53
|
|
|
$this->assertNotNull($result); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function testSearch(): void |
57
|
|
|
{ |
58
|
|
|
$rawResponse = <<<'EOD' |
59
|
|
|
{ |
60
|
|
|
"artist" : [ { |
61
|
|
|
"mbid" : "b10bbbfc-cf9e-42e0-be17-e2c3e1d2600d", |
62
|
|
|
"tmid" : 735610, |
63
|
|
|
"name" : "The Beatles", |
64
|
|
|
"sortName" : "Beatles, The", |
65
|
|
|
"disambiguation" : "John, Paul, George and Ringo", |
66
|
|
|
"url" : "https://www.setlist.fm/setlists/the-beatles-23d6a88b.html" |
67
|
|
|
}], |
68
|
|
|
"total" : 1, |
69
|
|
|
"page" : 1, |
70
|
|
|
"itemsPerPage" : 20 |
71
|
|
|
} |
72
|
|
|
EOD; |
73
|
|
|
|
74
|
|
|
$this->connection->call('search/artists', ['p' => 1, 'artistName' => 'The Beatles']) |
75
|
|
|
->willReturn(json_decode($rawResponse, true)) |
76
|
|
|
; |
77
|
|
|
|
78
|
|
|
$service = new ArtistService($this->connection->reveal()); |
79
|
|
|
$result = $service->search(ArtistSearchBuilder::create() |
80
|
|
|
->withName('The Beatles')); |
81
|
|
|
|
82
|
|
|
$this->assertCount(1, $result); |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|