Skip to content

Commit 8d55b13

Browse files
Merge pull request #57367 from nextcloud/work/carl/psalm-unittests
refactor(psalm): Enable psalm for comments unit tests
2 parents 40b79f5 + 6eb1609 commit 8d55b13

File tree

9 files changed

+218
-333
lines changed

9 files changed

+218
-333
lines changed

apps/webhook_listeners/lib/Service/TokenService.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,11 @@ public function __construct(
6565
*
6666
* @param WebhookListener $webhookListener
6767
* @param ?string $triggerUserId the user that triggered the webhook call
68-
* @return array{user_ids?:array<string,string>,user_roles?:array{owner?:array<string,string>,trigger?:array<string,string>}}
68+
* @return array{
69+
* user_ids?: array<string, array{baseUrl: string, token: string, userId: mixed}>,
70+
* trigger?: array{baseUrl: string, token: string, userId: string},
71+
* owner?: array{baseUrl: string, token: string, userId: string},
72+
* }
6973
*/
7074
public function getTokens(WebhookListener $webhookListener, ?string $triggerUserId): array {
7175
$tokens = [];

build/psalm-baseline.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4306,4 +4306,13 @@
43064306
<code><![CDATA[getAppValue]]></code>
43074307
</DeprecatedMethod>
43084308
</file>
4309+
<file src="tests/lib/TestCase.php">
4310+
<DeprecatedMethod>
4311+
<code><![CDATA[$container]]></code>
4312+
</DeprecatedMethod>
4313+
<InternalMethod>
4314+
<code><![CDATA[lockFile]]></code>
4315+
<code><![CDATA[unlockFile]]></code>
4316+
</InternalMethod>
4317+
</file>
43094318
</files>

lib/private/OpenMetrics/Exporters/FilesByType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public function gatherMetrics(): Generator {
7272
foreach ($metrics->iterateAssociative() as $count) {
7373
yield new Metric(
7474
$count['count'],
75-
['mimetype' => $this->mimetypeLoader->getMimetypeById($count['mimetype'])],
75+
['mimetype' => $this->mimetypeLoader->getMimetypeById($count['mimetype']) ?? ''],
7676
$now,
7777
);
7878
}

lib/public/Comments/ICommentsManager.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,7 @@ public function deleteReadMarksOnObject($objectType, $objectId);
438438
* to consumers of the comments infrastructure
439439
*
440440
* @param \Closure $closure
441+
* @return void
441442
* @since 11.0.0
442443
*/
443444
public function registerEventHandler(\Closure $closure);
@@ -447,6 +448,7 @@ public function registerEventHandler(\Closure $closure);
447448
*
448449
* @param string $type
449450
* @param \Closure $closure
451+
* @return void
450452
* @throws \OutOfBoundsException
451453
* @since 11.0.0
452454
*

psalm.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,15 @@
5454
<directory name="core"/>
5555
<directory name="lib"/>
5656
<directory name="ocs"/>
57+
<directory name="tests/lib/Comments"/>
5758
<directory name="ocs-provider"/>
5859
<file name="cron.php"/>
5960
<file name="index.php"/>
6061
<file name="public.php"/>
6162
<file name="remote.php"/>
6263
<file name="status.php"/>
6364
<file name="version.php"/>
65+
<file name="tests/lib/TestCase.php"/>
6466
<ignoreFiles>
6567
<directory name="apps/**/composer"/>
6668
<directory name="apps/**/tests"/>
@@ -71,6 +73,7 @@
7173
</projectFiles>
7274
<extraFiles>
7375
<directory name="3rdparty"/>
76+
<directory name="vendor-bin/phpunit/vendor/phpunit"/>
7477
</extraFiles>
7578
<stubs>
7679
<file name="build/stubs/apcu.php"/>

tests/lib/Comments/CommentTest.php

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use OCP\Comments\IComment;
1212
use OCP\Comments\IllegalIDChangeException;
1313
use OCP\Comments\MessageTooLongException;
14+
use PHPUnit\Framework\Attributes\DataProvider;
1415
use Test\TestCase;
1516

1617
class CommentTest extends TestCase {
@@ -96,7 +97,7 @@ public static function simpleSetterProvider(): array {
9697
];
9798
}
9899

99-
#[\PHPUnit\Framework\Attributes\DataProvider('simpleSetterProvider')]
100+
#[DataProvider(methodName: 'simpleSetterProvider')]
100101
public function testSimpleSetterInvalidInput($field, $input): void {
101102
$this->expectException(\InvalidArgumentException::class);
102103

@@ -119,7 +120,7 @@ public static function roleSetterProvider(): array {
119120
];
120121
}
121122

122-
#[\PHPUnit\Framework\Attributes\DataProvider('roleSetterProvider')]
123+
#[DataProvider(methodName: 'roleSetterProvider')]
123124
public function testSetRoleInvalidInput($role, $type, $id): void {
124125
$this->expectException(\InvalidArgumentException::class);
125126

@@ -204,13 +205,7 @@ public static function mentionsProvider(): array {
204205
];
205206
}
206207

207-
/**
208-
*
209-
* @param string $message
210-
* @param array $expectedMentions
211-
* @param ?string $author
212-
*/
213-
#[\PHPUnit\Framework\Attributes\DataProvider('mentionsProvider')]
208+
#[DataProvider(methodName: 'mentionsProvider')]
214209
public function testMentions(string $message, array $expectedMentions, ?string $author = null): void {
215210
$comment = new Comment();
216211
$comment->setMessage($message);

tests/lib/Comments/FakeManager.php

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@
1616
* Class FakeManager
1717
*/
1818
class FakeManager implements ICommentsManager {
19-
public function get($id) {
19+
public function get($id): IComment {
20+
throw new \Exception('Not implemented');
2021
}
2122

22-
public function getTree($id, $limit = 0, $offset = 0) {
23+
public function getTree($id, $limit = 0, $offset = 0): array {
24+
return ['comment' => new Comment(), 'replies' => []];
2325
}
2426

2527
public function getForObject(
@@ -28,7 +30,8 @@ public function getForObject(
2830
$limit = 0,
2931
$offset = 0,
3032
?\DateTime $notOlderThan = null,
31-
) {
33+
): array {
34+
return [];
3235
}
3336

3437
public function getForObjectSince(
@@ -57,6 +60,7 @@ public function getCommentsWithVerbForObjectSinceComment(
5760
}
5861

5962
public function getNumberOfCommentsForObject($objectType, $objectId, ?\DateTime $notOlderThan = null, $verb = ''): int {
63+
return 0;
6064
}
6165

6266
public function getNumberOfCommentsForObjects(string $objectType, array $objectIds, ?\DateTime $notOlderThan = null, string $verb = ''): array {
@@ -67,10 +71,12 @@ public function search(string $search, string $objectType, string $objectId, str
6771
return [];
6872
}
6973

70-
public function create($actorType, $actorId, $objectType, $objectId) {
74+
public function create($actorType, $actorId, $objectType, $objectId): IComment {
75+
return new Comment();
7176
}
7277

73-
public function delete($id) {
78+
public function delete($id): bool {
79+
return false;
7480
}
7581

7682
public function getReactionComment(int $parentId, string $actorType, string $actorId, string $reaction): IComment {
@@ -89,47 +95,52 @@ public function supportReactions(): bool {
8995
return false;
9096
}
9197

92-
public function save(IComment $comment) {
98+
public function save(IComment $comment): bool {
99+
return false;
93100
}
94101

95-
public function deleteReferencesOfActor($actorType, $actorId) {
102+
public function deleteReferencesOfActor($actorType, $actorId): bool {
103+
return false;
96104
}
97105

98-
public function deleteCommentsAtObject($objectType, $objectId) {
106+
public function deleteCommentsAtObject($objectType, $objectId): bool {
107+
return false;
99108
}
100109

101-
public function setReadMark($objectType, $objectId, \DateTime $dateTime, IUser $user) {
110+
public function setReadMark($objectType, $objectId, \DateTime $dateTime, IUser $user): bool {
111+
return false;
102112
}
103113

104-
public function getReadMark($objectType, $objectId, IUser $user) {
114+
public function getReadMark($objectType, $objectId, IUser $user): bool {
115+
return false;
105116
}
106117

107-
public function deleteReadMarksFromUser(IUser $user) {
118+
public function deleteReadMarksFromUser(IUser $user): bool {
119+
return false;
108120
}
109121

110-
public function deleteReadMarksOnObject($objectType, $objectId) {
122+
public function deleteReadMarksOnObject($objectType, $objectId): bool {
123+
return false;
111124
}
112125

113-
public function registerEventHandler(\Closure $closure) {
126+
public function registerEventHandler(\Closure $closure): void {
114127
}
115128

116-
public function registerDisplayNameResolver($type, \Closure $closure) {
129+
public function registerDisplayNameResolver($type, \Closure $closure): void {
117130
}
118131

119-
public function resolveDisplayName($type, $id) {
132+
public function resolveDisplayName($type, $id): string {
133+
return '';
120134
}
121135

122-
public function getNumberOfUnreadCommentsForFolder($folderId, IUser $user) {
136+
public function getNumberOfUnreadCommentsForFolder($folderId, IUser $user): array {
137+
return [];
123138
}
124139

125140
public function getNumberOfUnreadCommentsForObjects(string $objectType, array $objectIds, IUser $user, $verb = ''): array {
126141
return [];
127142
}
128143

129-
130-
public function getActorsInTree($id) {
131-
}
132-
133144
public function load(): void {
134145
}
135146

0 commit comments

Comments
 (0)