HandlerWrapperTest.php 2.0 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 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. }
  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. }