Skip to content

Commit

Permalink
tests: Fix url generation mocks and cleanup some phpunit code
Browse files Browse the repository at this point in the history
Signed-off-by: Julius Knorr <[email protected]>
  • Loading branch information
juliusknorr committed Jan 17, 2025
1 parent 313fccc commit c3e9bde
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 23 deletions.
4 changes: 2 additions & 2 deletions tests/unit/Activity/ActivityManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ public function testCreateEventLabel() {
$this->assertEquals($event, $actual);
}

public function dataSendToUsers() {
public static function dataSendToUsers() {
return [
[ActivityManager::DECK_OBJECT_BOARD],
[ActivityManager::DECK_OBJECT_CARD],
Expand Down Expand Up @@ -344,7 +344,7 @@ public function testSendToUser($objectType) {
$this->invokePrivate($this->activityManager, 'sendToUsers', [$event]);
}

public function dataFindObjectForEntity() {
public static function dataFindObjectForEntity() {
$board = new Board();
$board->setId(1);
$stack = new Stack();
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/Activity/DeckProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public function testParseFailureApp() {
$this->provider->parse('en_US', $event, $event);
}

public function dataEventIcons() {
public static function dataEventIcons() {
return [
[ActivityManager::SUBJECT_LABEL_ASSIGN, 'core', 'actions/tag.svg'],
[ActivityManager::SUBJECT_CARD_CREATE, 'files', 'add-color.svg'],
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/Db/CardTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ private function createCard() {
return $card;
}

public function dataDuedate() {
public static function dataDuedate() {
return [
[(new DateTime()), Card::DUEDATE_NOW],
[(new DateTime())->sub(new DateInterval('P1D')), Card::DUEDATE_OVERDUE],
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/Middleware/ExceptionMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function setUp(): void {
}


public function dataAfterException() {
public static function dataAfterException() {
return [
[new NoPermissionException('No permission'), 403, 'No permission'],
[new NotFoundException('Not found'), 404, 'Not found']
Expand Down
28 changes: 17 additions & 11 deletions tests/unit/Notification/NotifierTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,15 @@ public function setUp(): void {
$this->l10nFactory->expects($this->once())
->method('get')
->willReturn($this->l10n);

$this->url->expects($this->any())
->method('linkToRouteAbsolute')
->willReturnCallback(function ($route) {
return match ($route) {
'deck.page.indexBoard' => '/board/123',
'deck.page.indexCard' => '/board/123/card/234',
};
});
}

public function testPrepareWrongApp() {
Expand Down Expand Up @@ -178,7 +187,7 @@ public function testPrepareCardCommentMentioned() {
$this->assertEquals($notification, $actualNotification);
}

public function dataPrepareCardAssigned() {
public static function dataPrepareCardAssigned() {
return [
[true], [false]
];
Expand Down Expand Up @@ -239,13 +248,13 @@ public function testPrepareCardAssigned($withUserFound = true) {
'name' => 'Card title',
'boardname' => 'Board title',
'stackname' => null,
'link' => '#/board/123/card/123',
'link' => '/board/123/card/234',
],
'deck-board' => [
'type' => 'deck-board',
'id' => 123,
'name' => 'Board title',
'link' => '#/board/123',
'link' => '/board/123',
]
]);

Expand All @@ -266,7 +275,7 @@ public function testPrepareCardAssigned($withUserFound = true) {
$this->assertEquals($notification, $actualNotification);
}

public function dataPrepareBoardShared() {
public static function dataPrepareBoardShared() {
return [
[true], [false]
];
Expand Down Expand Up @@ -321,7 +330,7 @@ public function testPrepareBoardShared($withUserFound = true) {
'type' => 'deck-board',
'id' => 123,
'name' => 'Board title',
'link' => '#/board/123',
'link' => '/board/123',
]
]);

Expand All @@ -347,11 +356,8 @@ public function testPrepareBoardShared($withUserFound = true) {
* @return Stack|MockObject
*/
private function buildMockStack(int $boardId = 999) {
$mockStack = $this->getMockBuilder(Stack::class)
->addMethods(['getBoardId'])
->getMock();

$mockStack->method('getBoardId')->willReturn($boardId);
return $mockStack;
$stack = new Stack();
$stack->setBoardId($boardId);
return $stack;
}
}
2 changes: 1 addition & 1 deletion tests/unit/Reference/CardReferenceProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function setUp() : void {
);
}

public static function dataUrl(): array {
public static static function dataUrl(): array {
return [
['https://nextcloud.com', null],
['https://localhost/apps/deck/#!/board/2/card/11', 11],
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/Search/FilterStringParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public function testParseTextTokenQuotesWrong() {
Assert::assertEquals($expected, $result);
}

public function dataParseDate() {
public static function dataParseDate() {
return [
['date:today', [new DateQueryParameter('date', SearchQuery::COMPARATOR_EQUAL, 'today')], []],
['date:>today', [new DateQueryParameter('date', SearchQuery::COMPARATOR_MORE, 'today')], []],
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/Search/Query/AQueryParameterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
use PHPUnit\Framework\TestCase;

class AQueryParameterTest extends TestCase {
public function dataValue() {
public static function dataValue() {
return [
['foo', 'foo'],
['spätial character', 'spätial character'],
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/Service/BoardServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ public function testAddAcl() {
));
}

public function dataAddAclExtendPermission() {
public static function dataAddAclExtendPermission() {
return [
[[false, false, false], [false, false, false], [false, false, false]],
[[false, false, false], [true, true, true], [false, false, false]],
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/Service/CardServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ public function testRenameArchived() {
$this->cardService->rename(123, 'newtitle');
}

public function dataReorder() {
public static function dataReorder() {
return [
[0, 0, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]],
[0, 9, [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]],
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/Service/PermissionServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public function testUserIsBoardOwnerNull() {
$this->assertEquals(false, $this->service->userIsBoardOwner(123));
}

public function dataTestUserCan() {
public static function dataTestUserCan() {
return [
// participant permissions type
['admin', false, false, false, 'user', true, false, false, false],
Expand Down Expand Up @@ -183,7 +183,7 @@ public function testUserCanFail() {
$this->assertFalse($this->service->userCan([], Acl::PERMISSION_EDIT));
}

public function dataCheckPermission() {
public static function dataCheckPermission() {
return [
// see getAcls() for set permissions
[1, Acl::PERMISSION_READ, true],
Expand Down

0 comments on commit c3e9bde

Please sign in to comment.