From 0937d1f68018f5e952a6475411e0898971f6a04b Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Sun, 6 Jan 2013 23:09:50 +0100 Subject: [PATCH] Extract interface for storage --- src/Igorw/Trashbin/Provider.php | 2 +- src/Igorw/Trashbin/RedisStorage.php | 25 +++++++++++++++++++ src/Igorw/Trashbin/Storage.php | 22 +++------------- .../{StorageTest.php => RedisStorageTest.php} | 6 ++--- 4 files changed, 32 insertions(+), 23 deletions(-) create mode 100644 src/Igorw/Trashbin/RedisStorage.php rename tests/unit/{StorageTest.php => RedisStorageTest.php} (67%) diff --git a/src/Igorw/Trashbin/Provider.php b/src/Igorw/Trashbin/Provider.php index 215b69a..beda78b 100644 --- a/src/Igorw/Trashbin/Provider.php +++ b/src/Igorw/Trashbin/Provider.php @@ -23,7 +23,7 @@ public function register(Application $app) }); $app['app.storage'] = $app->share(function ($app) { - return new Storage($app['predis']); + return new RedisStorage($app['predis']); }); $app['app.validator'] = $app->share(function () { diff --git a/src/Igorw/Trashbin/RedisStorage.php b/src/Igorw/Trashbin/RedisStorage.php new file mode 100644 index 0000000..817875d --- /dev/null +++ b/src/Igorw/Trashbin/RedisStorage.php @@ -0,0 +1,25 @@ +redis = $redis; + } + + public function get($id) + { + return $this->redis->hgetall($id); + } + + public function set($id, array $data) + { + return $this->redis->hmset($id, $data); + } +} diff --git a/src/Igorw/Trashbin/Storage.php b/src/Igorw/Trashbin/Storage.php index 308c3b2..6d4e75f 100644 --- a/src/Igorw/Trashbin/Storage.php +++ b/src/Igorw/Trashbin/Storage.php @@ -2,24 +2,8 @@ namespace Igorw\Trashbin; -use Predis\Client; - -class Storage +interface Storage { - private $redis; - - public function __construct(Client $redis) - { - $this->redis = $redis; - } - - public function get($id) - { - return $this->redis->hgetall($id); - } - - public function set($id, array $data) - { - return $this->redis->hmset($id, $data); - } + public function get($id); + public function set($id, array $data); } diff --git a/tests/unit/StorageTest.php b/tests/unit/RedisStorageTest.php similarity index 67% rename from tests/unit/StorageTest.php rename to tests/unit/RedisStorageTest.php index 30e0d98..f625d63 100644 --- a/tests/unit/StorageTest.php +++ b/tests/unit/RedisStorageTest.php @@ -2,13 +2,13 @@ namespace Igorw\Trashbin; -class StorageTest extends \PHPUnit_Framework_TestCase +class RedisStorageTest extends \PHPUnit_Framework_TestCase { public function testGet() { $redis = $this->getMock('Predis\Client'); - $storage = new Storage($redis); + $storage = new RedisStorage($redis); $storage->get('foo'); } @@ -16,7 +16,7 @@ public function testSet() { $redis = $this->getMock('Predis\Client'); - $storage = new Storage($redis); + $storage = new RedisStorage($redis); $storage->set('foo', array('a' => 'b')); } }