Skip to content

Commit d9867d7

Browse files
committed
chore(sharing): Improve typing in tests to please psalm:strict
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
1 parent fe96dd9 commit d9867d7

3 files changed

Lines changed: 64 additions & 26 deletions

File tree

apps/sharing/tests/Command/CommandTest.php

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ protected function searchRecipients(ShareAccessContext $accessContext, ?array $f
164164
}
165165

166166
/**
167-
* @return array<string, mixed>
167+
* @return SharingShare
168168
*/
169169
#[Override]
170170
protected function createShare(ShareAccessContext $accessContext): array {
@@ -177,12 +177,12 @@ protected function createShare(ShareAccessContext $accessContext): array {
177177
],
178178
[],
179179
);
180-
/** @psalm-suppress MixedReturnStatement */
180+
/** @var SharingShare */
181181
return json_decode($stdout, true, 512, JSON_THROW_ON_ERROR);
182182
}
183183

184184
/**
185-
* @return array<string, mixed>
185+
* @return SharingShare
186186
*/
187187
#[Override]
188188
protected function updateShareState(ShareAccessContext $accessContext, string $id, ShareState $state): array {
@@ -195,12 +195,12 @@ protected function updateShareState(ShareAccessContext $accessContext, string $i
195195
],
196196
[],
197197
);
198-
/** @psalm-suppress MixedReturnStatement */
198+
/** @var SharingShare */
199199
return json_decode($stdout, true, 512, JSON_THROW_ON_ERROR);
200200
}
201201

202202
/**
203-
* @return array<string, mixed>
203+
* @return SharingShare
204204
*/
205205
#[Override]
206206
protected function addShareSource(ShareAccessContext $accessContext, string $id, ShareSource $source): array {
@@ -214,12 +214,12 @@ protected function addShareSource(ShareAccessContext $accessContext, string $id,
214214
],
215215
[],
216216
);
217-
/** @psalm-suppress MixedReturnStatement */
217+
/** @var SharingShare */
218218
return json_decode($stdout, true, 512, JSON_THROW_ON_ERROR);
219219
}
220220

221221
/**
222-
* @return array<string, mixed>
222+
* @return SharingShare
223223
*/
224224
#[Override]
225225
protected function removeShareSource(ShareAccessContext $accessContext, string $id, ShareSource $source): array {
@@ -233,12 +233,12 @@ protected function removeShareSource(ShareAccessContext $accessContext, string $
233233
],
234234
[],
235235
);
236-
/** @psalm-suppress MixedReturnStatement */
236+
/** @var SharingShare */
237237
return json_decode($stdout, true, 512, JSON_THROW_ON_ERROR);
238238
}
239239

240240
/**
241-
* @return array<string, mixed>
241+
* @return SharingShare
242242
*/
243243
#[Override]
244244
protected function addShareRecipient(ShareAccessContext $accessContext, string $id, ShareRecipient $recipient): array {
@@ -253,12 +253,12 @@ protected function addShareRecipient(ShareAccessContext $accessContext, string $
253253
],
254254
[],
255255
);
256-
/** @psalm-suppress MixedReturnStatement */
256+
/** @var SharingShare */
257257
return json_decode($stdout, true, 512, JSON_THROW_ON_ERROR);
258258
}
259259

260260
/**
261-
* @return array<string, mixed>
261+
* @return SharingShare
262262
*/
263263
#[Override]
264264
protected function removeShareRecipient(ShareAccessContext $accessContext, string $id, ShareRecipient $recipient): array {
@@ -273,12 +273,12 @@ protected function removeShareRecipient(ShareAccessContext $accessContext, strin
273273
],
274274
[],
275275
);
276-
/** @psalm-suppress MixedReturnStatement */
276+
/** @var SharingShare */
277277
return json_decode($stdout, true, 512, JSON_THROW_ON_ERROR);
278278
}
279279

280280
/**
281-
* @return array<string, mixed>
281+
* @return SharingShare
282282
*/
283283
#[Override]
284284
protected function updateShareRecipientSecret(ShareAccessContext $accessContext, string $id, ShareRecipient $recipient, string $secret): array {
@@ -294,12 +294,12 @@ protected function updateShareRecipientSecret(ShareAccessContext $accessContext,
294294
],
295295
[],
296296
);
297-
/** @psalm-suppress MixedReturnStatement */
297+
/** @var SharingShare */
298298
return json_decode($stdout, true, 512, JSON_THROW_ON_ERROR);
299299
}
300300

301301
/**
302-
* @return array<string, mixed>
302+
* @return SharingShare
303303
*/
304304
#[Override]
305305
protected function updateShareProperty(ShareAccessContext $accessContext, string $id, ShareProperty $property): array {
@@ -313,12 +313,12 @@ protected function updateShareProperty(ShareAccessContext $accessContext, string
313313
],
314314
[],
315315
);
316-
/** @psalm-suppress MixedReturnStatement */
316+
/** @var SharingShare */
317317
return json_decode($stdout, true, 512, JSON_THROW_ON_ERROR);
318318
}
319319

320320
/**
321-
* @return array<string, mixed>
321+
* @return SharingShare
322322
*/
323323
#[Override]
324324
protected function updateSharePermission(ShareAccessContext $accessContext, string $id, SharePermission $permission): array {
@@ -332,12 +332,12 @@ protected function updateSharePermission(ShareAccessContext $accessContext, stri
332332
],
333333
[],
334334
);
335-
/** @psalm-suppress MixedReturnStatement */
335+
/** @var SharingShare */
336336
return json_decode($stdout, true, 512, JSON_THROW_ON_ERROR);
337337
}
338338

339339
/**
340-
* @return array<string, mixed>
340+
* @return SharingShare
341341
*/
342342
#[Override]
343343
protected function selectSharePermissionPreset(ShareAccessContext $accessContext, string $id, string $permissionPresetClass): array {
@@ -350,7 +350,7 @@ protected function selectSharePermissionPreset(ShareAccessContext $accessContext
350350
],
351351
[],
352352
);
353-
/** @psalm-suppress MixedReturnStatement */
353+
/** @var SharingShare */
354354
return json_decode($stdout, true, 512, JSON_THROW_ON_ERROR);
355355
}
356356

@@ -379,7 +379,7 @@ protected function getShare(ShareAccessContext $accessContext, string $id): arra
379379
],
380380
[],
381381
);
382-
/** @psalm-suppress MixedReturnStatement */
382+
/** @var SharingShare */
383383
return json_decode($stdout, true, 512, JSON_THROW_ON_ERROR);
384384
}
385385

@@ -399,7 +399,7 @@ protected function getShares(ShareAccessContext $accessContext, ?string $filterS
399399
['limit', $limit],
400400
],
401401
);
402-
/** @psalm-suppress MixedReturnStatement */
402+
/** @var SharingShare[] */
403403
return json_decode($stdout, true, 512, JSON_THROW_ON_ERROR);
404404
}
405405
}

apps/sharing/tests/Controller/ApiV1ControllerTest.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,53 +95,63 @@ protected function searchRecipients(ShareAccessContext $accessContext, ?array $f
9595

9696
#[Override]
9797
protected function createShare(ShareAccessContext $accessContext): array {
98+
/** @var SharingShare */
9899
return $this->executeRequest($accessContext, fn (ApiV1Controller $controller): DataResponse => $controller->createShare());
99100
}
100101

101102
#[Override]
102103
protected function updateShareState(ShareAccessContext $accessContext, string $id, ShareState $state): array {
104+
/** @var SharingShare */
103105
return $this->executeRequest($accessContext, fn (ApiV1Controller $controller): DataResponse => $controller->updateShareState($id, $state->value));
104106
}
105107

106108
#[Override]
107109
protected function addShareSource(ShareAccessContext $accessContext, string $id, ShareSource $source): array {
110+
/** @var SharingShare */
108111
return $this->executeRequest($accessContext, fn (ApiV1Controller $controller): DataResponse => $controller->addShareSource($id, $source->class, $source->value));
109112
}
110113

111114
#[Override]
112115
protected function removeShareSource(ShareAccessContext $accessContext, string $id, ShareSource $source): array {
116+
/** @var SharingShare */
113117
return $this->executeRequest($accessContext, fn (ApiV1Controller $controller): DataResponse => $controller->removeShareSource($id, $source->class, $source->value));
114118
}
115119

116120
#[Override]
117121
protected function addShareRecipient(ShareAccessContext $accessContext, string $id, ShareRecipient $recipient): array {
122+
/** @var SharingShare */
118123
return $this->executeRequest($accessContext, fn (ApiV1Controller $controller): DataResponse => $controller->addShareRecipient($id, $recipient->class, $recipient->value, $recipient->instance));
119124
}
120125

121126
#[Override]
122127
protected function removeShareRecipient(ShareAccessContext $accessContext, string $id, ShareRecipient $recipient): array {
128+
/** @var SharingShare */
123129
return $this->executeRequest($accessContext, fn (ApiV1Controller $controller): DataResponse => $controller->removeShareRecipient($id, $recipient->class, $recipient->value, $recipient->instance));
124130
}
125131

126132
#[Override]
127133
protected function updateShareRecipientSecret(ShareAccessContext $accessContext, string $id, ShareRecipient $recipient, string $secret): array {
128134
/** @psalm-suppress ArgumentTypeCoercion */
135+
/** @var SharingShare */
129136
return $this->executeRequest($accessContext, fn (ApiV1Controller $controller): DataResponse => $controller->updateShareRecipientSecret($id, $recipient->class, $recipient->value, $recipient->instance, $secret));
130137
}
131138

132139
#[Override]
133140
protected function updateShareProperty(ShareAccessContext $accessContext, string $id, ShareProperty $property): array {
141+
/** @var SharingShare */
134142
return $this->executeRequest($accessContext, fn (ApiV1Controller $controller): DataResponse => $controller->updateShareProperty($id, $property->class, $property->value));
135143
}
136144

137145
#[Override]
138146
protected function updateSharePermission(ShareAccessContext $accessContext, string $id, SharePermission $permission): array {
147+
/** @var SharingShare */
139148
return $this->executeRequest($accessContext, fn (ApiV1Controller $controller): DataResponse => $controller->updateSharePermission($id, $permission->class, $permission->enabled));
140149
}
141150

142151
#[Override]
143152
protected function selectSharePermissionPreset(ShareAccessContext $accessContext, string $id, string $permissionPresetClass): array {
144153
/** @psalm-suppress ArgumentTypeCoercion */
154+
/** @var SharingShare */
145155
return $this->executeRequest($accessContext, fn (ApiV1Controller $controller): DataResponse => $controller->selectSharePermissionPreset($id, $permissionPresetClass));
146156
}
147157

@@ -150,11 +160,9 @@ protected function deleteShare(ShareAccessContext $accessContext, string $id): v
150160
$this->executeRequest($accessContext, fn (ApiV1Controller $controller): DataResponse => $controller->deleteShare($id));
151161
}
152162

153-
/**
154-
* @psalm-suppress MixedReturnTypeCoercion
155-
*/
156163
#[Override]
157164
protected function getShare(ShareAccessContext $accessContext, string $id): array {
165+
/** @var SharingShare */
158166
return $this->executeRequest(new ShareAccessContext($accessContext->currentUser, null, [], $accessContext->overrideChecks), fn (ApiV1Controller $controller): DataResponse => $controller->getShare($id, $accessContext->secret, $accessContext->arguments));
159167
}
160168

tests/lib/Sharing/AbstractSharingManagerTests.php

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,24 +42,54 @@
4242
abstract class AbstractSharingManagerTests extends TestCase {
4343
abstract protected function searchRecipients(ShareAccessContext $accessContext, ?array $filterRecipientTypeClasses, string $query, int $limit, int $offset, ?string $id = null): array;
4444

45+
/**
46+
* @return SharingShare
47+
*/
4548
abstract protected function createShare(ShareAccessContext $accessContext): array;
4649

50+
/**
51+
* @return SharingShare
52+
*/
4753
abstract protected function updateShareState(ShareAccessContext $accessContext, string $id, ShareState $state): array;
4854

55+
/**
56+
* @return SharingShare
57+
*/
4958
abstract protected function addShareSource(ShareAccessContext $accessContext, string $id, ShareSource $source): array;
5059

60+
/**
61+
* @return SharingShare
62+
*/
5163
abstract protected function removeShareSource(ShareAccessContext $accessContext, string $id, ShareSource $source): array;
5264

65+
/**
66+
* @return SharingShare
67+
*/
5368
abstract protected function addShareRecipient(ShareAccessContext $accessContext, string $id, ShareRecipient $recipient): array;
5469

70+
/**
71+
* @return SharingShare
72+
*/
5573
abstract protected function removeShareRecipient(ShareAccessContext $accessContext, string $id, ShareRecipient $recipient): array;
5674

75+
/**
76+
* @return SharingShare
77+
*/
5778
abstract protected function updateShareRecipientSecret(ShareAccessContext $accessContext, string $id, ShareRecipient $recipient, string $secret): array;
5879

80+
/**
81+
* @return SharingShare
82+
*/
5983
abstract protected function updateShareProperty(ShareAccessContext $accessContext, string $id, ShareProperty $property): array;
6084

85+
/**
86+
* @return SharingShare
87+
*/
6188
abstract protected function updateSharePermission(ShareAccessContext $accessContext, string $id, SharePermission $permission): array;
6289

90+
/**
91+
* @return SharingShare
92+
*/
6393
abstract protected function selectSharePermissionPreset(ShareAccessContext $accessContext, string $id, string $permissionPresetClass): array;
6494

6595
abstract protected function deleteShare(ShareAccessContext $accessContext, string $id): void;
@@ -86,7 +116,7 @@ abstract protected function getShares(ShareAccessContext $accessContext, ?string
86116

87117
protected IUser $user2;
88118

89-
private function parseTime(mixed $timestampMs): \DateTimeImmutable {
119+
private function parseTime(string $timestampMs): \DateTimeImmutable {
90120
$time = \DateTimeImmutable::createFromFormat('U.u', number_format((float)$timestampMs / 1000.0, 3, '.', ''));
91121
if ($time === false) {
92122
throw new \RuntimeException('invalid timestamp: ' . $timestampMs);

0 commit comments

Comments
 (0)