Skip to content

Commit 6c4ac31

Browse files
committed
Improve quality of some of the integration tests
1 parent c63423e commit 6c4ac31

File tree

3 files changed

+58
-7
lines changed

3 files changed

+58
-7
lines changed

src/Providers/GeocoderService.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
*/
2626
class GeocoderService extends ServiceProvider
2727
{
28+
protected $defer = false;
29+
2830
/**
2931
* Bootstrap the application events.
3032
*

tests/Laravel5_3/Providers/GeocoderServiceTest.php

Lines changed: 56 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,30 @@
77
use Geocoder\Provider\Chain;
88
use Geocoder\Provider\FreeGeoIp;
99
use Geocoder\Provider\GoogleMaps;
10+
use Geocoder\Provider\MaxMindBinary;
11+
use Geocoder\Exception\FunctionNotFound;
1012
use Ivory\HttpAdapter\CurlHttpAdapter;
1113

1214
class GeocoderServiceTest extends TestCase
1315
{
16+
public function setUp()
17+
{
18+
parent::setUp();
19+
20+
app()->register(GeocoderService::class);
21+
}
22+
1423
public function testItResolvesAGivenAddress()
1524
{
25+
// Arrange
26+
27+
// Act
1628
$result = app('geocoder')
1729
->using('chain')
1830
->geocode('1600 Pennsylvania Ave., Washington, DC USA')
1931
->all();
32+
33+
// Assert
2034
$this->assertEquals('1600', $result[0]->getStreetNumber());
2135
$this->assertEquals('Pennsylvania Avenue Southeast', $result[0]->getStreetName());
2236
$this->assertEquals('Washington', $result[0]->getLocality());
@@ -25,32 +39,68 @@ public function testItResolvesAGivenAddress()
2539

2640
public function testItResolvesAGivenIPAddress()
2741
{
42+
// Arrange
43+
44+
// Act
2845
$result = app('geocoder')
2946
->geocode('8.8.8.8')
3047
->all();
48+
49+
// Assert
3150
$this->assertEquals('US', $result[0]->getCountry()->getCode());
3251
}
3352

3453
public function testItResolvesAGivenAddressWithUmlauts()
3554
{
55+
// Arrange
56+
57+
// Act
3658
$result = app('geocoder')
3759
->geocode('Obere Donaustrasse 22, Wien, Österreich')
3860
->all();
61+
62+
// Assert
3963
$this->assertEquals('22', $result[0]->getStreetNumber());
4064
$this->assertEquals('Obere Donaustraße', $result[0]->getStreetName());
4165
$this->assertEquals('Wien', $result[0]->getLocality());
4266
$this->assertEquals('1020', $result[0]->getPostalCode());
4367
}
4468

45-
public function testItCanUseMaxMindBinaryWithoutProvider()
69+
public function testItResolvesAGivenAddressWithUmlautsInRegion()
4670
{
71+
// Arrange
72+
config()->set('geocoder.providers.Geocoder\Provider\Chain.Geocoder\Provider\GoogleMaps', [
73+
'de-DE',
74+
'Wien, Österreich',
75+
true,
76+
null,
77+
]);
78+
app()->register(GeocoderService::class);
79+
80+
// Act
4781
$result = app('geocoder')
48-
->geocode('1600 Pennsylvania Ave., Washington, DC USA')
82+
->geocode('Obere Donaustrasse 22, Wien, Österreich')
4983
->all();
50-
$this->assertEquals('1600', $result[0]->getStreetNumber());
51-
$this->assertEquals('Pennsylvania Avenue Southeast', $result[0]->getStreetName());
52-
$this->assertEquals('Washington', $result[0]->getLocality());
53-
$this->assertEquals('20003', $result[0]->getPostalCode());
84+
85+
// Assert
86+
$this->assertEquals('22', $result[0]->getStreetNumber());
87+
$this->assertEquals('Obere Donaustraße', $result[0]->getStreetName());
88+
$this->assertEquals('Wien', $result[0]->getLocality());
89+
$this->assertEquals('1020', $result[0]->getPostalCode());
90+
}
91+
92+
public function testItCanUseMaxMindBinaryWithoutProvider()
93+
{
94+
//Arrange
95+
$this->expectException(FunctionNotFound::class);
96+
$provider = new MaxMindBinary('dummy');
97+
98+
// Act
99+
app('geocoder')->registerProvider($provider);
100+
101+
// Assert
102+
// By getting past the constructor parameters requirements, we know we
103+
// are instantiating the provider correctly.
54104
}
55105

56106
public function testItCanUseASpecificProvider()

tests/Laravel5_3/TestCase.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ public function createApplication()
1919
{
2020
$app = require __DIR__ . '/../../vendor/laravel/laravel/bootstrap/app.php';
2121
$app->make(Kernel::class)->bootstrap();
22-
$app->register(GeocoderService::class);
2322

2423
return $app;
2524
}

0 commit comments

Comments
 (0)