Skip to content

Commit 339d070

Browse files
committed
chore(tests): Adapt tests to IUser strict typing
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
1 parent f7f644b commit 339d070

5 files changed

Lines changed: 24 additions & 12 deletions

File tree

apps/dav/tests/unit/Connector/Sabre/AddExtraHeadersPluginTest.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,13 @@ function ($method, $callback) use (&$afterPut): void {
8181
$this->tree->expects($this->once())->method('getNodeForPath')
8282
->willReturn($node);
8383

84-
$user = $this->createMock(IUser::class);
85-
$node->expects($this->once())->method('getOwner')->willReturn($user);
86-
$user->expects($this->once())->method('getUID')->willReturn($ownerId);
84+
if ($ownerId !== null) {
85+
$user = $this->createMock(IUser::class);
86+
$node->expects($this->once())->method('getOwner')->willReturn($user);
87+
$user->expects($this->once())->method('getUID')->willReturn($ownerId);
88+
} else {
89+
$node->expects($this->once())->method('getOwner')->willReturn(null);
90+
}
8791
$node->expects($this->once())->method('getDavPermissions')->willReturn($permissions);
8892

8993
$matcher = $this->exactly($expectedInvocations);

apps/dav/tests/unit/Connector/Sabre/PrincipalTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@ public function testGetPrincipalsByPrefixWithUsers(): void {
101101
->expects($this->once())
102102
->method('getSystemEMailAddress')
103103
->willReturn('bar@nextcloud.com');
104+
$barUser
105+
->expects($this->once())
106+
->method('getDisplayName')
107+
->willReturn('bar');
104108
$this->userManager
105109
->expects($this->once())
106110
->method('search')
@@ -189,6 +193,10 @@ public function testGetPrincipalsByPathWithoutMail(): void {
189193
->expects($this->once())
190194
->method('getUID')
191195
->willReturn('foo');
196+
$fooUser
197+
->expects($this->once())
198+
->method('getDisplayName')
199+
->willReturn('foo');
192200
$this->userManager
193201
->expects($this->once())
194202
->method('get')
@@ -221,6 +229,10 @@ public function testGetPrincipalsByPathWithMail(): void {
221229
->expects($this->once())
222230
->method('getUID')
223231
->willReturn('foo');
232+
$fooUser
233+
->expects($this->once())
234+
->method('getDisplayName')
235+
->willReturn('foo');
224236
$this->userManager
225237
->expects($this->once())
226238
->method('get')

apps/settings/tests/Controller/UsersControllerTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,7 @@ public static function dataTestSetUserSettingsSubset(): array {
675675
}
676676

677677
#[\PHPUnit\Framework\Attributes\DataProvider(methodName: 'dataTestSaveUserSettings')]
678-
public function testSaveUserSettings(array $data, ?string $oldEmailAddress, ?string $oldDisplayName): void {
678+
public function testSaveUserSettings(array $data, ?string $oldEmailAddress, string $oldDisplayName): void {
679679
$controller = $this->getController();
680680
$user = $this->createMock(IUser::class);
681681

@@ -690,7 +690,7 @@ public function testSaveUserSettings(array $data, ?string $oldEmailAddress, ?str
690690
->with($data[IAccountManager::PROPERTY_EMAIL]['value']);
691691
}
692692

693-
if ($data[IAccountManager::PROPERTY_DISPLAYNAME]['value'] === $oldDisplayName ?? '') {
693+
if ($data[IAccountManager::PROPERTY_DISPLAYNAME]['value'] === $oldDisplayName) {
694694
$user->expects($this->never())->method('setDisplayName');
695695
} else {
696696
$user->expects($this->once())->method('setDisplayName')
@@ -775,15 +775,15 @@ public static function dataTestSaveUserSettings(): array {
775775
IAccountManager::PROPERTY_DISPLAYNAME => ['value' => 'john doe'],
776776
],
777777
'john@example.com',
778-
null
778+
''
779779
],
780780
[
781781
[
782782
IAccountManager::PROPERTY_EMAIL => ['value' => 'john@example.com'],
783783
IAccountManager::PROPERTY_DISPLAYNAME => ['value' => 'john doe'],
784784
],
785785
'JOHN@example.com',
786-
null
786+
''
787787
],
788788
];
789789
}

tests/lib/Contacts/ContactsMenu/Providers/LocalTimeProviderTest.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,10 +186,6 @@ public function testProcessNoUser(): void {
186186
->with('UID')
187187
->willReturn('user1');
188188

189-
$user = $this->createMock(IUser::class);
190-
$user->method('getUID')
191-
->willReturn(null);
192-
193189
$entry->expects($this->never())
194190
->method('addAction');
195191

tests/lib/TaskProcessing/TaskProcessingTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -912,7 +912,7 @@ public function testProviderShouldBeRegisteredAndTaskWithFilesFailValidation():
912912
new ServiceRegistration('test', AsyncProvider::class)
913913
]);
914914
$user = $this->createMock(IUser::class);
915-
$user->expects($this->any())->method('getUID')->willReturn(null);
915+
$user->expects($this->any())->method('getUID')->willReturn('uid');
916916
$mount = $this->createMock(ICachedMountInfo::class);
917917
$mount->expects($this->any())->method('getUser')->willReturn($user);
918918
$this->userMountCache->expects($this->any())->method('getMountsForFileId')->willReturn([$mount]);

0 commit comments

Comments
 (0)