123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- <?php
- define('I_AM_AWARE_OF_THE_DESTRUCTIVE_POWER_OF_THIS_TEST_SUITE', false);
- require_once 'PHPUnit/Framework.php';
- require_once 'PredisShared.php';
- class RedisCommandTestSuite extends PHPUnit_Framework_TestCase {
- public $redis;
- protected function setUp() {
- $this->redis = RC::getConnection();
- $this->redis->flushDatabase();
- }
- protected function tearDown() {
- }
- protected function onNotSuccessfulTest($exception) {
- // drops and reconnect to a redis server on uncaught exceptions
- RC::resetConnection();
- parent::onNotSuccessfulTest($exception);
- }
- /* ConnectionParameters */
- function testConnectionParametersDefaultValues() {
- $params = new Predis\ConnectionParameters();
- $this->assertEquals(Predis\ConnectionParameters::DEFAULT_HOST, $params->host);
- $this->assertEquals(Predis\ConnectionParameters::DEFAULT_PORT, $params->port);
- $this->assertEquals(Predis\ConnectionParameters::DEFAULT_TIMEOUT, $params->connection_timeout);
- $this->assertNull($params->read_write_timeout);
- $this->assertNull($params->database);
- $this->assertNull($params->password);
- $this->assertNull($params->alias);
- }
- function testConnectionParametersSetupValuesArray() {
- $paramsArray = RC::getConnectionParametersArgumentsArray();
- $params = new Predis\ConnectionParameters($paramsArray);
- $this->assertEquals($paramsArray['host'], $params->host);
- $this->assertEquals($paramsArray['port'], $params->port);
- $this->assertEquals($paramsArray['connection_timeout'], $params->connection_timeout);
- $this->assertEquals($paramsArray['read_write_timeout'], $params->read_write_timeout);
- $this->assertEquals($paramsArray['database'], $params->database);
- $this->assertEquals($paramsArray['password'], $params->password);
- $this->assertEquals($paramsArray['alias'], $params->alias);
- }
- function testConnectionParametersSetupValuesString() {
- $paramsArray = RC::getConnectionParametersArgumentsArray();
- $paramsString = RC::getConnectionParametersArgumentsString($paramsArray);
- $params = new Predis\ConnectionParameters($paramsArray);
- $this->assertEquals($paramsArray['host'], $params->host);
- $this->assertEquals($paramsArray['port'], $params->port);
- $this->assertEquals($paramsArray['connection_timeout'], $params->connection_timeout);
- $this->assertEquals($paramsArray['read_write_timeout'], $params->read_write_timeout);
- $this->assertEquals($paramsArray['database'], $params->database);
- $this->assertEquals($paramsArray['password'], $params->password);
- $this->assertEquals($paramsArray['alias'], $params->alias);
- }
- /* RedisServerProfile and derivates */
- function testRedisServerProfile_GetSpecificVersions() {
- $this->assertType('\Predis\RedisServer_v1_0', \Predis\RedisServerProfile::get('1.0'));
- $this->assertType('\Predis\RedisServer_v1_2', \Predis\RedisServerProfile::get('1.2'));
- $this->assertType('\Predis\RedisServer_vNext', \Predis\RedisServerProfile::get('dev'));
- $this->assertType('\Predis\RedisServerProfile', \Predis\RedisServerProfile::get('default'));
- $this->assertEquals(\Predis\RedisServerProfile::get('default'), \Predis\RedisServerProfile::getDefault());
- }
- function testRedisServerProfile_SupportedCommands() {
- $profile_10 = \Predis\RedisServerProfile::get('1.0');
- $profile_12 = \Predis\RedisServerProfile::get('1.2');
- $this->assertTrue($profile_10->supportsCommand('info'));
- $this->assertTrue($profile_12->supportsCommand('info'));
- $this->assertFalse($profile_10->supportsCommand('mset'));
- $this->assertTrue($profile_12->supportsCommand('mset'));
- $this->assertFalse($profile_10->supportsCommand('multi'));
- $this->assertFalse($profile_12->supportsCommand('multi'));
- }
- function testRedisServerProfile_CommandsCreation() {
- $profile = \Predis\RedisServerProfile::get('1.0');
- $cmdNoArgs = $profile->createCommand('info');
- $this->assertType('\Predis\Commands\Info', $cmdNoArgs);
- $this->assertNull($cmdNoArgs->getArgument());
- $args = array('key1', 'key2');
- $cmdWithArgs = $profile->createCommand('mget', $args);
- $this->assertType('\Predis\Commands\GetMultiple', $cmdWithArgs);
- $this->assertEquals($args[0], $cmdWithArgs->getArgument()); // TODO: why?
- $this->assertEquals($args[0], $cmdWithArgs->getArgument(0));
- $this->assertEquals($args[1], $cmdWithArgs->getArgument(1));
- $bogusCommand = 'not_existing_command';
- $expectedMessage = "'$bogusCommand' is not a registered Redis command";
- RC::testForClientException($this, $expectedMessage, function($test)
- use($profile, $bogusCommand) {
- $profile->createCommand($bogusCommand);
- });
- }
- function testRedisServerProfile_CommandsRegistration() {
- $profile = \Predis\RedisServerProfile::get('1.0');
- $cmdId = 'mset';
- $cmdClass = '\Predis\Commands\SetMultiple';
- $this->assertFalse($profile->supportsCommand($cmdId));
- $profile->registerCommand(new $cmdClass(), $cmdId);
- $this->assertTrue($profile->supportsCommand($cmdId));
- $this->assertType($cmdClass, $profile->createCommand($cmdId));
- }
- }
- ?>
|