Skip to content

Commit 6934692

Browse files
committed
Change to use Orchastral Testbench for testing
1 parent 2cebf12 commit 6934692

File tree

13 files changed

+174
-95
lines changed

13 files changed

+174
-95
lines changed

composer.json

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,26 +23,31 @@
2323
}
2424
],
2525
"require": {
26-
"php-http/curl-client": "^1.7",
2726
"geocoder-php/chain-provider": "^4.0",
2827
"geocoder-php/geo-plugin-provider": "^4.0",
2928
"geocoder-php/google-maps-provider": "^4.0",
3029
"guzzlehttp/psr7": "*",
3130
"illuminate/cache": "5.0 - 5.5",
3231
"illuminate/support": "5.0 - 5.5",
32+
"php-http/curl-client": "^1.7",
3333
"php": "^7.0",
3434
"willdurand/geocoder": "^4.0"
3535
},
3636
"require-dev": {
37-
"codedungeon/phpunit-result-printer": "^0.4.4",
37+
"codedungeon/phpunit-result-printer": "*",
3838
"doctrine/dbal": "^2.5",
3939
"fzaninotto/faker": "~1.4",
4040
"geocoder-php/bing-maps-provider": "^4.0",
41+
"geocoder-php/geoip2-provider": "^4.0",
4142
"geocoder-php/maxmind-binary-provider": "^4.0",
4243
"laravel/laravel": "5.5.*",
4344
"mockery/mockery": "0.9.*",
44-
"php-coveralls/php-coveralls": "^2.0",
45-
"phpunit/phpunit": "~5.0",
45+
"orchestra/database": "^3.5",
46+
"orchestra/testbench": "^3.5",
47+
"orchestra/testbench-browser-kit": "^3.5",
48+
"orchestra/testbench-dusk": "3.5.x-dev@dev",
49+
"php-coveralls/php-coveralls": "*",
50+
"phpunit/phpunit": "*",
4651
"sebastian/phpcpd": "*"
4752
},
4853
"autoload": {

config/geocoder.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,21 @@
6464
*/
6565
'adapter' => Client::class,
6666

67+
/*
68+
|--------------------------------------------------------------------------
69+
| Reader
70+
|--------------------------------------------------------------------------
71+
|
72+
| You can specify a reader for specific providers, like GeoIp2, which
73+
| connect to a local file-database. The reader should be set to an
74+
| instance of the required reader class.
75+
|
76+
| Please consult the official Geocoder documentation for more info.
77+
| https://github.com/geocoder-php/geoip2-provider
78+
|
79+
| Default: null
80+
|
81+
*/
82+
'reader' => null,
83+
6784
];

phpunit.xml

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,31 @@
1212
stopOnFailure="false"
1313
syntaxCheck="false"
1414
>
15-
<testsuites>
16-
<testsuite name="Geocoder library for Laravel Test Suite">
17-
<directory suffix="Test.php">./tests/Laravel5_5</directory>
18-
</testsuite>
19-
</testsuites>
20-
<filter>
21-
<whitelist processUncoveredFilesFromWhitelist="true">
22-
<directory suffix=".php">./src</directory>
23-
</whitelist>
24-
</filter>
15+
<testsuites>
16+
<testsuite name="Browser">
17+
<directory suffix="Test.php">./tests/Browser</directory>
18+
</testsuite>
19+
20+
<testsuite name="Feature">
21+
<directory suffix="Test.php">./tests/Feature</directory>
22+
</testsuite>
23+
24+
<testsuite name="Unit">
25+
<directory suffix="Test.php">./tests/Unit</directory>
26+
</testsuite>
27+
</testsuites>
28+
<filter>
29+
<whitelist processUncoveredFilesFromWhitelist="true">
30+
<directory suffix=".php">./src</directory>
31+
</whitelist>
32+
</filter>
2533
<php>
2634
<env name="APP_KEY" value="base64:Xgs1LQt1GdVHhD6qyYCXnyq61DE3UKqJ5k2SJc+Nw2g="/>
2735
<env name="APP_ENV" value="testing"/>
36+
<env name="APP_URL" value="http://127.0.0.1:8000"/>
2837
<env name="CACHE_DRIVER" value="array"/>
2938
<env name="SESSION_DRIVER" value="array"/>
3039
<env name="QUEUE_DRIVER" value="sync"/>
31-
<env name="DB_CONNECTION" value="sqlite"/>
32-
<env name="DB_DATABASE" value=":memory:"/>
33-
<env name="GOOGLE_MAPS_API_KEY" value="AIzaSyAQXO2koTp27Sx9Nt53ZgpTUHfxYlxnvBI"/>
40+
<env name="DB_CONNECTION" value="testing"/>
3441
</php>
3542
</phpunit>

tests/BrowserTestCase.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php namespace Geocoder\Laravel\Tests;
2+
3+
use Orchestra\Testbench\Dusk\TestCase as BaseTestCase;
4+
5+
abstract class BrowserTestCase extends BaseTestCase
6+
{
7+
use CreatesApplication;
8+
9+
public static function setUpBeforeClass()
10+
{
11+
static::serve();
12+
}
13+
14+
public static function tearDownAfterClass()
15+
{
16+
static::stopServing();
17+
}
18+
}

tests/CreatesApplication.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php namespace Geocoder\Laravel\Tests;
2+
3+
use Orchestra\Database\ConsoleServiceProvider;
4+
use Geocoder\Laravel\Providers\GeocoderService;
5+
6+
trait CreatesApplication
7+
{
8+
public function setUp()
9+
{
10+
parent::setUp();
11+
12+
$this->withFactories(__DIR__ . '/database/factories');
13+
$this->loadMigrationsFrom(__DIR__ . '/database/migrations');
14+
}
15+
16+
/**
17+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
18+
*/
19+
protected function getPackageProviders($app)
20+
{
21+
return [
22+
GeocoderService::class,
23+
ConsoleServiceProvider::class,
24+
];
25+
}
26+
27+
protected function getEnvironmentSetUp($app)
28+
{
29+
$config = require(__DIR__ . '/config/testConfig.php');
30+
$app['config']->set('geocoder', $config);
31+
}
32+
}

tests/Laravel5_5/Providers/GeocoderServiceTest.php renamed to tests/Feature/Providers/GeocoderServiceTest.php

Lines changed: 57 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
1-
<?php namespace Geocoder\Laravel\Tests\Laravel5_5\Providers;
1+
<?php namespace Geocoder\Laravel\Tests\Feature\Providers;
22

33
use Geocoder\Exception\FunctionNotFound;
4-
use Geocoder\Laravel\Tests\Laravel5_5\TestCase;
54
use Geocoder\Laravel\Exceptions\InvalidDumperException;
65
use Geocoder\Laravel\Facades\Geocoder;
76
use Geocoder\Laravel\ProviderAndDumperAggregator;
7+
use Geocoder\Laravel\Tests\FeatureTestCase;
88
use Geocoder\Laravel\Providers\GeocoderService;
9+
use Geocoder\Model\Coordinates;
910
use Geocoder\Provider\Chain\Chain;
1011
use Geocoder\Provider\GeoPlugin\GeoPlugin;
11-
use Geocoder\Provider\MaxMindBinary\MaxMindBinary;
1212
use Geocoder\Provider\GoogleMaps\GoogleMaps;
13+
use Geocoder\Provider\GoogleMaps\Model\GoogleAddress;
14+
use Geocoder\Provider\MaxMindBinary\MaxMindBinary;
1315
use Geocoder\Query\GeocodeQuery;
1416
use Geocoder\Query\ReverseQuery;
15-
use Geocoder\Model\Coordinates;
1617
use Http\Client\Curl\Client as CurlAdapter;
1718
use Illuminate\Support\Collection;
1819

@@ -21,38 +22,38 @@
2122
* @SuppressWarnings(PHPMD.TooManyMethods)
2223
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
2324
*/
24-
class GeocoderServiceTest extends TestCase
25+
class GeocoderServiceTest extends FeatureTestCase
2526
{
26-
public function setUp()
27-
{
28-
parent::setUp();
29-
30-
app()->register(GeocoderService::class);
31-
}
32-
3327
public function testItReverseGeocodesCoordinates()
3428
{
35-
$results = app('geocoder')->reverse(38.8791981, -76.9818437)->get();
36-
37-
$this->assertEquals('1600', $results->first()->getStreetNumber());
38-
$this->assertEquals('Pennsylvania Avenue Southeast', $results->first()->getStreetName());
39-
$this->assertEquals('Washington', $results->first()->getLocality());
40-
$this->assertEquals('20003', $results->first()->getPostalCode());
41-
$this->assertTrue($results->isNotEmpty());
29+
$result = app('geocoder')
30+
->reverse(38.897957, -77.036560)
31+
->get()
32+
->filter(function (GoogleAddress $address) {
33+
return str_contains($address->getStreetName() ?? '', 'Northwest');
34+
})
35+
->first();
36+
37+
$this->assertNotNull($result);
38+
$this->assertEquals('1600', $result->getStreetNumber());
39+
$this->assertEquals('Pennsylvania Avenue Northwest', $result->getStreetName());
40+
$this->assertEquals('Washington', $result->getLocality());
41+
$this->assertEquals('20500', $result->getPostalCode());
4242
}
4343

4444
public function testItResolvesAGivenAddress()
4545
{
46-
$results = app('geocoder')
46+
$result = app('geocoder')
4747
->using('chain')
48-
->geocode('1600 Pennsylvania Ave., Washington, DC USA')
49-
->get();
48+
->geocode('1600 Pennsylvania Ave NW, Washington, DC 20500, USA')
49+
->get()
50+
->first();
5051

51-
$this->assertEquals('1600', $results->first()->getStreetNumber());
52-
$this->assertEquals('Pennsylvania Avenue Northwest', $results->first()->getStreetName());
53-
$this->assertEquals('Washington', $results->first()->getLocality());
54-
$this->assertEquals('20500', $results->first()->getPostalCode());
55-
$this->assertTrue($results->isNotEmpty());
52+
$this->assertNotNull($result);
53+
$this->assertEquals('1600', $result->getStreetNumber());
54+
$this->assertEquals('Pennsylvania Avenue Northwest', $result->getStreetName());
55+
$this->assertEquals('Washington', $result->getLocality());
56+
$this->assertEquals('20500', $result->getPostalCode());
5657
}
5758

5859
public function testItResolvesAGivenIPAddress()
@@ -99,23 +100,26 @@ public function testItResolvesAGivenAddressWithUmlautsInRegion()
99100

100101
public function testItCanUseASpecificProvider()
101102
{
102-
$results = app('geocoder')
103+
$result = app('geocoder')
103104
->using('google_maps')
104-
->geocode('1600 Pennsylvania Ave., Washington, DC USA')
105-
->get();
106-
$this->assertEquals('1600', $results->first()->getStreetNumber());
107-
$this->assertEquals('Pennsylvania Avenue Northwest', $results->first()->getStreetName());
108-
$this->assertEquals('Washington', $results->first()->getLocality());
109-
$this->assertEquals('20500', $results->first()->getPostalCode());
110-
$this->assertTrue($results->isNotEmpty());
105+
->geocode('1600 Pennsylvania Ave NW, Washington, DC 20500, USA')
106+
->get()
107+
->first();
108+
109+
$this->assertNotNull($result);
110+
$this->assertEquals('1600', $result->getStreetNumber());
111+
$this->assertEquals('Pennsylvania Avenue Northwest', $result->getStreetName());
112+
$this->assertEquals('Washington', $result->getLocality());
113+
$this->assertEquals('20500', $result->getPostalCode());
111114
}
112115

113116
public function testItDumpsAndAddress()
114117
{
115118
$results = app('geocoder')
116119
->using('google_maps')
117-
->geocode('1600 Pennsylvania Ave., Washington, DC USA')
120+
->geocode('1600 Pennsylvania Ave NW, Washington, DC 20500, USA')
118121
->dump('geojson');
122+
119123
$jsonAddress = json_decode($results->first());
120124

121125
$this->assertEquals('1600', $jsonAddress->properties->streetNumber);
@@ -127,7 +131,7 @@ public function testItThrowsAnExceptionForInvalidDumper()
127131
$this->expectException(InvalidDumperException::class);
128132
$results = app('geocoder')
129133
->using('google_maps')
130-
->geocode('1600 Pennsylvania Ave., Washington, DC USA')
134+
->geocode('1600 Pennsylvania Ave NW, Washington, DC 20500, USA')
131135
->dump('test');
132136
$jsonAddress = json_decode($results->first());
133137

@@ -160,9 +164,9 @@ public function testGeocoder()
160164

161165
public function testCacheIsUsed()
162166
{
163-
$cacheKey = str_slug(strtolower(urlencode('1600 Pennsylvania Ave., Washington, DC USA')));
167+
$cacheKey = str_slug(strtolower(urlencode('1600 Pennsylvania Ave NW, Washington, DC 20500, USA')));
164168

165-
$result = app('geocoder')->geocode('1600 Pennsylvania Ave., Washington, DC USA')
169+
$result = app('geocoder')->geocode('1600 Pennsylvania Ave NW, Washington, DC 20500, USA')
166170
->get();
167171

168172
$this->assertTrue(app('cache')->has("geocoder-{$cacheKey}"));
@@ -174,7 +178,7 @@ public function testCacheIsUsed()
174178
*/
175179
public function testGeocodeQueryProvidesResults()
176180
{
177-
$query = GeocodeQuery::create('1600 Pennsylvania Ave., Washington, DC USA');
181+
$query = GeocodeQuery::create('1600 Pennsylvania Ave NW, Washington, DC 20500, USA');
178182

179183
$results = app('geocoder')->geocodeQuery($query)->get();
180184

@@ -198,16 +202,16 @@ public function testReverseQueryProvidesResults()
198202

199203
public function testFacadeProvidesResults()
200204
{
201-
$results = Geocoder::geocode('1600 Pennsylvania Ave., Washington, DC USA')->get();
205+
$results = Geocoder::geocode('1600 Pennsylvania Ave NW, Washington, DC 20500, USA')
206+
->get();
202207

203208
$this->assertInstanceOf(Collection::class, $results);
204209
$this->assertTrue($results->isNotEmpty());
205210
}
206211

207212
public function testItCanUseMaxMindBinaryWithoutProvider()
208213
{
209-
$provider = new MaxMindBinary(__DIR__ . '/../../assets/GeoIP.dat');
210-
214+
$provider = new MaxMindBinary(__DIR__ . '/../../resources/assets/GeoIP.dat');
211215
app('geocoder')->registerProvider($provider);
212216
}
213217

@@ -232,11 +236,11 @@ public function testLimitingOfResults()
232236
public function testFetchingAllResults()
233237
{
234238
$expectedResults = app('geocoder')
235-
->geocode('1600 Pennsylvania Ave., Washington, DC USA')
239+
->geocode('1600 Pennsylvania Ave NW, Washington, DC 20500, USA')
236240
->get()
237241
->all();
238242
$actualResults = app('geocoder')
239-
->geocode('1600 Pennsylvania Ave., Washington, DC USA')
243+
->geocode('1600 Pennsylvania Ave NW, Washington, DC 20500, USA')
240244
->all();
241245

242246
$this->assertEquals($expectedResults, $actualResults);
@@ -265,20 +269,25 @@ public function testJapaneseCharacterGeocoding()
265269
app('geocoder')->geocode('108-0075 東京都港区港南2丁目16-3')
266270
->get();
267271

268-
$this->assertEquals($cacheKey, '108-0075e69db1e4baace983bde6b8afe58cbae6b8afe58d97efbc92e4b881e79baeefbc91efbc96efbc8defbc93');
272+
$this->assertEquals(
273+
$cacheKey,
274+
'108-0075e69db1e4baace983bde6b8afe58cbae6b8afe58d97efbc92e4b881e79baeefbc91efbc96efbc8defbc93'
275+
);
269276
$this->assertTrue(app('cache')->has("geocoder-{$cacheKey}"));
270277
}
271278

272279
public function testItProvidesState()
273280
{
274-
$results = Geocoder::geocode('1600 Pennsylvania Ave., Washington, DC USA')->get();
281+
$results = Geocoder::geocode('1600 Pennsylvania Ave NW, Washington, DC 20500, USA')
282+
->get();
275283

276284
$this->assertEquals('Washington', $results->first()->getLocality());
277285
}
278286

279287
public function testItProvidesAdminLevel()
280288
{
281-
$results = Geocoder::geocode('1600 Pennsylvania Ave., Washington, DC USA')->get();
289+
$results = Geocoder::geocode('1600 Pennsylvania Ave NW, Washington, DC 20500, USA')
290+
->get();
282291

283292
$this->assertEquals('District of Columbia', $results->first()->getAdminLevels()->first()->getName());
284293
}

tests/FeatureTestCase.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php namespace Geocoder\Laravel\Tests;
2+
3+
use Orchestra\Testbench\BrowserKit\TestCase as BaseTestCase;
4+
5+
abstract class FeatureTestCase extends BaseTestCase
6+
{
7+
use CreatesApplication;
8+
}

tests/Laravel5_5/CreatesApplication.php

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)