Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Review Required] Drop cache adapter support with Laravel 5.8+ #73

Merged
merged 7 commits into from
Oct 10, 2019
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ phpunit.xml
vendor
bin/
.php_cs.cache
.phpunit.*
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please add the same to /doc/readme.md ?

### Laravel 5.5+

If you don't use auto-discovery, add the `ServiceProvider` to the providers array in `config/app.php`:
Expand Down
6 changes: 2 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
6 changes: 4 additions & 2 deletions src/SwapServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you throw an exception if the class does not exist with a message suggesting to install the php-cache package ?

Copy link
Contributor Author

@kslimani kslimani Oct 10, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added changes in order to throw an exception if PSR-6 adapter or PSR-16 bridge is missing.

}

return null;
Expand Down
16 changes: 7 additions & 9 deletions tests/SwapServiceProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,23 @@ 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,
]);

$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,
]);
Expand All @@ -49,7 +47,7 @@ public function testUnknownService()

public function testEmptyServices()
{
$this->app['swap'];
Assert::assertInstanceOf(Swap::class, $this->app['swap']);
}

public function testSwapIsInjectable()
Expand Down