ARedisListTest.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. require_once("common.php");
  3. /**
  4. * Tests for the {@link ARedisList} class
  5. * @author Charles Pick
  6. * @package packages.redis.tests
  7. */
  8. class ARedisListTest 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. $list = new ARedisList("TestSet:".uniqid(),$redis);
  20. $list[] = "Hello World";
  21. $this->assertEquals("Hello World",$list->pop());
  22. $this->assertEquals(0,$list->getCount());
  23. $this->assertFalse($redis->exists($list->name));
  24. $testData = array();
  25. for($i = 0; $i < 100; $i++) {
  26. $testData[] = "Test Item ".$i;
  27. }
  28. $list = new ARedisList("Test_List".uniqid(), $redis);
  29. $list->copyFrom($testData);
  30. $this->assertEquals(100,count($list));
  31. foreach($list as $i => $item) {
  32. $this->assertEquals($testData[$i],$item);
  33. }
  34. $list->clear();
  35. $this->assertFalse($redis->exists($list->name));
  36. }
  37. /**
  38. * Sets the redis connection to use with this test
  39. * @param ARedisConnection $connection the connection
  40. */
  41. public function setConnection($connection)
  42. {
  43. $this->_connection = $connection;
  44. }
  45. /**
  46. * Gets the redis connection to use with this test
  47. * @return ARedisConnection the redis connection
  48. */
  49. public function getConnection()
  50. {
  51. if ($this->_connection === null) {
  52. $this->_connection = Yii::createComponent(
  53. array(
  54. "class" => "packages.redis.ARedisConnection",
  55. "hostname" => REDIS_HOSTNAME,
  56. "port" => REDIS_PORT,
  57. "database" => REDIS_DATABASE,
  58. "password" => REDIS_PASSWORD
  59. ));
  60. }
  61. return $this->_connection;
  62. }
  63. }