Skip to content

Commit c969882

Browse files
committed
Refactored: adapters and its tests
1 parent ffd9255 commit c969882

File tree

5 files changed

+35
-22
lines changed

5 files changed

+35
-22
lines changed

src/Geocoder/HttpAdapter/ZendHttpAdapter.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,7 @@ public function getContent($url)
3737
{
3838
try {
3939
$response = $this->client->setUri($url)->send();
40-
41-
if ($response->isSuccess()) {
42-
$content = $response->getBody();
43-
} else {
44-
$content = null;
45-
}
40+
$content = $response->isSuccess() ? $response->getBody() : null;
4641
} catch (\Exception $e) {
4742
$content = null;
4843
}

tests/Geocoder/Tests/HttpAdapter/BuzzHttpAdapterTest.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,30 @@
1111
*/
1212
class BuzzHttpAdapterTest extends TestCase
1313
{
14+
protected $buzz;
15+
1416
protected function setUp()
1517
{
1618
if (!class_exists('Buzz\Browser')) {
1719
$this->markTestSkipped('Buzz library has to be installed');
1820
}
21+
22+
$this->buzz = new BuzzHttpAdapter();
1923
}
2024

2125
public function testGetNullContent()
2226
{
23-
$buzz = new BuzzHttpAdapter();
24-
$this->assertNull($buzz->getContent(null));
27+
$this->assertNull($this->buzz->getContent(null));
2528
}
2629

2730
public function testGetFalseContent()
2831
{
29-
$buzz = new BuzzHttpAdapter();
30-
$this->assertNull($buzz->getContent(false));
32+
$this->assertNull($this->buzz->getContent(false));
33+
}
34+
35+
public function testGetName()
36+
{
37+
$this->assertEquals('buzz', $this->buzz->getName());
3138
}
3239

3340
public function testGetContentWithCustomBrowser()

tests/Geocoder/Tests/HttpAdapter/CurlHttpAdapterTest.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,29 @@
1111
*/
1212
class CurlHttpAdapterTest extends TestCase
1313
{
14+
protected $curl;
15+
1416
protected function setUp()
1517
{
1618
if (!function_exists('curl_init')) {
1719
$this->markTestSkipped('cURL has to be enabled.');
1820
}
21+
22+
$this->curl = new CurlHttpAdapter();
1923
}
2024

2125
public function testGetNullContent()
2226
{
23-
$curl = new CurlHttpAdapter();
24-
$this->assertNull($curl->getContent(null));
27+
$this->assertNull($this->curl->getContent(null));
2528
}
2629

2730
public function testGetFalseContent()
2831
{
29-
$curl = new CurlHttpAdapter();
30-
$this->assertNull($curl->getContent(null));
32+
$this->assertNull($this->curl->getContent(false));
33+
}
34+
35+
public function testGetName()
36+
{
37+
$this->assertEquals('curl', $this->curl->getName());
3138
}
3239
}

tests/Geocoder/Tests/HttpAdapter/GuzzleHttpAdapterTest.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,7 @@ protected function setUp()
2121
}
2222
}
2323

24-
/**
25-
* @covers Geocoder\HttpAdapter\GuzzleHttpAdapter::__construct
26-
*/
27-
public function testCreatesDefaultClient()
24+
public function testGetName()
2825
{
2926
$adapter = new GuzzleHttpAdapter();
3027
$this->assertEquals('guzzle', $adapter->getName());

tests/Geocoder/Tests/HttpAdapter/ZendHttpAdapterTest.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,30 @@
1212
*/
1313
class ZendHttpAdapterTest extends TestCase
1414
{
15+
protected $zend;
16+
1517
protected function setUp()
1618
{
1719
if (!class_exists('Zend\Http\Client')) {
1820
$this->markTestSkipped('Zend library has to be installed');
1921
}
22+
23+
$this->zend = new ZendHttpAdapter();
2024
}
2125

2226
public function testGetNullContent()
2327
{
24-
$zend = new ZendHttpAdapter();
25-
$this->assertNull($zend->getContent(null));
28+
$this->assertNull($this->zend->getContent(null));
2629
}
2730

2831
public function testGetFalseContent()
2932
{
30-
$zend = new ZendHttpAdapter();
31-
$this->assertNull($zend->getContent(false));
33+
$this->assertNull($this->zend->getContent(false));
34+
}
35+
36+
public function testGetName()
37+
{
38+
$this->assertEquals('zend', $this->zend->getName());
3239
}
3340

3441
public function testGetContentWithCustomAdapter()

0 commit comments

Comments
 (0)