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.

105 lines
3.0 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__) . '/../../Registry.php';
  12. require_once dirname(__FILE__) . '/../../Config.php';
  13. require_once dirname(__FILE__) . '/../../exception/GeneralException.php';
  14. require_once dirname(__FILE__) . '/../../util/profiler/CommandProfiler.php';
  15. require_once dirname(__FILE__) . '/../../util/profiler/Profiler.php';
  16. require_once dirname(__FILE__) . '/../../redis/RedisDebug.php';
  17. require_once dirname(__FILE__) . '/../../exception/GeneralException.php';
  18. class RedisDebugTest extends PHPUnit_Framework_TestCase
  19. {
  20. public function run(PHPUnit_Framework_TestResult $result = NULL)
  21. {
  22. $this->setPreserveGlobalState(false);
  23. return parent::run($result);
  24. }
  25. /**
  26. * @group Redis
  27. */
  28. public function testConstructException()
  29. {
  30. $this->setExpectedException('GeneralException');
  31. $redisDebug = new RedisDebug('redis');
  32. }
  33. /**
  34. * @group Redis
  35. */
  36. public function testConstructGood()
  37. {
  38. $mock = $this->getMock('Redis');
  39. $redisDebug = new RedisDebug($mock);
  40. $class = new ReflectionClass('RedisDebug');
  41. $redis = $class->getProperty('redis');
  42. $redis->setAccessible(true);
  43. $redis = $redis->getValue($redisDebug);
  44. $this->assertSame($mock, $redis);
  45. }
  46. /**
  47. * @runInSeparateProcess
  48. * @group Redis
  49. */
  50. public function testCallSimpleParams()
  51. {
  52. Config::set('PROFILER', true);
  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. Config::set('PROFILER', true);
  68. $mock = $this->getMock('Redis', array('connect'));
  69. $mock->expects($this->once())
  70. ->method('connect')
  71. ->with($this->equalTo(array('localhost', 4322)))
  72. ->will($this->returnValue(true));
  73. $redisDebug = new RedisDebug($mock);
  74. $this->assertTrue($redisDebug->connect(array('localhost', 4322)));
  75. }
  76. /**
  77. * @runInSeparateProcess
  78. * @group Redis
  79. */
  80. public function testCallUndefinedMethod()
  81. {
  82. Config::set('PROFILER', true);
  83. $mock = $this->getMock('Redis', array('connect'));
  84. $redisDebug = new RedisDebug($mock);
  85. $this->setExpectedException('PHPUnit_Framework_Error', 'call_user_func_array() expects parameter 1 to be a valid callback, class \'Mock_Redis_');
  86. $this->assertNull($redisDebug->nothing('localhost', 4322));
  87. }
  88. }