. */ declare(strict_types=1); namespace Fisharebest\Webtrees\Http\Middleware; use Fig\Http\Message\StatusCodeInterface; use Fisharebest\Webtrees\Exceptions\InternalServerErrorException; 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 = $this->createMock(TreeService::class); $handler = $this->createMock(RequestHandlerInterface::class); $handler->method('handle')->willThrowException(new InternalServerErrorException('eek')); $module_service = $this->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); $this->assertSame(StatusCodeInterface::STATUS_INTERNAL_SERVER_ERROR, $response->getStatusCode()); app()->forgetInstance(ModuleService::class); app()->forgetInstance(UserService::class); } }