Skip to content

Commit 6297d50

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 6297d50

2 files changed

Lines changed: 42 additions & 4 deletions

File tree

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)