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.

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