refactor: Fix psalm issues
- Add typing for most of the services, controllers and mappers - Add api doc for mappers - Use vendor-bin for psalm - Use attributes for controllers - Fix upload of attachments Signed-off-by: Carl Schwan <carl.schwan@nextcloud.com>
This commit is contained in:
@@ -90,8 +90,8 @@
|
||||
}
|
||||
],
|
||||
"assignedUsers": [],
|
||||
"attachments": null,
|
||||
"attachmentCount": null,
|
||||
"attachments": [],
|
||||
"attachmentCount": 0,
|
||||
"owner": {
|
||||
"primaryKey": "admin",
|
||||
"uid": "admin",
|
||||
@@ -123,8 +123,8 @@
|
||||
"createdAt": 1689667572,
|
||||
"labels": [],
|
||||
"assignedUsers": [],
|
||||
"attachments": null,
|
||||
"attachmentCount": null,
|
||||
"attachments": [],
|
||||
"attachmentCount": 0,
|
||||
"owner": {
|
||||
"primaryKey": "admin",
|
||||
"uid": "admin",
|
||||
@@ -168,8 +168,8 @@
|
||||
"type": 0
|
||||
}
|
||||
],
|
||||
"attachments": null,
|
||||
"attachmentCount": null,
|
||||
"attachments": [],
|
||||
"attachmentCount": 0,
|
||||
"owner": {
|
||||
"primaryKey": "admin",
|
||||
"uid": "admin",
|
||||
@@ -240,8 +240,8 @@
|
||||
}
|
||||
],
|
||||
"assignedUsers": [],
|
||||
"attachments": null,
|
||||
"attachmentCount": null,
|
||||
"attachments": [],
|
||||
"attachmentCount": 0,
|
||||
"owner": {
|
||||
"primaryKey": "admin",
|
||||
"uid": "admin",
|
||||
@@ -283,8 +283,8 @@
|
||||
}
|
||||
],
|
||||
"assignedUsers": [],
|
||||
"attachments": null,
|
||||
"attachmentCount": null,
|
||||
"attachments": [],
|
||||
"attachmentCount": 0,
|
||||
"owner": {
|
||||
"primaryKey": "admin",
|
||||
"uid": "admin",
|
||||
@@ -328,8 +328,8 @@
|
||||
"type": 0
|
||||
}
|
||||
],
|
||||
"attachments": null,
|
||||
"attachmentCount": null,
|
||||
"attachments": [],
|
||||
"attachmentCount": 0,
|
||||
"owner": {
|
||||
"primaryKey": "admin",
|
||||
"uid": "admin",
|
||||
@@ -493,8 +493,8 @@
|
||||
"createdAt": 1689667483,
|
||||
"labels": [],
|
||||
"assignedUsers": [],
|
||||
"attachments": null,
|
||||
"attachmentCount": null,
|
||||
"attachments": [],
|
||||
"attachmentCount": 0,
|
||||
"owner": {
|
||||
"primaryKey": "admin",
|
||||
"uid": "admin",
|
||||
@@ -526,8 +526,8 @@
|
||||
"createdAt": 1689667518,
|
||||
"labels": [],
|
||||
"assignedUsers": [],
|
||||
"attachments": null,
|
||||
"attachmentCount": null,
|
||||
"attachments": [],
|
||||
"attachmentCount": 0,
|
||||
"owner": {
|
||||
"primaryKey": "admin",
|
||||
"uid": "admin",
|
||||
@@ -559,8 +559,8 @@
|
||||
"createdAt": 1689667527,
|
||||
"labels": [],
|
||||
"assignedUsers": [],
|
||||
"attachments": null,
|
||||
"attachmentCount": null,
|
||||
"attachments": [],
|
||||
"attachmentCount": 0,
|
||||
"owner": {
|
||||
"primaryKey": "admin",
|
||||
"uid": "admin",
|
||||
@@ -592,8 +592,8 @@
|
||||
"createdAt": 1689667537,
|
||||
"labels": [],
|
||||
"assignedUsers": [],
|
||||
"attachments": null,
|
||||
"attachmentCount": null,
|
||||
"attachments": [],
|
||||
"attachmentCount": 0,
|
||||
"owner": {
|
||||
"primaryKey": "admin",
|
||||
"uid": "admin",
|
||||
@@ -636,8 +636,8 @@
|
||||
"createdAt": 1689667488,
|
||||
"labels": [],
|
||||
"assignedUsers": [],
|
||||
"attachments": null,
|
||||
"attachmentCount": null,
|
||||
"attachments": [],
|
||||
"attachmentCount": 0,
|
||||
"owner": {
|
||||
"primaryKey": "admin",
|
||||
"uid": "admin",
|
||||
@@ -680,8 +680,8 @@
|
||||
"createdAt": 1689667493,
|
||||
"labels": [],
|
||||
"assignedUsers": [],
|
||||
"attachments": null,
|
||||
"attachmentCount": null,
|
||||
"attachments": [],
|
||||
"attachmentCount": 0,
|
||||
"owner": {
|
||||
"primaryKey": "admin",
|
||||
"uid": "admin",
|
||||
@@ -713,8 +713,8 @@
|
||||
"createdAt": 1689667502,
|
||||
"labels": [],
|
||||
"assignedUsers": [],
|
||||
"attachments": null,
|
||||
"attachmentCount": null,
|
||||
"attachments": [],
|
||||
"attachmentCount": 0,
|
||||
"owner": {
|
||||
"primaryKey": "admin",
|
||||
"uid": "admin",
|
||||
|
||||
@@ -1 +1 @@
|
||||
82773
|
||||
82774
|
||||
|
||||
@@ -1,152 +1,78 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<files psalm-version="5.6.0@e784128902dfe01d489c4123d69918a9f3c1eac5">
|
||||
<files psalm-version="6.5.0@38fc8444edf0cebc9205296ee6e30e906ade783b">
|
||||
<file src="lib/Activity/Filter.php">
|
||||
<MethodSignatureMismatch>
|
||||
<code>$types</code>
|
||||
<code><![CDATA[$types]]></code>
|
||||
</MethodSignatureMismatch>
|
||||
</file>
|
||||
<file src="lib/Command/UserExport.php">
|
||||
<ImplementedReturnTypeMismatch>
|
||||
<code>void</code>
|
||||
</ImplementedReturnTypeMismatch>
|
||||
<UndefinedThisPropertyAssignment>
|
||||
<code>$this->boardMapper</code>
|
||||
<code>$this->stackMapper</code>
|
||||
</UndefinedThisPropertyAssignment>
|
||||
<UndefinedThisPropertyFetch>
|
||||
<code>$this->boardMapper</code>
|
||||
<code>$this->stackMapper</code>
|
||||
</UndefinedThisPropertyFetch>
|
||||
</file>
|
||||
<file src="lib/Controller/BoardApiController.php">
|
||||
<TypeDoesNotContainNull>
|
||||
<code>$modified === null</code>
|
||||
<code>$modified === null</code>
|
||||
</TypeDoesNotContainNull>
|
||||
<UndefinedClass>
|
||||
<code>Util</code>
|
||||
</UndefinedClass>
|
||||
<UndefinedThisPropertyAssignment>
|
||||
<code>$this->userId</code>
|
||||
</UndefinedThisPropertyAssignment>
|
||||
<UndefinedThisPropertyFetch>
|
||||
<code>$this->userId</code>
|
||||
</UndefinedThisPropertyFetch>
|
||||
</file>
|
||||
<file src="lib/Controller/CommentsApiController.php">
|
||||
<InvalidScalarArgument>
|
||||
<code>$cardId</code>
|
||||
<code>$cardId</code>
|
||||
<code>$cardId</code>
|
||||
<code>$commentId</code>
|
||||
<code>$commentId</code>
|
||||
<code>$parentId</code>
|
||||
</InvalidScalarArgument>
|
||||
<UndefinedFunction>
|
||||
<code><![CDATA[parseDate($modified)]]></code>
|
||||
</UndefinedFunction>
|
||||
</file>
|
||||
<file src="lib/Controller/PageController.php">
|
||||
<UndefinedClass>
|
||||
<code>LoadSidebar</code>
|
||||
<code><![CDATA[LoadSidebar]]></code>
|
||||
</UndefinedClass>
|
||||
</file>
|
||||
<file src="lib/Controller/StackApiController.php">
|
||||
<RedundantCondition>
|
||||
<code>$modified !== null</code>
|
||||
</RedundantCondition>
|
||||
<UndefinedClass>
|
||||
<code>Util</code>
|
||||
</UndefinedClass>
|
||||
<UndefinedFunction>
|
||||
<code><![CDATA[parseDate($modified)]]></code>
|
||||
</UndefinedFunction>
|
||||
</file>
|
||||
<file src="lib/DAV/Calendar.php">
|
||||
<UndefinedClass>
|
||||
<code>ExternalCalendar</code>
|
||||
<code><![CDATA[ExternalCalendar]]></code>
|
||||
</UndefinedClass>
|
||||
</file>
|
||||
<file src="lib/DAV/CalendarObject.php">
|
||||
<UndefinedClass>
|
||||
<code>ICalendarObject</code>
|
||||
<code><![CDATA[ICalendarObject]]></code>
|
||||
</UndefinedClass>
|
||||
</file>
|
||||
<file src="lib/DAV/CalendarPlugin.php">
|
||||
<UndefinedClass>
|
||||
<code>ICalendarProvider</code>
|
||||
<code><![CDATA[ICalendarProvider]]></code>
|
||||
</UndefinedClass>
|
||||
</file>
|
||||
<file src="lib/DAV/DeckCalendarBackend.php">
|
||||
<UndefinedClass>
|
||||
<code>NotFound</code>
|
||||
<code><![CDATA[NotFound]]></code>
|
||||
</UndefinedClass>
|
||||
</file>
|
||||
<file src="lib/Db/Card.php">
|
||||
<UndefinedClass>
|
||||
<code>VCalendar</code>
|
||||
<code>VCalendar</code>
|
||||
<code><![CDATA[VCalendar]]></code>
|
||||
<code><![CDATA[VCalendar]]></code>
|
||||
</UndefinedClass>
|
||||
</file>
|
||||
<file src="lib/Db/CardMapper.php">
|
||||
<InvalidScalarArgument>
|
||||
<code>$entity->getId()</code>
|
||||
</InvalidScalarArgument>
|
||||
<UndefinedInterfaceMethod>
|
||||
<code>getUserIdGroups</code>
|
||||
</UndefinedInterfaceMethod>
|
||||
</file>
|
||||
<file src="lib/Db/LabelMapper.php">
|
||||
<ParamNameMismatch>
|
||||
<code>$labelId</code>
|
||||
</ParamNameMismatch>
|
||||
</file>
|
||||
<file src="lib/Db/Stack.php">
|
||||
<UndefinedClass>
|
||||
<code>VCalendar</code>
|
||||
<code>VCalendar</code>
|
||||
<code><![CDATA[VCalendar]]></code>
|
||||
<code><![CDATA[VCalendar]]></code>
|
||||
</UndefinedClass>
|
||||
</file>
|
||||
<file src="lib/Model/BoardSummary.php">
|
||||
<ConstructorSignatureMismatch>
|
||||
<code>public function __construct(Board $board) {</code>
|
||||
<code>public function __construct(Board $board) {</code>
|
||||
</ConstructorSignatureMismatch>
|
||||
</file>
|
||||
<file src="lib/Model/CardDetails.php">
|
||||
<ConstructorSignatureMismatch>
|
||||
<code>public function __construct(Card $card, ?Board $board = null) {</code>
|
||||
<code>public function __construct(Card $card, ?Board $board = null) {</code>
|
||||
</ConstructorSignatureMismatch>
|
||||
</file>
|
||||
<file src="lib/Service/AttachmentService.php">
|
||||
<InvalidCatch>
|
||||
<code>try {
|
||||
$attachment = $this->attachmentMapper->find($attachmentId);
|
||||
} catch (IMapperException $e) {
|
||||
throw new NoPermissionException('Permission denied');
|
||||
}</code>
|
||||
</InvalidCatch>
|
||||
</file>
|
||||
<file src="lib/Service/BoardService.php">
|
||||
<TooManyArguments>
|
||||
<code>findAll</code>
|
||||
<code>findAll</code>
|
||||
</TooManyArguments>
|
||||
</file>
|
||||
<file src="lib/Service/CirclesService.php">
|
||||
<RedundantCondition>
|
||||
<code>$member !== null</code>
|
||||
</RedundantCondition>
|
||||
</file>
|
||||
<file src="lib/Service/FileService.php">
|
||||
<RedundantCondition>
|
||||
<code>is_resource($content)</code>
|
||||
<code>is_resource($content)</code>
|
||||
<code><![CDATA[is_resource($content)]]></code>
|
||||
<code><![CDATA[is_resource($content)]]></code>
|
||||
</RedundantCondition>
|
||||
</file>
|
||||
<file src="lib/Sharing/DeckShareProvider.php">
|
||||
<InvalidReturnType>
|
||||
<code>getShareByToken</code>
|
||||
</InvalidReturnType>
|
||||
<file src="lib/Service/Importer/BoardImportCommandService.php">
|
||||
<UndefinedInterfaceMethod>
|
||||
<code><![CDATA[ask]]></code>
|
||||
<code><![CDATA[ask]]></code>
|
||||
<code><![CDATA[ask]]></code>
|
||||
</UndefinedInterfaceMethod>
|
||||
</file>
|
||||
<file src="lib/Sharing/Listener.php">
|
||||
<InvalidArgument>
|
||||
<code>[self::class, 'listenPreShare']</code>
|
||||
</InvalidArgument>
|
||||
<file src="lib/Service/Importer/Systems/TrelloJsonService.php">
|
||||
<InvalidPropertyFetch>
|
||||
<code><![CDATA[$createCardDate->date]]></code>
|
||||
</InvalidPropertyFetch>
|
||||
</file>
|
||||
<file src="lib/Teams/DeckTeamResourceProvider.php">
|
||||
<FalsableReturnStatement>
|
||||
<code><![CDATA[file_get_contents(__DIR__ . '/../../img/deck-current.svg')]]></code>
|
||||
</FalsableReturnStatement>
|
||||
</file>
|
||||
</files>
|
||||
|
||||
@@ -160,6 +160,7 @@ class ActivityManagerTest extends TestCase {
|
||||
'id' => 123,
|
||||
'title' => 'My card',
|
||||
'description' => str_repeat('A', 1000),
|
||||
'stackId' => 42,
|
||||
]);
|
||||
$this->cardMapper->expects(self::any())
|
||||
->method('find')
|
||||
@@ -170,6 +171,7 @@ class ActivityManagerTest extends TestCase {
|
||||
]);
|
||||
$this->stackMapper->expects(self::any())
|
||||
->method('find')
|
||||
->with(42)
|
||||
->willReturn($stack);
|
||||
|
||||
$expectedCard = $card->jsonSerialize();
|
||||
@@ -207,6 +209,7 @@ class ActivityManagerTest extends TestCase {
|
||||
$card->setDescription(str_repeat('A', 5000));
|
||||
$card->setTitle('My card');
|
||||
$card->setId(123);
|
||||
$card->setStackId(42);
|
||||
$this->cardMapper->expects(self::any())
|
||||
->method('find')
|
||||
->willReturn($card);
|
||||
@@ -254,6 +257,7 @@ class ActivityManagerTest extends TestCase {
|
||||
$card->setDescription(str_repeat('A', 5000));
|
||||
$card->setTitle('My card');
|
||||
$card->setId(123);
|
||||
$card->setStackId(42);
|
||||
$this->cardMapper->expects(self::any())
|
||||
->method('find')
|
||||
->willReturn($card);
|
||||
|
||||
@@ -119,7 +119,7 @@ class AttachmentMapperTest extends TestCase {
|
||||
->method('isOwner')
|
||||
->with('admin', 1)
|
||||
->willReturn(true);
|
||||
$this->assertTrue($this->attachmentMapper->isOwner('admin', (string)$this->attachments[0]->getId()));
|
||||
$this->assertTrue($this->attachmentMapper->isOwner('admin', $this->attachments[0]->getId()));
|
||||
}
|
||||
|
||||
public function testIsOwnerInvalid() {
|
||||
@@ -127,7 +127,7 @@ class AttachmentMapperTest extends TestCase {
|
||||
->method('isOwner')
|
||||
->with('admin', 1)
|
||||
->will($this->throwException(new DoesNotExistException('does not exist')));
|
||||
$this->assertFalse($this->attachmentMapper->isOwner('admin', (string)$this->attachments[0]->getId()));
|
||||
$this->assertFalse($this->attachmentMapper->isOwner('admin', $this->attachments[0]->getId()));
|
||||
}
|
||||
|
||||
public function testFindBoardId() {
|
||||
|
||||
@@ -81,8 +81,8 @@ class CardTest extends TestCase {
|
||||
'duedate' => null,
|
||||
'overdue' => 0,
|
||||
'archived' => false,
|
||||
'attachments' => null,
|
||||
'attachmentCount' => null,
|
||||
'attachments' => [],
|
||||
'attachmentCount' => 0,
|
||||
'assignedUsers' => null,
|
||||
'deletedAt' => 0,
|
||||
'commentsUnread' => 0,
|
||||
@@ -110,8 +110,8 @@ class CardTest extends TestCase {
|
||||
'duedate' => null,
|
||||
'overdue' => 0,
|
||||
'archived' => false,
|
||||
'attachments' => null,
|
||||
'attachmentCount' => null,
|
||||
'attachments' => [],
|
||||
'attachmentCount' => 0,
|
||||
'assignedUsers' => null,
|
||||
'deletedAt' => 0,
|
||||
'commentsUnread' => 0,
|
||||
@@ -141,8 +141,8 @@ class CardTest extends TestCase {
|
||||
'duedate' => null,
|
||||
'overdue' => 0,
|
||||
'archived' => false,
|
||||
'attachments' => null,
|
||||
'attachmentCount' => null,
|
||||
'attachments' => [],
|
||||
'attachmentCount' => 0,
|
||||
'assignedUsers' => ['user1'],
|
||||
'deletedAt' => 0,
|
||||
'commentsUnread' => 0,
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @copyright Copyright (c) 2018 Julius Härtl <jus@bitgrid.net>
|
||||
*
|
||||
@@ -116,7 +118,7 @@ class AttachmentServiceTest extends TestCase {
|
||||
$this->activityManager = $this->createMock(ActivityManager::class);
|
||||
|
||||
$this->appContainer->expects($this->exactly(2))
|
||||
->method('query')
|
||||
->method('get')
|
||||
->withConsecutive(
|
||||
[FileService::class],
|
||||
[FilesAppService::class]
|
||||
@@ -156,7 +158,7 @@ class AttachmentServiceTest extends TestCase {
|
||||
$fileAppServiceMock = $this->createMock(FilesAppService::class);
|
||||
|
||||
$appContainer->expects($this->exactly(3))
|
||||
->method('query')
|
||||
->method('get')
|
||||
->withConsecutive(
|
||||
[FileService::class],
|
||||
[FilesAppService::class],
|
||||
@@ -185,7 +187,7 @@ class AttachmentServiceTest extends TestCase {
|
||||
$fileAppServiceMock = $this->createMock(FilesAppService::class);
|
||||
|
||||
$appContainer->expects($this->exactly(3))
|
||||
->method('query')
|
||||
->method('get')
|
||||
->withConsecutive(
|
||||
[FileService::class],
|
||||
[FilesAppService::class],
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @copyright Copyright (c) 2016 Julius Härtl <jus@bitgrid.net>
|
||||
*
|
||||
@@ -240,6 +242,7 @@ class BoardServiceTest extends TestCase {
|
||||
|
||||
public function testDelete() {
|
||||
$board = new Board();
|
||||
$board->setId(42);
|
||||
$board->setOwner('admin');
|
||||
$board->setDeletedAt(0);
|
||||
$this->boardMapper->expects($this->once())
|
||||
@@ -252,7 +255,7 @@ class BoardServiceTest extends TestCase {
|
||||
]);
|
||||
$this->sessionMapper->expects($this->once())
|
||||
->method('findAllActive')
|
||||
->with(null)
|
||||
->with(42)
|
||||
->willReturn([]);
|
||||
$boardDeleted = clone $board;
|
||||
$boardDeleted->setDeletedAt(1);
|
||||
@@ -267,7 +270,7 @@ class BoardServiceTest extends TestCase {
|
||||
$user->method('getUID')->willReturn('admin');
|
||||
$acl = new Acl();
|
||||
$acl->setBoardId(123);
|
||||
$acl->setType('user');
|
||||
$acl->setType(Acl::PERMISSION_TYPE_USER);
|
||||
$acl->setParticipant('admin');
|
||||
$acl->setPermissionEdit(true);
|
||||
$acl->setPermissionShare(true);
|
||||
@@ -287,7 +290,7 @@ class BoardServiceTest extends TestCase {
|
||||
'admin' => 'admin',
|
||||
]);
|
||||
$this->assertEquals($acl, $this->service->addAcl(
|
||||
123, 'user', 'admin', true, true, true
|
||||
123, Acl::PERMISSION_TYPE_USER, 'admin', true, true, true
|
||||
));
|
||||
}
|
||||
|
||||
@@ -323,7 +326,7 @@ class BoardServiceTest extends TestCase {
|
||||
public function testAddAclExtendPermission($currentUserAcl, $providedAcl, $resultingAcl) {
|
||||
$existingAcl = new Acl();
|
||||
$existingAcl->setBoardId(123);
|
||||
$existingAcl->setType('user');
|
||||
$existingAcl->setType(Acl::PERMISSION_TYPE_USER);
|
||||
$existingAcl->setParticipant('admin');
|
||||
$existingAcl->setPermissionEdit($currentUserAcl[0]);
|
||||
$existingAcl->setPermissionShare($currentUserAcl[1]);
|
||||
@@ -391,14 +394,14 @@ class BoardServiceTest extends TestCase {
|
||||
->method('dispatchTyped')
|
||||
->with(new AclCreatedEvent($acl));
|
||||
$this->assertEquals($expected, $this->service->addAcl(
|
||||
123, 'user', 'admin', $providedAcl[0], $providedAcl[1], $providedAcl[2]
|
||||
123, Acl::PERMISSION_TYPE_USER, 'admin', $providedAcl[0], $providedAcl[1], $providedAcl[2]
|
||||
));
|
||||
}
|
||||
|
||||
public function testUpdateAcl() {
|
||||
$acl = new Acl();
|
||||
$acl->setBoardId(123);
|
||||
$acl->setType('user');
|
||||
$acl->setType(Acl::PERMISSION_TYPE_USER);
|
||||
$acl->setParticipant('admin');
|
||||
$acl->setPermissionEdit(true);
|
||||
$acl->setPermissionShare(true);
|
||||
|
||||
@@ -183,6 +183,7 @@ class CardServiceTest extends TestCase {
|
||||
->willReturn($boardMock);
|
||||
$card = new Card();
|
||||
$card->setId(1337);
|
||||
$card->setStackId(123);
|
||||
$this->cardMapper->expects($this->any())
|
||||
->method('find')
|
||||
->with(123)
|
||||
@@ -200,6 +201,7 @@ class CardServiceTest extends TestCase {
|
||||
->with([1337])
|
||||
->willReturn([$a1, $a2]);
|
||||
$cardExpected = new Card();
|
||||
$cardExpected->setStackId(123);
|
||||
$cardExpected->setId(1337);
|
||||
$cardExpected->setAssignedUsers([$a1, $a2]);
|
||||
$cardExpected->setRelatedBoard($boardMock);
|
||||
@@ -218,6 +220,7 @@ class CardServiceTest extends TestCase {
|
||||
'stackId' => 123,
|
||||
'order' => 999,
|
||||
'type' => 'text',
|
||||
'id' => 0,
|
||||
]);
|
||||
$stack = Stack::fromParams([
|
||||
'id' => 123,
|
||||
@@ -243,6 +246,8 @@ class CardServiceTest extends TestCase {
|
||||
$card = new Card();
|
||||
$card->setId(1);
|
||||
$card->setTitle('Card title');
|
||||
$card->setType('test');
|
||||
$card->setOrder(0);
|
||||
$card->setOwner('admin');
|
||||
$card->setStackId(12345);
|
||||
$clonedCard = clone $card;
|
||||
@@ -290,8 +295,7 @@ class CardServiceTest extends TestCase {
|
||||
->willReturn([$label]);
|
||||
$this->cardMapper->expects($this->once())
|
||||
->method('assignLabel')
|
||||
->with($clonedCard->getId(), $label->getId())
|
||||
->willReturn($label);
|
||||
->with($clonedCard->getId(), $label->getId());
|
||||
|
||||
$stackMock = new Stack();
|
||||
$stackMock->setBoardId(1234);
|
||||
@@ -329,6 +333,7 @@ class CardServiceTest extends TestCase {
|
||||
]);
|
||||
$this->cardMapper->expects($this->once())->method('find')->willReturn($card);
|
||||
$this->cardMapper->expects($this->once())->method('update')->willReturnCallback(function ($c) {
|
||||
$c->setId(1);
|
||||
return $c;
|
||||
});
|
||||
$this->stackMapper->expects($this->once())
|
||||
|
||||
@@ -220,8 +220,9 @@ class DefaultBoardServiceTest extends TestCase {
|
||||
return $stack;
|
||||
}
|
||||
|
||||
private function assembleTestCard($title, $stackId, $userId) {
|
||||
private function assembleTestCard(string $title, int $stackId, string $userId): Card {
|
||||
$card = new Card();
|
||||
$card->setId(1);
|
||||
$card->setTitle($title);
|
||||
$card->setStackId($stackId);
|
||||
$card->setType('text');
|
||||
|
||||
@@ -192,14 +192,17 @@ class BoardImportServiceTest extends \Test\TestCase {
|
||||
->expects($this->once())
|
||||
->method('save');
|
||||
|
||||
$assignment = new Assignment();
|
||||
$assignment->setId(1);
|
||||
$this->trelloJsonService
|
||||
->method('getCardAssignments')
|
||||
->willReturn([
|
||||
'fakecardid' => [new Assignment()]
|
||||
'fakecardid' => [$assignment]
|
||||
]);
|
||||
$this->assignmentMapper
|
||||
->expects($this->once())
|
||||
->method('insert');
|
||||
->method('insert')
|
||||
->willReturn($assignment);
|
||||
|
||||
$this->boardImportService->import();
|
||||
self::assertTrue(true);
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @copyright Copyright (c) 2016 Julius Härtl <jus@bitgrid.net>
|
||||
*
|
||||
@@ -29,6 +31,7 @@ use OCA\Deck\Db\ChangeHelper;
|
||||
use OCA\Deck\Db\Label;
|
||||
use OCA\Deck\Db\LabelMapper;
|
||||
use OCA\Deck\Validators\LabelServiceValidator;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use Test\TestCase;
|
||||
|
||||
class LabelServiceTest extends TestCase {
|
||||
@@ -42,9 +45,8 @@ class LabelServiceTest extends TestCase {
|
||||
/** @var BoardService|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $boardService;
|
||||
/** @var ChangeHelper|\PHPUnit\Framework\MockObject\MockObject */
|
||||
private $changeHelper;
|
||||
/** @var LabelServiceValidator\MockObject */
|
||||
private $labelServiceValidator;
|
||||
private ChangeHelper&MockObject $changeHelper;
|
||||
private LabelServiceValidator&MockObject $labelServiceValidator;
|
||||
|
||||
public function setUp(): void {
|
||||
parent::setUp();
|
||||
@@ -66,8 +68,9 @@ class LabelServiceTest extends TestCase {
|
||||
}
|
||||
|
||||
public function testFind() {
|
||||
$this->labelMapper->expects($this->once())->method('find')->willReturn(true);
|
||||
$this->assertTrue($this->labelService->find(123));
|
||||
$label = $this->createMock(Label::class);
|
||||
$this->labelMapper->expects($this->once())->method('find')->willReturn($label);
|
||||
$this->assertEquals($label, $this->labelService->find(123));
|
||||
}
|
||||
|
||||
public function testCreate() {
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @copyright Copyright (c) 2016 Julius Härtl <jus@bitgrid.net>
|
||||
*
|
||||
@@ -48,8 +50,7 @@ use Test\TestCase;
|
||||
*/
|
||||
class StackServiceTest extends TestCase {
|
||||
|
||||
/** @var StackService */
|
||||
private $stackService;
|
||||
private StackService $stackService;
|
||||
/** @var \PHPUnit\Framework\MockObject\MockObject|StackMapper */
|
||||
private $stackMapper;
|
||||
/** @var \PHPUnit\Framework\MockObject\MockObject|CardMapper */
|
||||
@@ -251,6 +252,9 @@ class StackServiceTest extends TestCase {
|
||||
$this->stackMapper->expects($this->once())
|
||||
->method('findAll')
|
||||
->willReturn($stacks);
|
||||
$this->stackMapper->expects($this->any())
|
||||
->method('update')
|
||||
->willReturnCallback(fn (Stack $stack): Stack => $stack);
|
||||
$actual = $this->stackService->reorder(1, 2);
|
||||
$a = $this->createStack(1, 2);
|
||||
$b = $this->createStack(2, 0);
|
||||
@@ -259,7 +263,7 @@ class StackServiceTest extends TestCase {
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
private function createStack($id, $order) {
|
||||
private function createStack(int $id, int $order) {
|
||||
$stack = new Stack();
|
||||
$stack->setId($id);
|
||||
$stack->setBoardId(1);
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @copyright Copyright (c) 2016 Julius Härtl <jus@bitgrid.net>
|
||||
*
|
||||
@@ -26,46 +28,47 @@ namespace OCA\Deck\Controller;
|
||||
|
||||
use OCA\Deck\Db\Acl;
|
||||
use OCA\Deck\Db\Board;
|
||||
use OCA\Deck\Service\BoardService;
|
||||
use OCA\Deck\Service\Importer\BoardImportService;
|
||||
use OCA\Deck\Service\PermissionService;
|
||||
use OCP\IGroupManager;
|
||||
use OCP\IL10N;
|
||||
use OCP\IRequest;
|
||||
use OCP\IUser;
|
||||
use OCP\IUserManager;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
|
||||
class BoardControllerTest extends \Test\TestCase {
|
||||
private $l10n;
|
||||
private $controller;
|
||||
private $request;
|
||||
private $userManager;
|
||||
private $groupManager;
|
||||
private $boardService;
|
||||
private $permissionService;
|
||||
private $boardImportService;
|
||||
private IL10N&MockObject $l10n;
|
||||
private BoardController $controller;
|
||||
private IRequest&MockObject $request;
|
||||
private IUserManager&MockObject $userManager;
|
||||
private IGroupManager&MockObject $groupManager;
|
||||
private BoardService&MockObject $boardService;
|
||||
private PermissionService&MockObject $permissionService;
|
||||
private BoardImportService&MockObject $boardImportService;
|
||||
private $userId = 'user';
|
||||
|
||||
public function setUp(): void {
|
||||
$this->l10n = $this->request = $this->getMockBuilder(
|
||||
'\OCP\IL10n')
|
||||
$this->l10n = $this->getMockBuilder(IL10N::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->request = $this->getMockBuilder(
|
||||
'\OCP\IRequest')
|
||||
$this->request = $this->getMockBuilder(IRequest::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->userManager = $this->getMockBuilder(
|
||||
'\OCP\IUserManager')
|
||||
$this->userManager = $this->getMockBuilder(IUserManager::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->groupManager = $this->getMockBuilder(
|
||||
'\OCP\IGroupManager')
|
||||
$this->groupManager = $this->getMockBuilder(IGroupManager::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->boardService = $this->getMockBuilder(
|
||||
'\OCA\Deck\Service\BoardService')
|
||||
$this->boardService = $this->getMockBuilder(BoardService::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->permissionService = $this->getMockBuilder(
|
||||
'\OCA\Deck\Service\PermissionService')
|
||||
$this->permissionService = $this->getMockBuilder(PermissionService::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->boardImportService = $this->getMockBuilder(
|
||||
'\OCA\Deck\Service\Importer\BoardImportService')
|
||||
$this->boardImportService = $this->getMockBuilder(BoardImportService::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
@@ -107,35 +110,39 @@ class BoardControllerTest extends \Test\TestCase {
|
||||
}
|
||||
|
||||
public function testCreate() {
|
||||
$board = $this->createMock(Board::class);
|
||||
$this->boardService->expects($this->once())
|
||||
->method('create')
|
||||
->with(1, 'user', 3)
|
||||
->willReturn(1);
|
||||
$this->assertEquals(1, $this->controller->create(1, 3));
|
||||
->with('abc', 'user', 'green')
|
||||
->willReturn($board);
|
||||
$this->assertEquals($board, $this->controller->create('abc', 'green'));
|
||||
}
|
||||
|
||||
public function testUpdate() {
|
||||
public function testUpdate(): void {
|
||||
$board = $this->createMock(Board::class);
|
||||
$this->boardService->expects($this->once())
|
||||
->method('update')
|
||||
->with(1, 2, 3, false)
|
||||
->willReturn(1);
|
||||
$this->assertEquals(1, $this->controller->update(1, 2, 3, false));
|
||||
->with(1, 'abc', 'green', false)
|
||||
->willReturn($board);
|
||||
$this->assertEquals($board, $this->controller->update(1, 'abc', 'green', false));
|
||||
}
|
||||
|
||||
public function testDelete() {
|
||||
public function testDelete(): void {
|
||||
$board = $this->createMock(Board::class);
|
||||
$this->boardService->expects($this->once())
|
||||
->method('delete')
|
||||
->with(123)
|
||||
->willReturn(1);
|
||||
$this->assertEquals(1, $this->controller->delete(123));
|
||||
->willReturn($board);
|
||||
$this->assertEquals($board, $this->controller->delete(123));
|
||||
}
|
||||
|
||||
public function testDeleteUndo() {
|
||||
$board = $this->createMock(Board::class);
|
||||
$this->boardService->expects($this->once())
|
||||
->method('deleteUndo')
|
||||
->with(123)
|
||||
->willReturn(1);
|
||||
$this->assertEquals(1, $this->controller->deleteUndo(123));
|
||||
->willReturn($board);
|
||||
$this->assertEquals($board, $this->controller->deleteUndo(123));
|
||||
}
|
||||
|
||||
public function testGetUserPermissions() {
|
||||
@@ -158,20 +165,22 @@ class BoardControllerTest extends \Test\TestCase {
|
||||
$this->assertEquals($expected, $this->controller->getUserPermissions(123));
|
||||
}
|
||||
|
||||
public function testAddAcl() {
|
||||
public function testAddAcl(): void {
|
||||
$acl = $this->createMock(Acl::class);
|
||||
$this->boardService->expects($this->once())
|
||||
->method('addAcl')
|
||||
->with(1, 2, 3, 4, 5, 6)
|
||||
->willReturn(1);
|
||||
$this->assertEquals(1, $this->controller->addAcl(1, 2, 3, 4, 5, 6));
|
||||
->with(1, 2, 'user1', true, true, true)
|
||||
->willReturn($acl);
|
||||
$this->assertEquals($acl, $this->controller->addAcl(1, 2, 'user1', true, true, true));
|
||||
}
|
||||
|
||||
public function testUpdateAcl() {
|
||||
public function testUpdateAcl(): void {
|
||||
$acl = $this->createMock(Acl::class);
|
||||
$this->boardService->expects($this->once())
|
||||
->method('updateAcl')
|
||||
->with(1, 2, 3, 4)
|
||||
->willReturn(1);
|
||||
$this->assertEquals(1, $this->controller->updateAcl(1, 2, 3, 4));
|
||||
->with(1, true, true, true)
|
||||
->willReturn($acl);
|
||||
$this->assertEquals($acl, $this->controller->updateAcl(1, true, true, true));
|
||||
}
|
||||
|
||||
public function testDeleteAcl() {
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @copyright Copyright (c) 2018 Ryan Fletcher <ryan.fletcher@codepassion.ca>
|
||||
*
|
||||
@@ -30,15 +32,16 @@ use OCP\AppFramework\Http;
|
||||
|
||||
use OCP\AppFramework\Http\DataResponse;
|
||||
use OCP\IRequest;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
|
||||
class CardApiControllerTest extends \Test\TestCase {
|
||||
private $controller;
|
||||
private $request;
|
||||
private $cardService;
|
||||
private $userId = 'admin';
|
||||
private $cardExample;
|
||||
private $stackExample;
|
||||
private $assignmentService;
|
||||
private CardApiController $controller;
|
||||
private IRequest&MockObject $request;
|
||||
private CardService&MockObject $cardService;
|
||||
private string $userId = 'admin';
|
||||
private array $cardExample;
|
||||
private array $stackExample;
|
||||
private AssignmentService&MockObject $assignmentService;
|
||||
|
||||
public function setUp(): void {
|
||||
parent::setUp();
|
||||
@@ -51,7 +54,7 @@ class CardApiControllerTest extends \Test\TestCase {
|
||||
$this->stackExample['id'] = 1;
|
||||
|
||||
$this->controller = new CardApiController(
|
||||
$appName = 'deck',
|
||||
'deck',
|
||||
$this->request,
|
||||
$this->cardService,
|
||||
$this->assignmentService,
|
||||
@@ -59,7 +62,7 @@ class CardApiControllerTest extends \Test\TestCase {
|
||||
);
|
||||
}
|
||||
|
||||
public function testGet() {
|
||||
public function testGet(): void {
|
||||
$card = new Card();
|
||||
$card->setId($this->cardExample['id']);
|
||||
|
||||
@@ -116,7 +119,7 @@ class CardApiControllerTest extends \Test\TestCase {
|
||||
->willReturn($card);
|
||||
|
||||
$expected = new DataResponse($card, HTTP::STATUS_OK);
|
||||
$actual = $this->controller->update('title', 'plain', 0, 'description', $this->userId, null);
|
||||
$actual = $this->controller->update('title', 'plain', $this->userId, 'description', 0, null);
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @copyright Copyright (c) 2016 Julius Härtl <jus@bitgrid.net>
|
||||
*
|
||||
@@ -24,6 +26,7 @@
|
||||
|
||||
namespace OCA\Deck\Controller;
|
||||
|
||||
use OCA\Deck\Db\Card;
|
||||
use OCA\Deck\Service\AssignmentService;
|
||||
use OCA\Deck\Service\CardService;
|
||||
use OCP\IRequest;
|
||||
@@ -32,17 +35,11 @@ use Test\TestCase;
|
||||
|
||||
class CardControllerTest extends TestCase {
|
||||
|
||||
/** @var CardController|MockObject */
|
||||
private $controller;
|
||||
/** @var IRequest|MockObject */
|
||||
private $request;
|
||||
/** @var CardService|MockObject */
|
||||
private $cardService;
|
||||
/** @var AssignmentService|MockObject */
|
||||
private $assignmentService;
|
||||
/** @var string */
|
||||
private $userId = 'user';
|
||||
|
||||
private CardController $controller;
|
||||
private IRequest&MockObject $request;
|
||||
private CardService&MockObject $cardService;
|
||||
private AssignmentService&MockObject $assignmentService;
|
||||
private string $userId = 'user';
|
||||
|
||||
public function setUp(): void {
|
||||
$this->request = $this->createMock(IRequest::class);
|
||||
@@ -58,39 +55,43 @@ class CardControllerTest extends TestCase {
|
||||
}
|
||||
|
||||
public function testRead() {
|
||||
$card = $this->createMock(Card::class);
|
||||
$this->cardService->expects($this->once())
|
||||
->method('find')
|
||||
->with(123)
|
||||
->willReturn(1);
|
||||
$this->assertEquals(1, $this->controller->read(123));
|
||||
->willReturn($card);
|
||||
$this->assertEquals($card, $this->controller->read(123));
|
||||
}
|
||||
|
||||
public function testCreate() {
|
||||
public function testCreate(): void {
|
||||
$card = $this->createMock(Card::class);
|
||||
$this->cardService->expects($this->once())
|
||||
->method('create')
|
||||
->with('foo', 1, 'text', 3, $this->userId)
|
||||
->willReturn(1);
|
||||
$this->assertEquals(1, $this->controller->create('foo', 1, 'text', 3));
|
||||
->willReturn($card);
|
||||
$this->assertEquals($card, $this->controller->create('foo', 1, 'text', 3));
|
||||
}
|
||||
|
||||
public function testUpdate() {
|
||||
public function testUpdate(): void {
|
||||
$card = $this->createMock(Card::class);
|
||||
$this->cardService->expects($this->once())
|
||||
->method('update')
|
||||
->with(1, 'title', 3, 'text', $this->userId, 'foo', 5, '2017-01-01 00:00:00')
|
||||
->willReturn(1);
|
||||
$this->assertEquals(1, $this->controller->update(1, 'title', 3, 'text', 5, 'foo', '2017-01-01 00:00:00', null));
|
||||
->willReturn($card);
|
||||
$this->assertEquals($card, $this->controller->update(1, 'title', 3, 'text', 5, 'foo', '2017-01-01 00:00:00', null));
|
||||
}
|
||||
|
||||
public function testDelete() {
|
||||
public function testDelete(): void {
|
||||
$card = $this->createMock(Card::class);
|
||||
$this->cardService->expects($this->once())
|
||||
->method('delete')
|
||||
->with(123)
|
||||
->willReturn(1);
|
||||
$this->assertEquals(1, $this->controller->delete(123));
|
||||
->willReturn($card);
|
||||
$this->assertEquals($card, $this->controller->delete(123));
|
||||
}
|
||||
|
||||
public function testArchive() {
|
||||
$this->cardService->expects($this->once())->method('archive')->willReturn(true);
|
||||
$this->cardService->expects($this->once())->method('archive');
|
||||
$this->controller->archive(1);
|
||||
}
|
||||
public function testUnarchive() {
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
|
||||
namespace OCA\Deck\Controller;
|
||||
|
||||
use OCA\Deck\Db\Label;
|
||||
use OCA\Deck\Service\LabelService;
|
||||
use OCP\AppFramework\Controller;
|
||||
use OCP\IRequest;
|
||||
@@ -56,27 +57,30 @@ class LabelControllerTest extends \Test\TestCase {
|
||||
}
|
||||
|
||||
|
||||
public function testCreate() {
|
||||
public function testCreate(): void {
|
||||
$label = $this->createMock(Label::class);
|
||||
$this->labelService->expects($this->once())
|
||||
->method('create')
|
||||
->with(1, 2, 3)
|
||||
->willReturn(1);
|
||||
$this->assertEquals(1, $this->controller->create(1, 2, 3));
|
||||
->willReturn($label);
|
||||
$this->assertEquals($label, $this->controller->create(1, 2, 3));
|
||||
}
|
||||
|
||||
public function testUpdate() {
|
||||
public function testUpdate(): void {
|
||||
$label = $this->createMock(Label::class);
|
||||
$this->labelService->expects($this->once())
|
||||
->method('update')
|
||||
->with(1, 2, 3)
|
||||
->willReturn(1);
|
||||
$this->assertEquals(1, $this->controller->update(1, 2, 3));
|
||||
->willReturn($label);
|
||||
$this->assertEquals($label, $this->controller->update(1, 2, 3));
|
||||
}
|
||||
|
||||
public function testDelete() {
|
||||
public function testDelete(): void {
|
||||
$label = $this->createMock(Label::class);
|
||||
$this->labelService->expects($this->once())
|
||||
->method('delete')
|
||||
->with(123)
|
||||
->willReturn(1);
|
||||
$this->assertEquals(1, $this->controller->delete(123));
|
||||
->willReturn($label);
|
||||
$this->assertEquals($label, $this->controller->delete(123));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @copyright Copyright (c) 2016 Julius Härtl <jus@bitgrid.net>
|
||||
*
|
||||
@@ -24,6 +26,7 @@
|
||||
|
||||
namespace OCA\Deck\Controller;
|
||||
|
||||
use OCA\Deck\Db\Stack;
|
||||
use OCA\Deck\Service\StackService;
|
||||
use OCP\AppFramework\Controller;
|
||||
use OCP\IRequest;
|
||||
@@ -67,34 +70,38 @@ class StackControllerTest extends \Test\TestCase {
|
||||
}
|
||||
|
||||
public function testCreate() {
|
||||
$stack = $this->createMock(Stack::class);
|
||||
$this->stackService->expects($this->once())
|
||||
->method('create')
|
||||
->with(1, 2, 3)
|
||||
->willReturn(1);
|
||||
$this->assertEquals(1, $this->controller->create(1, 2, 3));
|
||||
->with('abc', 2, 3)
|
||||
->willReturn($stack);
|
||||
$this->assertEquals($stack, $this->controller->create('abc', 2, 3));
|
||||
}
|
||||
|
||||
public function testUpdate() {
|
||||
$stack = $this->createMock(Stack::class);
|
||||
$this->stackService->expects($this->once())
|
||||
->method('update')
|
||||
->with(1, 2, 3, 4)
|
||||
->willReturn(1);
|
||||
$this->assertEquals(1, $this->controller->update(1, 2, 3, 4, null));
|
||||
->with(1, 'abc', 3, 4)
|
||||
->willReturn($stack);
|
||||
$this->assertEquals($stack, $this->controller->update(1, 'abc', 3, 4, null));
|
||||
}
|
||||
|
||||
public function testReorder() {
|
||||
$stack = $this->createMock(Stack::class);
|
||||
$this->stackService->expects($this->once())
|
||||
->method('reorder')
|
||||
->with(1, 2)
|
||||
->willReturn(1);
|
||||
$this->assertEquals(1, $this->controller->reorder(1, 2));
|
||||
->willReturn([$stack]);
|
||||
$this->assertEquals([$stack], $this->controller->reorder(1, 2));
|
||||
}
|
||||
|
||||
public function testDelete() {
|
||||
$stack = $this->createMock(Stack::class);
|
||||
$this->stackService->expects($this->once())
|
||||
->method('delete')
|
||||
->with(123)
|
||||
->willReturn(1);
|
||||
$this->assertEquals(1, $this->controller->delete(123));
|
||||
->willReturn($stack);
|
||||
$this->assertEquals($stack, $this->controller->delete(123));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user