Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Mock GuestAvatar in unit test
Signed-off-by: nabim777 <[email protected]>
  • Loading branch information
nabim777 committed Aug 8, 2025
commit e5ace0c16907965e43ad951be440f54d79ad563b
21 changes: 13 additions & 8 deletions tests/lib/Service/OpenProjectAPIServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
use OCP\Files\IRootFolder;
use OCP\Files\NotFoundException;
use OCP\Files\NotPermittedException;
use OCP\Files\SimpleFS\ISimpleFile;
use OCP\Group\ISubAdmin;
use OCP\Http\Client\IClientService;
use OCP\IAvatarManager;
Expand Down Expand Up @@ -755,19 +756,23 @@ private function getOpenProjectAPIService(
$this->createMock(IRemoteHostValidator::class),
$this->createMock(LoggerInterface::class));

$clientService = $this->getMockBuilder('\OCP\Http\Client\IClientService')->getMock();
$clientService = $this->getMockBuilder(IClientService::class)->getMock();
$clientService->method('newClient')->willReturn($ocClient);

$avatarManagerMock = $this->getMockBuilder('\OCP\IAvatarManager')
$guestAvatarMock = $this->getMockBuilder(GuestAvatar::class)->disableOriginalConstructor()->getMock();

$avatarFileMock = $this->createMock(ISimpleFile::class);
$avatarFileMock->method('getContent')
->willReturn(\file_get_contents(__DIR__ . "/../fixtures/openproject-icon.jpg"));

$guestAvatarMock->method('getFile')
->willReturn($avatarFileMock);

$avatarManagerMock = $this->getMockBuilder(IAvatarManager::class)
->getMock();
$avatarManagerMock
->method('getGuestAvatar')
->willReturn(
new GuestAvatar(
'test',
$this->createMock(LoggerInterface::class)
)
);
->willReturn($guestAvatarMock);
if ($storageMock === null) {
$storageMock = $this->createMock(IRootFolder::class);
}
Expand Down