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