HandlerWrapperTest.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. /**
  13. * @author Alexey Karapetov <alexey@karapetov.com>
  14. */
  15. class HandlerWrapperTest extends TestCase
  16. {
  17. /**
  18. * @var HandlerWrapper
  19. */
  20. private $wrapper;
  21. private $handler;
  22. public function setUp()
  23. {
  24. parent::setUp();
  25. $this->handler = $this->getMock('Monolog\\Handler\\HandlerInterface');
  26. $this->wrapper = new HandlerWrapper($this->handler);
  27. }
  28. /**
  29. * @return array
  30. */
  31. public function trueFalseDataProvider()
  32. {
  33. return array(
  34. array(true),
  35. array(false),
  36. );
  37. }
  38. /**
  39. * @param $result
  40. * @dataProvider trueFalseDataProvider
  41. */
  42. public function testIsHandling($result)
  43. {
  44. $record = $this->getRecord();
  45. $this->handler->expects($this->once())
  46. ->method('isHandling')
  47. ->with($record)
  48. ->willReturn($result);
  49. $this->assertEquals($result, $this->wrapper->isHandling($record));
  50. }
  51. /**
  52. * @param $result
  53. * @dataProvider trueFalseDataProvider
  54. */
  55. public function testHandle($result)
  56. {
  57. $record = $this->getRecord();
  58. $this->handler->expects($this->once())
  59. ->method('handle')
  60. ->with($record)
  61. ->willReturn($result);
  62. $this->assertEquals($result, $this->wrapper->handle($record));
  63. }
  64. /**
  65. * @param $result
  66. * @dataProvider trueFalseDataProvider
  67. */
  68. public function testHandleBatch($result)
  69. {
  70. $records = $this->getMultipleRecords();
  71. $this->handler->expects($this->once())
  72. ->method('handleBatch')
  73. ->with($records)
  74. ->willReturn($result);
  75. $this->assertEquals($result, $this->wrapper->handleBatch($records));
  76. }
  77. public function testPushProcessor()
  78. {
  79. $processor = function () {};
  80. $this->handler->expects($this->once())
  81. ->method('pushProcessor')
  82. ->with($processor);
  83. $this->assertEquals($this->wrapper, $this->wrapper->pushProcessor($processor));
  84. }
  85. public function testPopProcessor()
  86. {
  87. $processor = function () {};
  88. $this->handler->expects($this->once())
  89. ->method('popProcessor')
  90. ->willReturn($processor);
  91. $this->assertEquals($processor, $this->wrapper->popProcessor());
  92. }
  93. public function testSetFormatter()
  94. {
  95. $formatter = $this->getMock('Monolog\\Formatter\\FormatterInterface');
  96. $this->handler->expects($this->once())
  97. ->method('setFormatter')
  98. ->with($formatter);
  99. $this->assertEquals($this->wrapper, $this->wrapper->setFormatter($formatter));
  100. }
  101. public function testGetFormatter()
  102. {
  103. $formatter = $this->getMock('Monolog\\Formatter\\FormatterInterface');
  104. $this->handler->expects($this->once())
  105. ->method('getFormatter')
  106. ->willReturn($formatter);
  107. $this->assertEquals($formatter, $this->wrapper->getFormatter());
  108. }
  109. }