2
0

RedisPubSubHandlerTest.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4. * This file is part of the Monolog package.
  5. *
  6. * (c) Jordi Boggiano <j.boggiano@seld.be>
  7. *
  8. * For the full copyright and license information, please view the LICENSE
  9. * file that was distributed with this source code.
  10. */
  11. namespace Monolog\Handler;
  12. use Monolog\Level;
  13. use Monolog\Formatter\LineFormatter;
  14. class RedisPubSubHandlerTest extends \Monolog\Test\MonologTestCase
  15. {
  16. public function testConstructorShouldWorkWithPredis()
  17. {
  18. $redis = $this->createMock('Predis\Client');
  19. $this->assertInstanceof('Monolog\Handler\RedisPubSubHandler', new RedisPubSubHandler($redis, 'key'));
  20. }
  21. public function testConstructorShouldWorkWithRedis()
  22. {
  23. if (!class_exists('Redis')) {
  24. $this->markTestSkipped('The redis ext is required to run this test');
  25. }
  26. $redis = $this->createMock('Redis');
  27. $this->assertInstanceof('Monolog\Handler\RedisPubSubHandler', new RedisPubSubHandler($redis, 'key'));
  28. }
  29. public function testPredisHandle()
  30. {
  31. $redis = $this->getMockBuilder('Predis\Client')->getMock();
  32. $redis->expects($this->atLeastOnce())
  33. ->method('__call')
  34. ->with(self::equalTo('publish'), self::equalTo(['key', 'test']));
  35. $record = $this->getRecord(Level::Warning, 'test', ['data' => new \stdClass(), 'foo' => 34]);
  36. $handler = new RedisPubSubHandler($redis, 'key');
  37. $handler->setFormatter(new LineFormatter("%message%"));
  38. $handler->handle($record);
  39. }
  40. public function testRedisHandle()
  41. {
  42. if (!class_exists('Redis')) {
  43. $this->markTestSkipped('The redis ext is required to run this test');
  44. }
  45. $redis = $this->createPartialMock('Redis', ['publish']);
  46. $redis->expects($this->once())
  47. ->method('publish')
  48. ->with('key', 'test');
  49. $record = $this->getRecord(Level::Warning, 'test', ['data' => new \stdClass(), 'foo' => 34]);
  50. $handler = new RedisPubSubHandler($redis, 'key');
  51. $handler->setFormatter(new LineFormatter("%message%"));
  52. $handler->handle($record);
  53. }
  54. }