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.

103 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. Config::set('DEBUG', 1);
  51. $mock = $this->getMock('Redis', array('connect'));
  52. $mock->expects($this->once())
  53. ->method('connect')
  54. ->with($this->equalTo('localhost'), $this->equalTo(4322))
  55. ->will($this->returnValue(true));
  56. $redisDebug = new RedisDebug($mock);
  57. $this->assertTrue($redisDebug->connect('localhost', 4322));
  58. }
  59. /**
  60. * @runInSeparateProcess
  61. * @group Redis
  62. */
  63. public function testCallArrayParam()
  64. {
  65. Config::set('DEBUG', 1);
  66. $mock = $this->getMock('Redis', array('connect'));
  67. $mock->expects($this->once())
  68. ->method('connect')
  69. ->with($this->equalTo(array('localhost', 4322)))
  70. ->will($this->returnValue(true));
  71. $redisDebug = new RedisDebug($mock);
  72. $this->assertTrue($redisDebug->connect(array('localhost', 4322)));
  73. }
  74. /**
  75. * @runInSeparateProcess
  76. * @group Redis
  77. */
  78. public function testCallUndefinedMethod()
  79. {
  80. Config::set('DEBUG', 1);
  81. $mock = $this->getMock('Redis', array('connect'));
  82. $redisDebug = new RedisDebug($mock);
  83. $this->setExpectedException('PHPUnit_Framework_Error', 'call_user_func_array() expects parameter 1 to be a valid callback, class \'Mock_Redis_');
  84. $this->assertNull($redisDebug->nothing('localhost', 4322));
  85. }
  86. }