createMock(IRequest::class); $service = $this->createMock(ShortcutService::class); $userSession = $this->createMock(IUserSession::class); $user = $this->createMock(IUser::class); $userSession->method('getUser')->willReturn($user); $payload = [ 'fileId' => 11, 'name' => 'main.tex.nextcloudshortcut', 'path' => '/test/main.tex.nextcloudshortcut', 'targetFileId' => 320, 'targetType' => 'file', ]; $service->expects($this->once()) ->method('create') ->with($user, 320, '/test', null) ->willReturn($payload); $controller = new ApiController(Application::APP_ID, $request, $service, $userSession); $this->assertSame($payload, $controller->create(320, '/test')->getData()); } public function testResolve(): void { $request = $this->createMock(IRequest::class); $service = $this->createMock(ShortcutService::class); $userSession = $this->createMock(IUserSession::class); $user = $this->createMock(IUser::class); $userSession->method('getUser')->willReturn($user); $payload = [ 'targetFileId' => 320, 'targetType' => 'file', 'name' => 'main.tex', 'path' => '/docs/main.tex', 'dirname' => '/docs', ]; $service->expects($this->once()) ->method('resolve') ->with($user, 50) ->willReturn($payload); $controller = new ApiController(Application::APP_ID, $request, $service, $userSession); $this->assertSame($payload, $controller->resolve(50)->getData()); } }