Skip to content

Commit

Permalink
Improve quality of some of the integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mikebronner committed Oct 5, 2016
1 parent c63423e commit 6c4ac31
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 7 deletions.
2 changes: 2 additions & 0 deletions src/Providers/GeocoderService.php
Expand Up @@ -25,6 +25,8 @@
*/
class GeocoderService extends ServiceProvider
{
protected $defer = false;

/**
* Bootstrap the application events.
*
Expand Down
62 changes: 56 additions & 6 deletions tests/Laravel5_3/Providers/GeocoderServiceTest.php
Expand Up @@ -7,16 +7,30 @@
use Geocoder\Provider\Chain;
use Geocoder\Provider\FreeGeoIp;
use Geocoder\Provider\GoogleMaps;
use Geocoder\Provider\MaxMindBinary;
use Geocoder\Exception\FunctionNotFound;
use Ivory\HttpAdapter\CurlHttpAdapter;

class GeocoderServiceTest extends TestCase
{
public function setUp()
{
parent::setUp();

app()->register(GeocoderService::class);
}

public function testItResolvesAGivenAddress()
{
// Arrange

// Act
$result = app('geocoder')
->using('chain')
->geocode('1600 Pennsylvania Ave., Washington, DC USA')
->all();

// Assert
$this->assertEquals('1600', $result[0]->getStreetNumber());
$this->assertEquals('Pennsylvania Avenue Southeast', $result[0]->getStreetName());
$this->assertEquals('Washington', $result[0]->getLocality());
Expand All @@ -25,32 +39,68 @@ public function testItResolvesAGivenAddress()

public function testItResolvesAGivenIPAddress()
{
// Arrange

// Act
$result = app('geocoder')
->geocode('8.8.8.8')
->all();

// Assert
$this->assertEquals('US', $result[0]->getCountry()->getCode());
}

public function testItResolvesAGivenAddressWithUmlauts()
{
// Arrange

// Act
$result = app('geocoder')
->geocode('Obere Donaustrasse 22, Wien, Österreich')
->all();

// Assert
$this->assertEquals('22', $result[0]->getStreetNumber());
$this->assertEquals('Obere Donaustraße', $result[0]->getStreetName());
$this->assertEquals('Wien', $result[0]->getLocality());
$this->assertEquals('1020', $result[0]->getPostalCode());
}

public function testItCanUseMaxMindBinaryWithoutProvider()
public function testItResolvesAGivenAddressWithUmlautsInRegion()
{
// Arrange
config()->set('geocoder.providers.Geocoder\Provider\Chain.Geocoder\Provider\GoogleMaps', [
'de-DE',
'Wien, Österreich',
true,
null,
]);
app()->register(GeocoderService::class);

// Act
$result = app('geocoder')
->geocode('1600 Pennsylvania Ave., Washington, DC USA')
->geocode('Obere Donaustrasse 22, Wien, Österreich')
->all();
$this->assertEquals('1600', $result[0]->getStreetNumber());
$this->assertEquals('Pennsylvania Avenue Southeast', $result[0]->getStreetName());
$this->assertEquals('Washington', $result[0]->getLocality());
$this->assertEquals('20003', $result[0]->getPostalCode());

// Assert
$this->assertEquals('22', $result[0]->getStreetNumber());
$this->assertEquals('Obere Donaustraße', $result[0]->getStreetName());
$this->assertEquals('Wien', $result[0]->getLocality());
$this->assertEquals('1020', $result[0]->getPostalCode());
}

public function testItCanUseMaxMindBinaryWithoutProvider()
{
//Arrange
$this->expectException(FunctionNotFound::class);
$provider = new MaxMindBinary('dummy');

// Act
app('geocoder')->registerProvider($provider);

// Assert
// By getting past the constructor parameters requirements, we know we
// are instantiating the provider correctly.
}

public function testItCanUseASpecificProvider()
Expand Down
1 change: 0 additions & 1 deletion tests/Laravel5_3/TestCase.php
Expand Up @@ -19,7 +19,6 @@ public function createApplication()
{
$app = require __DIR__ . '/../../vendor/laravel/laravel/bootstrap/app.php';
$app->make(Kernel::class)->bootstrap();
$app->register(GeocoderService::class);

return $app;
}
Expand Down

0 comments on commit 6c4ac31

Please sign in to comment.