fix: unit test & psalm static code analysis issues
Signed-off-by: Luka Trovic <luka@nextcloud.com>
This commit is contained in:
committed by
Julius Härtl
parent
b6340e54c3
commit
afbbdf0c1b
@@ -110,8 +110,22 @@ class AttachmentServiceTest extends TestCase {
|
||||
$this->cache = $this->createMock(ICache::class);
|
||||
$this->cacheFactory->expects($this->any())->method('createDistributed')->willReturn($this->cache);
|
||||
|
||||
$this->appContainer->expects($this->at(0))->method('query')->with(FileService::class)->willReturn($this->attachmentServiceImpl);
|
||||
$this->appContainer->expects($this->at(1))->method('query')->with(FilesAppService::class)->willReturn($this->filesAppServiceImpl);
|
||||
$this->appContainer->expects($this->exactly(2))
|
||||
->method('query')
|
||||
->withConsecutive(
|
||||
[FileService::class],
|
||||
[FilesAppService::class]
|
||||
)
|
||||
->willReturnOnConsecutiveCalls($this->attachmentServiceImpl, $this->filesAppServiceImpl);
|
||||
|
||||
/* $this->appContainer->expects($this->at(0))
|
||||
->method('query')
|
||||
->with(FileService::class)
|
||||
->willReturn($this->attachmentServiceImpl);
|
||||
$this->appContainer->expects($this->at(1))
|
||||
->method('query')
|
||||
->with(FilesAppService::class)
|
||||
->willReturn($this->filesAppServiceImpl); */
|
||||
|
||||
$this->application->expects($this->any())
|
||||
->method('getContainer')
|
||||
@@ -129,9 +143,27 @@ class AttachmentServiceTest extends TestCase {
|
||||
$fileServiceMock = $this->createMock(FileService::class);
|
||||
$fileAppServiceMock = $this->createMock(FilesAppService::class);
|
||||
|
||||
$appContainer->expects($this->at(0))->method('query')->with(FileService::class)->willReturn($fileServiceMock);
|
||||
$appContainer->expects($this->at(1))->method('query')->with(FilesAppService::class)->willReturn($fileAppServiceMock);
|
||||
$appContainer->expects($this->at(2))->method('query')->with(MyAttachmentService::class)->willReturn(new MyAttachmentService());
|
||||
$appContainer->expects($this->exactly(3))
|
||||
->method('query')
|
||||
->withConsecutive(
|
||||
[FileService::class],
|
||||
[FilesAppService::class],
|
||||
[MyAttachmentService::class]
|
||||
)
|
||||
->willReturnOnConsecutiveCalls($fileServiceMock, $fileAppServiceMock, new MyAttachmentService());
|
||||
|
||||
/* $appContainer->expects($this->at(0))
|
||||
->method('query')
|
||||
->with(FileService::class)
|
||||
->willReturn($fileServiceMock);
|
||||
$appContainer->expects($this->at(1))
|
||||
->method('query')
|
||||
->with(FilesAppService::class)
|
||||
->willReturn($fileAppServiceMock);
|
||||
$appContainer->expects($this->at(2))
|
||||
->method('query')
|
||||
->with(MyAttachmentService::class)
|
||||
->willReturn(new MyAttachmentService()); */
|
||||
|
||||
$application->expects($this->any())
|
||||
->method('getContainer')
|
||||
@@ -148,12 +180,32 @@ class AttachmentServiceTest extends TestCase {
|
||||
$appContainer = $this->createMock(IAppContainer::class);
|
||||
$fileServiceMock = $this->createMock(FileService::class);
|
||||
$fileAppServiceMock = $this->createMock(FilesAppService::class);
|
||||
$appContainer->expects($this->at(0))->method('query')->with(FileService::class)->willReturn($fileServiceMock);
|
||||
$appContainer->expects($this->at(1))->method('query')->with(FilesAppService::class)->willReturn($fileAppServiceMock);
|
||||
$appContainer->expects($this->at(2))->method('query')->with(MyAttachmentService::class)->willReturn(new MyAttachmentService());
|
||||
|
||||
$appContainer->expects($this->exactly(3))
|
||||
->method('query')
|
||||
->withConsecutive(
|
||||
[FileService::class],
|
||||
[FilesAppService::class],
|
||||
[MyAttachmentService::class]
|
||||
)
|
||||
->willReturnOnConsecutiveCalls($fileServiceMock, $fileAppServiceMock, new MyAttachmentService());
|
||||
|
||||
/* $appContainer->expects($this->at(0))
|
||||
->method('query')
|
||||
->with(FileService::class)
|
||||
->willReturn($fileServiceMock);
|
||||
$appContainer->expects($this->at(1))
|
||||
->method('query')
|
||||
->with(FilesAppService::class)
|
||||
->willReturn($fileAppServiceMock);
|
||||
$appContainer->expects($this->at(2))
|
||||
->method('query')
|
||||
->with(MyAttachmentService::class)
|
||||
->willReturn(new MyAttachmentService()); */
|
||||
$application->expects($this->any())
|
||||
->method('getContainer')
|
||||
->willReturn($appContainer);
|
||||
|
||||
$attachmentService = new AttachmentService($this->attachmentMapper, $this->cardMapper, $this->changeHelper, $this->permissionService, $application, $this->cacheFactory, $this->userId, $this->l10n, $this->activityManager);
|
||||
$attachmentService->registerAttachmentService('custom', MyAttachmentService::class);
|
||||
$attachmentService->getService('deck_file_invalid');
|
||||
@@ -185,12 +237,19 @@ class AttachmentServiceTest extends TestCase {
|
||||
->with(123)
|
||||
->willReturn($attachments);
|
||||
|
||||
$this->attachmentServiceImpl->expects($this->at(0))
|
||||
$this->attachmentServiceImpl->expects($this->exactly(2))
|
||||
->method('extendData')
|
||||
->withConsecutive(
|
||||
[$attachments[0]],
|
||||
[$attachments[1]]
|
||||
);
|
||||
|
||||
/* $this->attachmentServiceImpl->expects($this->at(0))
|
||||
->method('extendData')
|
||||
->with($attachments[0]);
|
||||
$this->attachmentServiceImpl->expects($this->at(1))
|
||||
->method('extendData')
|
||||
->with($attachments[1]);
|
||||
->with($attachments[1]); */
|
||||
$this->assertEquals($attachments, $this->attachmentService->findAll(123, false));
|
||||
}
|
||||
|
||||
@@ -215,12 +274,21 @@ class AttachmentServiceTest extends TestCase {
|
||||
->with(123, false)
|
||||
->willReturn($attachmentsDeleted);
|
||||
|
||||
$this->attachmentServiceImpl->expects($this->at(0))
|
||||
$this->attachmentServiceImpl->expects($this->exactly(4))
|
||||
->method('extendData')
|
||||
->withConsecutive(
|
||||
[$attachments[0]],
|
||||
[$attachments[1]],
|
||||
[$attachmentsDeleted[0]],
|
||||
[$attachmentsDeleted[1]]
|
||||
);
|
||||
|
||||
/* $this->attachmentServiceImpl->expects($this->at(0))
|
||||
->method('extendData')
|
||||
->with($attachments[0]);
|
||||
$this->attachmentServiceImpl->expects($this->at(1))
|
||||
->method('extendData')
|
||||
->with($attachments[1]);
|
||||
->with($attachments[1]); */
|
||||
$this->assertEquals(array_merge($attachments, $attachmentsDeleted), $this->attachmentService->findAll(123, true));
|
||||
}
|
||||
|
||||
|
||||
@@ -300,22 +300,41 @@ class BoardServiceTest extends TestCase {
|
||||
$existingAcl->setPermissionEdit($currentUserAcl[0]);
|
||||
$existingAcl->setPermissionShare($currentUserAcl[1]);
|
||||
$existingAcl->setPermissionManage($currentUserAcl[2]);
|
||||
$this->permissionService->expects($this->at(0))
|
||||
->method('checkPermission')
|
||||
->with($this->boardMapper, 123, Acl::PERMISSION_SHARE, null);
|
||||
|
||||
if ($currentUserAcl[2]) {
|
||||
$this->permissionService->expects($this->at(1))
|
||||
$this->permissionService->expects($this->exactly(2))
|
||||
->method('checkPermission')
|
||||
->with($this->boardMapper, 123, Acl::PERMISSION_MANAGE, null);
|
||||
->withConsecutive(
|
||||
[$this->boardMapper, 123, Acl::PERMISSION_SHARE, null],
|
||||
[$this->boardMapper, 123, Acl::PERMISSION_MANAGE, null]
|
||||
);
|
||||
} else {
|
||||
$this->aclMapper->expects($this->once())
|
||||
->method('findAll')
|
||||
->willReturn([$existingAcl]);
|
||||
$this->permissionService->expects($this->at(1))
|
||||
|
||||
$this->permissionService->expects($this->exactly(2))
|
||||
->method('checkPermission')
|
||||
->with($this->boardMapper, 123, Acl::PERMISSION_MANAGE, null)
|
||||
->willThrowException(new NoPermissionException('No permission'));
|
||||
$this->permissionService->expects($this->at(2))
|
||||
->withConsecutive(
|
||||
[$this->boardMapper, 123, Acl::PERMISSION_SHARE, null],
|
||||
[$this->boardMapper, 123, Acl::PERMISSION_MANAGE, null]
|
||||
)
|
||||
->will(
|
||||
$this->onConsecutiveCalls(
|
||||
true,
|
||||
$this->throwException(new NoPermissionException('No permission'))
|
||||
)
|
||||
);
|
||||
|
||||
$this->permissionService->expects($this->exactly(3))
|
||||
->method('userCan')
|
||||
->willReturnOnConsecutiveCalls(
|
||||
$currentUserAcl[0],
|
||||
$currentUserAcl[1],
|
||||
$currentUserAcl[2]
|
||||
);
|
||||
|
||||
/* $this->permissionService->expects($this->at(2))
|
||||
->method('userCan')
|
||||
->willReturn($currentUserAcl[0]);
|
||||
$this->permissionService->expects($this->at(3))
|
||||
@@ -323,7 +342,7 @@ class BoardServiceTest extends TestCase {
|
||||
->willReturn($currentUserAcl[1]);
|
||||
$this->permissionService->expects($this->at(4))
|
||||
->method('userCan')
|
||||
->willReturn($currentUserAcl[2]);
|
||||
->willReturn($currentUserAcl[2]); */
|
||||
}
|
||||
|
||||
$user = $this->createMock(IUser::class);
|
||||
|
||||
@@ -139,13 +139,17 @@ class PermissionServiceTest extends \Test\TestCase {
|
||||
}
|
||||
|
||||
public function testUserIsBoardOwner() {
|
||||
$board = new Board();
|
||||
$board->setOwner('admin');
|
||||
$this->boardMapper->expects($this->at(0))->method('find')->with(123)->willReturn($board);
|
||||
$adminBoard = new Board();
|
||||
$adminBoard->setOwner('admin');
|
||||
$userBoard = new Board();
|
||||
$userBoard->setOwner('user1');
|
||||
|
||||
$this->boardMapper->expects($this->exactly(2))
|
||||
->method('find')
|
||||
->withConsecutive([123], [234])
|
||||
->willReturnOnConsecutiveCalls($adminBoard, $userBoard);
|
||||
|
||||
$this->assertEquals(true, $this->service->userIsBoardOwner(123));
|
||||
$board = new Board();
|
||||
$board->setOwner('user1');
|
||||
$this->boardMapper->expects($this->at(0))->method('find')->with(234)->willReturn($board);
|
||||
$this->assertEquals(false, $this->service->userIsBoardOwner(234));
|
||||
}
|
||||
|
||||
@@ -336,7 +340,7 @@ class PermissionServiceTest extends \Test\TestCase {
|
||||
$aclGroup->setParticipant('group1');
|
||||
|
||||
$board = $this->createMock(Board::class);
|
||||
$board->expects($this->at(0))
|
||||
$board->expects($this->once())
|
||||
->method('__call')
|
||||
->with('getOwner', [])
|
||||
->willReturn('user1');
|
||||
@@ -348,14 +352,11 @@ class PermissionServiceTest extends \Test\TestCase {
|
||||
->method('find')
|
||||
->with(123)
|
||||
->willReturn($board);
|
||||
$this->userManager->expects($this->at(0))
|
||||
$this->userManager->expects($this->exactly(2))
|
||||
->method('get')
|
||||
->with('user1')
|
||||
->willReturn($user1);
|
||||
$this->userManager->expects($this->at(1))
|
||||
->method('get')
|
||||
->with('user2')
|
||||
->willReturn($user2);
|
||||
->withConsecutive(['user1'], ['user2'])
|
||||
->willReturnOnConsecutiveCalls($user1, $user2);
|
||||
|
||||
$group = $this->createMock(IGroup::class);
|
||||
$group->expects($this->once())
|
||||
->method('getUsers')
|
||||
|
||||
Reference in New Issue
Block a user