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