ARedisConnectionTest.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. require_once("common.php");
  3. /**
  4. * Tests for the {@link ARedisConnection} class
  5. * @author Charles Pick
  6. * @package packages.redis.tests
  7. */
  8. class ARedisConnectionTest extends CTestCase {
  9. /**
  10. * Holds the redis connection
  11. * @var ARedisConnection
  12. */
  13. protected $_connection;
  14. /**
  15. * Tests the basic functionality
  16. */
  17. public function testBasics() {
  18. $redis = $this->getConnection();
  19. $keyId = "TEST_KEY:".uniqid();
  20. $this->assertEquals(null,$redis->get($keyId));
  21. $redis->set($keyId,"TEST");
  22. $this->assertEquals("TEST",$redis->get($keyId));
  23. $redis->delete($keyId);
  24. $this->assertEquals(null,$redis->get($keyId));
  25. }
  26. /**
  27. * Sets the redis connection to use with this test
  28. * @param ARedisConnection $connection the connection
  29. */
  30. public function setConnection($connection)
  31. {
  32. $this->_connection = $connection;
  33. }
  34. /**
  35. * Gets the redis connection to use with this test
  36. * @return ARedisConnection the redis connection
  37. */
  38. public function getConnection()
  39. {
  40. if ($this->_connection === null) {
  41. $this->_connection = Yii::createComponent(
  42. array(
  43. "class" => "packages.redis.ARedisConnection",
  44. "hostname" => REDIS_HOSTNAME,
  45. "port" => REDIS_PORT,
  46. "database" => REDIS_DATABASE,
  47. "password" => REDIS_PASSWORD
  48. ));
  49. }
  50. return $this->_connection;
  51. }
  52. }