Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6934692

Browse files
committed
Change to use Orchastral Testbench for testing
1 parent2cebf12 commit6934692

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-
<testsuitename="Geocoder library for Laravel Test Suite">
17-
<directorysuffix="Test.php">./tests/Laravel5_5</directory>
18-
</testsuite>
19-
</testsuites>
20-
<filter>
21-
<whitelistprocessUncoveredFilesFromWhitelist="true">
22-
<directorysuffix=".php">./src</directory>
23-
</whitelist>
24-
</filter>
15+
<testsuites>
16+
<testsuitename="Browser">
17+
<directorysuffix="Test.php">./tests/Browser</directory>
18+
</testsuite>
19+
20+
<testsuitename="Feature">
21+
<directorysuffix="Test.php">./tests/Feature</directory>
22+
</testsuite>
23+
24+
<testsuitename="Unit">
25+
<directorysuffix="Test.php">./tests/Unit</directory>
26+
</testsuite>
27+
</testsuites>
28+
<filter>
29+
<whitelistprocessUncoveredFilesFromWhitelist="true">
30+
<directorysuffix=".php">./src</directory>
31+
</whitelist>
32+
</filter>
2533
<php>
2634
<envname="APP_KEY"value="base64:Xgs1LQt1GdVHhD6qyYCXnyq61DE3UKqJ5k2SJc+Nw2g="/>
2735
<envname="APP_ENV"value="testing"/>
36+
<envname="APP_URL"value="http://127.0.0.1:8000"/>
2837
<envname="CACHE_DRIVER"value="array"/>
2938
<envname="SESSION_DRIVER"value="array"/>
3039
<envname="QUEUE_DRIVER"value="sync"/>
31-
<envname="DB_CONNECTION"value="sqlite"/>
32-
<envname="DB_DATABASE"value=":memory:"/>
33-
<envname="GOOGLE_MAPS_API_KEY"value="AIzaSyAQXO2koTp27Sx9Nt53ZgpTUHfxYlxnvBI"/>
40+
<envname="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+
<?phpnamespaceGeocoder\Laravel\Tests;
2+
3+
useOrchestra\Testbench\Dusk\TestCaseasBaseTestCase;
4+
5+
abstractclass BrowserTestCaseextends BaseTestCase
6+
{
7+
use CreatesApplication;
8+
9+
publicstaticfunctionsetUpBeforeClass()
10+
{
11+
static::serve();
12+
}
13+
14+
publicstaticfunctiontearDownAfterClass()
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+
<?phpnamespaceGeocoder\Laravel\Tests;
2+
3+
useOrchestra\Database\ConsoleServiceProvider;
4+
useGeocoder\Laravel\Providers\GeocoderService;
5+
6+
trait CreatesApplication
7+
{
8+
publicfunctionsetUp()
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+
protectedfunctiongetPackageProviders($app)
20+
{
21+
return [
22+
GeocoderService::class,
23+
ConsoleServiceProvider::class,
24+
];
25+
}
26+
27+
protectedfunctiongetEnvironmentSetUp($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-
<?phpnamespaceGeocoder\Laravel\Tests\Laravel5_5\Providers;
1+
<?phpnamespaceGeocoder\Laravel\Tests\Feature\Providers;
22

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

@@ -21,38 +22,38 @@
2122
* @SuppressWarnings(PHPMD.TooManyMethods)
2223
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
2324
*/
24-
class GeocoderServiceTestextendsTestCase
25+
class GeocoderServiceTestextendsFeatureTestCase
2526
{
26-
publicfunctionsetUp()
27-
{
28-
parent::setUp();
29-
30-
app()->register(GeocoderService::class);
31-
}
32-
3327
publicfunctiontestItReverseGeocodesCoordinates()
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+
returnstr_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
publicfunctiontestItResolvesAGivenAddress()
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
publicfunctiontestItResolvesAGivenIPAddress()
@@ -99,23 +100,26 @@ public function testItResolvesAGivenAddressWithUmlautsInRegion()
99100

100101
publicfunctiontestItCanUseASpecificProvider()
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
publicfunctiontestItDumpsAndAddress()
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
publicfunctiontestCacheIsUsed()
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
publicfunctiontestGeocodeQueryProvidesResults()
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
publicfunctiontestFacadeProvidesResults()
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
publicfunctiontestItCanUseMaxMindBinaryWithoutProvider()
208213
{
209-
$provider =newMaxMindBinary(__DIR__ .'/../../assets/GeoIP.dat');
210-
214+
$provider =newMaxMindBinary(__DIR__ .'/../../resources/assets/GeoIP.dat');
211215
app('geocoder')->registerProvider($provider);
212216
}
213217

@@ -232,11 +236,11 @@ public function testLimitingOfResults()
232236
publicfunctiontestFetchingAllResults()
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
publicfunctiontestItProvidesState()
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
publicfunctiontestItProvidesAdminLevel()
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+
<?phpnamespaceGeocoder\Laravel\Tests;
2+
3+
useOrchestra\Testbench\BrowserKit\TestCaseasBaseTestCase;
4+
5+
abstractclass FeatureTestCaseextends 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)

[8]ページ先頭

©2009-2025 Movatter.jp