ARedisChannelTest.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. require_once("common.php");
  3. /**
  4. * Tests for the {@link ARedisChannel} class
  5. * @author Charles Pick
  6. * @package packages.redis.tests
  7. */
  8. class ARedisChannelTest 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. $channel1 = new ARedisChannel("TestSet:".uniqid(),$redis);
  20. $this->assertEquals(0, $channel1->publish("a test message"));
  21. $this->assertEquals("a test message",$channel1[0]);
  22. // todo: implement threading so that we can properly test subscribe / unsubscribe
  23. }
  24. /**
  25. * Sets the redis connection to use with this test
  26. * @param ARedisConnection $connection the connection
  27. */
  28. public function setConnection($connection)
  29. {
  30. $this->_connection = $connection;
  31. }
  32. /**
  33. * Gets the redis connection to use with this test
  34. * @return ARedisConnection the redis connection
  35. */
  36. public function getConnection()
  37. {
  38. if ($this->_connection === null) {
  39. $this->_connection = Yii::createComponent(
  40. array(
  41. "class" => "packages.redis.ARedisConnection",
  42. "hostname" => REDIS_HOSTNAME,
  43. "port" => REDIS_PORT,
  44. "database" => REDIS_DATABASE,
  45. "password" => REDIS_PASSWORD
  46. ));
  47. }
  48. return $this->_connection;
  49. }
  50. }