forked from geocoder-php/Geocoder
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChainTest.php
More file actions
95 lines (76 loc) · 2.76 KB
/
Copy pathChainTest.php
File metadata and controls
95 lines (76 loc) · 2.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?php
namespace Geocoder\Tests\Provider;
use Geocoder\Tests\TestCase;
use Geocoder\Exception\ChainNoResult;
use Geocoder\Provider\Chain;
/**
* @author Markus Bachmann <markus.bachmann@bachi.biz>
*/
class ChainTest extends TestCase
{
public function testAdd()
{
$mock = $this->getMock('Geocoder\Provider\Provider');
$chain = new Chain();
$chain->add($mock);
}
public function testGetName()
{
$chain = new Chain();
$this->assertEquals('chain', $chain->getName());
}
public function testReverse()
{
$mockOne = $this->getMock('Geocoder\\Provider\\Provider');
$mockOne->expects($this->once())
->method('reverse')
->will($this->returnCallback(function () { throw new \Exception; }));
$mockTwo = $this->getMock('Geocoder\\Provider\\Provider');
$mockTwo->expects($this->once())
->method('reverse')
->with('11', '22')
->will($this->returnValue(array('foo' => 'bar')));
$chain = new Chain(array($mockOne, $mockTwo));
$this->assertEquals(array('foo' => 'bar'), $chain->reverse('11', '22'));
}
public function testReverseThrowsChainNoResult()
{
$mockOne = $this->getMock('Geocoder\\Provider\\Provider');
$mockOne->expects($this->exactly(2))
->method('reverse')
->will($this->returnCallback(function () { throw new \Exception; }));
$chain = new Chain(array($mockOne, $mockOne));
try {
$chain->reverse('11', '22');
} catch (ChainNoResult $e) {
$this->assertCount(2, $e->getExceptions());
}
}
public function testGeocode()
{
$mockOne = $this->getMock('Geocoder\\Provider\\Provider');
$mockOne->expects($this->once())
->method('geocode')
->will($this->returnCallback(function () { throw new \Exception; }));
$mockTwo = $this->getMock('Geocoder\\Provider\\Provider');
$mockTwo->expects($this->once())
->method('geocode')
->with('Paris')
->will($this->returnValue(array('foo' => 'bar')));
$chain = new Chain(array($mockOne, $mockTwo));
$this->assertEquals(array('foo' => 'bar'), $chain->geocode('Paris'));
}
public function testGeocodeThrowsChainNoResult()
{
$mockOne = $this->getMock('Geocoder\\Provider\\Provider');
$mockOne->expects($this->exactly(2))
->method('geocode')
->will($this->returnCallback(function () { throw new \Exception; }));
$chain = new Chain(array($mockOne, $mockOne));
try {
$chain->geocode('Paris');
} catch (ChainNoResult $e) {
$this->assertCount(2, $e->getExceptions());
}
}
}