RedisHandlerTest.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. /*
  3. * This file is part of the Monolog package.
  4. *
  5. * (c) Jordi Boggiano <j.boggiano@seld.be>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Monolog\Handler;
  11. use Monolog\TestCase;
  12. use Monolog\Logger;
  13. use Monolog\Formatter\LineFormatter;
  14. class RedisHandlerTest extends TestCase
  15. {
  16. /**
  17. * @expectedException InvalidArgumentException
  18. */
  19. public function testConstructorShouldThrowExceptionForInvalidRedis()
  20. {
  21. new RedisHandler(new \stdClass(), 'key');
  22. }
  23. public function testConstructorShouldWorkWithPredis()
  24. {
  25. $redis = $this->getMock('Predis\Client');
  26. $this->assertInstanceof('Monolog\Handler\RedisHandler', new RedisHandler($redis, 'key'));
  27. }
  28. public function testConstructorShouldWorkWithRedis()
  29. {
  30. $redis = $this->getMock('Redis');
  31. $this->assertInstanceof('Monolog\Handler\RedisHandler', new RedisHandler($redis, 'key'));
  32. }
  33. public function testPredisHandle()
  34. {
  35. $redis = $this->getMock('Predis\Client', array('rpush'));
  36. // Predis\Client uses rpush
  37. $redis->expects($this->once())
  38. ->method('rpush')
  39. ->with('key', 'test');
  40. $record = $this->getRecord(Logger::WARNING, 'test', array('data' => new \stdClass, 'foo' => 34));
  41. $handler = new RedisHandler($redis, 'key');
  42. $handler->setFormatter(new LineFormatter("%message%"));
  43. $handler->handle($record);
  44. }
  45. public function testRedisHandle()
  46. {
  47. $redis = $this->getMock('Redis', array('rpush'));
  48. // Redis uses rPush
  49. $redis->expects($this->once())
  50. ->method('rPush')
  51. ->with('key', 'test');
  52. $record = $this->getRecord(Logger::WARNING, 'test', array('data' => new \stdClass, 'foo' => 34));
  53. $handler = new RedisHandler($redis, 'key');
  54. $handler->setFormatter(new LineFormatter("%message%"));
  55. $handler->handle($record);
  56. }
  57. }