diff --git a/.travis.yml b/.travis.yml index 4925748..ae01043 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/tests/cases/extensions/data/source/RedisTest.php b/tests/cases/extensions/data/source/RedisTest.php index 9552853..3d042fd 100644 --- a/tests/cases/extensions/data/source/RedisTest.php +++ b/tests/cases/extensions/data/source/RedisTest.php @@ -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()); diff --git a/tests/cases/storage/LeaderboardTest.php b/tests/cases/storage/LeaderboardTest.php index 61e0973..59858c7 100644 --- a/tests/cases/storage/LeaderboardTest.php +++ b/tests/cases/storage/LeaderboardTest.php @@ -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,11 +20,6 @@ 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() { @@ -32,6 +27,7 @@ public function setUp() { $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')).':'; } diff --git a/tests/cases/storage/RedisTest.php b/tests/cases/storage/RedisTest.php index 3be9526..c46e190 100644 --- a/tests/cases/storage/RedisTest.php +++ b/tests/cases/storage/RedisTest.php @@ -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() { diff --git a/tests/cases/storage/StatsTest.php b/tests/cases/storage/StatsTest.php index df09dbf..b019a95 100644 --- a/tests/cases/storage/StatsTest.php +++ b/tests/cases/storage/StatsTest.php @@ -20,11 +20,6 @@ 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() { @@ -32,6 +27,7 @@ public function setUp() { $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))); diff --git a/tests/data/connections.php b/tests/data/connections.php deleted file mode 100644 index 00b87e9..0000000 --- a/tests/data/connections.php +++ /dev/null @@ -1,22 +0,0 @@ - 'Redis', - 'host' => '127.0.0.1:6379', - 'database' => 1, - 'persistent' => true, - 'expiry' => 0, -)); - -?> \ No newline at end of file