* @link http://netmonsters.ru * @package Majestic * @subpackage UnitTests * @since 2011-10-11 * * Unit tests for RedisDebug class */ require_once dirname(__FILE__) . '/../../exception/GeneralException.php'; require_once dirname(__FILE__) . '/../../util/profiler/CommandProfiler.php'; require_once dirname(__FILE__) . '/../../util/profiler/Profiler.php'; require_once dirname(__FILE__) . '/../../redis/RedisDebug.php'; require_once dirname(__FILE__) . '/../../exception/GeneralException.php'; class RedisDebugTest extends PHPUnit_Framework_TestCase { public function run(PHPUnit_Framework_TestResult $result = NULL) { $this->setPreserveGlobalState(false); return parent::run($result); } public function testConstructException() { $this->setExpectedException('GeneralException'); $redisDebug = new RedisDebug('redis'); } public function testConstructGood() { $mock = $this->getMock('Redis'); $redisDebug = new RedisDebug($mock); $class = new ReflectionClass('RedisDebug'); $redis = $class->getProperty('redis'); $redis->setAccessible(true); $redis = $redis->getValue($redisDebug); $this->assertSame($mock, $redis); } /** * @runInSeparateProcess */ public function testCallSimpleParams() { if (!defined('DEBUG')) { define('DEBUG', true); } $mock = $this->getMock('Redis', array('connect')); $mock->expects($this->once()) ->method('connect') ->with($this->equalTo('localhost'), $this->equalTo(4322)) ->will($this->returnValue(true)); $redisDebug = new RedisDebug($mock); $this->assertTrue($redisDebug->connect('localhost', 4322)); } /** * @runInSeparateProcess */ public function testCallArrayParam() { if (!defined('DEBUG')) { define('DEBUG', true); } $mock = $this->getMock('Redis', array('connect')); $mock->expects($this->once()) ->method('connect') ->with($this->equalTo(array('localhost', 4322))) ->will($this->returnValue(true)); $redisDebug = new RedisDebug($mock); $this->assertTrue($redisDebug->connect(array('localhost', 4322))); } /** * @runInSeparateProcess */ public function testCallUndefinedMethod() { if (!defined('DEBUG')) { define('DEBUG', true); } $mock = $this->getMock('Redis', array('connect')); $redisDebug = new RedisDebug($mock); $this->setExpectedException('GeneralException'); $this->assertNull($redisDebug->nothing('localhost', 4322)); } }