Skip to content

Commit

Permalink
set connection object into Redis::connection on tests()
Browse files Browse the repository at this point in the history
  • Loading branch information
d1rk committed Mar 14, 2013
1 parent 5a16347 commit 0cf7fb6
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 76 deletions.
6 changes: 2 additions & 4 deletions .travis.yml
Expand Up @@ -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
Expand Down
45 changes: 14 additions & 31 deletions tests/cases/extensions/data/source/RedisTest.php
Expand Up @@ -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(
Expand All @@ -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());
Expand Down
8 changes: 2 additions & 6 deletions tests/cases/storage/LeaderboardTest.php
Expand Up @@ -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;
Expand All @@ -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')).':';
}
Expand Down
12 changes: 4 additions & 8 deletions tests/cases/storage/RedisTest.php
Expand Up @@ -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() {
Expand Down
12 changes: 7 additions & 5 deletions tests/cases/storage/StatsTest.php
Expand Up @@ -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() {
Expand Down Expand Up @@ -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)));
Expand Down
22 changes: 0 additions & 22 deletions tests/data/connections.php

This file was deleted.

0 comments on commit 0cf7fb6

Please sign in to comment.