Skip to content

Commit ae08bec

Browse files
committed
Merge pull request #213 from toin0u/master
Set a custom result factory via a setter
2 parents 1a4f69d + b641072 commit ae08bec

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/Geocoder/Geocoder.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,16 @@ class Geocoder implements GeocoderInterface
4444
*/
4545
public function __construct(ProviderInterface $provider = null, ResultFactory $resultFactory = null)
4646
{
47-
$this->provider = $provider;
47+
$this->provider = $provider;
48+
49+
$this->setResultFactory($resultFactory);
50+
}
51+
52+
/**
53+
* @param ResultFactory $resultFactory
54+
*/
55+
public function setResultFactory(ResultFactory $resultFactory = null)
56+
{
4857
$this->resultFactory = $resultFactory ?: new ResultFactory();
4958
}
5059

tests/Geocoder/Tests/GeocoderTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,19 @@ public function testUseCustomResultFactory()
126126
$this->assertInstanceOf('Geocoder\Tests\DummyResult', $geocoder->returnResult(array()));
127127
}
128128

129+
public function testSetAndUseCustomResultFactory()
130+
{
131+
$factoryMock = $this->getMock('Geocoder\Result\ResultFactory');
132+
$factoryMock
133+
->expects($this->once())
134+
->method('newInstance')
135+
->will($this->returnValue(new DummyResult()));
136+
137+
$geocoder = new TestableGeocoder(null);
138+
$geocoder->setResultFactory($factoryMock);
139+
$this->assertInstanceOf('Geocoder\Tests\DummyResult', $geocoder->returnResult(array()));
140+
}
141+
129142
protected function assertEmptyResult($result)
130143
{
131144
$this->assertEquals(0, $result->getLatitude());

0 commit comments

Comments
 (0)