1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the Geocoder package. |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
* |
10
|
|
|
* @license MIT License |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace Geocoder\Provider\Chain\Tests; |
14
|
|
|
|
15
|
|
|
use Geocoder\Model\AddressCollection; |
16
|
|
|
use Geocoder\Query\GeocodeQuery; |
17
|
|
|
use Geocoder\Query\ReverseQuery; |
18
|
|
|
use Geocoder\Provider\Provider; |
19
|
|
|
use Geocoder\Provider\Chain\Chain; |
20
|
|
|
use PHPUnit\Framework\TestCase; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @author Markus Bachmann <[email protected]> |
24
|
|
|
*/ |
25
|
|
|
class ChainTest extends TestCase |
26
|
|
|
{ |
27
|
|
|
public function testAdd() |
28
|
|
|
{ |
29
|
|
|
$mock = $this->getMockBuilder('Geocoder\Provider\Provider')->getMock(); |
30
|
|
|
$chain = new Chain(); |
31
|
|
|
|
32
|
|
|
$chain->add($mock); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function testGetName() |
36
|
|
|
{ |
37
|
|
|
$chain = new Chain(); |
38
|
|
|
$this->assertEquals('chain', $chain->getName()); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function testReverse() |
42
|
|
|
{ |
43
|
|
|
$mockOne = $this->getMockBuilder(Provider::class)->getMock(); |
44
|
|
|
$mockOne->expects($this->once()) |
45
|
|
|
->method('reverseQuery') |
46
|
|
|
->will($this->returnCallback(function () { |
47
|
|
|
throw new \Exception(); |
48
|
|
|
})); |
49
|
|
|
|
50
|
|
|
$mockTwo = $this->getMockBuilder('Geocoder\\Provider\\Provider')->getMock(); |
51
|
|
|
$result = new AddressCollection(['foo' => 'bar']); |
52
|
|
|
$mockTwo->expects($this->once()) |
53
|
|
|
->method('reverseQuery') |
54
|
|
|
->will($this->returnValue($result)); |
55
|
|
|
|
56
|
|
|
$chain = new Chain([$mockOne, $mockTwo]); |
57
|
|
|
|
58
|
|
|
$this->assertEquals($result, $chain->reverseQuery(ReverseQuery::fromCoordinates(11, 22))); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function testGeocode() |
62
|
|
|
{ |
63
|
|
|
$query = GeocodeQuery::create('Paris'); |
64
|
|
|
$mockOne = $this->getMockBuilder('Geocoder\\Provider\\Provider')->getMock(); |
65
|
|
|
$mockOne->expects($this->once()) |
66
|
|
|
->method('geocodeQuery') |
67
|
|
|
->will($this->returnCallback(function () { |
68
|
|
|
throw new \Exception(); |
69
|
|
|
})); |
70
|
|
|
|
71
|
|
|
$mockTwo = $this->getMockBuilder('Geocoder\\Provider\\Provider')->getMock(); |
72
|
|
|
$result = new AddressCollection(['foo' => 'bar']); |
73
|
|
|
$mockTwo->expects($this->once()) |
74
|
|
|
->method('geocodeQuery') |
75
|
|
|
->with($query) |
76
|
|
|
->will($this->returnValue($result)); |
77
|
|
|
|
78
|
|
|
$chain = new Chain([$mockOne, $mockTwo]); |
79
|
|
|
|
80
|
|
|
$this->assertEquals($result, $chain->geocodeQuery($query)); |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|