ClientUnitTestCase.test 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. class Redis_Tests_Client_UnitTestCase extends Redis_Tests_AbstractUnitTestCase
  3. {
  4. public static function getInfo()
  5. {
  6. return array(
  7. 'name' => 'Redis client manager',
  8. 'description' => 'Tests Redis module client manager feature.',
  9. 'group' => 'Redis',
  10. );
  11. }
  12. protected function getClientInterface()
  13. {
  14. return 'PhpRedis';
  15. }
  16. public function getManager()
  17. {
  18. return new Redis_Client_Manager(
  19. new Redis_Tests_Client_MockFactory(),
  20. array(
  21. 'default' => array(),
  22. 'foo' => array(
  23. 'host' => 'foo.com',
  24. 'port' => 666,
  25. ),
  26. 'bar' => array(
  27. 'host' => 'bar.com',
  28. ),
  29. )
  30. );
  31. }
  32. public function testManagerServerList()
  33. {
  34. $manager = $this->getManager();
  35. $defaultClient = $manager->getClient();
  36. $this->assertTrue(is_object($defaultClient));
  37. // Ensure defaults are OK
  38. $this->assertIdentical(Redis_Client_Manager::REDIS_DEFAULT_HOST, $defaultClient->host);
  39. $this->assertIdentical(Redis_Client_Manager::REDIS_DEFAULT_PORT, $defaultClient->port);
  40. $this->assertFalse(property_exists($defaultClient, 'base'));
  41. $this->assertFalse(property_exists($defaultClient, 'password'));
  42. $client = $manager->getClient('foo');
  43. $this->assertIdentical('foo.com', $client->host);
  44. $this->assertIdentical(666, $client->port);
  45. $client = $manager->getClient('bar');
  46. $this->assertIdentical('bar.com', $client->host);
  47. $this->assertIdentical(Redis_Client_Manager::REDIS_DEFAULT_PORT, $client->port);
  48. $this->assertIdentical($defaultClient, $manager->getClient('non_existing'));
  49. try {
  50. $manager->getClient('other_non_existing', false);
  51. $this->assert(false);
  52. } catch (\InvalidArgumentException $e) {
  53. $this->assert(true);
  54. }
  55. }
  56. }