|
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\Connection\ConnectionInterface; |
|
13
|
|
|
use Core23\SetlistFm\Service\UserService; |
|
14
|
|
|
use PHPUnit\Framework\TestCase; |
|
15
|
|
|
|
|
16
|
|
|
final class UserServiceTest extends TestCase |
|
17
|
|
|
{ |
|
18
|
|
|
private $connection; |
|
19
|
|
|
|
|
20
|
|
|
protected function setUp(): void |
|
21
|
|
|
{ |
|
22
|
|
|
$this->connection = $this->prophesize(ConnectionInterface::class); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
public function testGetUser(): void |
|
26
|
|
|
{ |
|
27
|
|
|
$rawResponse = <<<'EOD' |
|
28
|
|
|
{ |
|
29
|
|
|
"userId": "Metal-42", |
|
30
|
|
|
"fullname": "Max", |
|
31
|
|
|
"about": "Some dummy text", |
|
32
|
|
|
"website": "http://example.com", |
|
33
|
|
|
"url": "https://www.setlist.fm/user/Metal-42" |
|
34
|
|
|
} |
|
35
|
|
|
EOD; |
|
36
|
|
|
|
|
37
|
|
|
$this->connection->call('user/Metal-42') |
|
38
|
|
|
->willReturn(json_decode($rawResponse, true)) |
|
39
|
|
|
; |
|
40
|
|
|
|
|
41
|
|
|
$service = new UserService($this->connection->reveal()); |
|
42
|
|
|
$result = $service->getUser('Metal-42'); |
|
43
|
|
|
|
|
44
|
|
|
static::assertSame('Metal-42', $result->getId()); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public function testGetEdits(): void |
|
48
|
|
|
{ |
|
49
|
|
|
$rawResponse = <<<'EOD' |
|
50
|
|
|
{ |
|
51
|
|
|
"setlist" : [ { |
|
52
|
|
|
"artist" : { |
|
53
|
|
|
"mbid" : "b10bbbfc-cf9e-42e0-be17-e2c3e1d2600d", |
|
54
|
|
|
"tmid" : 735610, |
|
55
|
|
|
"name" : "The Beatles", |
|
56
|
|
|
"sortName" : "Beatles, The", |
|
57
|
|
|
"disambiguation" : "John, Paul, George and Ringo", |
|
58
|
|
|
"url" : "https://www.setlist.fm/setlists/the-beatles-23d6a88b.html" |
|
59
|
|
|
}, |
|
60
|
|
|
"venue" : { |
|
61
|
|
|
"city" : { }, |
|
62
|
|
|
"url" : "https://www.setlist.fm/venue/compaq-center-san-jose-ca-usa-6bd6ca6e.html", |
|
63
|
|
|
"id" : "6bd6ca6e", |
|
64
|
|
|
"name" : "Compaq Center" |
|
65
|
|
|
}, |
|
66
|
|
|
"tour" : { |
|
67
|
|
|
"name" : "North American Tour 1964" |
|
68
|
|
|
}, |
|
69
|
|
|
"info" : "Recorded and published as 'The Beatles at the Hollywood Bowl'", |
|
70
|
|
|
"url" : "https://www.setlist.fm/setlist/the-beatles/1964/hollywood-bowl-hollywood-ca-63de4613.html", |
|
71
|
|
|
"id" : "63de4613", |
|
72
|
|
|
"versionId" : "7be1aaa0", |
|
73
|
|
|
"eventDate" : "23-08-1964", |
|
74
|
|
|
"lastUpdated" : "2013-10-20T05:18:08.000+0000" |
|
75
|
|
|
} ], |
|
76
|
|
|
"total" : 1, |
|
77
|
|
|
"page" : 1, |
|
78
|
|
|
"itemsPerPage" : 20 |
|
79
|
|
|
} |
|
80
|
|
|
EOD; |
|
81
|
|
|
|
|
82
|
|
|
$this->connection->call('user/42/edited', ['p' => 1]) |
|
83
|
|
|
->willReturn(json_decode($rawResponse, true)) |
|
84
|
|
|
; |
|
85
|
|
|
|
|
86
|
|
|
$service = new UserService($this->connection->reveal()); |
|
87
|
|
|
$result = $service->getEdits('42'); |
|
88
|
|
|
|
|
89
|
|
|
static::assertCount(1, $result); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
public function testGetAttends(): void |
|
93
|
|
|
{ |
|
94
|
|
|
$rawResponse = <<<'EOD' |
|
95
|
|
|
{ |
|
96
|
|
|
"setlist" : [ { |
|
97
|
|
|
"artist" : { |
|
98
|
|
|
"mbid" : "b10bbbfc-cf9e-42e0-be17-e2c3e1d2600d", |
|
99
|
|
|
"tmid" : 735610, |
|
100
|
|
|
"name" : "The Beatles", |
|
101
|
|
|
"sortName" : "Beatles, The", |
|
102
|
|
|
"disambiguation" : "John, Paul, George and Ringo", |
|
103
|
|
|
"url" : "https://www.setlist.fm/setlists/the-beatles-23d6a88b.html" |
|
104
|
|
|
}, |
|
105
|
|
|
"venue" : { |
|
106
|
|
|
"city" : { }, |
|
107
|
|
|
"url" : "https://www.setlist.fm/venue/compaq-center-san-jose-ca-usa-6bd6ca6e.html", |
|
108
|
|
|
"id" : "6bd6ca6e", |
|
109
|
|
|
"name" : "Compaq Center" |
|
110
|
|
|
}, |
|
111
|
|
|
"tour" : { |
|
112
|
|
|
"name" : "North American Tour 1964" |
|
113
|
|
|
}, |
|
114
|
|
|
"info" : "Recorded and published as 'The Beatles at the Hollywood Bowl'", |
|
115
|
|
|
"url" : "https://www.setlist.fm/setlist/the-beatles/1964/hollywood-bowl-hollywood-ca-63de4613.html", |
|
116
|
|
|
"id" : "63de4613", |
|
117
|
|
|
"versionId" : "7be1aaa0", |
|
118
|
|
|
"eventDate" : "23-08-1964", |
|
119
|
|
|
"lastUpdated" : "2013-10-20T05:18:08.000+0000" |
|
120
|
|
|
}], |
|
121
|
|
|
"total" : 1, |
|
122
|
|
|
"page" : 1, |
|
123
|
|
|
"itemsPerPage" : 20 |
|
124
|
|
|
} |
|
125
|
|
|
EOD; |
|
126
|
|
|
|
|
127
|
|
|
$this->connection->call('user/42/attended', ['p' => 1]) |
|
128
|
|
|
->willReturn(json_decode($rawResponse, true)) |
|
129
|
|
|
; |
|
130
|
|
|
|
|
131
|
|
|
$service = new UserService($this->connection->reveal()); |
|
132
|
|
|
$result = $service->getAttends('42'); |
|
133
|
|
|
|
|
134
|
|
|
static::assertCount(1, $result); |
|
135
|
|
|
} |
|
136
|
|
|
} |
|
137
|
|
|
|