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.

100 lines
2.8 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. public function testConstructException()
  24. {
  25. $this->setExpectedException('GeneralException');
  26. $redisDebug = new RedisDebug('redis');
  27. }
  28. public function testConstructGood()
  29. {
  30. $mock = $this->getMock('Redis');
  31. $redisDebug = new RedisDebug($mock);
  32. $class = new ReflectionClass('RedisDebug');
  33. $redis = $class->getProperty('redis');
  34. $redis->setAccessible(true);
  35. $redis = $redis->getValue($redisDebug);
  36. $this->assertSame($mock, $redis);
  37. }
  38. /**
  39. * @runInSeparateProcess
  40. */
  41. public function testCallSimpleParams()
  42. {
  43. if (!defined('DEBUG')) {
  44. define('DEBUG', true);
  45. }
  46. $mock = $this->getMock('Redis', array('connect'));
  47. $mock->expects($this->once())
  48. ->method('connect')
  49. ->with($this->equalTo('localhost'), $this->equalTo(4322))
  50. ->will($this->returnValue(true));
  51. $redisDebug = new RedisDebug($mock);
  52. $this->assertTrue($redisDebug->connect('localhost', 4322));
  53. }
  54. /**
  55. * @runInSeparateProcess
  56. */
  57. public function testCallArrayParam()
  58. {
  59. if (!defined('DEBUG')) {
  60. define('DEBUG', true);
  61. }
  62. $mock = $this->getMock('Redis', array('connect'));
  63. $mock->expects($this->once())
  64. ->method('connect')
  65. ->with($this->equalTo(array('localhost', 4322)))
  66. ->will($this->returnValue(true));
  67. $redisDebug = new RedisDebug($mock);
  68. $this->assertTrue($redisDebug->connect(array('localhost', 4322)));
  69. }
  70. /**
  71. * @runInSeparateProcess
  72. */
  73. public function testCallUndefinedMethod()
  74. {
  75. if (!defined('DEBUG')) {
  76. define('DEBUG', true);
  77. }
  78. $mock = $this->getMock('Redis', array('connect'));
  79. $redisDebug = new RedisDebug($mock);
  80. $this->setExpectedException('GeneralException');
  81. $this->assertNull($redisDebug->nothing('localhost', 4322));
  82. }
  83. }