|
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\CitySearchBuilder; |
|
13
|
|
|
use Core23\SetlistFm\Connection\ConnectionInterface; |
|
14
|
|
|
use Core23\SetlistFm\Service\CityService; |
|
15
|
|
|
use PHPUnit\Framework\TestCase; |
|
16
|
|
|
|
|
17
|
|
|
final class CityServiceTest 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 testGetCity(): void |
|
27
|
|
|
{ |
|
28
|
|
|
$rawResponse = <<<'EOD' |
|
29
|
|
|
{ |
|
30
|
|
|
"id" : "5357527", |
|
31
|
|
|
"name" : "Hollywood", |
|
32
|
|
|
"stateCode" : "CA", |
|
33
|
|
|
"state" : "California", |
|
34
|
|
|
"coords" : { |
|
35
|
|
|
"long" : -118.3267434, |
|
36
|
|
|
"lat" : 34.0983425 |
|
37
|
|
|
}, |
|
38
|
|
|
"country" : { |
|
39
|
|
|
"code" : "US", |
|
40
|
|
|
"name" : "United States" |
|
41
|
|
|
} |
|
42
|
|
|
} |
|
43
|
|
|
EOD; |
|
44
|
|
|
|
|
45
|
|
|
$this->connection->call('city/5357527') |
|
46
|
|
|
->willReturn(json_decode($rawResponse, true)) |
|
47
|
|
|
; |
|
48
|
|
|
|
|
49
|
|
|
$service = new CityService($this->connection->reveal()); |
|
50
|
|
|
$result = $service->getCity(5357527); |
|
51
|
|
|
|
|
52
|
|
|
static::assertSame('Hollywood', $result->getName()); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function testSearch(): void |
|
56
|
|
|
{ |
|
57
|
|
|
$rawResponse = <<<'EOD' |
|
58
|
|
|
{ |
|
59
|
|
|
"cities" : [ { |
|
60
|
|
|
"id" : "5357527", |
|
61
|
|
|
"name" : "Hollywood", |
|
62
|
|
|
"stateCode" : "CA", |
|
63
|
|
|
"state" : "California", |
|
64
|
|
|
"coords" : { |
|
65
|
|
|
"long" : -118.3267434, |
|
66
|
|
|
"lat" : 34.0983425 |
|
67
|
|
|
}, |
|
68
|
|
|
"country" : { |
|
69
|
|
|
"code" : "US", |
|
70
|
|
|
"name" : "United States" |
|
71
|
|
|
} |
|
72
|
|
|
} ], |
|
73
|
|
|
"total" : 1, |
|
74
|
|
|
"page" : 1, |
|
75
|
|
|
"itemsPerPage" : 20 |
|
76
|
|
|
} |
|
77
|
|
|
EOD; |
|
78
|
|
|
|
|
79
|
|
|
$this->connection->call('search/cities', ['p' => 1, 'name' => 'Hollywood']) |
|
80
|
|
|
->willReturn(json_decode($rawResponse, true)) |
|
81
|
|
|
; |
|
82
|
|
|
|
|
83
|
|
|
$service = new CityService($this->connection->reveal()); |
|
84
|
|
|
$result = $service->search(CitySearchBuilder::create() |
|
85
|
|
|
->withName('Hollywood')); |
|
86
|
|
|
|
|
87
|
|
|
static::assertCount(1, $result->getResult()); |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|