You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

109 lines
2.9 KiB

  1. <?php
  2. /*
  3. * @copyright NetMonsters <team@netmonsters.ru>
  4. * @link http://netmonsters.ru
  5. * @package Majestic
  6. * @subpackage UnitTests
  7. * @since 2011-10-11
  8. *
  9. * Unit tests for RedisDebug class
  10. */
  11. require_once dirname(__FILE__) . '/../../exception/GeneralException.php';
  12. require_once dirname(__FILE__) . '/../../util/profiler/CommandProfiler.php';
  13. require_once dirname(__FILE__) . '/../../util/profiler/Profiler.php';
  14. require_once dirname(__FILE__) . '/../../redis/RedisDebug.php';
  15. require_once dirname(__FILE__) . '/../../exception/GeneralException.php';
  16. class RedisDebugTest extends PHPUnit_Framework_TestCase
  17. {
  18. public function run(PHPUnit_Framework_TestResult $result = NULL)
  19. {
  20. $this->setPreserveGlobalState(false);
  21. return parent::run($result);
  22. }
  23. /**
  24. * @group Redis
  25. */
  26. public function testConstructException()
  27. {
  28. $this->setExpectedException('GeneralException');
  29. $redisDebug = new RedisDebug('redis');
  30. }
  31. /**
  32. * @group Redis
  33. */
  34. public function testConstructGood()
  35. {
  36. $mock = $this->getMock('Redis');
  37. $redisDebug = new RedisDebug($mock);
  38. $class = new ReflectionClass('RedisDebug');
  39. $redis = $class->getProperty('redis');
  40. $redis->setAccessible(true);
  41. $redis = $redis->getValue($redisDebug);
  42. $this->assertSame($mock, $redis);
  43. }
  44. /**
  45. * @runInSeparateProcess
  46. * @group Redis
  47. */
  48. public function testCallSimpleParams()
  49. {
  50. if (!defined('DEBUG')) {
  51. define('DEBUG', true);
  52. }
  53. $mock = $this->getMock('Redis', array('connect'));
  54. $mock->expects($this->once())
  55. ->method('connect')
  56. ->with($this->equalTo('localhost'), $this->equalTo(4322))
  57. ->will($this->returnValue(true));
  58. $redisDebug = new RedisDebug($mock);
  59. $this->assertTrue($redisDebug->connect('localhost', 4322));
  60. }
  61. /**
  62. * @runInSeparateProcess
  63. * @group Redis
  64. */
  65. public function testCallArrayParam()
  66. {
  67. if (!defined('DEBUG')) {
  68. define('DEBUG', true);
  69. }
  70. $mock = $this->getMock('Redis', array('connect'));
  71. $mock->expects($this->once())
  72. ->method('connect')
  73. ->with($this->equalTo(array('localhost', 4322)))
  74. ->will($this->returnValue(true));
  75. $redisDebug = new RedisDebug($mock);
  76. $this->assertTrue($redisDebug->connect(array('localhost', 4322)));
  77. }
  78. /**
  79. * @runInSeparateProcess
  80. * @group Redis
  81. */
  82. public function testCallUndefinedMethod()
  83. {
  84. if (!defined('DEBUG')) {
  85. define('DEBUG', true);
  86. }
  87. $mock = $this->getMock('Redis', array('connect'));
  88. $redisDebug = new RedisDebug($mock);
  89. $this->setExpectedException('GeneralException');
  90. $this->assertNull($redisDebug->nothing('localhost', 4322));
  91. }
  92. }