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