fix: unit test & psalm static code analysis issues

Signed-off-by: Luka Trovic <luka@nextcloud.com>
This commit is contained in:
Luka Trovic
2022-03-04 18:06:08 +01:00
committed by Julius Härtl
parent b6340e54c3
commit afbbdf0c1b
9 changed files with 200 additions and 155 deletions

View File

@@ -33,7 +33,7 @@ final class TransferOwnership extends Command {
); );
} }
protected function execute(InputInterface $input, OutputInterface $output) { protected function execute(InputInterface $input, OutputInterface $output): int {
$owner = $input->getArgument('owner'); $owner = $input->getArgument('owner');
$newOwner = $input->getArgument('newOwner'); $newOwner = $input->getArgument('newOwner');
@@ -42,5 +42,7 @@ final class TransferOwnership extends Command {
$this->boardService->transferOwnership($owner, $newOwner); $this->boardService->transferOwnership($owner, $newOwner);
$output->writeln("Transfer deck boards from $owner to $newOwner completed"); $output->writeln("Transfer deck boards from $owner to $newOwner completed");
return 0;
} }
} }

View File

@@ -148,11 +148,12 @@ class AssignmentMapper extends QBMapper implements IPermissionMapper {
} }
/** /**
* @psalm-suppress InvalidScalarArgument
* @param $ownerId * @param $ownerId
* @param $newOwnerId * @param $newOwnerId
* @return void * @return void
*/ */
public function transferOwnership($ownerId, $newOwnerId) { public function transferOwnership(string $ownerId, string $newOwnerId) {
$params = [ $params = [
'newOwner' => $newOwnerId, 'newOwner' => $newOwnerId,
'type' => Assignment::TYPE_USER 'type' => Assignment::TYPE_USER

View File

@@ -169,18 +169,15 @@ class ActivityManagerTest extends TestCase {
$this->mockUser('user2'), $this->mockUser('user2'),
]; ];
$event = $this->createMock(IEvent::class); $event = $this->createMock(IEvent::class);
$event->expects($this->at(0)) $event->expects($this->once())
->method('getObjectType') ->method('getObjectType')
->willReturn($objectType); ->willReturn($objectType);
$event->expects($this->at(0)) $event->expects($this->once())
->method('getObjectId') ->method('getObjectId')
->willReturn(1); ->willReturn(1);
$event->expects($this->at(2)) $event->expects($this->exactly(2))
->method('setAffectedUser') ->method('setAffectedUser')
->with('user1'); ->withConsecutive(['user1'], ['user2']);
$event->expects($this->at(3))
->method('setAffectedUser')
->with('user2');
$mapper = null; $mapper = null;
switch ($objectType) { switch ($objectType) {
case ActivityManager::DECK_OBJECT_BOARD: case ActivityManager::DECK_OBJECT_BOARD:
@@ -196,10 +193,7 @@ class ActivityManagerTest extends TestCase {
$this->permissionService->expects($this->once()) $this->permissionService->expects($this->once())
->method('findUsers') ->method('findUsers')
->willReturn($users); ->willReturn($users);
$this->manager->expects($this->at(0)) $this->manager->expects($this->exactly(2))
->method('publish')
->with($event);
$this->manager->expects($this->at(1))
->method('publish') ->method('publish')
->with($event); ->with($event);
$this->invokePrivate($this->activityManager, 'sendToUsers', [$event]); $this->invokePrivate($this->activityManager, 'sendToUsers', [$event]);

View File

@@ -66,18 +66,14 @@ class DeleteCronTest extends \Test\TestCase {
$this->boardMapper->expects($this->once()) $this->boardMapper->expects($this->once())
->method('findToDelete') ->method('findToDelete')
->willReturn($boards); ->willReturn($boards);
$this->boardMapper->expects($this->at(1)) $this->boardMapper->expects($this->exactly(count($boards)))
->method('delete') ->method('delete')
->with($boards[0]); ->withConsecutive(
$this->boardMapper->expects($this->at(2)) [$boards[0]],
->method('delete') [$boards[1]],
->with($boards[1]); [$boards[2]],
$this->boardMapper->expects($this->at(3)) [$boards[3]]
->method('delete') );
->with($boards[2]);
$this->boardMapper->expects($this->at(4))
->method('delete')
->with($boards[3]);
$attachment = new Attachment(); $attachment = new Attachment();
$attachment->setType('deck_file'); $attachment->setType('deck_file');

View File

@@ -54,10 +54,7 @@ class ScheduledNoificationsTest extends \Test\TestCase {
$this->cardMapper->expects($this->once()) $this->cardMapper->expects($this->once())
->method('findOverdue') ->method('findOverdue')
->willReturn($cards); ->willReturn($cards);
$this->notificationHelper->expects($this->at(0)) $this->notificationHelper->expects($this->exactly(2))
->method('sendCardDuedate')
->with($c1);
$this->notificationHelper->expects($this->at(1))
->method('sendCardDuedate') ->method('sendCardDuedate')
->with($c1); ->with($c1);
$this->scheduledNotifications->run(null); $this->scheduledNotifications->run(null);

View File

@@ -114,17 +114,18 @@ class NotificationHelperTest extends \Test\TestCase {
} }
public function testSendCardDuedate() { public function testSendCardDuedate() {
$this->config->expects($this->at(0)) $param1 = ['foo', 'bar', 'asd'];
$param2 = 'deck';
$param3 = 'board:234:notify-due';
$DUE_ASSIGNED = ConfigService::SETTING_BOARD_NOTIFICATION_DUE_ASSIGNED;
$this->config->expects($this->exactly(3))
->method('getUserValue') ->method('getUserValue')
->with('foo', 'deck', 'board:234:notify-due', ConfigService::SETTING_BOARD_NOTIFICATION_DUE_ASSIGNED) ->withConsecutive(
->willReturn(ConfigService::SETTING_BOARD_NOTIFICATION_DUE_ALL); [$param1[0], $param2, $param3, $DUE_ASSIGNED],
$this->config->expects($this->at(1)) [$param1[1], $param2, $param3, $DUE_ASSIGNED],
->method('getUserValue') [$param1[2], $param2, $param3, $DUE_ASSIGNED],
->with('bar', 'deck', 'board:234:notify-due', ConfigService::SETTING_BOARD_NOTIFICATION_DUE_ASSIGNED) )
->willReturn(ConfigService::SETTING_BOARD_NOTIFICATION_DUE_ALL);
$this->config->expects($this->at(2))
->method('getUserValue')
->with('asd', 'deck', 'board:234:notify-due', ConfigService::SETTING_BOARD_NOTIFICATION_DUE_ASSIGNED)
->willReturn(ConfigService::SETTING_BOARD_NOTIFICATION_DUE_ALL); ->willReturn(ConfigService::SETTING_BOARD_NOTIFICATION_DUE_ALL);
$card = Card::fromParams([ $card = Card::fromParams([
@@ -180,24 +181,12 @@ class NotificationHelperTest extends \Test\TestCase {
$n3->expects($this->once())->method('setSubject')->with('card-overdue', ['MyCardTitle', 'MyBoardTitle'])->willReturn($n3); $n3->expects($this->once())->method('setSubject')->with('card-overdue', ['MyCardTitle', 'MyBoardTitle'])->willReturn($n3);
$n3->expects($this->once())->method('setDateTime')->willReturn($n3); $n3->expects($this->once())->method('setDateTime')->willReturn($n3);
$this->notificationManager->expects($this->at(0)) $this->notificationManager->expects($this->exactly(3))
->method('createNotification') ->method('createNotification')
->willReturn($n1); ->willReturnOnConsecutiveCalls($n1, $n2, $n3);
$this->notificationManager->expects($this->at(1)) $this->notificationManager->expects($this->exactly(3))
->method('notify') ->method('notify')
->with($n1); ->withConsecutive([$n1], [$n2], [$n3]);
$this->notificationManager->expects($this->at(2))
->method('createNotification')
->willReturn($n2);
$this->notificationManager->expects($this->at(3))
->method('notify')
->with($n2);
$this->notificationManager->expects($this->at(4))
->method('createNotification')
->willReturn($n3);
$this->notificationManager->expects($this->at(5))
->method('notify')
->with($n3);
$this->cardMapper->expects($this->once()) $this->cardMapper->expects($this->once())
->method('markNotified') ->method('markNotified')
@@ -207,18 +196,19 @@ class NotificationHelperTest extends \Test\TestCase {
} }
public function testSendCardDuedateAssigned() { public function testSendCardDuedateAssigned() {
$this->config->expects($this->at(0)) $param1 = ['foo', 'bar', 'asd'];
$param2 = 'deck';
$param3 = 'board:234:notify-due';
$DUE_ASSIGNED = ConfigService::SETTING_BOARD_NOTIFICATION_DUE_ASSIGNED;
$this->config->expects($this->exactly(3))
->method('getUserValue') ->method('getUserValue')
->with('foo', 'deck', 'board:234:notify-due', ConfigService::SETTING_BOARD_NOTIFICATION_DUE_ASSIGNED) ->withConsecutive(
->willReturn(ConfigService::SETTING_BOARD_NOTIFICATION_DUE_ASSIGNED); [$param1[0], $param2, $param3, $DUE_ASSIGNED],
$this->config->expects($this->at(1)) [$param1[1], $param2, $param3, $DUE_ASSIGNED],
->method('getUserValue') [$param1[2], $param2, $param3, $DUE_ASSIGNED]
->with('bar', 'deck', 'board:234:notify-due', ConfigService::SETTING_BOARD_NOTIFICATION_DUE_ASSIGNED) )
->willReturn(ConfigService::SETTING_BOARD_NOTIFICATION_DUE_ASSIGNED); ->willReturn($DUE_ASSIGNED);
$this->config->expects($this->at(2))
->method('getUserValue')
->with('asd', 'deck', 'board:234:notify-due', ConfigService::SETTING_BOARD_NOTIFICATION_DUE_ASSIGNED)
->willReturn(ConfigService::SETTING_BOARD_NOTIFICATION_DUE_ASSIGNED);
$users = [ $users = [
new DummyUser('foo'), new DummyUser('bar'), new DummyUser('asd') new DummyUser('foo'), new DummyUser('bar'), new DummyUser('asd')
@@ -278,24 +268,12 @@ class NotificationHelperTest extends \Test\TestCase {
$n3->expects($this->once())->method('setSubject')->with('card-overdue', ['MyCardTitle', 'MyBoardTitle'])->willReturn($n3); $n3->expects($this->once())->method('setSubject')->with('card-overdue', ['MyCardTitle', 'MyBoardTitle'])->willReturn($n3);
$n3->expects($this->once())->method('setDateTime')->willReturn($n3); $n3->expects($this->once())->method('setDateTime')->willReturn($n3);
$this->notificationManager->expects($this->at(0)) $this->notificationManager->expects($this->exactly(3))
->method('createNotification') ->method('createNotification')
->willReturn($n1); ->willReturnOnConsecutiveCalls($n1, $n2, $n3);
$this->notificationManager->expects($this->at(1)) $this->notificationManager->expects($this->exactly(3))
->method('notify') ->method('notify')
->with($n1); ->withConsecutive([$n1], [$n2], [$n3]);
$this->notificationManager->expects($this->at(2))
->method('createNotification')
->willReturn($n2);
$this->notificationManager->expects($this->at(3))
->method('notify')
->with($n2);
$this->notificationManager->expects($this->at(4))
->method('createNotification')
->willReturn($n3);
$this->notificationManager->expects($this->at(5))
->method('notify')
->with($n3);
$this->cardMapper->expects($this->once()) $this->cardMapper->expects($this->once())
->method('markNotified') ->method('markNotified')
@@ -306,18 +284,20 @@ class NotificationHelperTest extends \Test\TestCase {
public function testSendCardDuedateNever() { public function testSendCardDuedateNever() {
$this->config->expects($this->at(0)) $param1 = ['foo', 'bar', 'asd'];
$param2 = 'deck';
$param3 = 'board:234:notify-due';
$DUE_ASSIGNED = ConfigService::SETTING_BOARD_NOTIFICATION_DUE_ASSIGNED;
$DUE_OFF = ConfigService::SETTING_BOARD_NOTIFICATION_DUE_OFF;
$this->config->expects($this->exactly(3))
->method('getUserValue') ->method('getUserValue')
->with('foo', 'deck', 'board:234:notify-due', ConfigService::SETTING_BOARD_NOTIFICATION_DUE_ASSIGNED) ->withConsecutive(
->willReturn(ConfigService::SETTING_BOARD_NOTIFICATION_DUE_ASSIGNED); [$param1[0], $param2, $param3, $DUE_ASSIGNED],
$this->config->expects($this->at(1)) [$param1[1], $param2, $param3, $DUE_ASSIGNED],
->method('getUserValue') [$param1[2], $param2, $param3, $DUE_ASSIGNED]
->with('bar', 'deck', 'board:234:notify-due', ConfigService::SETTING_BOARD_NOTIFICATION_DUE_ASSIGNED) )
->willReturn(ConfigService::SETTING_BOARD_NOTIFICATION_DUE_ASSIGNED); ->willReturnOnConsecutiveCalls($DUE_ASSIGNED, $DUE_ASSIGNED, $DUE_OFF);
$this->config->expects($this->at(2))
->method('getUserValue')
->with('asd', 'deck', 'board:234:notify-due', ConfigService::SETTING_BOARD_NOTIFICATION_DUE_ASSIGNED)
->willReturn(ConfigService::SETTING_BOARD_NOTIFICATION_DUE_OFF);
$users = [ $users = [
new DummyUser('foo'), new DummyUser('bar'), new DummyUser('asd') new DummyUser('foo'), new DummyUser('bar'), new DummyUser('asd')
@@ -370,18 +350,12 @@ class NotificationHelperTest extends \Test\TestCase {
$n2->expects($this->once())->method('setSubject')->with('card-overdue', ['MyCardTitle', 'MyBoardTitle'])->willReturn($n2); $n2->expects($this->once())->method('setSubject')->with('card-overdue', ['MyCardTitle', 'MyBoardTitle'])->willReturn($n2);
$n2->expects($this->once())->method('setDateTime')->willReturn($n2); $n2->expects($this->once())->method('setDateTime')->willReturn($n2);
$this->notificationManager->expects($this->at(0)) $this->notificationManager->expects($this->exactly(2))
->method('createNotification') ->method('createNotification')
->willReturn($n1); ->willReturnOnConsecutiveCalls($n1, $n2);
$this->notificationManager->expects($this->at(1)) $this->notificationManager->expects($this->exactly(2))
->method('notify') ->method('notify')
->with($n1); ->withConsecutive([$n1], [$n2]);
$this->notificationManager->expects($this->at(2))
->method('createNotification')
->willReturn($n2);
$this->notificationManager->expects($this->at(3))
->method('notify')
->with($n2);
$this->cardMapper->expects($this->once()) $this->cardMapper->expects($this->once())
->method('markNotified') ->method('markNotified')
@@ -423,10 +397,10 @@ class NotificationHelperTest extends \Test\TestCase {
$notification->expects($this->once())->method('setSubject')->with('card-assigned', ['MyCardTitle', 'MyBoardTitle', 'admin'])->willReturn($notification); $notification->expects($this->once())->method('setSubject')->with('card-assigned', ['MyCardTitle', 'MyBoardTitle', 'admin'])->willReturn($notification);
$notification->expects($this->once())->method('setDateTime')->willReturn($notification); $notification->expects($this->once())->method('setDateTime')->willReturn($notification);
$this->notificationManager->expects($this->at(0)) $this->notificationManager->expects($this->once())
->method('createNotification') ->method('createNotification')
->willReturn($notification); ->willReturn($notification);
$this->notificationManager->expects($this->at(1)) $this->notificationManager->expects($this->once())
->method('notify') ->method('notify')
->with($notification); ->with($notification);
@@ -451,10 +425,10 @@ class NotificationHelperTest extends \Test\TestCase {
$notification->expects($this->once())->method('setSubject')->with('board-shared', ['MyBoardTitle', 'admin'])->willReturn($notification); $notification->expects($this->once())->method('setSubject')->with('board-shared', ['MyBoardTitle', 'admin'])->willReturn($notification);
$notification->expects($this->once())->method('setDateTime')->willReturn($notification); $notification->expects($this->once())->method('setDateTime')->willReturn($notification);
$this->notificationManager->expects($this->at(0)) $this->notificationManager->expects($this->once())
->method('createNotification') ->method('createNotification')
->willReturn($notification); ->willReturn($notification);
$this->notificationManager->expects($this->at(1)) $this->notificationManager->expects($this->once())
->method('notify') ->method('notify')
->with($notification); ->with($notification);
@@ -490,10 +464,10 @@ class NotificationHelperTest extends \Test\TestCase {
$notification->expects($this->once())->method('setSubject')->with('board-shared', ['MyBoardTitle', 'admin'])->willReturn($notification); $notification->expects($this->once())->method('setSubject')->with('board-shared', ['MyBoardTitle', 'admin'])->willReturn($notification);
$notification->expects($this->once())->method('setDateTime')->willReturn($notification); $notification->expects($this->once())->method('setDateTime')->willReturn($notification);
$this->notificationManager->expects($this->at(0)) $this->notificationManager->expects($this->once())
->method('createNotification') ->method('createNotification')
->willReturn($notification); ->willReturn($notification);
$this->notificationManager->expects($this->at(1)) $this->notificationManager->expects($this->once())
->method('notify') ->method('notify')
->with($notification); ->with($notification);
@@ -540,19 +514,12 @@ class NotificationHelperTest extends \Test\TestCase {
$notification2->expects($this->once())->method('setSubject')->with('card-comment-mentioned', ['MyCard', 1, 'admin'])->willReturn($notification2); $notification2->expects($this->once())->method('setSubject')->with('card-comment-mentioned', ['MyCard', 1, 'admin'])->willReturn($notification2);
$notification2->expects($this->once())->method('setDateTime')->willReturn($notification2); $notification2->expects($this->once())->method('setDateTime')->willReturn($notification2);
$this->notificationManager->expects($this->at(0)) $this->notificationManager->expects($this->exactly(2))
->method('createNotification') ->method('createNotification')
->willReturn($notification1); ->willReturnOnConsecutiveCalls($notification1, $notification2);
$this->notificationManager->expects($this->at(1)) $this->notificationManager->expects($this->exactly(2))
->method('notify') ->method('notify')
->with($notification1); ->withConsecutive([$notification1], [$notification2]);
$this->notificationManager->expects($this->at(2))
->method('createNotification')
->willReturn($notification2);
$this->notificationManager->expects($this->at(3))
->method('notify')
->with($notification2);
$this->notificationHelper->sendMention($comment); $this->notificationHelper->sendMention($comment);
} }

View File

@@ -110,8 +110,22 @@ class AttachmentServiceTest extends TestCase {
$this->cache = $this->createMock(ICache::class); $this->cache = $this->createMock(ICache::class);
$this->cacheFactory->expects($this->any())->method('createDistributed')->willReturn($this->cache); $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->exactly(2))
$this->appContainer->expects($this->at(1))->method('query')->with(FilesAppService::class)->willReturn($this->filesAppServiceImpl); ->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()) $this->application->expects($this->any())
->method('getContainer') ->method('getContainer')
@@ -129,9 +143,27 @@ class AttachmentServiceTest extends TestCase {
$fileServiceMock = $this->createMock(FileService::class); $fileServiceMock = $this->createMock(FileService::class);
$fileAppServiceMock = $this->createMock(FilesAppService::class); $fileAppServiceMock = $this->createMock(FilesAppService::class);
$appContainer->expects($this->at(0))->method('query')->with(FileService::class)->willReturn($fileServiceMock); $appContainer->expects($this->exactly(3))
$appContainer->expects($this->at(1))->method('query')->with(FilesAppService::class)->willReturn($fileAppServiceMock); ->method('query')
$appContainer->expects($this->at(2))->method('query')->with(MyAttachmentService::class)->willReturn(new MyAttachmentService()); ->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()) $application->expects($this->any())
->method('getContainer') ->method('getContainer')
@@ -148,12 +180,32 @@ class AttachmentServiceTest extends TestCase {
$appContainer = $this->createMock(IAppContainer::class); $appContainer = $this->createMock(IAppContainer::class);
$fileServiceMock = $this->createMock(FileService::class); $fileServiceMock = $this->createMock(FileService::class);
$fileAppServiceMock = $this->createMock(FilesAppService::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->exactly(3))
$appContainer->expects($this->at(2))->method('query')->with(MyAttachmentService::class)->willReturn(new MyAttachmentService()); ->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()) $application->expects($this->any())
->method('getContainer') ->method('getContainer')
->willReturn($appContainer); ->willReturn($appContainer);
$attachmentService = new AttachmentService($this->attachmentMapper, $this->cardMapper, $this->changeHelper, $this->permissionService, $application, $this->cacheFactory, $this->userId, $this->l10n, $this->activityManager); $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->registerAttachmentService('custom', MyAttachmentService::class);
$attachmentService->getService('deck_file_invalid'); $attachmentService->getService('deck_file_invalid');
@@ -185,12 +237,19 @@ class AttachmentServiceTest extends TestCase {
->with(123) ->with(123)
->willReturn($attachments); ->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') ->method('extendData')
->with($attachments[0]); ->with($attachments[0]);
$this->attachmentServiceImpl->expects($this->at(1)) $this->attachmentServiceImpl->expects($this->at(1))
->method('extendData') ->method('extendData')
->with($attachments[1]); ->with($attachments[1]); */
$this->assertEquals($attachments, $this->attachmentService->findAll(123, false)); $this->assertEquals($attachments, $this->attachmentService->findAll(123, false));
} }
@@ -215,12 +274,21 @@ class AttachmentServiceTest extends TestCase {
->with(123, false) ->with(123, false)
->willReturn($attachmentsDeleted); ->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') ->method('extendData')
->with($attachments[0]); ->with($attachments[0]);
$this->attachmentServiceImpl->expects($this->at(1)) $this->attachmentServiceImpl->expects($this->at(1))
->method('extendData') ->method('extendData')
->with($attachments[1]); ->with($attachments[1]); */
$this->assertEquals(array_merge($attachments, $attachmentsDeleted), $this->attachmentService->findAll(123, true)); $this->assertEquals(array_merge($attachments, $attachmentsDeleted), $this->attachmentService->findAll(123, true));
} }

View File

@@ -300,22 +300,41 @@ class BoardServiceTest extends TestCase {
$existingAcl->setPermissionEdit($currentUserAcl[0]); $existingAcl->setPermissionEdit($currentUserAcl[0]);
$existingAcl->setPermissionShare($currentUserAcl[1]); $existingAcl->setPermissionShare($currentUserAcl[1]);
$existingAcl->setPermissionManage($currentUserAcl[2]); $existingAcl->setPermissionManage($currentUserAcl[2]);
$this->permissionService->expects($this->at(0))
->method('checkPermission')
->with($this->boardMapper, 123, Acl::PERMISSION_SHARE, null);
if ($currentUserAcl[2]) { if ($currentUserAcl[2]) {
$this->permissionService->expects($this->at(1)) $this->permissionService->expects($this->exactly(2))
->method('checkPermission') ->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 { } else {
$this->aclMapper->expects($this->once()) $this->aclMapper->expects($this->once())
->method('findAll') ->method('findAll')
->willReturn([$existingAcl]); ->willReturn([$existingAcl]);
$this->permissionService->expects($this->at(1))
$this->permissionService->expects($this->exactly(2))
->method('checkPermission') ->method('checkPermission')
->with($this->boardMapper, 123, Acl::PERMISSION_MANAGE, null) ->withConsecutive(
->willThrowException(new NoPermissionException('No permission')); [$this->boardMapper, 123, Acl::PERMISSION_SHARE, null],
$this->permissionService->expects($this->at(2)) [$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') ->method('userCan')
->willReturn($currentUserAcl[0]); ->willReturn($currentUserAcl[0]);
$this->permissionService->expects($this->at(3)) $this->permissionService->expects($this->at(3))
@@ -323,7 +342,7 @@ class BoardServiceTest extends TestCase {
->willReturn($currentUserAcl[1]); ->willReturn($currentUserAcl[1]);
$this->permissionService->expects($this->at(4)) $this->permissionService->expects($this->at(4))
->method('userCan') ->method('userCan')
->willReturn($currentUserAcl[2]); ->willReturn($currentUserAcl[2]); */
} }
$user = $this->createMock(IUser::class); $user = $this->createMock(IUser::class);

View File

@@ -139,13 +139,17 @@ class PermissionServiceTest extends \Test\TestCase {
} }
public function testUserIsBoardOwner() { public function testUserIsBoardOwner() {
$board = new Board(); $adminBoard = new Board();
$board->setOwner('admin'); $adminBoard->setOwner('admin');
$this->boardMapper->expects($this->at(0))->method('find')->with(123)->willReturn($board); $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)); $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)); $this->assertEquals(false, $this->service->userIsBoardOwner(234));
} }
@@ -336,7 +340,7 @@ class PermissionServiceTest extends \Test\TestCase {
$aclGroup->setParticipant('group1'); $aclGroup->setParticipant('group1');
$board = $this->createMock(Board::class); $board = $this->createMock(Board::class);
$board->expects($this->at(0)) $board->expects($this->once())
->method('__call') ->method('__call')
->with('getOwner', []) ->with('getOwner', [])
->willReturn('user1'); ->willReturn('user1');
@@ -348,14 +352,11 @@ class PermissionServiceTest extends \Test\TestCase {
->method('find') ->method('find')
->with(123) ->with(123)
->willReturn($board); ->willReturn($board);
$this->userManager->expects($this->at(0)) $this->userManager->expects($this->exactly(2))
->method('get') ->method('get')
->with('user1') ->withConsecutive(['user1'], ['user2'])
->willReturn($user1); ->willReturnOnConsecutiveCalls($user1, $user2);
$this->userManager->expects($this->at(1))
->method('get')
->with('user2')
->willReturn($user2);
$group = $this->createMock(IGroup::class); $group = $this->createMock(IGroup::class);
$group->expects($this->once()) $group->expects($this->once())
->method('getUsers') ->method('getUsers')