Skip to content

Commit

Permalink
Extract interface for storage
Browse files Browse the repository at this point in the history
  • Loading branch information
igorw committed Jan 6, 2013
1 parent a7d7325 commit 0937d1f
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/Igorw/Trashbin/Provider.php
Expand Up @@ -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 () {
Expand Down
25 changes: 25 additions & 0 deletions src/Igorw/Trashbin/RedisStorage.php
@@ -0,0 +1,25 @@
<?php

namespace Igorw\Trashbin;

use Predis\Client;

class RedisStorage implements 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);
}
}
22 changes: 3 additions & 19 deletions src/Igorw/Trashbin/Storage.php
Expand Up @@ -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);
}
Expand Up @@ -2,21 +2,21 @@

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');
}

public function testSet()
{
$redis = $this->getMock('Predis\Client');

$storage = new Storage($redis);
$storage = new RedisStorage($redis);
$storage->set('foo', array('a' => 'b'));
}
}

0 comments on commit 0937d1f

Please sign in to comment.