HandlerWrapperTest.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 tearDown(): void
  27. {
  28. parent::tearDown();
  29. unset($this->wrapper);
  30. }
  31. public function trueFalseDataProvider(): array
  32. {
  33. return [
  34. [true],
  35. [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. $this->wrapper->handleBatch($records);
  75. }
  76. }