Skip to content

Commit 56f3d19

Browse files
Merge pull request #53146 from nextcloud/tests/noid/finish-dav
test: Migrate remaining DAV tests to PHPUnit 10
2 parents d03f6d8 + 9f8f775 commit 56f3d19

File tree

79 files changed

+1056
-1753
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+1056
-1753
lines changed

apps/dav/lib/BulkUpload/MultipartRequestParser.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,13 @@ public function __construct(
5757
*/
5858
private function parseBoundaryFromHeaders(string $contentType): string {
5959
try {
60+
if (!str_contains($contentType, ';')) {
61+
throw new \InvalidArgumentException('No semicolon in header');
62+
}
6063
[$mimeType, $boundary] = explode(';', $contentType);
64+
if (!str_contains($boundary, '=')) {
65+
throw new \InvalidArgumentException('No equal in boundary header');
66+
}
6167
[$boundaryKey, $boundaryValue] = explode('=', $boundary);
6268
} catch (\Exception $e) {
6369
throw new BadRequest('Error while parsing boundary in Content-Type header.', Http::STATUS_BAD_REQUEST, $e);

apps/dav/tests/unit/Avatars/AvatarHomeTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* SPDX-FileCopyrightText: 2017 ownCloud GmbH
77
* SPDX-License-Identifier: AGPL-3.0-only
88
*/
9-
namespace OCA\DAV\Tests\Unit\Avatars;
9+
namespace OCA\DAV\Tests\unit\Avatars;
1010

1111
use OCA\DAV\Avatars\AvatarHome;
1212
use OCA\DAV\Avatars\AvatarNode;

apps/dav/tests/unit/Avatars/AvatarNodeTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* SPDX-FileCopyrightText: 2017 ownCloud GmbH
77
* SPDX-License-Identifier: AGPL-3.0-only
88
*/
9-
namespace OCA\DAV\Tests\Unit\Avatars;
9+
namespace OCA\DAV\Tests\unit\Avatars;
1010

1111
use OCA\DAV\Avatars\AvatarNode;
1212
use OCP\IAvatar;

apps/dav/tests/unit/Command/DeleteCalendarTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* SPDX-License-Identifier: AGPL-3.0-or-later
77
*/
88

9-
namespace OCA\DAV\Tests\Command;
9+
namespace OCA\DAV\Tests\unit\Command;
1010

1111
use OCA\DAV\CalDAV\BirthdayService;
1212
use OCA\DAV\CalDAV\CalDavBackend;

apps/dav/tests/unit/Command/ListAddressbooksTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
66
* SPDX-License-Identifier: AGPL-3.0-or-later
77
*/
8-
namespace OCA\DAV\Tests\Command;
8+
namespace OCA\DAV\Tests\unit\Command;
99

1010
use OCA\DAV\CardDAV\CardDavBackend;
1111
use OCA\DAV\Command\ListAddressbooks;

apps/dav/tests/unit/Command/ListCalendarSharesTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* SPDX-License-Identifier: AGPL-3.0-or-later
77
*/
88

9-
namespace OCA\DAV\Tests\Command;
9+
namespace OCA\DAV\Tests\unit\Command;
1010

1111
use OCA\DAV\CalDAV\CalDavBackend;
1212
use OCA\DAV\Command\ListCalendarShares;

apps/dav/tests/unit/Command/ListCalendarsTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
66
* SPDX-License-Identifier: AGPL-3.0-or-later
77
*/
8-
namespace OCA\DAV\Tests\Command;
8+
namespace OCA\DAV\Tests\unit\Command;
99

1010
use OCA\DAV\CalDAV\BirthdayService;
1111
use OCA\DAV\CalDAV\CalDavBackend;

apps/dav/tests/unit/Command/MoveCalendarTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
66
* SPDX-License-Identifier: AGPL-3.0-or-later
77
*/
8-
namespace OCA\DAV\Tests\Command;
8+
namespace OCA\DAV\Tests\unit\Command;
99

1010
use InvalidArgumentException;
1111
use OCA\DAV\CalDAV\CalDavBackend;

apps/dav/tests/unit/Command/RemoveInvalidSharesTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* SPDX-FileCopyrightText: 2018 ownCloud GmbH
77
* SPDX-License-Identifier: AGPL-3.0-only
88
*/
9-
namespace OCA\DAV\Tests\Unit\Command;
9+
namespace OCA\DAV\Tests\unit\Command;
1010

1111
use OCA\DAV\Command\RemoveInvalidShares;
1212
use OCA\DAV\Connector\Sabre\Principal;

apps/dav/tests/unit/Connector/LegacyPublicAuthTest.php

Lines changed: 23 additions & 51 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,6 +15,7 @@
1415
use OCP\Share\Exceptions\ShareNotFound;
1516
use OCP\Share\IManager;
1617
use OCP\Share\IShare;
18+
use PHPUnit\Framework\MockObject\MockObject;
1719

1820
/**
1921
* Class LegacyPublicAuthTest
@@ -23,36 +25,20 @@
2325
* @package OCA\DAV\Tests\unit\Connector
2426
*/
2527
class LegacyPublicAuthTest extends \Test\TestCase {
26-
27-
/** @var ISession|\PHPUnit\Framework\MockObject\MockObject */
28-
private $session;
29-
/** @var IRequest|\PHPUnit\Framework\MockObject\MockObject */
30-
private $request;
31-
/** @var IManager|\PHPUnit\Framework\MockObject\MockObject */
32-
private $shareManager;
33-
/** @var LegacyPublicAuth */
34-
private $auth;
35-
/** @var IThrottler|\PHPUnit\Framework\MockObject\MockObject */
36-
private $throttler;
37-
38-
/** @var string */
39-
private $oldUser;
28+
private ISession&MockObject $session;
29+
private IRequest&MockObject $request;
30+
private IManager&MockObject $shareManager;
31+
private IThrottler&MockObject $throttler;
32+
private LegacyPublicAuth $auth;
33+
private string|false $oldUser;
4034

4135
protected function setUp(): void {
4236
parent::setUp();
4337

44-
$this->session = $this->getMockBuilder(ISession::class)
45-
->disableOriginalConstructor()
46-
->getMock();
47-
$this->request = $this->getMockBuilder(IRequest::class)
48-
->disableOriginalConstructor()
49-
->getMock();
50-
$this->shareManager = $this->getMockBuilder(IManager::class)
51-
->disableOriginalConstructor()
52-
->getMock();
53-
$this->throttler = $this->getMockBuilder(IThrottler::class)
54-
->disableOriginalConstructor()
55-
->getMock();
38+
$this->session = $this->createMock(ISession::class);
39+
$this->request = $this->createMock(IRequest::class);
40+
$this->shareManager = $this->createMock(IManager::class);
41+
$this->throttler = $this->createMock(IThrottler::class);
5642

5743
$this->auth = new LegacyPublicAuth(
5844
$this->request,
@@ -70,7 +56,9 @@ protected function tearDown(): void {
7056

7157
// Set old user
7258
\OC_User::setUserId($this->oldUser);
73-
\OC_Util::setupFS($this->oldUser);
59+
if ($this->oldUser !== false) {
60+
\OC_Util::setupFS($this->oldUser);
61+
}
7462

7563
parent::tearDown();
7664
}
@@ -86,9 +74,7 @@ public function testNoShare(): void {
8674
}
8775

8876
public function testShareNoPassword(): void {
89-
$share = $this->getMockBuilder(IShare::class)
90-
->disableOriginalConstructor()
91-
->getMock();
77+
$share = $this->createMock(IShare::class);
9278
$share->method('getPassword')->willReturn(null);
9379

9480
$this->shareManager->expects($this->once())
@@ -101,9 +87,7 @@ public function testShareNoPassword(): void {
10187
}
10288

10389
public function testSharePasswordFancyShareType(): void {
104-
$share = $this->getMockBuilder(IShare::class)
105-
->disableOriginalConstructor()
106-
->getMock();
90+
$share = $this->createMock(IShare::class);
10791
$share->method('getPassword')->willReturn('password');
10892
$share->method('getShareType')->willReturn(42);
10993

@@ -118,9 +102,7 @@ public function testSharePasswordFancyShareType(): void {
118102

119103

120104
public function testSharePasswordRemote(): void {
121-
$share = $this->getMockBuilder(IShare::class)
122-
->disableOriginalConstructor()
123-
->getMock();
105+
$share = $this->createMock(IShare::class);
124106
$share->method('getPassword')->willReturn('password');
125107
$share->method('getShareType')->willReturn(IShare::TYPE_REMOTE);
126108

@@ -134,9 +116,7 @@ public function testSharePasswordRemote(): void {
134116
}
135117

136118
public function testSharePasswordLinkValidPassword(): void {
137-
$share = $this->getMockBuilder(IShare::class)
138-
->disableOriginalConstructor()
139-
->getMock();
119+
$share = $this->createMock(IShare::class);
140120
$share->method('getPassword')->willReturn('password');
141121
$share->method('getShareType')->willReturn(IShare::TYPE_LINK);
142122

@@ -156,9 +136,7 @@ public function testSharePasswordLinkValidPassword(): void {
156136
}
157137

158138
public function testSharePasswordMailValidPassword(): void {
159-
$share = $this->getMockBuilder(IShare::class)
160-
->disableOriginalConstructor()
161-
->getMock();
139+
$share = $this->createMock(IShare::class);
162140
$share->method('getPassword')->willReturn('password');
163141
$share->method('getShareType')->willReturn(IShare::TYPE_EMAIL);
164142

@@ -178,9 +156,7 @@ public function testSharePasswordMailValidPassword(): void {
178156
}
179157

180158
public function testInvalidSharePasswordLinkValidSession(): void {
181-
$share = $this->getMockBuilder(IShare::class)
182-
->disableOriginalConstructor()
183-
->getMock();
159+
$share = $this->createMock(IShare::class);
184160
$share->method('getPassword')->willReturn('password');
185161
$share->method('getShareType')->willReturn(IShare::TYPE_LINK);
186162
$share->method('getId')->willReturn('42');
@@ -204,9 +180,7 @@ public function testInvalidSharePasswordLinkValidSession(): void {
204180
}
205181

206182
public function testSharePasswordLinkInvalidSession(): void {
207-
$share = $this->getMockBuilder(IShare::class)
208-
->disableOriginalConstructor()
209-
->getMock();
183+
$share = $this->createMock(IShare::class);
210184
$share->method('getPassword')->willReturn('password');
211185
$share->method('getShareType')->willReturn(IShare::TYPE_LINK);
212186
$share->method('getId')->willReturn('42');
@@ -231,9 +205,7 @@ public function testSharePasswordLinkInvalidSession(): void {
231205

232206

233207
public function testSharePasswordMailInvalidSession(): void {
234-
$share = $this->getMockBuilder(IShare::class)
235-
->disableOriginalConstructor()
236-
->getMock();
208+
$share = $this->createMock(IShare::class);
237209
$share->method('getPassword')->willReturn('password');
238210
$share->method('getShareType')->willReturn(IShare::TYPE_EMAIL);
239211
$share->method('getId')->willReturn('42');

0 commit comments

Comments
 (0)