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\VenueSearchBuilder; |
13
|
|
|
use Core23\SetlistFm\Connection\ConnectionInterface; |
14
|
|
|
use Core23\SetlistFm\Service\VenueService; |
15
|
|
|
use PHPUnit\Framework\TestCase; |
16
|
|
|
|
17
|
|
|
final class VenueServiceTest extends TestCase |
18
|
|
|
{ |
19
|
|
|
private $connection; |
20
|
|
|
|
21
|
|
|
protected function setUp(): void |
22
|
|
|
{ |
23
|
|
|
$this->connection = $this->prophesize(ConnectionInterface::class); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
public function testGetVenue(): void |
27
|
|
|
{ |
28
|
|
|
$rawResponse = <<<'EOD' |
29
|
|
|
{ |
30
|
|
|
"city" : { |
31
|
|
|
"id" : "5357527", |
32
|
|
|
"name" : "Hollywood", |
33
|
|
|
"stateCode" : "CA", |
34
|
|
|
"state" : "California", |
35
|
|
|
"coords" : { |
36
|
|
|
"long" : -118.3267434, |
37
|
|
|
"lat" : 34.0983425 |
38
|
|
|
}, |
39
|
|
|
"country" : { |
40
|
|
|
"code" : "US", |
41
|
|
|
"name" : "United States" |
42
|
|
|
} |
43
|
|
|
}, |
44
|
|
|
"url" : "https://www.setlist.fm/venue/compaq-center-san-jose-ca-usa-6bd6ca6e.html", |
45
|
|
|
"id" : "6bd6ca6e", |
46
|
|
|
"name" : "Compaq Center" |
47
|
|
|
} |
48
|
|
|
EOD; |
49
|
|
|
|
50
|
|
|
$this->connection->call('venue/6bd6ca6e') |
51
|
|
|
->willReturn(json_decode($rawResponse, true)) |
52
|
|
|
; |
53
|
|
|
|
54
|
|
|
$service = new VenueService($this->connection->reveal()); |
55
|
|
|
$result = $service->getVenue('6bd6ca6e'); |
56
|
|
|
|
57
|
|
|
static::assertSame('6bd6ca6e', $result->getId()); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function testSearch(): void |
61
|
|
|
{ |
62
|
|
|
$rawResponse = <<<'EOD' |
63
|
|
|
{ |
64
|
|
|
"venue" : [ { |
65
|
|
|
"city" : { |
66
|
|
|
"id" : "5357527", |
67
|
|
|
"name" : "Hollywood", |
68
|
|
|
"stateCode" : "CA", |
69
|
|
|
"state" : "California", |
70
|
|
|
"coords" : { }, |
71
|
|
|
"country" : { } |
72
|
|
|
}, |
73
|
|
|
"url" : "https://www.setlist.fm/venue/compaq-center-san-jose-ca-usa-6bd6ca6e.html", |
74
|
|
|
"id" : "6bd6ca6e", |
75
|
|
|
"name" : "Compaq Center" |
76
|
|
|
} ], |
77
|
|
|
"total" : 1, |
78
|
|
|
"page" : 1, |
79
|
|
|
"itemsPerPage" : 20 |
80
|
|
|
} |
81
|
|
|
EOD; |
82
|
|
|
|
83
|
|
|
$this->connection->call('search/venues', ['p' => 1, 'name' => 'Compaq Center']) |
84
|
|
|
->willReturn(json_decode($rawResponse, true)) |
85
|
|
|
; |
86
|
|
|
|
87
|
|
|
$service = new VenueService($this->connection->reveal()); |
88
|
|
|
$result = $service->search(VenueSearchBuilder::create() |
89
|
|
|
->withName('Compaq Center')); |
90
|
|
|
|
91
|
|
|
static::assertCount(1, $result->getResult()); |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|