Skip to content

Commit 5bade98

Browse files
Merge pull request #53122 from nextcloud/tests/noid/dav-systemtag
test: Migrate DAV Systemtags tests to PHPUnit 10
2 parents c3f16a5 + 96a1dd3 commit 5bade98

11 files changed

+250
-386
lines changed

apps/dav/tests/unit/CapabilitiesTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
3+
declare(strict_types=1);
24
/**
35
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
46
* SPDX-License-Identifier: AGPL-3.0-or-later

apps/dav/tests/unit/ServerTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php
22

3+
declare(strict_types=1);
34
/**
45
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
56
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -22,7 +23,7 @@ class ServerTest extends \Test\TestCase {
2223
/**
2324
* @dataProvider providesUris
2425
*/
25-
public function test($uri, array $plugins): void {
26+
public function test(string $uri, array $plugins): void {
2627
/** @var IRequest | \PHPUnit\Framework\MockObject\MockObject $r */
2728
$r = $this->createMock(IRequest::class);
2829
$r->expects($this->any())->method('getRequestUri')->willReturn($uri);
@@ -33,7 +34,7 @@ public function test($uri, array $plugins): void {
3334
$this->assertNotNull($s->server->getPlugin($plugin));
3435
}
3536
}
36-
public function providesUris() {
37+
public static function providesUris(): array {
3738
return [
3839
'principals' => ['principals/users/admin', ['caldav', 'oc-resource-sharing', 'carddav']],
3940
'calendars' => ['calendars/admin', ['caldav', 'oc-resource-sharing']],

apps/dav/tests/unit/Settings/CalDAVSettingsTest.php

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
3+
declare(strict_types=1);
24
/**
35
* SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
46
* SPDX-License-Identifier: AGPL-3.0-or-later
@@ -15,19 +17,10 @@
1517
use Test\TestCase;
1618

1719
class CalDAVSettingsTest extends TestCase {
18-
19-
/** @var IConfig|MockObject */
20-
private $config;
21-
22-
/** @var IInitialState|MockObject */
23-
private $initialState;
24-
25-
/** @var IURLGenerator|MockObject */
26-
private $urlGenerator;
27-
28-
/** @var IAppManager|MockObject */
29-
private $appManager;
30-
20+
private IConfig&MockObject $config;
21+
private IInitialState&MockObject $initialState;
22+
private IURLGenerator&MockObject $urlGenerator;
23+
private IAppManager&MockObject $appManager;
3124
private CalDAVSettings $settings;
3225

3326
protected function setUp(): void {
@@ -42,28 +35,32 @@ protected function setUp(): void {
4235

4336
public function testGetForm(): void {
4437
$this->config->method('getAppValue')
45-
->withConsecutive(
46-
['dav', 'sendInvitations', 'yes'],
47-
['dav', 'generateBirthdayCalendar', 'yes'],
48-
['dav', 'sendEventReminders', 'yes'],
49-
['dav', 'sendEventRemindersToSharedUsers', 'yes'],
50-
['dav', 'sendEventRemindersPush', 'yes'],
51-
)
52-
->will($this->onConsecutiveCalls('yes', 'no', 'yes', 'yes', 'yes'));
38+
->willReturnMap([
39+
['dav', 'sendInvitations', 'yes', 'yes'],
40+
['dav', 'generateBirthdayCalendar', 'yes', 'no'],
41+
['dav', 'sendEventReminders', 'yes', 'yes'],
42+
['dav', 'sendEventRemindersToSharedUsers', 'yes', 'yes'],
43+
['dav', 'sendEventRemindersPush', 'yes', 'yes'],
44+
]);
5345
$this->urlGenerator
5446
->expects($this->once())
5547
->method('linkToDocs')
5648
->with('user-sync-calendars')
5749
->willReturn('Some docs URL');
50+
51+
$calls = [
52+
['userSyncCalendarsDocUrl', 'Some docs URL'],
53+
['sendInvitations', true],
54+
['generateBirthdayCalendar', false],
55+
['sendEventReminders', true],
56+
['sendEventRemindersToSharedUsers', true],
57+
['sendEventRemindersPush', true],
58+
];
5859
$this->initialState->method('provideInitialState')
59-
->withConsecutive(
60-
['userSyncCalendarsDocUrl', 'Some docs URL'],
61-
['sendInvitations', true],
62-
['generateBirthdayCalendar', false],
63-
['sendEventReminders', true],
64-
['sendEventRemindersToSharedUsers', true],
65-
['sendEventRemindersPush', true],
66-
);
60+
->willReturnCallback(function () use (&$calls) {
61+
$expected = array_shift($calls);
62+
$this->assertEquals($expected, func_get_args());
63+
});
6764
$result = $this->settings->getForm();
6865

6966
$this->assertInstanceOf(TemplateResponse::class, $result);
@@ -88,5 +85,4 @@ public function testGetSectionWithoutCaldavBackend(): void {
8885
public function testGetPriority(): void {
8986
$this->assertEquals(10, $this->settings->getPriority());
9087
}
91-
9288
}

apps/dav/tests/unit/SystemTag/SystemTagMappingNodeTest.php

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php
22

3+
declare(strict_types=1);
34
/**
45
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
56
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -14,30 +15,28 @@
1415
use OCP\SystemTag\ISystemTagManager;
1516
use OCP\SystemTag\ISystemTagObjectMapper;
1617
use OCP\SystemTag\TagNotFoundException;
18+
use PHPUnit\Framework\MockObject\MockObject;
1719

1820
class SystemTagMappingNodeTest extends \Test\TestCase {
19-
private ISystemTagManager $tagManager;
20-
private ISystemTagObjectMapper $tagMapper;
21-
private IUser $user;
21+
private ISystemTagManager&MockObject $tagManager;
22+
private ISystemTagObjectMapper&MockObject $tagMapper;
23+
private IUser&MockObject $user;
2224

2325
protected function setUp(): void {
2426
parent::setUp();
2527

26-
$this->tagManager = $this->getMockBuilder(ISystemTagManager::class)
27-
->getMock();
28-
$this->tagMapper = $this->getMockBuilder(ISystemTagObjectMapper::class)
29-
->getMock();
30-
$this->user = $this->getMockBuilder(IUser::class)
31-
->getMock();
28+
$this->tagManager = $this->createMock(ISystemTagManager::class);
29+
$this->tagMapper = $this->createMock(ISystemTagObjectMapper::class);
30+
$this->user = $this->createMock(IUser::class);
3231
}
3332

3433
public function getMappingNode($tag = null, array $writableNodeIds = []) {
3534
if ($tag === null) {
36-
$tag = new SystemTag(1, 'Test', true, true);
35+
$tag = new SystemTag('1', 'Test', true, true);
3736
}
3837
return new SystemTagMappingNode(
3938
$tag,
40-
123,
39+
'123',
4140
'files',
4241
$this->user,
4342
$this->tagManager,
@@ -47,7 +46,7 @@ public function getMappingNode($tag = null, array $writableNodeIds = []) {
4746
}
4847

4948
public function testGetters(): void {
50-
$tag = new SystemTag(1, 'Test', true, false);
49+
$tag = new SystemTag('1', 'Test', true, false);
5150
$node = $this->getMappingNode($tag);
5251
$this->assertEquals('1', $node->getName());
5352
$this->assertEquals($tag, $node->getSystemTag());
@@ -93,16 +92,16 @@ public function testDeleteTagForbidden(): void {
9392
$node->delete();
9493
}
9594

96-
public function tagNodeDeleteProviderPermissionException() {
95+
public static function tagNodeDeleteProviderPermissionException(): array {
9796
return [
9897
[
9998
// cannot unassign invisible tag
100-
new SystemTag(1, 'Original', false, true),
99+
new SystemTag('1', 'Original', false, true),
101100
'Sabre\DAV\Exception\NotFound',
102101
],
103102
[
104103
// cannot unassign non-assignable tag
105-
new SystemTag(1, 'Original', true, false),
104+
new SystemTag('1', 'Original', true, false),
106105
'Sabre\DAV\Exception\Forbidden',
107106
],
108107
];
@@ -141,7 +140,7 @@ public function testDeleteTagNotFound(): void {
141140

142141
// assuming the tag existed at the time the node was created,
143142
// but got deleted concurrently in the database
144-
$tag = new SystemTag(1, 'Test', true, true);
143+
$tag = new SystemTag('1', 'Test', true, true);
145144
$this->tagManager->expects($this->once())
146145
->method('canUserSeeTag')
147146
->with($tag)

0 commit comments

Comments
 (0)