HandlerWrapperTest.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 PHPUnit\Framework\Attributes\DataProvider;
  12. use PHPUnit\Framework\MockObject\MockObject;
  13. /**
  14. * @author Alexey Karapetov <alexey@karapetov.com>
  15. */
  16. class HandlerWrapperTest extends \Monolog\Test\MonologTestCase
  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. unset($this->handler);
  31. }
  32. public static function trueFalseDataProvider(): array
  33. {
  34. return [
  35. [true],
  36. [false],
  37. ];
  38. }
  39. #[DataProvider('trueFalseDataProvider')]
  40. public function testIsHandling(bool $result)
  41. {
  42. $record = $this->getRecord();
  43. $this->handler->expects($this->once())
  44. ->method('isHandling')
  45. ->with($record)
  46. ->willReturn($result);
  47. $this->assertEquals($result, $this->wrapper->isHandling($record));
  48. }
  49. #[DataProvider('trueFalseDataProvider')]
  50. public function testHandle(bool $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. #[DataProvider('trueFalseDataProvider')]
  60. public function testHandleBatch(bool $result)
  61. {
  62. $records = $this->getMultipleRecords();
  63. $this->handler->expects($this->once())
  64. ->method('handleBatch')
  65. ->with($records);
  66. $this->wrapper->handleBatch($records);
  67. }
  68. }