1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Class NominatimClientTest |
4
|
|
|
* |
5
|
|
|
* @author Mauro Moreno <[email protected]> |
6
|
|
|
*/ |
7
|
|
|
namespace MauroMoreno\OpenStreetMap\Client\Tests\Client; |
8
|
|
|
|
9
|
|
|
use MauroMoreno\OpenStreetMap\Client\NominatimClient; |
10
|
|
|
use GuzzleHttp\Client; |
11
|
|
|
use GuzzleHttp\Psr7; |
12
|
|
|
use GuzzleHttp\Handler\MockHandler; |
13
|
|
|
use GuzzleHttp\Psr7\Response; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Class NominatimClientTest |
17
|
|
|
* @package MauroMoreno\Client\Tests\Client |
18
|
|
|
*/ |
19
|
|
|
class NominatimClientTest extends \PHPUnit_Framework_TestCase |
20
|
|
|
{ |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Test valid client |
24
|
|
|
*/ |
25
|
|
|
public function testValidClient() |
26
|
|
|
{ |
27
|
|
|
$client = new NominatimClient(); |
28
|
|
|
$this->assertInstanceOf(Client::class, $client->getGuzzleClient()); |
29
|
|
|
$this->assertEquals( |
30
|
|
|
'http://nominatim.openstreetmap.org', |
31
|
|
|
$client->getGuzzleClient()->getConfig('base_uri') |
32
|
|
|
); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Test reverse, wrong params |
37
|
|
|
* |
38
|
|
|
* @dataProvider setWrongLatitudeAndLongitude |
39
|
|
|
* @expectedException \InvalidArgumentException |
40
|
|
|
*/ |
41
|
|
|
public function testReverseWrongParams($latitude, $longitude) |
42
|
|
|
{ |
43
|
|
|
$client = new NominatimClient(); |
44
|
|
|
$client->reverse($latitude, $longitude); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Test reverse, ok |
49
|
|
|
*/ |
50
|
|
|
public function testReverseOk() |
51
|
|
|
{ |
52
|
|
|
$client = new NominatimClient(); |
53
|
|
|
$mock = new MockHandler( |
54
|
|
|
[ |
55
|
|
|
new Response(200, [], Psr7\stream_for('ABC')), |
56
|
|
|
] |
57
|
|
|
); |
58
|
|
|
$client->getGuzzleClient()->getConfig('handler')->setHandler($mock); |
59
|
|
|
$response = $client->reverse(0.01, 0.01); |
60
|
|
|
$this->assertEquals('ABC', $response->getBody()->getContents()); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Set wrong Latitude and Longitude data provider |
65
|
|
|
* |
66
|
|
|
* @return array |
67
|
|
|
*/ |
68
|
|
|
public function setWrongLatitudeAndLongitude() |
69
|
|
|
{ |
70
|
|
|
return [ |
71
|
|
|
['', 0.00], |
72
|
|
|
[0.00, ''] |
73
|
|
|
]; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
} |
77
|
|
|
|