From 16d2e2a47fc09b29216da537574cb24a627bcd64 Mon Sep 17 00:00:00 2001 From: Ngoc Linh Pham Date: Mon, 7 Oct 2019 22:50:31 +0700 Subject: [PATCH 1/2] Migrate config key update readme --- README.md | 4 ++-- src/Providers/GoogleDistanceServiceProvider.php | 10 ++++++---- src/config/{distance.php => google-distance.php} | 0 3 files changed, 8 insertions(+), 6 deletions(-) rename src/config/{distance.php => google-distance.php} (100%) diff --git a/README.md b/README.md index 5b6dfcb..e51204a 100755 --- a/README.md +++ b/README.md @@ -14,10 +14,10 @@ Require this package with composer. composer require pnlinh/laravel-google-distance ``` -To publishes config `config/distance.php`, use command: +To publishes config `config/google-distance.php`, use command: ```bash -php artisan vendor:publish --tag="distance-config" +php artisan vendor:publish --tag="google-distance" ``` You must set your [Google Maps API Key](https://developers.google.com/maps/documentation/distance-matrix/get-api-key) GOOGLE_MAPS_DISTANCE_API_KEY in your .env file like so: diff --git a/src/Providers/GoogleDistanceServiceProvider.php b/src/Providers/GoogleDistanceServiceProvider.php index dac7764..8635519 100755 --- a/src/Providers/GoogleDistanceServiceProvider.php +++ b/src/Providers/GoogleDistanceServiceProvider.php @@ -16,9 +16,11 @@ class GoogleDistanceServiceProvider extends ServiceProvider */ public function boot() { - $this->publishes([ - __DIR__.'/../config/distance.php' => config_path('distance.php'), - ], 'distance-config'); + if ($this->app->runningInConsole()) { + $this->publishes([ + __DIR__.'/../config/google-distance.php' => config_path('google-distance.php'), + ], 'google-distance'); + } } /** @@ -29,7 +31,7 @@ public function boot() public function register() { $this->app->singleton('google-distance', function (Container $app) { - return new GoogleDistance($app['config']['distance.api_key']); + return new GoogleDistance($app['config']['google-distance.api_key']); }); $this->app->booting(function () { diff --git a/src/config/distance.php b/src/config/google-distance.php similarity index 100% rename from src/config/distance.php rename to src/config/google-distance.php From 5f57007843c20dad1bf7464158cf1dcaa9c028ea Mon Sep 17 00:00:00 2001 From: Ngoc Linh Pham Date: Mon, 7 Oct 2019 22:50:47 +0700 Subject: [PATCH 2/2] Add service provider test --- .../GoogleDistanceServiceProviderTest.php | 16 ++++++++++++++++ tests/TestCase.php | 1 + 2 files changed, 17 insertions(+) create mode 100644 tests/Feature/GoogleDistanceServiceProviderTest.php diff --git a/tests/Feature/GoogleDistanceServiceProviderTest.php b/tests/Feature/GoogleDistanceServiceProviderTest.php new file mode 100644 index 0000000..b166579 --- /dev/null +++ b/tests/Feature/GoogleDistanceServiceProviderTest.php @@ -0,0 +1,16 @@ +assertInstanceOf(ServiceProvider::class, new GoogleDistanceServiceProvider($this->app)); + } +} diff --git a/tests/TestCase.php b/tests/TestCase.php index 901b140..82801d0 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -20,5 +20,6 @@ public function getPackageProviders($app) public function getEnvironmentSetUp($app) { + $app['config']->set('google-distance.api_key', 'foo'); } }