1 | <?php |
||
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 |