HandlerWrapperTest.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php declare(strict_types=1);
  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\Test\TestCase;
  12. use PHPUnit\Framework\MockObject\MockObject;
  13. /**
  14. * @author Alexey Karapetov <alexey@karapetov.com>
  15. */
  16. class HandlerWrapperTest extends TestCase
  17. {
  18. private HandlerWrapper $wrapper;
  19. private HandlerInterface&MockObject $handler;
  20. public function setUp(): void
  21. {
  22. parent::setUp();
  23. $this->handler = $this->createMock(HandlerInterface::class);
  24. $this->wrapper = new HandlerWrapper($this->handler);
  25. }
  26. public function trueFalseDataProvider(): array
  27. {
  28. return [
  29. [true],
  30. [false],
  31. ];
  32. }
  33. /**
  34. * @param $result
  35. * @dataProvider trueFalseDataProvider
  36. */
  37. public function testIsHandling($result)
  38. {
  39. $record = $this->getRecord();
  40. $this->handler->expects($this->once())
  41. ->method('isHandling')
  42. ->with($record)
  43. ->willReturn($result);
  44. $this->assertEquals($result, $this->wrapper->isHandling($record));
  45. }
  46. /**
  47. * @param $result
  48. * @dataProvider trueFalseDataProvider
  49. */
  50. public function testHandle($result)
  51. {
  52. $record = $this->getRecord();
  53. $this->handler->expects($this->once())
  54. ->method('handle')
  55. ->with($record)
  56. ->willReturn($result);
  57. $this->assertEquals($result, $this->wrapper->handle($record));
  58. }
  59. /**
  60. * @param $result
  61. * @dataProvider trueFalseDataProvider
  62. */
  63. public function testHandleBatch($result)
  64. {
  65. $records = $this->getMultipleRecords();
  66. $this->handler->expects($this->once())
  67. ->method('handleBatch')
  68. ->with($records);
  69. $this->wrapper->handleBatch($records);
  70. }
  71. }