|
| 1 | +<?php |
| 2 | +declare(strict_types=1); |
| 3 | + |
| 4 | +namespace Firehed\API; |
| 5 | + |
| 6 | +use ErrorException; |
| 7 | +use Exception; |
| 8 | +use Psr\Log\LoggerInterface; |
| 9 | + |
| 10 | +/** |
| 11 | + * @coversDefaultClass Firehed\API\ErrorHandler |
| 12 | + * @covers ::<protected> |
| 13 | + * @covers ::<private> |
| 14 | + */ |
| 15 | +class ErrorHandlerTest extends \PHPUnit\Framework\TestCase |
| 16 | +{ |
| 17 | + /** |
| 18 | + * @covers ::__construct |
| 19 | + */ |
| 20 | + public function testConstruct() |
| 21 | + { |
| 22 | + $this->assertInstanceOf( |
| 23 | + ErrorHandler::class, |
| 24 | + new ErrorHandler($this->createMock(LoggerInterface::class)) |
| 25 | + ); |
| 26 | + } |
| 27 | + |
| 28 | + /** |
| 29 | + * @covers ::handleThrowable |
| 30 | + * @runInSeparateProcess |
| 31 | + */ |
| 32 | + public function testHandleThrowable() |
| 33 | + { |
| 34 | + $logger = $this->createMock(LoggerInterface::class); |
| 35 | + $logger->expects($this->atLeastOnce()) |
| 36 | + ->method('error'); |
| 37 | + |
| 38 | + $handler = new ErrorHandler($logger); |
| 39 | + $handler->handleThrowable(new Exception()); |
| 40 | + } |
| 41 | + |
| 42 | + /** |
| 43 | + * @covers ::handleError |
| 44 | + */ |
| 45 | + public function testHandleError() |
| 46 | + { |
| 47 | + $handler = new ErrorHandler($this->createMock(LoggerInterface::class)); |
| 48 | + $this->expectException(ErrorException::class); |
| 49 | + $handler->handleError(\E_ERROR, 'Some error', __FILE__, __LINE__); |
| 50 | + } |
| 51 | + |
| 52 | + /** |
| 53 | + * @covers ::handleError |
| 54 | + * @doesNotPerformAssertions |
| 55 | + */ |
| 56 | + public function testHandleErrorDoesNotThrowWithErrorReportingDisabled() |
| 57 | + { |
| 58 | + $handler = new ErrorHandler($this->createMock(LoggerInterface::class)); |
| 59 | + // @ turns error_reporting() to 0 for the next line. The error handler |
| 60 | + // should respect this. |
| 61 | + @$handler->handleError(\E_ERROR, 'Some error', __FILE__, __LINE__); |
| 62 | + } |
| 63 | +} |
0 commit comments