. */ declare(strict_types=1); namespace Fisharebest\Webtrees\Http\Middleware; use Fig\Http\Message\StatusCodeInterface; use Fisharebest\Webtrees\Exceptions\HttpServerErrorException; use Fisharebest\Webtrees\Services\ModuleService; use Fisharebest\Webtrees\Services\TreeService; use Fisharebest\Webtrees\Services\UserService; use Fisharebest\Webtrees\TestCase; use Illuminate\Support\Collection; use Psr\Http\Server\RequestHandlerInterface; use function app; /** * Test the HandleExceptions middleware. * * @covers \Fisharebest\Webtrees\Http\Middleware\HandleExceptions */ class HandleExceptionsTest extends TestCase { /** * @return void */ public function testMiddleware(): void { $tree_service = self::createMock(TreeService::class); $handler = self::createMock(RequestHandlerInterface::class); $handler->method('handle')->willThrowException(new HttpServerErrorException('eek')); $module_service = self::createMock(ModuleService::class); $module_service->method('findByInterface')->willReturn(new Collection()); $module_service->method('findByComponent')->willReturn(new Collection()); app()->instance(ModuleService::class, $module_service); $request = self::createRequest(); $middleware = new HandleExceptions($tree_service); $response = $middleware->process($request, $handler); self::assertSame(StatusCodeInterface::STATUS_INTERNAL_SERVER_ERROR, $response->getStatusCode()); app()->forgetInstance(ModuleService::class); app()->forgetInstance(UserService::class); } }