ARedisStatePersisterTest.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. require_once("common.php");
  3. /**
  4. * Tests for the {@link ARedisStatePersisterTest} class
  5. * @author Vasily Gudoshnikov <vgoodvin@gmail.com>
  6. * @package packages.redis.tests
  7. */
  8. class ARedisStatePersisterTest extends CTestCase {
  9. /**
  10. * Holds the redis connection component
  11. * @var ARedisConnection
  12. */
  13. protected $_connection;
  14. /**
  15. * Tests the basic functionality
  16. */
  17. public function testBasics() {
  18. $persister = new ARedisStatePersister();
  19. $persister->setConnection($this->getConnection());
  20. $persister->key = 'Yii.ARedisStatePersister.test';
  21. $this->getConnection()->getClient()->del($persister->key);
  22. $this->assertEquals($persister->load(), null);
  23. $persister->save(array('testKey' => 'testValue'));
  24. $this->assertEquals($persister->load(), array('testKey' => 'testValue'));
  25. $this->getConnection()->getClient()->del($persister->key);
  26. }
  27. /**
  28. * Sets the redis connection to use with this test
  29. * @param ARedisConnection $connection the connection
  30. */
  31. public function setConnection($connection)
  32. {
  33. $this->_connection = $connection;
  34. }
  35. /**
  36. * Gets the redis connection to use with this test
  37. * @return ARedisConnection the redis connection
  38. */
  39. public function getConnection()
  40. {
  41. if ($this->_connection === null) {
  42. $this->_connection = Yii::createComponent(
  43. array(
  44. "class" => "packages.redis.ARedisConnection",
  45. "hostname" => REDIS_HOSTNAME,
  46. "port" => REDIS_PORT,
  47. "database" => REDIS_DATABASE,
  48. "password" => REDIS_PASSWORD
  49. ));
  50. }
  51. return $this->_connection;
  52. }
  53. }