diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..d243d3b --- /dev/null +++ b/.travis.yml @@ -0,0 +1,12 @@ +language: php +sudo: false +php: + - '7.0' + - '7.1' + +install: + - composer install --no-interaction --prefer-source + - composer require laravel/lumen-framework + +script: + - php vendor/bin/phpunit \ No newline at end of file diff --git a/composer.json b/composer.json index a59dea0..0611eaa 100644 --- a/composer.json +++ b/composer.json @@ -1,14 +1,20 @@ { "name": "websight/l5-google-cloud-storage", - "description": "Laravel 5 Flysystem Google Cloud Storage Service Provider", + "description": "Laravel 5 Flysystem Google Cloud Storage Service Provider", "require": { "illuminate/filesystem": "~5.0.17|5.1.*|5.2.*|5.3.*|5.4.*|5.5.*", "illuminate/support": "~5.0.17|5.1.*|5.2.*|5.3.*|5.4.*|5.5.*", "cedricziel/flysystem-gcs": "^1.0" }, - "keywords": ["laravel", "laravel5", "flysystem"], + "require-dev": { + "phpunit/phpunit": "^6.5" + }, + "keywords": ["laravel", "laravel5", "flysystem", "lumen"], "homepage": "https://github.com/websightgmbh/l5-google-cloud-storage", "license": "MIT", + "suggest": { + "laravel/lumen-framework": "To test the Lumen bindings" + }, "authors": [ { "name": "Cedric Ziel", @@ -17,7 +23,8 @@ ], "autoload": { "psr-4": { - "Websight\\GcsProvider\\": "src/Websight/GcsProvider/" + "Websight\\GcsProvider\\": "src/Websight/GcsProvider/", + "Websight\\GcsProvider\\Tests\\": "src/Websight/GcsProvider/tests/" } }, "extra": { diff --git a/phpunit.xml b/phpunit.xml new file mode 100644 index 0000000..07758f7 --- /dev/null +++ b/phpunit.xml @@ -0,0 +1,18 @@ + + + + + + tests + + + + + + src + + tests + + + + \ No newline at end of file diff --git a/src/Websight/GcsProvider/CloudStorageServiceProvider.php b/src/Websight/GcsProvider/CloudStorageServiceProvider.php index a002185..4c98562 100644 --- a/src/Websight/GcsProvider/CloudStorageServiceProvider.php +++ b/src/Websight/GcsProvider/CloudStorageServiceProvider.php @@ -3,7 +3,7 @@ namespace Websight\GcsProvider; use CedricZiel\FlysystemGcs\GoogleCloudStorageAdapter; -use Google\Cloud\ServiceBuilder; +use Google\Cloud\Storage\StorageClient; use Illuminate\Support\ServiceProvider; use League\Flysystem\Filesystem; use Storage; @@ -35,7 +35,7 @@ public function boot() if (array_key_exists('credentials', $config) && false === empty($config['credentials'])) { $serviceBuilderConfig += ['keyFilePath' => $config['credentials']]; - $optionalServiceBuilder = new ServiceBuilder($serviceBuilderConfig); + $optionalServiceBuilder = new StorageClient($serviceBuilderConfig); } $adapter = new GoogleCloudStorageAdapter($optionalServiceBuilder, $adapterConfiguration); @@ -43,4 +43,54 @@ public function boot() return new Filesystem($adapter); }); } + + /** + * Register bindings in the container. + * + * @return void + */ + public function register() + { + if (!$this->app->has('filesystem')) { + $this->app->singleton('filesystem', function ($app) { + /** @var \Laravel\Lumen\Application $app */ + return $app->loadComponent( + 'filesystems', + \Illuminate\Filesystem\FilesystemServiceProvider::class, + 'filesystem' + ); + }); + + $this->app->singleton( + \Illuminate\Contracts\Filesystem\Factory::class, + function ($app) { + return new \Illuminate\Filesystem\FilesystemManager($app); + } + ); + } + + $this->registerFacades(); + } + + /** + * Register Storage facade. + * + * @return void + */ + protected function registerFacades() + { + if (!class_exists('Storage')) { + class_alias(\Illuminate\Support\Facades\Storage::class, 'Storage'); + } + } + + /** + * Decides wheter the current app is lumen. + * + * @return bool + */ + protected function isLumen() + { + return str_contains($this->app->version(), 'Lumen'); + } } diff --git a/tests/LumenSupportTest.php b/tests/LumenSupportTest.php new file mode 100644 index 0000000..f99c7ff --- /dev/null +++ b/tests/LumenSupportTest.php @@ -0,0 +1,62 @@ +markTestSkipped(); + } + + $this->app = $this->setupApplication(); + $this->provider = $this->setupServiceProvider($this->app); + + parent::setUp(); + } + + protected function setupApplication() + { + $app = new Application(sys_get_temp_dir()); + $app->instance('config', new Repository()); + + $app->withFacades(); + + return $app; + } + + protected function setupServiceProvider(Application $app) + { + $provider = new CloudStorageServiceProvider($app); + $app->register($provider); + $provider->boot(); + + return $provider; + } + + public function testFacadeIsExists() + { + $this->assertTrue(class_exists('Storage')); + } + + public function testRequiredProvidersAreRegistered() + { + $this->assertTrue($this->app->has('filesystem')); + } +}