From 0fd38a5fce2ea3c65859abce25e22e0da6214fe0 Mon Sep 17 00:00:00 2001 From: Karim Slimani Date: Mon, 30 Sep 2019 17:32:40 +0200 Subject: [PATCH 1/7] chore(composer): drop default cache adapter requirements Upgrade test bench for Laravel 6. --- composer.json | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index 0d481a5..f6a638c 100644 --- a/composer.json +++ b/composer.json @@ -32,12 +32,10 @@ }, "require": { "php": "^7.1.3", - "florianv/swap": "^4.0", - "cache/illuminate-adapter": "^0.2.0", - "cache/simple-cache-bridge": "^1.0" + "florianv/swap": "^4.0" }, "require-dev": { - "graham-campbell/testbench": "~5.2", + "graham-campbell/testbench": "^5.3", "php-http/guzzle6-adapter": "^1.0", "nyholm/psr7": "^1.0" }, From d5849f6e6c36b93b737fd99d621346535a804416 Mon Sep 17 00:00:00 2001 From: Karim Slimani Date: Mon, 30 Sep 2019 17:34:29 +0200 Subject: [PATCH 2/7] chore: update git ignore file --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 0602d69..273fe7b 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ phpunit.xml vendor bin/ .php_cs.cache +.phpunit.* From 055a0f487d3db2da84499419066aa249cc5fb6c7 Mon Sep 17 00:00:00 2001 From: Karim Slimani Date: Mon, 30 Sep 2019 17:34:50 +0200 Subject: [PATCH 3/7] test: fix PHPUnit 8 deprecation warnings --- tests/SwapServiceProviderTest.php | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/tests/SwapServiceProviderTest.php b/tests/SwapServiceProviderTest.php index abfe5b8..8c06915 100644 --- a/tests/SwapServiceProviderTest.php +++ b/tests/SwapServiceProviderTest.php @@ -21,12 +21,11 @@ class SwapServiceProviderTest extends AbstractTestCase { use ServiceProviderTrait; - /** - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage The "access_key" option must be provided. - */ public function testMissingServiceConfig() { + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('The "access_key" option must be provided.'); + $this->app->config->set('swap.services', [ 'currency_layer' => true, ]); @@ -34,12 +33,11 @@ public function testMissingServiceConfig() $this->app['swap']; } - /** - * @expectedException \LogicException - * @expectedExceptionMessage The service "unknown" is not registered. - */ public function testUnknownService() { + $this->expectException(\LogicException::class); + $this->expectExceptionMessage('The service "unknown" is not registered.'); + $this->app->config->set('swap.services', [ 'unknown' => true, ]); @@ -49,7 +47,7 @@ public function testUnknownService() public function testEmptyServices() { - $this->app['swap']; + Assert::assertInstanceOf(Swap::class, $this->app['swap']); } public function testSwapIsInjectable() From c859098a7582337d337c0be287c61fb2a67dec43 Mon Sep 17 00:00:00 2001 From: Karim Slimani Date: Mon, 30 Sep 2019 17:35:40 +0200 Subject: [PATCH 4/7] feat: check if cache store implements cache interface --- src/SwapServiceProvider.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/SwapServiceProvider.php b/src/SwapServiceProvider.php index 6bab127..6606103 100644 --- a/src/SwapServiceProvider.php +++ b/src/SwapServiceProvider.php @@ -99,9 +99,11 @@ private function getConfigPath($path = '') private function getSimpleCache() { if ($cache = $this->app->config->get('swap.cache')) { - $store = $this->app['cache']->store($cache)->getStore(); + $store = $this->app['cache']->store($cache); - return new SimpleCacheBridge(new IlluminateCachePool($store)); + return $store instanceof \Psr\SimpleCache\CacheInterface + ? $store + : new SimpleCacheBridge(new IlluminateCachePool($store->getStore())); } return null; From 9643090dfc831be5bf31ad54ef71d6ba987cb3bc Mon Sep 17 00:00:00 2001 From: Karim Slimani Date: Mon, 30 Sep 2019 17:44:19 +0200 Subject: [PATCH 5/7] docs: update readme file --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.md b/README.md index cbdacbe..60be8ff 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,16 @@ Swap allows you to retrieve currency exchange rates from various services such a $ composer require php-http/curl-client nyholm/psr7 php-http/message florianv/laravel-swap ``` +### Laravel 5.7 or lesser + +If you use cache, add also cache adapter dependencies : + +```bash +$ composer require cache/illuminate-adapter cache/simple-cache-bridge +``` + +These dependencies are not required with Laravel 5.8 or greater. + ### Laravel 5.5+ If you don't use auto-discovery, add the `ServiceProvider` to the providers array in `config/app.php`: From 84bd21137c9361e24161f133a27693f81b847a1d Mon Sep 17 00:00:00 2001 From: Karim Slimani Date: Thu, 10 Oct 2019 13:24:23 +0200 Subject: [PATCH 6/7] feat: ensure PSR-6 adapter & PSR-16 bridge classes exists --- src/SwapServiceProvider.php | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/SwapServiceProvider.php b/src/SwapServiceProvider.php index 6606103..9b47016 100644 --- a/src/SwapServiceProvider.php +++ b/src/SwapServiceProvider.php @@ -101,9 +101,24 @@ private function getSimpleCache() if ($cache = $this->app->config->get('swap.cache')) { $store = $this->app['cache']->store($cache); - return $store instanceof \Psr\SimpleCache\CacheInterface - ? $store - : new SimpleCacheBridge(new IlluminateCachePool($store->getStore())); + // Check simple cache PSR-16 compatibility + if ($store instanceof \Psr\SimpleCache\CacheInterface) { + return $store; + } + + // Ensure PSR-6 adapter class exists + if (! class_exists(IlluminateCachePool::class)) { + throw new \Exception("cache/illuminate-adapter dependency is missing"); + } + + // Ensure PSR-16 bridge class exists + if (! class_exists(SimpleCacheBridge::class)) { + throw new \Exception("cache/simple-cache-bridge dependency is missing"); + } + + return new SimpleCacheBridge( + new IlluminateCachePool($store->getStore()) + ); } return null; From 83bc8d7abae9a6179bc1a0010e311d7289eedc73 Mon Sep 17 00:00:00 2001 From: Karim Slimani Date: Thu, 10 Oct 2019 13:37:16 +0200 Subject: [PATCH 7/7] docs: add more info about Laravel PSR-16 conformity --- README.md | 4 ++-- doc/readme.md | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 60be8ff..94e26ab 100644 --- a/README.md +++ b/README.md @@ -17,13 +17,13 @@ $ composer require php-http/curl-client nyholm/psr7 php-http/message florianv/la ### Laravel 5.7 or lesser -If you use cache, add also cache adapter dependencies : +If you use cache, add also PSR-6 adapter and PSR-16 bridge cache dependencies : ```bash $ composer require cache/illuminate-adapter cache/simple-cache-bridge ``` -These dependencies are not required with Laravel 5.8 or greater. +These dependencies are not required with Laravel 5.8 or greater which [implements PSR-16](https://github.com/laravel/framework/pull/27217). ### Laravel 5.5+ diff --git a/doc/readme.md b/doc/readme.md index 6a8cf9a..838f754 100644 --- a/doc/readme.md +++ b/doc/readme.md @@ -56,6 +56,16 @@ Copy the package config to your local config with the publish command: $ php artisan vendor:publish --provider="Swap\Laravel\SwapServiceProvider" ``` +__Laravel 5.7 or lesser :__ + +If you use cache, add also PSR-6 adapter and PSR-16 bridge cache dependencies : + +```bash +$ composer require cache/illuminate-adapter cache/simple-cache-bridge +``` + +These dependencies are not required with Laravel 5.8 or greater which [implements PSR-16](https://github.com/laravel/framework/pull/27217). + ### Lumen Configure the Service Provider and alias: