Permalink
Browse files

set connection object into Redis::connection on tests()

  • Loading branch information...
1 parent 5a16347 commit 0cf7fb6275249bb98525ec7e278c52ffad33d424 @d1rk d1rk committed Mar 14, 2013
View
@@ -7,13 +7,11 @@ before_install:
- wget -O phpredis.tar.gz --no-check-certificate https://github.com/nicolasff/phpredis/tarball/master
- tar -xzf phpredis.tar.gz
- sh -c "cd nicolasff-phpredis-* && phpize && ./configure && make && sudo make install"
- # - echo "extension=redis.so" > redis.ini && phpenv config-add redis.ini
- - echo "extension=redis.so" >> `php --ini | grep "Loaded Configuration" | sed -e "s|.*:\s*||"`
+ - echo "extension=redis.so" > redis.ini && phpenv config-add redis.ini
before_script:
- - php -m
+ # install lithium
- cd ../
- git clone git://github.com/UnionOfRAD/framework.git
- - cp -fr li3_redis/tests/data/connections.php framework/app/config/bootstrap/connections.php
- sed -i -e 's|// Libraries::add('li3_docs');|Libraries::add('li3_redis');|' framework/app/config/bootstrap/libraries.php
- mv li3_redis/ framework/app/libraries/li3_redis
- cd framework
@@ -18,36 +18,15 @@
*/
class RedisTest extends \lithium\test\Unit {
- /**
- * Connection configuration.
- */
- protected $_connectionConfig = array();
-
- /**
- * Connection to the database.
- */
- public $connection = null;
-
- /**
- * Skip the test if a Redis adapter configuration is unavailable.
- */
- // public function skip() {
- // $this->skipIf(!Redis::enabled(), 'The Redis extension is not loaded!');
-
- // $this->_connectionConfig = Connections::get('li3_redis', array('config' => true));
- // $hasDb = (isset($this->_connectionConfig['type']) && $this->_connectionConfig['type'] == 'Redis');
- // $message = 'Test database is either unavailable, or not a Redis connection!';
- // $this->skipIf(!$hasDb, $message);
-
- // $this->connection = new Redis($this->_connectionConfig);
- // $this->connection->select(1);
- // }
+ public function skip() {
+ $this->skipIf(!Redis::enabled(), 'The Redis extension is not loaded!');
+ }
- // public function testEnabled() {
- // $this->assertTrue(Redis::enabled());
- // $this->assertTrue(Redis::enabled('transactions'));
- // $this->assertFalse(Redis::enabled('relations'));
- // }
+ public function testEnabled() {
+ $this->assertTrue(Redis::enabled());
+ $this->assertTrue(Redis::enabled('transactions'));
+ $this->assertFalse(Redis::enabled('relations'));
+ }
public function testDefaults() {
$expected = array(
@@ -69,14 +48,18 @@ public function testDefaults() {
}
public function testConnect() {
- $result = new Redis($this->_connectionConfig);
+ $result = new Redis(array());
+ $this->assertTrue($result->isConnected());
+ $this->assertTrue(is_array($result->connection->config('GET', '*')));
+ $this->assertTrue(is_array($result->connection->info()));
+ $result = new Redis;
$this->assertTrue($result->isConnected());
$this->assertTrue(is_array($result->connection->config('GET', '*')));
$this->assertTrue(is_array($result->connection->info()));
}
public function testDisconnect() {
- $redis = new Redis($this->_connectionConfig);
+ $redis = new Redis(array());
$this->assertTrue($redis->isConnected());
$this->assertTrue($redis->disconnect());
$this->assertFalse($redis->isConnected());
@@ -8,8 +8,8 @@
namespace li3_redis\tests\cases\storage;
-use li3_redis\storage\Leaderboard;
use li3_redis\storage\Redis;
+use li3_redis\storage\Leaderboard;
use lithium\data\Connections;
use Redis as RedisCore;
@@ -20,18 +20,14 @@ class LeaderboardTest extends \lithium\test\Unit {
public function skip() {
$this->skipIf(!Redis::enabled(), 'The Redis extension is not loaded!');
-
- $this->_connectionConfig = Connections::get('li3_redis', array('config' => true));
- $hasDb = (isset($this->_connectionConfig['type']) && $this->_connectionConfig['type'] == 'Redis');
- $message = 'Test database is either unavailable, or not a Redis connection!';
- $this->skipIf(!$hasDb, $message);
}
public function setUp() {
$this->redis = new RedisCore();
$this->redis->connect('127.0.0.1', 6379);
$this->redis->select(1);
$this->redis->flushDB();
+ Redis::connection($this->redis);
$namespace = Leaderboard::$namespace;
$this->prefix = Redis::resolveFormat(null, compact('namespace')).':';
}
@@ -17,20 +17,16 @@ class RedisTest extends \lithium\test\Unit {
public $redis;
- // public function skip() {
- // $this->skipIf(!Redis::enabled(), 'The Redis extension is not loaded!');
-
- // $this->_connectionConfig = Connections::get('li3_redis', array('config' => true));
- // $hasDb = (isset($this->_connectionConfig['type']) && $this->_connectionConfig['type'] == 'Redis');
- // $message = 'Test database is either unavailable, or not a Redis connection!';
- // $this->skipIf(!$hasDb, $message);
- // }
+ public function skip() {
+ $this->skipIf(!Redis::enabled(), 'The Redis extension is not loaded!');
+ }
public function setUp() {
$this->redis = new RedisCore();
$this->redis->connect('127.0.0.1', 6379);
$this->redis->select(1);
$this->redis->flushDB();
+ Redis::connection($this->redis);
}
public function tearDown() {
@@ -20,18 +20,14 @@ class StatsTest extends \lithium\test\Unit {
public function skip() {
$this->skipIf(!Redis::enabled(), 'The Redis extension is not loaded!');
-
- $this->_connectionConfig = Connections::get('li3_redis', array('config' => true));
- $hasDb = (isset($this->_connectionConfig['type']) && $this->_connectionConfig['type'] == 'Redis');
- $message = 'Test database is either unavailable, or not a Redis connection!';
- $this->skipIf(!$hasDb, $message);
}
public function setUp() {
$this->redis = new RedisCore();
$this->redis->connect('127.0.0.1', 6379);
$this->redis->select(1);
$this->redis->flushDB();
+ Redis::connection($this->redis);
}
public function tearDown() {
@@ -63,6 +59,12 @@ function testInc() {
$this->assertEqual(array('baz' => 2), Stats::inc('foo', 'baz'));
$this->assertEqual($expected, $this->redis->hGetAll("$scope:stats:global:foo"));
+ // multiple at once as flat array
+ // would be cool to have!
+ // $expected = array('field1' => 1, 'field2' => 1);
+ // $this->assertEqual($expected, Stats::inc('multiFlat', array('field1', 'field2')));
+ // $this->assertEqual($expected, $this->redis->hGetAll("$scope:stats:global:multiFlat"));
+
// multiple at once
$expected = array('field1' => 1, 'field2' => 1);
$this->assertEqual($expected, Stats::inc('multi', array('field1' => 1, 'field2' => 1)));
View
@@ -1,22 +0,0 @@
-<?php
-/**
- * li3_redis: redis made ready for lithium
- *
- * @copyright Copyright 2013, brünsicke.com GmbH (http://bruensicke.com)
- * @license http://opensource.org/licenses/BSD-3-Clause The BSD License
- */
-
-use lithium\data\Connections;
-
-/**
- * connection to redis via li3_redis library
- */
-Connections::add('li3_redis', array(
- 'type' => 'Redis',
- 'host' => '127.0.0.1:6379',
- 'database' => 1,
- 'persistent' => true,
- 'expiry' => 0,
-));
-
-?>

0 comments on commit 0cf7fb6

Please sign in to comment.