. */ declare(strict_types=1); namespace Fisharebest\Webtrees\Http\Middleware; use Fig\Http\Message\StatusCodeInterface; use Fisharebest\Webtrees\Http\Exceptions\HttpServerErrorException; use Fisharebest\Webtrees\Registry; use Fisharebest\Webtrees\Services\ModuleService; use Fisharebest\Webtrees\Services\TreeService; use Fisharebest\Webtrees\Services\UserService; use Fisharebest\Webtrees\TestCase; use Illuminate\Support\Collection; use PHPUnit\Framework\Attributes\CoversClass; use Psr\Http\Server\RequestHandlerInterface; #[CoversClass(HandleExceptions::class)] class HandleExceptionsTest extends TestCase { protected static bool $uses_database = true; public function testMiddleware(): void { $tree_service = $this->createMock(TreeService::class); $handler = $this->createMock(RequestHandlerInterface::class); $handler->method('handle')->willThrowException(new HttpServerErrorException('eek')); $module_service = $this->createMock(ModuleService::class); $module_service->method('findByInterface')->willReturn(new Collection()); $module_service->method('findByComponent')->willReturn(new Collection()); Registry::container()->set(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()); } }