Skip to content

Commit a6d9e34

Browse files
committed
Re-arrange tests, make sure IP addresses are geocoded.
Fixes #34
1 parent 4cab9bc commit a6d9e34

File tree

9 files changed

+60
-12
lines changed

9 files changed

+60
-12
lines changed

composer.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,14 @@
3434
},
3535
"autoload": {
3636
"psr-4": {
37-
"Toin0u\\Geocoder\\": "src/"
37+
"Toin0u\\Geocoder\\": "src/",
38+
"Toin0u\\GeocoderLaravel\\Tests\\Laravel5_3\\": "tests/Laravel5_3/"
3839
}
3940
},
4041
"autoload-dev": {
4142
"psr-4": {
42-
"Toin0u\\Tests\\Geocoder\\": "tests/"
43+
"Toin0u\\Tests\\Geocoder\\": "tests/Geocoder/",
44+
"Toin0u\\GeocoderLaravel\\Tests\\Laravel5_3\\": "tests/Laravel5_3/"
4345
}
4446
},
4547
"extra": {

config/geocoder.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,9 @@
1818
// Providers get called in the chain order given here.
1919
// The first one to return a result will be used.
2020
'providers' => [
21-
GoogleMaps::class => [
22-
'en_US',
23-
null,
24-
true,
25-
env('GOOGLE_MAPS_API_KEY'),
26-
],
21+
GoogleMaps::class => null,
2722
BingMaps::class => [
28-
'en_US',
23+
'en-US',
2924
env('BING_MAPS_API_KEY'),
3025
],
3126
FreeGeoIp::class => null,

phpunit.xml.dist renamed to phpunit.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@
99
stopOnFailure="false"
1010
syntaxCheck="false"
1111
bootstrap="vendor/autoload.php"
12-
>
12+
>
1313
<testsuites>
1414
<testsuite name="Geocoder library for Laravel Test Suite">
15-
<directory>./tests/</directory>
15+
<directory suffix="Test.php">./tests/Geocoder</directory>
16+
<directory suffix="Test.php">./tests/Laravel5_3</directory>
1617
</testsuite>
1718
</testsuites>
1819
<filter>

src/GeocoderServiceProvider.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@
1313

1414
use Geocoder\ProviderAggregator;
1515
use Geocoder\Provider\Chain;
16+
use Illuminate\Support\ServiceProvider;
1617
use ReflectionClass;
1718

1819
/**
1920
* Geocoder service provider
2021
*
2122
* @author Antoine Corcy <[email protected]>
2223
*/
23-
class GeocoderServiceProvider extends \Illuminate\Support\ServiceProvider
24+
class GeocoderServiceProvider extends ServiceProvider
2425
{
2526
/**
2627
* Bootstrap the application events.
File renamed without changes.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php namespace Toin0u\GeocoderLaravel\Tests\Laravel5_3\Providers;
2+
3+
use Toin0u\GeocoderLaravel\Tests\Laravel5_3\TestCase;
4+
5+
class GeocoderServiceProviderTest extends TestCase
6+
{
7+
public function testItResolvesAGivenAddress()
8+
{
9+
$result = app('geocoder')
10+
->geocode('1600 Pennsylvania Ave., Washington, DC USA')
11+
->all();
12+
$this->assertEquals('1600', $result[0]->getStreetNumber());
13+
$this->assertEquals('Pennsylvania Avenue Southeast', $result[0]->getStreetName());
14+
$this->assertEquals('Washington', $result[0]->getLocality());
15+
$this->assertEquals('20003', $result[0]->getPostalCode());
16+
}
17+
18+
public function testItResolvesAGivenIPAddress()
19+
{
20+
$result = app('geocoder')
21+
->geocode('8.8.8.8')
22+
->all();
23+
$this->assertEquals('US', $result[0]->getCountry()->getCode());
24+
}
25+
}

tests/Laravel5_3/TestCase.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php namespace Toin0u\GeocoderLaravel\Tests\Laravel5_3;
2+
3+
use Illuminate\Contracts\Console\Kernel;
4+
use Illuminate\Foundation\Application;
5+
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
6+
use Illuminate\Foundation\Testing\WithoutMiddleware;
7+
use Illuminate\Foundation\Testing\DatabaseMigrations;
8+
use Illuminate\Foundation\Testing\DatabaseTransactions;
9+
10+
abstract class TestCase extends BaseTestCase
11+
{
12+
use DatabaseMigrations;
13+
use DatabaseTransactions;
14+
15+
protected $baseUrl = 'http://localhost';
16+
17+
public function createApplication() : Application
18+
{
19+
$app = require __DIR__ . '/../../../../../bootstrap/app.php';
20+
$app->make(Kernel::class)->bootstrap();
21+
22+
return $app;
23+
}
24+
}

0 commit comments

Comments
 (0)