aboutsummaryrefslogtreecommitdiffstats
path: root/apps/dav/tests/unit/Connector
diff options
context:
space:
mode:
Diffstat (limited to 'apps/dav/tests/unit/Connector')
-rw-r--r--apps/dav/tests/unit/Connector/LegacyPublicAuthTest.php74
-rw-r--r--apps/dav/tests/unit/Connector/Sabre/AuthTest.php221
-rw-r--r--apps/dav/tests/unit/Connector/Sabre/BearerAuthTest.php18
-rw-r--r--apps/dav/tests/unit/Connector/Sabre/BlockLegacyClientPluginTest.php2
-rw-r--r--apps/dav/tests/unit/Connector/Sabre/CommentsPropertiesPluginTest.php80
-rw-r--r--apps/dav/tests/unit/Connector/Sabre/CopyEtagHeaderPluginTest.php17
-rw-r--r--apps/dav/tests/unit/Connector/Sabre/CustomPropertiesBackendTest.php48
-rw-r--r--apps/dav/tests/unit/Connector/Sabre/DirectoryTest.php61
-rw-r--r--apps/dav/tests/unit/Connector/Sabre/DummyGetResponsePluginTest.php17
-rw-r--r--apps/dav/tests/unit/Connector/Sabre/Exception/ForbiddenTest.php6
-rw-r--r--apps/dav/tests/unit/Connector/Sabre/Exception/InvalidPathTest.php6
-rw-r--r--apps/dav/tests/unit/Connector/Sabre/ExceptionLoggerPluginTest.php16
-rw-r--r--apps/dav/tests/unit/Connector/Sabre/FakeLockerPluginTest.php69
-rw-r--r--apps/dav/tests/unit/Connector/Sabre/FileTest.php106
-rw-r--r--apps/dav/tests/unit/Connector/Sabre/FilesPluginTest.php139
-rw-r--r--apps/dav/tests/unit/Connector/Sabre/FilesReportPluginTest.php221
-rw-r--r--apps/dav/tests/unit/Connector/Sabre/MaintenancePluginTest.php15
-rw-r--r--apps/dav/tests/unit/Connector/Sabre/NodeTest.php70
-rw-r--r--apps/dav/tests/unit/Connector/Sabre/ObjectTreeTest.php51
-rw-r--r--apps/dav/tests/unit/Connector/Sabre/PrincipalTest.php98
-rw-r--r--apps/dav/tests/unit/Connector/Sabre/PropfindCompressionPluginTest.php3
-rw-r--r--apps/dav/tests/unit/Connector/Sabre/PublicAuthTest.php89
-rw-r--r--apps/dav/tests/unit/Connector/Sabre/QuotaPluginTest.php51
-rw-r--r--apps/dav/tests/unit/Connector/Sabre/RequestTest/Auth.php1
-rw-r--r--apps/dav/tests/unit/Connector/Sabre/RequestTest/DeleteTest.php5
-rw-r--r--apps/dav/tests/unit/Connector/Sabre/RequestTest/DownloadTest.php7
-rw-r--r--apps/dav/tests/unit/Connector/Sabre/RequestTest/EncryptionMasterKeyUploadTest.php3
-rw-r--r--apps/dav/tests/unit/Connector/Sabre/RequestTest/EncryptionUploadTest.php3
-rw-r--r--apps/dav/tests/unit/Connector/Sabre/RequestTest/ExceptionPlugin.php1
-rw-r--r--apps/dav/tests/unit/Connector/Sabre/RequestTest/PartFileInRootUploadTest.php4
-rw-r--r--apps/dav/tests/unit/Connector/Sabre/RequestTest/RequestTestCase.php18
-rw-r--r--apps/dav/tests/unit/Connector/Sabre/RequestTest/Sapi.php1
-rw-r--r--apps/dav/tests/unit/Connector/Sabre/RequestTest/UploadTest.php9
-rw-r--r--apps/dav/tests/unit/Connector/Sabre/SharesPluginTest.php51
-rw-r--r--apps/dav/tests/unit/Connector/Sabre/TagsPluginTest.php143
35 files changed, 623 insertions, 1101 deletions
diff --git a/apps/dav/tests/unit/Connector/LegacyPublicAuthTest.php b/apps/dav/tests/unit/Connector/LegacyPublicAuthTest.php
index 2bb68374162..8b8c775c8ec 100644
--- a/apps/dav/tests/unit/Connector/LegacyPublicAuthTest.php
+++ b/apps/dav/tests/unit/Connector/LegacyPublicAuthTest.php
@@ -1,5 +1,6 @@
<?php
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -14,6 +15,7 @@ use OCP\Security\Bruteforce\IThrottler;
use OCP\Share\Exceptions\ShareNotFound;
use OCP\Share\IManager;
use OCP\Share\IShare;
+use PHPUnit\Framework\MockObject\MockObject;
/**
* Class LegacyPublicAuthTest
@@ -23,36 +25,20 @@ use OCP\Share\IShare;
* @package OCA\DAV\Tests\unit\Connector
*/
class LegacyPublicAuthTest extends \Test\TestCase {
-
- /** @var ISession|\PHPUnit\Framework\MockObject\MockObject */
- private $session;
- /** @var IRequest|\PHPUnit\Framework\MockObject\MockObject */
- private $request;
- /** @var IManager|\PHPUnit\Framework\MockObject\MockObject */
- private $shareManager;
- /** @var LegacyPublicAuth */
- private $auth;
- /** @var IThrottler|\PHPUnit\Framework\MockObject\MockObject */
- private $throttler;
-
- /** @var string */
- private $oldUser;
+ private ISession&MockObject $session;
+ private IRequest&MockObject $request;
+ private IManager&MockObject $shareManager;
+ private IThrottler&MockObject $throttler;
+ private LegacyPublicAuth $auth;
+ private string|false $oldUser;
protected function setUp(): void {
parent::setUp();
- $this->session = $this->getMockBuilder(ISession::class)
- ->disableOriginalConstructor()
- ->getMock();
- $this->request = $this->getMockBuilder(IRequest::class)
- ->disableOriginalConstructor()
- ->getMock();
- $this->shareManager = $this->getMockBuilder(IManager::class)
- ->disableOriginalConstructor()
- ->getMock();
- $this->throttler = $this->getMockBuilder(IThrottler::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $this->session = $this->createMock(ISession::class);
+ $this->request = $this->createMock(IRequest::class);
+ $this->shareManager = $this->createMock(IManager::class);
+ $this->throttler = $this->createMock(IThrottler::class);
$this->auth = new LegacyPublicAuth(
$this->request,
@@ -70,7 +56,9 @@ class LegacyPublicAuthTest extends \Test\TestCase {
// Set old user
\OC_User::setUserId($this->oldUser);
- \OC_Util::setupFS($this->oldUser);
+ if ($this->oldUser !== false) {
+ \OC_Util::setupFS($this->oldUser);
+ }
parent::tearDown();
}
@@ -86,9 +74,7 @@ class LegacyPublicAuthTest extends \Test\TestCase {
}
public function testShareNoPassword(): void {
- $share = $this->getMockBuilder(IShare::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $share = $this->createMock(IShare::class);
$share->method('getPassword')->willReturn(null);
$this->shareManager->expects($this->once())
@@ -101,9 +87,7 @@ class LegacyPublicAuthTest extends \Test\TestCase {
}
public function testSharePasswordFancyShareType(): void {
- $share = $this->getMockBuilder(IShare::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $share = $this->createMock(IShare::class);
$share->method('getPassword')->willReturn('password');
$share->method('getShareType')->willReturn(42);
@@ -118,9 +102,7 @@ class LegacyPublicAuthTest extends \Test\TestCase {
public function testSharePasswordRemote(): void {
- $share = $this->getMockBuilder(IShare::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $share = $this->createMock(IShare::class);
$share->method('getPassword')->willReturn('password');
$share->method('getShareType')->willReturn(IShare::TYPE_REMOTE);
@@ -134,9 +116,7 @@ class LegacyPublicAuthTest extends \Test\TestCase {
}
public function testSharePasswordLinkValidPassword(): void {
- $share = $this->getMockBuilder(IShare::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $share = $this->createMock(IShare::class);
$share->method('getPassword')->willReturn('password');
$share->method('getShareType')->willReturn(IShare::TYPE_LINK);
@@ -156,9 +136,7 @@ class LegacyPublicAuthTest extends \Test\TestCase {
}
public function testSharePasswordMailValidPassword(): void {
- $share = $this->getMockBuilder(IShare::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $share = $this->createMock(IShare::class);
$share->method('getPassword')->willReturn('password');
$share->method('getShareType')->willReturn(IShare::TYPE_EMAIL);
@@ -178,9 +156,7 @@ class LegacyPublicAuthTest extends \Test\TestCase {
}
public function testInvalidSharePasswordLinkValidSession(): void {
- $share = $this->getMockBuilder(IShare::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $share = $this->createMock(IShare::class);
$share->method('getPassword')->willReturn('password');
$share->method('getShareType')->willReturn(IShare::TYPE_LINK);
$share->method('getId')->willReturn('42');
@@ -204,9 +180,7 @@ class LegacyPublicAuthTest extends \Test\TestCase {
}
public function testSharePasswordLinkInvalidSession(): void {
- $share = $this->getMockBuilder(IShare::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $share = $this->createMock(IShare::class);
$share->method('getPassword')->willReturn('password');
$share->method('getShareType')->willReturn(IShare::TYPE_LINK);
$share->method('getId')->willReturn('42');
@@ -231,9 +205,7 @@ class LegacyPublicAuthTest extends \Test\TestCase {
public function testSharePasswordMailInvalidSession(): void {
- $share = $this->getMockBuilder(IShare::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $share = $this->createMock(IShare::class);
$share->method('getPassword')->willReturn('password');
$share->method('getShareType')->willReturn(IShare::TYPE_EMAIL);
$share->method('getId')->willReturn('42');
diff --git a/apps/dav/tests/unit/Connector/Sabre/AuthTest.php b/apps/dav/tests/unit/Connector/Sabre/AuthTest.php
index c6d247b3951..501ef3ef1d1 100644
--- a/apps/dav/tests/unit/Connector/Sabre/AuthTest.php
+++ b/apps/dav/tests/unit/Connector/Sabre/AuthTest.php
@@ -1,5 +1,6 @@
<?php
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -29,33 +30,20 @@ use Test\TestCase;
* @group DB
*/
class AuthTest extends TestCase {
- /** @var ISession&MockObject */
- private $session;
- /** @var Auth */
- private $auth;
- /** @var Session&MockObject */
- private $userSession;
- /** @var IRequest&MockObject */
- private $request;
- /** @var Manager&MockObject */
- private $twoFactorManager;
- /** @var IThrottler&MockObject */
- private $throttler;
+ private ISession&MockObject $session;
+ private Session&MockObject $userSession;
+ private IRequest&MockObject $request;
+ private Manager&MockObject $twoFactorManager;
+ private IThrottler&MockObject $throttler;
+ private Auth $auth;
protected function setUp(): void {
parent::setUp();
- $this->session = $this->getMockBuilder(ISession::class)
- ->disableOriginalConstructor()->getMock();
- $this->userSession = $this->getMockBuilder(Session::class)
- ->disableOriginalConstructor()->getMock();
- $this->request = $this->getMockBuilder(IRequest::class)
- ->disableOriginalConstructor()->getMock();
- $this->twoFactorManager = $this->getMockBuilder(Manager::class)
- ->disableOriginalConstructor()
- ->getMock();
- $this->throttler = $this->getMockBuilder(IThrottler::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $this->session = $this->createMock(ISession::class);
+ $this->userSession = $this->createMock(Session::class);
+ $this->request = $this->createMock(IRequest::class);
+ $this->twoFactorManager = $this->createMock(Manager::class);
+ $this->throttler = $this->createMock(IThrottler::class);
$this->auth = new Auth(
$this->session,
$this->userSession,
@@ -72,7 +60,7 @@ class AuthTest extends TestCase {
->with('AUTHENTICATED_TO_DAV_BACKEND')
->willReturn(null);
- $this->assertFalse($this->invokePrivate($this->auth, 'isDavAuthenticated', ['MyTestUser']));
+ $this->assertFalse(self::invokePrivate($this->auth, 'isDavAuthenticated', ['MyTestUser']));
}
public function testIsDavAuthenticatedWithWrongDavSession(): void {
@@ -82,7 +70,7 @@ class AuthTest extends TestCase {
->with('AUTHENTICATED_TO_DAV_BACKEND')
->willReturn('AnotherUser');
- $this->assertFalse($this->invokePrivate($this->auth, 'isDavAuthenticated', ['MyTestUser']));
+ $this->assertFalse(self::invokePrivate($this->auth, 'isDavAuthenticated', ['MyTestUser']));
}
public function testIsDavAuthenticatedWithCorrectDavSession(): void {
@@ -92,13 +80,11 @@ class AuthTest extends TestCase {
->with('AUTHENTICATED_TO_DAV_BACKEND')
->willReturn('MyTestUser');
- $this->assertTrue($this->invokePrivate($this->auth, 'isDavAuthenticated', ['MyTestUser']));
+ $this->assertTrue(self::invokePrivate($this->auth, 'isDavAuthenticated', ['MyTestUser']));
}
public function testValidateUserPassOfAlreadyDAVAuthenticatedUser(): void {
- $user = $this->getMockBuilder(IUser::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $user = $this->createMock(IUser::class);
$user->expects($this->exactly(1))
->method('getUID')
->willReturn('MyTestUser');
@@ -119,13 +105,11 @@ class AuthTest extends TestCase {
->expects($this->once())
->method('close');
- $this->assertTrue($this->invokePrivate($this->auth, 'validateUserPass', ['MyTestUser', 'MyTestPassword']));
+ $this->assertTrue(self::invokePrivate($this->auth, 'validateUserPass', ['MyTestUser', 'MyTestPassword']));
}
public function testValidateUserPassOfInvalidDAVAuthenticatedUser(): void {
- $user = $this->getMockBuilder(IUser::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $user = $this->createMock(IUser::class);
$user->expects($this->once())
->method('getUID')
->willReturn('MyTestUser');
@@ -146,13 +130,11 @@ class AuthTest extends TestCase {
->expects($this->once())
->method('close');
- $this->assertFalse($this->invokePrivate($this->auth, 'validateUserPass', ['MyTestUser', 'MyTestPassword']));
+ $this->assertFalse(self::invokePrivate($this->auth, 'validateUserPass', ['MyTestUser', 'MyTestPassword']));
}
public function testValidateUserPassOfInvalidDAVAuthenticatedUserWithValidPassword(): void {
- $user = $this->getMockBuilder(IUser::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $user = $this->createMock(IUser::class);
$user->expects($this->exactly(2))
->method('getUID')
->willReturn('MyTestUser');
@@ -182,7 +164,7 @@ class AuthTest extends TestCase {
->expects($this->once())
->method('close');
- $this->assertTrue($this->invokePrivate($this->auth, 'validateUserPass', ['MyTestUser', 'MyTestPassword']));
+ $this->assertTrue(self::invokePrivate($this->auth, 'validateUserPass', ['MyTestUser', 'MyTestPassword']));
}
public function testValidateUserPassWithInvalidPassword(): void {
@@ -199,7 +181,7 @@ class AuthTest extends TestCase {
->expects($this->once())
->method('close');
- $this->assertFalse($this->invokePrivate($this->auth, 'validateUserPass', ['MyTestUser', 'MyTestPassword']));
+ $this->assertFalse(self::invokePrivate($this->auth, 'validateUserPass', ['MyTestUser', 'MyTestPassword']));
}
@@ -219,16 +201,12 @@ class AuthTest extends TestCase {
->expects($this->once())
->method('close');
- $this->invokePrivate($this->auth, 'validateUserPass', ['MyTestUser', 'MyTestPassword']);
+ self::invokePrivate($this->auth, 'validateUserPass', ['MyTestUser', 'MyTestPassword']);
}
public function testAuthenticateAlreadyLoggedInWithoutCsrfTokenForNonGet(): void {
- $request = $this->getMockBuilder(RequestInterface::class)
- ->disableOriginalConstructor()
- ->getMock();
- $response = $this->getMockBuilder(ResponseInterface::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $request = $this->createMock(RequestInterface::class);
+ $response = $this->createMock(ResponseInterface::class);
$this->userSession
->expects($this->any())
->method('isLoggedIn')
@@ -242,9 +220,7 @@ class AuthTest extends TestCase {
->method('get')
->with('AUTHENTICATED_TO_DAV_BACKEND')
->willReturn(null);
- $user = $this->getMockBuilder(IUser::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $user = $this->createMock(IUser::class);
$user->expects($this->any())
->method('getUID')
->willReturn('MyWrongDavUser');
@@ -266,12 +242,8 @@ class AuthTest extends TestCase {
}
public function testAuthenticateAlreadyLoggedInWithoutCsrfTokenAndCorrectlyDavAuthenticated(): void {
- $request = $this->getMockBuilder(RequestInterface::class)
- ->disableOriginalConstructor()
- ->getMock();
- $response = $this->getMockBuilder(ResponseInterface::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $request = $this->createMock(RequestInterface::class);
+ $response = $this->createMock(ResponseInterface::class);
$this->userSession
->expects($this->any())
->method('isLoggedIn')
@@ -289,9 +261,7 @@ class AuthTest extends TestCase {
->method('get')
->with('AUTHENTICATED_TO_DAV_BACKEND')
->willReturn('LoggedInUser');
- $user = $this->getMockBuilder(IUser::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $user = $this->createMock(IUser::class);
$user->expects($this->any())
->method('getUID')
->willReturn('LoggedInUser');
@@ -311,12 +281,8 @@ class AuthTest extends TestCase {
$this->expectException(\Sabre\DAV\Exception\NotAuthenticated::class);
$this->expectExceptionMessage('2FA challenge not passed.');
- $request = $this->getMockBuilder(RequestInterface::class)
- ->disableOriginalConstructor()
- ->getMock();
- $response = $this->getMockBuilder(ResponseInterface::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $request = $this->createMock(RequestInterface::class);
+ $response = $this->createMock(ResponseInterface::class);
$this->userSession
->expects($this->any())
->method('isLoggedIn')
@@ -334,9 +300,7 @@ class AuthTest extends TestCase {
->method('get')
->with('AUTHENTICATED_TO_DAV_BACKEND')
->willReturn('LoggedInUser');
- $user = $this->getMockBuilder(IUser::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $user = $this->createMock(IUser::class);
$user->expects($this->any())
->method('getUID')
->willReturn('LoggedInUser');
@@ -360,12 +324,8 @@ class AuthTest extends TestCase {
$this->expectException(\Sabre\DAV\Exception\NotAuthenticated::class);
$this->expectExceptionMessage('CSRF check not passed.');
- $request = $this->getMockBuilder(RequestInterface::class)
- ->disableOriginalConstructor()
- ->getMock();
- $response = $this->getMockBuilder(ResponseInterface::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $request = $this->createMock(RequestInterface::class);
+ $response = $this->createMock(ResponseInterface::class);
$this->userSession
->expects($this->any())
->method('isLoggedIn')
@@ -383,9 +343,7 @@ class AuthTest extends TestCase {
->method('get')
->with('AUTHENTICATED_TO_DAV_BACKEND')
->willReturn('AnotherUser');
- $user = $this->getMockBuilder(IUser::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $user = $this->createMock(IUser::class);
$user->expects($this->any())
->method('getUID')
->willReturn('LoggedInUser');
@@ -401,12 +359,8 @@ class AuthTest extends TestCase {
}
public function testAuthenticateAlreadyLoggedInWithoutCsrfTokenForNonGetAndDesktopClient(): void {
- $request = $this->getMockBuilder(RequestInterface::class)
- ->disableOriginalConstructor()
- ->getMock();
- $response = $this->getMockBuilder(ResponseInterface::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $request = $this->createMock(RequestInterface::class);
+ $response = $this->createMock(ResponseInterface::class);
$this->userSession
->expects($this->any())
->method('isLoggedIn')
@@ -424,9 +378,7 @@ class AuthTest extends TestCase {
->method('get')
->with('AUTHENTICATED_TO_DAV_BACKEND')
->willReturn(null);
- $user = $this->getMockBuilder(IUser::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $user = $this->createMock(IUser::class);
$user->expects($this->any())
->method('getUID')
->willReturn('MyWrongDavUser');
@@ -443,12 +395,8 @@ class AuthTest extends TestCase {
}
public function testAuthenticateAlreadyLoggedInWithoutCsrfTokenForGet(): void {
- $request = $this->getMockBuilder(RequestInterface::class)
- ->disableOriginalConstructor()
- ->getMock();
- $response = $this->getMockBuilder(ResponseInterface::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $request = $this->createMock(RequestInterface::class);
+ $response = $this->createMock(ResponseInterface::class);
$this->userSession
->expects($this->any())
->method('isLoggedIn')
@@ -458,9 +406,7 @@ class AuthTest extends TestCase {
->method('get')
->with('AUTHENTICATED_TO_DAV_BACKEND')
->willReturn(null);
- $user = $this->getMockBuilder(IUser::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $user = $this->createMock(IUser::class);
$user->expects($this->any())
->method('getUID')
->willReturn('MyWrongDavUser');
@@ -478,12 +424,8 @@ class AuthTest extends TestCase {
}
public function testAuthenticateAlreadyLoggedInWithCsrfTokenForGet(): void {
- $request = $this->getMockBuilder(RequestInterface::class)
- ->disableOriginalConstructor()
- ->getMock();
- $response = $this->getMockBuilder(ResponseInterface::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $request = $this->createMock(RequestInterface::class);
+ $response = $this->createMock(ResponseInterface::class);
$this->userSession
->expects($this->any())
->method('isLoggedIn')
@@ -493,9 +435,7 @@ class AuthTest extends TestCase {
->method('get')
->with('AUTHENTICATED_TO_DAV_BACKEND')
->willReturn(null);
- $user = $this->getMockBuilder(IUser::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $user = $this->createMock(IUser::class);
$user->expects($this->any())
->method('getUID')
->willReturn('MyWrongDavUser');
@@ -513,15 +453,9 @@ class AuthTest extends TestCase {
}
public function testAuthenticateNoBasicAuthenticateHeadersProvided(): void {
- $server = $this->getMockBuilder(Server::class)
- ->disableOriginalConstructor()
- ->getMock();
- $server->httpRequest = $this->getMockBuilder(RequestInterface::class)
- ->disableOriginalConstructor()
- ->getMock();
- $server->httpResponse = $this->getMockBuilder(ResponseInterface::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $server = $this->createMock(Server::class);
+ $server->httpRequest = $this->createMock(RequestInterface::class);
+ $server->httpResponse = $this->createMock(ResponseInterface::class);
$response = $this->auth->check($server->httpRequest, $server->httpResponse);
$this->assertEquals([false, 'No \'Authorization: Basic\' header found. Either the client didn\'t send one, or the server is misconfigured'], $response);
}
@@ -532,13 +466,9 @@ class AuthTest extends TestCase {
$this->expectExceptionMessage('Cannot authenticate over ajax calls');
/** @var \Sabre\HTTP\RequestInterface&MockObject $httpRequest */
- $httpRequest = $this->getMockBuilder(RequestInterface::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $httpRequest = $this->createMock(RequestInterface::class);
/** @var \Sabre\HTTP\ResponseInterface&MockObject $httpResponse */
- $httpResponse = $this->getMockBuilder(ResponseInterface::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $httpResponse = $this->createMock(ResponseInterface::class);
$this->userSession
->expects($this->any())
->method('isLoggedIn')
@@ -562,13 +492,9 @@ class AuthTest extends TestCase {
->willReturn(false);
/** @var \Sabre\HTTP\RequestInterface&MockObject $httpRequest */
- $httpRequest = $this->getMockBuilder(RequestInterface::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $httpRequest = $this->createMock(RequestInterface::class);
/** @var \Sabre\HTTP\ResponseInterface&MockObject $httpResponse */
- $httpResponse = $this->getMockBuilder(ResponseInterface::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $httpResponse = $this->createMock(ResponseInterface::class);
$httpRequest
->expects($this->any())
->method('getHeader')
@@ -577,9 +503,7 @@ class AuthTest extends TestCase {
['Authorization', 'basic dXNlcm5hbWU6cGFzc3dvcmQ='],
]);
- $user = $this->getMockBuilder(IUser::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $user = $this->createMock(IUser::class);
$user->expects($this->any())
->method('getUID')
->willReturn('MyDavUser');
@@ -602,17 +526,10 @@ class AuthTest extends TestCase {
public function testAuthenticateNoBasicAuthenticateHeadersProvidedWithAjaxButUserIsStillLoggedIn(): void {
/** @var \Sabre\HTTP\RequestInterface $httpRequest */
- $httpRequest = $this->getMockBuilder(RequestInterface::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $httpRequest = $this->createMock(RequestInterface::class);
/** @var \Sabre\HTTP\ResponseInterface $httpResponse */
- $httpResponse = $this->getMockBuilder(ResponseInterface::class)
- ->disableOriginalConstructor()
- ->getMock();
- /** @var IUser */
- $user = $this->getMockBuilder(IUser::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $httpResponse = $this->createMock(ResponseInterface::class);
+ $user = $this->createMock(IUser::class);
$user->method('getUID')->willReturn('MyTestUser');
$this->userSession
->expects($this->any())
@@ -643,29 +560,21 @@ class AuthTest extends TestCase {
}
public function testAuthenticateValidCredentials(): void {
- $server = $this->getMockBuilder(Server::class)
- ->disableOriginalConstructor()
- ->getMock();
- $server->httpRequest = $this->getMockBuilder(RequestInterface::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $server = $this->createMock(Server::class);
+ $server->httpRequest = $this->createMock(RequestInterface::class);
$server->httpRequest
->expects($this->once())
->method('getHeader')
->with('Authorization')
->willReturn('basic dXNlcm5hbWU6cGFzc3dvcmQ=');
- $server->httpResponse = $this->getMockBuilder(ResponseInterface::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $server->httpResponse = $this->createMock(ResponseInterface::class);
$this->userSession
->expects($this->once())
->method('logClientIn')
->with('username', 'password')
->willReturn(true);
- $user = $this->getMockBuilder(IUser::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $user = $this->createMock(IUser::class);
$user->expects($this->exactly(2))
->method('getUID')
->willReturn('MyTestUser');
@@ -678,12 +587,8 @@ class AuthTest extends TestCase {
}
public function testAuthenticateInvalidCredentials(): void {
- $server = $this->getMockBuilder(Server::class)
- ->disableOriginalConstructor()
- ->getMock();
- $server->httpRequest = $this->getMockBuilder(RequestInterface::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $server = $this->createMock(Server::class);
+ $server->httpRequest = $this->createMock(RequestInterface::class);
$server->httpRequest
->expects($this->exactly(2))
->method('getHeader')
@@ -691,9 +596,7 @@ class AuthTest extends TestCase {
['Authorization', 'basic dXNlcm5hbWU6cGFzc3dvcmQ='],
['X-Requested-With', null],
]);
- $server->httpResponse = $this->getMockBuilder(ResponseInterface::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $server->httpResponse = $this->createMock(ResponseInterface::class);
$this->userSession
->expects($this->once())
->method('logClientIn')
diff --git a/apps/dav/tests/unit/Connector/Sabre/BearerAuthTest.php b/apps/dav/tests/unit/Connector/Sabre/BearerAuthTest.php
index 99c2a461557..1e6267d4cbb 100644
--- a/apps/dav/tests/unit/Connector/Sabre/BearerAuthTest.php
+++ b/apps/dav/tests/unit/Connector/Sabre/BearerAuthTest.php
@@ -1,4 +1,6 @@
<?php
+
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
@@ -21,14 +23,10 @@ use Test\TestCase;
* @group DB
*/
class BearerAuthTest extends TestCase {
- /** @var IUserSession|\PHPUnit\Framework\MockObject\MockObject */
- private $userSession;
- /** @var ISession|\PHPUnit\Framework\MockObject\MockObject */
- private $session;
- /** @var IRequest|\PHPUnit\Framework\MockObject\MockObject */
- private $request;
- /** @var BearerAuth */
- private $bearerAuth;
+ private IUserSession&MockObject $userSession;
+ private ISession&MockObject $session;
+ private IRequest&MockObject $request;
+ private BearerAuth $bearerAuth;
private IConfig&MockObject $config;
@@ -74,9 +72,9 @@ class BearerAuthTest extends TestCase {
}
public function testChallenge(): void {
- /** @var \PHPUnit\Framework\MockObject\MockObject|RequestInterface $request */
+ /** @var RequestInterface&MockObject $request */
$request = $this->createMock(RequestInterface::class);
- /** @var \PHPUnit\Framework\MockObject\MockObject|ResponseInterface $response */
+ /** @var ResponseInterface&MockObject $response */
$response = $this->createMock(ResponseInterface::class);
$result = $this->bearerAuth->challenge($request, $response);
$this->assertEmpty($result);
diff --git a/apps/dav/tests/unit/Connector/Sabre/BlockLegacyClientPluginTest.php b/apps/dav/tests/unit/Connector/Sabre/BlockLegacyClientPluginTest.php
index 072dd1a3b58..27ddd3f4a1f 100644
--- a/apps/dav/tests/unit/Connector/Sabre/BlockLegacyClientPluginTest.php
+++ b/apps/dav/tests/unit/Connector/Sabre/BlockLegacyClientPluginTest.php
@@ -83,7 +83,7 @@ class BlockLegacyClientPluginTest extends TestCase {
}
/** @var RequestInterface|MockObject $request */
- $request = $this->createMock('\Sabre\HTTP\RequestInterface');
+ $request = $this->createMock(RequestInterface::class);
$request
->expects($this->once())
->method('getHeader')
diff --git a/apps/dav/tests/unit/Connector/Sabre/CommentsPropertiesPluginTest.php b/apps/dav/tests/unit/Connector/Sabre/CommentsPropertiesPluginTest.php
index 1cda0e4dbdb..6606dcd5717 100644
--- a/apps/dav/tests/unit/Connector/Sabre/CommentsPropertiesPluginTest.php
+++ b/apps/dav/tests/unit/Connector/Sabre/CommentsPropertiesPluginTest.php
@@ -1,5 +1,6 @@
<?php
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -8,62 +9,45 @@
namespace OCA\DAV\Tests\unit\Connector\Sabre;
use OCA\DAV\Connector\Sabre\CommentPropertiesPlugin as CommentPropertiesPluginImplementation;
+use OCA\DAV\Connector\Sabre\Directory;
use OCA\DAV\Connector\Sabre\File;
use OCP\Comments\ICommentsManager;
use OCP\IUser;
use OCP\IUserSession;
+use PHPUnit\Framework\MockObject\MockObject;
use Sabre\DAV\PropFind;
+use Sabre\DAV\Server;
class CommentsPropertiesPluginTest extends \Test\TestCase {
-
- /** @var CommentPropertiesPluginImplementation */
- protected $plugin;
- protected $commentsManager;
- protected $userSession;
- protected $server;
+ protected CommentPropertiesPluginImplementation $plugin;
+ protected ICommentsManager&MockObject $commentsManager;
+ protected IUserSession&MockObject $userSession;
+ protected Server&MockObject $server;
protected function setUp(): void {
parent::setUp();
- $this->commentsManager = $this->getMockBuilder(ICommentsManager::class)
- ->disableOriginalConstructor()
- ->getMock();
- $this->userSession = $this->getMockBuilder(IUserSession::class)
- ->disableOriginalConstructor()
- ->getMock();
-
- $this->server = $this->getMockBuilder('\Sabre\DAV\Server')
- ->disableOriginalConstructor()
- ->getMock();
+ $this->commentsManager = $this->createMock(ICommentsManager::class);
+ $this->userSession = $this->createMock(IUserSession::class);
+ $this->server = $this->createMock(Server::class);
$this->plugin = new CommentPropertiesPluginImplementation($this->commentsManager, $this->userSession);
$this->plugin->initialize($this->server);
}
- public function nodeProvider() {
- $mocks = [];
- foreach (['\OCA\DAV\Connector\Sabre\File', '\OCA\DAV\Connector\Sabre\Directory', '\Sabre\DAV\INode'] as $class) {
- $mocks[] = $this->getMockBuilder($class)
- ->disableOriginalConstructor()
- ->getMock();
- }
-
+ public static function nodeProvider(): array {
return [
- [$mocks[0], true],
- [$mocks[1], true],
- [$mocks[2], false]
+ [File::class, true],
+ [Directory::class, true],
+ [\Sabre\DAV\INode::class, false]
];
}
/**
* @dataProvider nodeProvider
- * @param $node
- * @param $expectedSuccessful
*/
- public function testHandleGetProperties($node, $expectedSuccessful): void {
- $propFind = $this->getMockBuilder(PropFind::class)
- ->disableOriginalConstructor()
- ->getMock();
+ public function testHandleGetProperties(string $class, bool $expectedSuccessful): void {
+ $propFind = $this->createMock(PropFind::class);
if ($expectedSuccessful) {
$propFind->expects($this->exactly(3))
@@ -73,10 +57,11 @@ class CommentsPropertiesPluginTest extends \Test\TestCase {
->method('handle');
}
+ $node = $this->createMock($class);
$this->plugin->handleGetProperties($propFind, $node);
}
- public function baseUriProvider() {
+ public static function baseUriProvider(): array {
return [
['owncloud/remote.php/webdav/', '4567', 'owncloud/remote.php/dav/comments/files/4567'],
['owncloud/remote.php/files/', '4567', 'owncloud/remote.php/dav/comments/files/4567'],
@@ -86,14 +71,9 @@ class CommentsPropertiesPluginTest extends \Test\TestCase {
/**
* @dataProvider baseUriProvider
- * @param $baseUri
- * @param $fid
- * @param $expectedHref
*/
- public function testGetCommentsLink($baseUri, $fid, $expectedHref): void {
- $node = $this->getMockBuilder(File::class)
- ->disableOriginalConstructor()
- ->getMock();
+ public function testGetCommentsLink(string $baseUri, string $fid, ?string $expectedHref): void {
+ $node = $this->createMock(File::class);
$node->expects($this->any())
->method('getId')
->willReturn($fid);
@@ -106,29 +86,25 @@ class CommentsPropertiesPluginTest extends \Test\TestCase {
$this->assertSame($expectedHref, $href);
}
- public function userProvider() {
+ public static function userProvider(): array {
return [
- [
- $this->getMockBuilder(IUser::class)
- ->disableOriginalConstructor()
- ->getMock()
- ],
+ [IUser::class],
[null]
];
}
/**
* @dataProvider userProvider
- * @param $user
*/
- public function testGetUnreadCount($user): void {
- $node = $this->getMockBuilder(File::class)
- ->disableOriginalConstructor()
- ->getMock();
+ public function testGetUnreadCount(?string $user): void {
+ $node = $this->createMock(File::class);
$node->expects($this->any())
->method('getId')
->willReturn('4567');
+ if ($user !== null) {
+ $user = $this->createMock($user);
+ }
$this->userSession->expects($this->once())
->method('getUser')
->willReturn($user);
diff --git a/apps/dav/tests/unit/Connector/Sabre/CopyEtagHeaderPluginTest.php b/apps/dav/tests/unit/Connector/Sabre/CopyEtagHeaderPluginTest.php
index bc19e071ee7..7067cf335ed 100644
--- a/apps/dav/tests/unit/Connector/Sabre/CopyEtagHeaderPluginTest.php
+++ b/apps/dav/tests/unit/Connector/Sabre/CopyEtagHeaderPluginTest.php
@@ -1,5 +1,6 @@
<?php
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -15,12 +16,8 @@ use Sabre\DAV\Tree;
use Test\TestCase;
class CopyEtagHeaderPluginTest extends TestCase {
-
- /** @var CopyEtagHeaderPlugin */
- private $plugin;
-
- /** @var Server */
- private $server;
+ private CopyEtagHeaderPlugin $plugin;
+ private Server $server;
protected function setUp(): void {
parent::setUp();
@@ -62,15 +59,11 @@ class CopyEtagHeaderPluginTest extends TestCase {
}
public function testAfterMove(): void {
- $node = $this->getMockBuilder(File::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $node = $this->createMock(File::class);
$node->expects($this->once())
->method('getETag')
->willReturn('123456');
- $tree = $this->getMockBuilder(Tree::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $tree = $this->createMock(Tree::class);
$tree->expects($this->once())
->method('getNodeForPath')
->with('test.txt')
diff --git a/apps/dav/tests/unit/Connector/Sabre/CustomPropertiesBackendTest.php b/apps/dav/tests/unit/Connector/Sabre/CustomPropertiesBackendTest.php
index eb3f291e9c0..381206e336e 100644
--- a/apps/dav/tests/unit/Connector/Sabre/CustomPropertiesBackendTest.php
+++ b/apps/dav/tests/unit/Connector/Sabre/CustomPropertiesBackendTest.php
@@ -1,5 +1,6 @@
<?php
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -25,42 +26,21 @@ use Sabre\DAV\Tree;
* @package OCA\DAV\Tests\unit\Connector\Sabre
*/
class CustomPropertiesBackendTest extends \Test\TestCase {
-
- /**
- * @var \Sabre\DAV\Server
- */
- private $server;
-
- /**
- * @var \Sabre\DAV\Tree
- */
- private $tree;
-
- /**
- * @var CustomPropertiesBackend
- */
- private $plugin;
-
- /**
- * @var IUser
- */
- private $user;
-
- /** @property MockObject|DefaultCalendarValidator */
- private $defaultCalendarValidator;
+ private \Sabre\DAV\Server $server;
+ private \Sabre\DAV\Tree&MockObject $tree;
+ private IUser&MockObject $user;
+ private DefaultCalendarValidator&MockObject $defaultCalendarValidator;
+ private CustomPropertiesBackend $plugin;
protected function setUp(): void {
parent::setUp();
+
$this->server = new \Sabre\DAV\Server();
- $this->tree = $this->getMockBuilder(Tree::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $this->tree = $this->createMock(Tree::class);
- $userId = $this->getUniqueID('testcustompropertiesuser');
+ $userId = self::getUniqueID('testcustompropertiesuser');
- $this->user = $this->getMockBuilder(IUser::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $this->user = $this->createMock(IUser::class);
$this->user->expects($this->any())
->method('getUID')
->willReturn($userId);
@@ -88,12 +68,12 @@ class CustomPropertiesBackendTest extends \Test\TestCase {
]
);
$deleteStatement->closeCursor();
+
+ parent::tearDown();
}
- private function createTestNode($class) {
- $node = $this->getMockBuilder($class)
- ->disableOriginalConstructor()
- ->getMock();
+ private function createTestNode(string $class) {
+ $node = $this->createMock($class);
$node->expects($this->any())
->method('getId')
->willReturn(123);
diff --git a/apps/dav/tests/unit/Connector/Sabre/DirectoryTest.php b/apps/dav/tests/unit/Connector/Sabre/DirectoryTest.php
index 7fefe3e06da..85890c0f987 100644
--- a/apps/dav/tests/unit/Connector/Sabre/DirectoryTest.php
+++ b/apps/dav/tests/unit/Connector/Sabre/DirectoryTest.php
@@ -1,11 +1,12 @@
<?php
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
* SPDX-License-Identifier: AGPL-3.0-only
*/
-namespace OCA\DAV\Tests\Unit\Connector\Sabre;
+namespace OCA\DAV\Tests\unit\Connector\Sabre;
use OC\Files\FileInfo;
use OC\Files\Filesystem;
@@ -21,6 +22,7 @@ use OCP\Files\ForbiddenException;
use OCP\Files\InvalidPathException;
use OCP\Files\Mount\IMountPoint;
use OCP\Files\StorageNotAvailableException;
+use PHPUnit\Framework\MockObject\MockObject;
use Test\Traits\UserTrait;
class TestViewDirectory extends View {
@@ -43,7 +45,7 @@ class TestViewDirectory extends View {
return $this->deletables[$path];
}
- public function rename($path1, $path2, array $options = []) {
+ public function rename($source, $target, array $options = []) {
return $this->canRename;
}
@@ -59,16 +61,14 @@ class TestViewDirectory extends View {
class DirectoryTest extends \Test\TestCase {
use UserTrait;
- /** @var View|\PHPUnit\Framework\MockObject\MockObject */
- private $view;
- /** @var FileInfo|\PHPUnit\Framework\MockObject\MockObject */
- private $info;
+ private View&MockObject $view;
+ private FileInfo&MockObject $info;
protected function setUp(): void {
parent::setUp();
- $this->view = $this->createMock('OC\Files\View');
- $this->info = $this->createMock('OC\Files\FileInfo');
+ $this->view = $this->createMock(View::class);
+ $this->info = $this->createMock(FileInfo::class);
$this->info->method('isReadable')
->willReturn(true);
$this->info->method('getType')
@@ -81,7 +81,7 @@ class DirectoryTest extends \Test\TestCase {
->willReturn(Constants::PERMISSION_READ);
}
- private function getDir($path = '/') {
+ private function getDir(string $path = '/'): Directory {
$this->view->expects($this->once())
->method('getRelativePath')
->willReturn($path);
@@ -174,12 +174,8 @@ class DirectoryTest extends \Test\TestCase {
}
public function testGetChildren(): void {
- $info1 = $this->getMockBuilder(FileInfo::class)
- ->disableOriginalConstructor()
- ->getMock();
- $info2 = $this->getMockBuilder(FileInfo::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $info1 = $this->createMock(FileInfo::class);
+ $info2 = $this->createMock(FileInfo::class);
$info1->method('getName')
->willReturn('first');
$info1->method('getPath')
@@ -214,7 +210,7 @@ class DirectoryTest extends \Test\TestCase {
$dir = new Directory($this->view, $this->info);
$nodes = $dir->getChildren();
- $this->assertEquals(2, count($nodes));
+ $this->assertCount(2, $nodes);
// calling a second time just returns the cached values,
// does not call getDirectoryContents again
@@ -273,12 +269,10 @@ class DirectoryTest extends \Test\TestCase {
}
public function testGetQuotaInfoUnlimited(): void {
- self::createUser('user', 'password');
+ $this->createUser('user', 'password');
self::loginAsUser('user');
$mountPoint = $this->createMock(IMountPoint::class);
- $storage = $this->getMockBuilder(Quota::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $storage = $this->createMock(Quota::class);
$mountPoint->method('getStorage')
->willReturn($storage);
@@ -329,12 +323,10 @@ class DirectoryTest extends \Test\TestCase {
}
public function testGetQuotaInfoSpecific(): void {
- self::createUser('user', 'password');
+ $this->createUser('user', 'password');
self::loginAsUser('user');
$mountPoint = $this->createMock(IMountPoint::class);
- $storage = $this->getMockBuilder(Quota::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $storage = $this->createMock(Quota::class);
$mountPoint->method('getStorage')
->willReturn($storage);
@@ -384,7 +376,7 @@ class DirectoryTest extends \Test\TestCase {
/**
* @dataProvider moveFailedProvider
*/
- public function testMoveFailed($source, $destination, $updatables, $deletables): void {
+ public function testMoveFailed(string $source, string $destination, array $updatables, array $deletables): void {
$this->expectException(\Sabre\DAV\Exception\Forbidden::class);
$this->moveTest($source, $destination, $updatables, $deletables);
@@ -393,7 +385,7 @@ class DirectoryTest extends \Test\TestCase {
/**
* @dataProvider moveSuccessProvider
*/
- public function testMoveSuccess($source, $destination, $updatables, $deletables): void {
+ public function testMoveSuccess(string $source, string $destination, array $updatables, array $deletables): void {
$this->moveTest($source, $destination, $updatables, $deletables);
$this->addToAssertionCount(1);
}
@@ -401,19 +393,19 @@ class DirectoryTest extends \Test\TestCase {
/**
* @dataProvider moveFailedInvalidCharsProvider
*/
- public function testMoveFailedInvalidChars($source, $destination, $updatables, $deletables): void {
+ public function testMoveFailedInvalidChars(string $source, string $destination, array $updatables, array $deletables): void {
$this->expectException(InvalidPath::class);
$this->moveTest($source, $destination, $updatables, $deletables);
}
- public function moveFailedInvalidCharsProvider() {
+ public static function moveFailedInvalidCharsProvider(): array {
return [
['a/valid', "a/i\nvalid", ['a' => true, 'a/valid' => true, 'a/c*' => false], []],
];
}
- public function moveFailedProvider() {
+ public static function moveFailedProvider(): array {
return [
['a/b', 'a/c', ['a' => false, 'a/b' => false, 'a/c' => false], []],
['a/b', 'b/b', ['a' => false, 'a/b' => false, 'b' => false, 'b/b' => false], []],
@@ -424,7 +416,7 @@ class DirectoryTest extends \Test\TestCase {
];
}
- public function moveSuccessProvider() {
+ public static function moveSuccessProvider(): array {
return [
['a/b', 'b/b', ['a' => true, 'a/b' => true, 'b' => true, 'b/b' => false], ['a/b' => true]],
// older files with special chars can still be renamed to valid names
@@ -432,12 +424,7 @@ class DirectoryTest extends \Test\TestCase {
];
}
- /**
- * @param $source
- * @param $destination
- * @param $updatables
- */
- private function moveTest($source, $destination, $updatables, $deletables): void {
+ private function moveTest(string $source, string $destination, array $updatables, array $deletables): void {
$view = new TestViewDirectory($updatables, $deletables);
$sourceInfo = new FileInfo($source, null, null, [
@@ -449,7 +436,7 @@ class DirectoryTest extends \Test\TestCase {
$sourceNode = new Directory($view, $sourceInfo);
$targetNode = $this->getMockBuilder(Directory::class)
- ->setMethods(['childExists'])
+ ->onlyMethods(['childExists'])
->setConstructorArgs([$view, $targetInfo])
->getMock();
$targetNode->expects($this->any())->method('childExists')
diff --git a/apps/dav/tests/unit/Connector/Sabre/DummyGetResponsePluginTest.php b/apps/dav/tests/unit/Connector/Sabre/DummyGetResponsePluginTest.php
index 03c31dc47f8..2d688d64600 100644
--- a/apps/dav/tests/unit/Connector/Sabre/DummyGetResponsePluginTest.php
+++ b/apps/dav/tests/unit/Connector/Sabre/DummyGetResponsePluginTest.php
@@ -1,5 +1,6 @@
<?php
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -19,8 +20,7 @@ use Test\TestCase;
* @package OCA\DAV\Tests\unit\Connector\Sabre
*/
class DummyGetResponsePluginTest extends TestCase {
- /** @var DummyGetResponsePlugin */
- private $dummyGetResponsePlugin;
+ private DummyGetResponsePlugin $dummyGetResponsePlugin;
protected function setUp(): void {
parent::setUp();
@@ -29,10 +29,7 @@ class DummyGetResponsePluginTest extends TestCase {
}
public function testInitialize(): void {
- /** @var Server $server */
- $server = $this->getMockBuilder(Server::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $server = $this->createMock(Server::class);
$server
->expects($this->once())
->method('on')
@@ -44,13 +41,9 @@ class DummyGetResponsePluginTest extends TestCase {
public function testHttpGet(): void {
/** @var \Sabre\HTTP\RequestInterface $request */
- $request = $this->getMockBuilder(RequestInterface::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $request = $this->createMock(RequestInterface::class);
/** @var \Sabre\HTTP\ResponseInterface $response */
- $response = $server = $this->getMockBuilder(ResponseInterface::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $response = $this->createMock(ResponseInterface::class);
$response
->expects($this->once())
->method('setBody');
diff --git a/apps/dav/tests/unit/Connector/Sabre/Exception/ForbiddenTest.php b/apps/dav/tests/unit/Connector/Sabre/Exception/ForbiddenTest.php
index c7fb6066ed4..2f9e0ae9196 100644
--- a/apps/dav/tests/unit/Connector/Sabre/Exception/ForbiddenTest.php
+++ b/apps/dav/tests/unit/Connector/Sabre/Exception/ForbiddenTest.php
@@ -1,5 +1,6 @@
<?php
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -8,6 +9,7 @@
namespace OCA\DAV\Tests\unit\Connector\Sabre\Exception;
use OCA\DAV\Connector\Sabre\Exception\Forbidden;
+use Sabre\DAV\Server;
class ForbiddenTest extends \Test\TestCase {
public function testSerialization(): void {
@@ -32,9 +34,7 @@ class ForbiddenTest extends \Test\TestCase {
EOD;
$ex = new Forbidden($message, $retry);
- $server = $this->getMockBuilder('Sabre\DAV\Server')
- ->disableOriginalConstructor()
- ->getMock();
+ $server = $this->createMock(Server::class);
$ex->serialize($server, $error);
// assert
diff --git a/apps/dav/tests/unit/Connector/Sabre/Exception/InvalidPathTest.php b/apps/dav/tests/unit/Connector/Sabre/Exception/InvalidPathTest.php
index 98921d735fa..6f62bef86a3 100644
--- a/apps/dav/tests/unit/Connector/Sabre/Exception/InvalidPathTest.php
+++ b/apps/dav/tests/unit/Connector/Sabre/Exception/InvalidPathTest.php
@@ -1,5 +1,6 @@
<?php
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -8,6 +9,7 @@
namespace OCA\DAV\Tests\unit\Connector\Sabre\Exception;
use OCA\DAV\Connector\Sabre\Exception\InvalidPath;
+use Sabre\DAV\Server;
class InvalidPathTest extends \Test\TestCase {
public function testSerialization(): void {
@@ -32,9 +34,7 @@ class InvalidPathTest extends \Test\TestCase {
EOD;
$ex = new InvalidPath($message, $retry);
- $server = $this->getMockBuilder('Sabre\DAV\Server')
- ->disableOriginalConstructor()
- ->getMock();
+ $server = $this->createMock(Server::class);
$ex->serialize($server, $error);
// assert
diff --git a/apps/dav/tests/unit/Connector/Sabre/ExceptionLoggerPluginTest.php b/apps/dav/tests/unit/Connector/Sabre/ExceptionLoggerPluginTest.php
index 1d50fb2fb9a..a330a885b1f 100644
--- a/apps/dav/tests/unit/Connector/Sabre/ExceptionLoggerPluginTest.php
+++ b/apps/dav/tests/unit/Connector/Sabre/ExceptionLoggerPluginTest.php
@@ -1,5 +1,6 @@
<?php
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -11,21 +12,16 @@ use OC\SystemConfig;
use OCA\DAV\Connector\Sabre\Exception\InvalidPath;
use OCA\DAV\Connector\Sabre\ExceptionLoggerPlugin;
use OCA\DAV\Exception\ServerMaintenanceMode;
+use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;
use Sabre\DAV\Exception\NotFound;
use Sabre\DAV\Server;
use Test\TestCase;
class ExceptionLoggerPluginTest extends TestCase {
-
- /** @var Server */
- private $server;
-
- /** @var ExceptionLoggerPlugin */
- private $plugin;
-
- /** @var LoggerInterface | \PHPUnit\Framework\MockObject\MockObject */
- private $logger;
+ private Server $server;
+ private ExceptionLoggerPlugin $plugin;
+ private LoggerInterface&MockObject $logger;
private function init(): void {
$config = $this->createMock(SystemConfig::class);
@@ -59,7 +55,7 @@ class ExceptionLoggerPluginTest extends TestCase {
$this->plugin->logException($e);
}
- public function providesExceptions() {
+ public static function providesExceptions(): array {
return [
['debug', new NotFound()],
['debug', new ServerMaintenanceMode('System is in maintenance mode.')],
diff --git a/apps/dav/tests/unit/Connector/Sabre/FakeLockerPluginTest.php b/apps/dav/tests/unit/Connector/Sabre/FakeLockerPluginTest.php
index 18165b79cb2..ef744d13e6a 100644
--- a/apps/dav/tests/unit/Connector/Sabre/FakeLockerPluginTest.php
+++ b/apps/dav/tests/unit/Connector/Sabre/FakeLockerPluginTest.php
@@ -1,5 +1,6 @@
<?php
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -22,8 +23,7 @@ use Test\TestCase;
* @package OCA\DAV\Tests\unit\Connector\Sabre
*/
class FakeLockerPluginTest extends TestCase {
- /** @var FakeLockerPlugin */
- private $fakeLockerPlugin;
+ private FakeLockerPlugin $fakeLockerPlugin;
protected function setUp(): void {
parent::setUp();
@@ -32,18 +32,19 @@ class FakeLockerPluginTest extends TestCase {
public function testInitialize(): void {
/** @var Server $server */
- $server = $this->getMockBuilder(Server::class)
- ->disableOriginalConstructor()
- ->getMock();
- $server
- ->expects($this->exactly(4))
+ $server = $this->createMock(Server::class);
+ $calls = [
+ ['method:LOCK', [$this->fakeLockerPlugin, 'fakeLockProvider'], 1],
+ ['method:UNLOCK', [$this->fakeLockerPlugin, 'fakeUnlockProvider'], 1],
+ ['propFind', [$this->fakeLockerPlugin, 'propFind'], 100],
+ ['validateTokens', [$this->fakeLockerPlugin, 'validateTokens'], 100],
+ ];
+ $server->expects($this->exactly(count($calls)))
->method('on')
- ->withConsecutive(
- ['method:LOCK', [$this->fakeLockerPlugin, 'fakeLockProvider'], 1],
- ['method:UNLOCK', [$this->fakeLockerPlugin, 'fakeUnlockProvider'], 1],
- ['propFind', [$this->fakeLockerPlugin, 'propFind']],
- ['validateTokens', [$this->fakeLockerPlugin, 'validateTokens']],
- );
+ ->willReturnCallback(function () use (&$calls) {
+ $expected = array_shift($calls);
+ $this->assertEquals($expected, func_get_args());
+ });
$this->fakeLockerPlugin->initialize($server);
}
@@ -64,24 +65,24 @@ class FakeLockerPluginTest extends TestCase {
}
public function testPropFind(): void {
- $propFind = $this->getMockBuilder(PropFind::class)
- ->disableOriginalConstructor()
- ->getMock();
- $node = $this->getMockBuilder(INode::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $propFind = $this->createMock(PropFind::class);
+ $node = $this->createMock(INode::class);
- $propFind->expects($this->exactly(2))
+ $calls = [
+ '{DAV:}supportedlock',
+ '{DAV:}lockdiscovery',
+ ];
+ $propFind->expects($this->exactly(count($calls)))
->method('handle')
- ->withConsecutive(
- ['{DAV:}supportedlock'],
- ['{DAV:}lockdiscovery'],
- );
+ ->willReturnCallback(function ($propertyName) use (&$calls) {
+ $expected = array_shift($calls);
+ $this->assertEquals($expected, $propertyName);
+ });
$this->fakeLockerPlugin->propFind($propFind, $node);
}
- public function tokenDataProvider() {
+ public static function tokenDataProvider(): array {
return [
[
[
@@ -120,21 +121,15 @@ class FakeLockerPluginTest extends TestCase {
/**
* @dataProvider tokenDataProvider
- * @param array $input
- * @param array $expected
*/
public function testValidateTokens(array $input, array $expected): void {
- $request = $this->getMockBuilder(RequestInterface::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $request = $this->createMock(RequestInterface::class);
$this->fakeLockerPlugin->validateTokens($request, $input);
$this->assertSame($expected, $input);
}
public function testFakeLockProvider(): void {
- $request = $this->getMockBuilder(RequestInterface::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $request = $this->createMock(RequestInterface::class);
$response = new Response();
$server = $this->getMockBuilder(Server::class)
->getMock();
@@ -152,12 +147,8 @@ class FakeLockerPluginTest extends TestCase {
}
public function testFakeUnlockProvider(): void {
- $request = $this->getMockBuilder(RequestInterface::class)
- ->disableOriginalConstructor()
- ->getMock();
- $response = $this->getMockBuilder(ResponseInterface::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $request = $this->createMock(RequestInterface::class);
+ $response = $this->createMock(ResponseInterface::class);
$response->expects($this->once())
->method('setStatus')
diff --git a/apps/dav/tests/unit/Connector/Sabre/FileTest.php b/apps/dav/tests/unit/Connector/Sabre/FileTest.php
index ef02f145375..4a7ddad7115 100644
--- a/apps/dav/tests/unit/Connector/Sabre/FileTest.php
+++ b/apps/dav/tests/unit/Connector/Sabre/FileTest.php
@@ -1,5 +1,6 @@
<?php
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -53,16 +54,9 @@ class FileTest extends TestCase {
use MountProviderTrait;
use UserTrait;
- /**
- * @var string
- */
- private $user;
-
- /** @var IConfig|MockObject */
- protected $config;
-
- /** @var IRequestId|MockObject */
- protected $requestId;
+ private string $user;
+ protected IConfig&MockObject $config;
+ protected IRequestId&MockObject $requestId;
protected function setUp(): void {
parent::setUp();
@@ -72,7 +66,7 @@ class FileTest extends TestCase {
$this->user = 'test_user';
$this->createUser($this->user, 'pass');
- $this->loginAsUser($this->user);
+ self::loginAsUser($this->user);
$this->config = $this->createMock(IConfig::class);
$this->requestId = $this->createMock(IRequestId::class);
@@ -86,9 +80,7 @@ class FileTest extends TestCase {
}
private function getMockStorage(): MockObject&IStorage {
- $storage = $this->getMockBuilder(IStorage::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $storage = $this->createMock(IStorage::class);
$storage->method('getId')
->willReturn('home::someuser');
return $storage;
@@ -102,7 +94,7 @@ class FileTest extends TestCase {
}
- public function fopenFailuresProvider() {
+ public static function fopenFailuresProvider(): array {
return [
[
// return false
@@ -161,14 +153,14 @@ class FileTest extends TestCase {
/**
* @dataProvider fopenFailuresProvider
*/
- public function testSimplePutFails($thrownException, $expectedException, $checkPreviousClass = true): void {
+ public function testSimplePutFails(?\Throwable $thrownException, string $expectedException, bool $checkPreviousClass = true): void {
// setup
$storage = $this->getMockBuilder(Local::class)
->onlyMethods(['writeStream'])
->setConstructorArgs([['datadir' => Server::get(ITempManager::class)->getTemporaryFolder()]])
->getMock();
Filesystem::mount($storage, [], $this->user . '/');
- /** @var View | MockObject $view */
+ /** @var View&MockObject $view */
$view = $this->getMockBuilder(View::class)
->onlyMethods(['getRelativePath', 'resolvePath'])
->getMock();
@@ -221,12 +213,12 @@ class FileTest extends TestCase {
* Simulate putting a file to the given path.
*
* @param string $path path to put the file into
- * @param string $viewRoot root to use for the view
+ * @param ?string $viewRoot root to use for the view
* @param null|Request $request the HTTP request
*
* @return null|string of the PUT operation which is usually the etag
*/
- private function doPut($path, $viewRoot = null, ?Request $request = null) {
+ private function doPut(string $path, ?string $viewRoot = null, ?Request $request = null) {
$view = Filesystem::getView();
if (!is_null($viewRoot)) {
$view = new View($viewRoot);
@@ -245,7 +237,7 @@ class FileTest extends TestCase {
null
);
- /** @var File|MockObject $file */
+ /** @var File&MockObject $file */
$file = $this->getMockBuilder(File::class)
->setConstructorArgs([$view, $info, null, $request])
->onlyMethods(['header'])
@@ -269,55 +261,55 @@ class FileTest extends TestCase {
$this->assertNotEmpty($this->doPut('/foo.txt'));
}
- public function legalMtimeProvider() {
+ public static function legalMtimeProvider(): array {
return [
'string' => [
- 'HTTP_X_OC_MTIME' => 'string',
- 'expected result' => null
+ 'requestMtime' => 'string',
+ 'resultMtime' => null
],
'castable string (int)' => [
- 'HTTP_X_OC_MTIME' => '987654321',
- 'expected result' => 987654321
+ 'requestMtime' => '987654321',
+ 'resultMtime' => 987654321
],
'castable string (float)' => [
- 'HTTP_X_OC_MTIME' => '123456789.56',
- 'expected result' => 123456789
+ 'requestMtime' => '123456789.56',
+ 'resultMtime' => 123456789
],
'float' => [
- 'HTTP_X_OC_MTIME' => 123456789.56,
- 'expected result' => 123456789
+ 'requestMtime' => 123456789.56,
+ 'resultMtime' => 123456789
],
'zero' => [
- 'HTTP_X_OC_MTIME' => 0,
- 'expected result' => null
+ 'requestMtime' => 0,
+ 'resultMtime' => null
],
'zero string' => [
- 'HTTP_X_OC_MTIME' => '0',
- 'expected result' => null
+ 'requestMtime' => '0',
+ 'resultMtime' => null
],
'negative zero string' => [
- 'HTTP_X_OC_MTIME' => '-0',
- 'expected result' => null
+ 'requestMtime' => '-0',
+ 'resultMtime' => null
],
'string starting with number following by char' => [
- 'HTTP_X_OC_MTIME' => '2345asdf',
- 'expected result' => null
+ 'requestMtime' => '2345asdf',
+ 'resultMtime' => null
],
'string castable hex int' => [
- 'HTTP_X_OC_MTIME' => '0x45adf',
- 'expected result' => null
+ 'requestMtime' => '0x45adf',
+ 'resultMtime' => null
],
'string that looks like invalid hex int' => [
- 'HTTP_X_OC_MTIME' => '0x123g',
- 'expected result' => null
+ 'requestMtime' => '0x123g',
+ 'resultMtime' => null
],
'negative int' => [
- 'HTTP_X_OC_MTIME' => -34,
- 'expected result' => null
+ 'requestMtime' => -34,
+ 'resultMtime' => null
],
'negative float' => [
- 'HTTP_X_OC_MTIME' => -34.43,
- 'expected result' => null
+ 'requestMtime' => -34.43,
+ 'resultMtime' => null
],
];
}
@@ -326,7 +318,7 @@ class FileTest extends TestCase {
* Test putting a file with string Mtime
* @dataProvider legalMtimeProvider
*/
- public function testPutSingleFileLegalMtime($requestMtime, $resultMtime): void {
+ public function testPutSingleFileLegalMtime(mixed $requestMtime, ?int $resultMtime): void {
$request = new Request([
'server' => [
'HTTP_X_OC_MTIME' => (string)$requestMtime,
@@ -482,7 +474,7 @@ class FileTest extends TestCase {
*/
public function testSimplePutFailsSizeCheck(): void {
// setup
- /** @var View|MockObject */
+ /** @var View&MockObject */
$view = $this->getMockBuilder(View::class)
->onlyMethods(['rename', 'getRelativePath', 'filesize'])
->getMock();
@@ -569,7 +561,7 @@ class FileTest extends TestCase {
*/
public function testSimplePutInvalidChars(): void {
// setup
- /** @var View|MockObject */
+ /** @var View&MockObject */
$view = $this->getMockBuilder(View::class)
->onlyMethods(['getRelativePath'])
->getMock();
@@ -609,7 +601,7 @@ class FileTest extends TestCase {
$this->expectException(InvalidPath::class);
// setup
- /** @var View|MockObject */
+ /** @var View&MockObject */
$view = $this->getMockBuilder(View::class)
->onlyMethods(['getRelativePath'])
->getMock();
@@ -630,7 +622,7 @@ class FileTest extends TestCase {
public function testUploadAbort(): void {
// setup
- /** @var View|MockObject */
+ /** @var View&MockObject */
$view = $this->getMockBuilder(View::class)
->onlyMethods(['rename', 'getRelativePath', 'filesize'])
->getMock();
@@ -680,7 +672,7 @@ class FileTest extends TestCase {
public function testDeleteWhenAllowed(): void {
// setup
- /** @var View|MockObject */
+ /** @var View&MockObject */
$view = $this->getMockBuilder(View::class)
->getMock();
@@ -704,7 +696,7 @@ class FileTest extends TestCase {
$this->expectException(\Sabre\DAV\Exception\Forbidden::class);
// setup
- /** @var View|MockObject */
+ /** @var View&MockObject */
$view = $this->getMockBuilder(View::class)
->getMock();
@@ -724,7 +716,7 @@ class FileTest extends TestCase {
$this->expectException(\Sabre\DAV\Exception\Forbidden::class);
// setup
- /** @var View|MockObject */
+ /** @var View&MockObject */
$view = $this->getMockBuilder(View::class)
->getMock();
@@ -749,7 +741,7 @@ class FileTest extends TestCase {
$this->expectException(Forbidden::class);
// setup
- /** @var View|MockObject */
+ /** @var View&MockObject */
$view = $this->getMockBuilder(View::class)
->getMock();
@@ -923,7 +915,7 @@ class FileTest extends TestCase {
public function testGetFopenFails(): void {
$this->expectException(\Sabre\DAV\Exception\ServiceUnavailable::class);
- /** @var View|MockObject */
+ /** @var View&MockObject */
$view = $this->getMockBuilder(View::class)
->onlyMethods(['fopen'])
->getMock();
@@ -945,7 +937,7 @@ class FileTest extends TestCase {
public function testGetFopenThrows(): void {
$this->expectException(Forbidden::class);
- /** @var View|MockObject */
+ /** @var View&MockObject */
$view = $this->getMockBuilder(View::class)
->onlyMethods(['fopen'])
->getMock();
@@ -967,7 +959,7 @@ class FileTest extends TestCase {
public function testGetThrowsIfNoPermission(): void {
$this->expectException(\Sabre\DAV\Exception\NotFound::class);
- /** @var View|MockObject */
+ /** @var View&MockObject */
$view = $this->getMockBuilder(View::class)
->onlyMethods(['fopen'])
->getMock();
diff --git a/apps/dav/tests/unit/Connector/Sabre/FilesPluginTest.php b/apps/dav/tests/unit/Connector/Sabre/FilesPluginTest.php
index 1352229b1f5..d8b32067dda 100644
--- a/apps/dav/tests/unit/Connector/Sabre/FilesPluginTest.php
+++ b/apps/dav/tests/unit/Connector/Sabre/FilesPluginTest.php
@@ -1,5 +1,6 @@
<?php
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -73,23 +74,15 @@ class FilesPluginTest extends TestCase {
$this->accountManager,
);
- $response = $this->getMockBuilder(ResponseInterface::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $response = $this->createMock(ResponseInterface::class);
$this->server->httpResponse = $response;
$this->server->xml = new Service();
$this->plugin->initialize($this->server);
}
- /**
- * @param string $class
- * @return \PHPUnit\Framework\MockObject\MockObject
- */
- private function createTestNode($class, $path = '/dummypath') {
- $node = $this->getMockBuilder($class)
- ->disableOriginalConstructor()
- ->getMock();
+ private function createTestNode(string $class, string $path = '/dummypath'): MockObject {
+ $node = $this->createMock($class);
$node->expects($this->any())
->method('getId')
@@ -129,8 +122,8 @@ class FilesPluginTest extends TestCase {
}
public function testGetPropertiesForFile(): void {
- /** @var File|\PHPUnit\Framework\MockObject\MockObject $node */
- $node = $this->createTestNode('\OCA\DAV\Connector\Sabre\File');
+ /** @var File&MockObject $node */
+ $node = $this->createTestNode(File::class);
$propFind = new PropFind(
'/dummyPath',
@@ -149,8 +142,7 @@ class FilesPluginTest extends TestCase {
0
);
- $user = $this->getMockBuilder(User::class)
- ->disableOriginalConstructor()->getMock();
+ $user = $this->createMock(User::class);
$user
->expects($this->once())
->method('getUID')
@@ -160,8 +152,7 @@ class FilesPluginTest extends TestCase {
->method('getDisplayName')
->willReturn('M. Foo');
- $owner = $this->getMockBuilder(Account::class)
- ->disableOriginalConstructor()->getMock();
+ $owner = $this->createMock(Account::class);
$this->accountManager->expects($this->once())
->method('getAccount')
->with($user)
@@ -174,8 +165,7 @@ class FilesPluginTest extends TestCase {
->method('getOwner')
->willReturn($user);
- $displayNameProp = $this->getMockBuilder(AccountProperty::class)
- ->disableOriginalConstructor()->getMock();
+ $displayNameProp = $this->createMock(AccountProperty::class);
$owner
->expects($this->once())
->method('getProperty')
@@ -205,9 +195,7 @@ class FilesPluginTest extends TestCase {
}
public function testGetDisplayNamePropertyWhenNotPublished(): void {
- /** @var File|\PHPUnit\Framework\MockObject\MockObject $node */
- $node = $this->createTestNode('\OCA\DAV\Connector\Sabre\File');
-
+ $node = $this->createTestNode(File::class);
$propFind = new PropFind(
'/dummyPath',
[
@@ -220,15 +208,12 @@ class FilesPluginTest extends TestCase {
->method('getUser')
->willReturn(null);
- $user = $this->getMockBuilder(User::class)
- ->disableOriginalConstructor()->getMock();
+ $user = $this->createMock(User::class);
- $user
- ->expects($this->never())
+ $user->expects($this->never())
->method('getDisplayName');
- $owner = $this->getMockBuilder(Account::class)
- ->disableOriginalConstructor()->getMock();
+ $owner = $this->createMock(Account::class);
$this->accountManager->expects($this->once())
->method('getAccount')
->with($user)
@@ -238,8 +223,7 @@ class FilesPluginTest extends TestCase {
->method('getOwner')
->willReturn($user);
- $displayNameProp = $this->getMockBuilder(AccountProperty::class)
- ->disableOriginalConstructor()->getMock();
+ $displayNameProp = $this->createMock(AccountProperty::class);
$owner
->expects($this->once())
->method('getProperty')
@@ -257,10 +241,9 @@ class FilesPluginTest extends TestCase {
$this->assertEquals(null, $propFind->get(FilesPlugin::OWNER_DISPLAY_NAME_PROPERTYNAME));
}
-
+
public function testGetDisplayNamePropertyWhenNotPublishedButLoggedIn(): void {
- /** @var File|\PHPUnit\Framework\MockObject\MockObject $node */
- $node = $this->createTestNode('\OCA\DAV\Connector\Sabre\File');
+ $node = $this->createTestNode(File::class);
$propFind = new PropFind(
'/dummyPath',
@@ -270,15 +253,13 @@ class FilesPluginTest extends TestCase {
0
);
- $user = $this->getMockBuilder(User::class)
- ->disableOriginalConstructor()->getMock();
+ $user = $this->createMock(User::class);
$node->expects($this->once())
->method('getOwner')
->willReturn($user);
- $loggedInUser = $this->getMockBuilder(User::class)
- ->disableOriginalConstructor()->getMock();
+ $loggedInUser = $this->createMock(User::class);
$this->userSession->expects($this->once())
->method('getUser')
->willReturn($loggedInUser);
@@ -300,8 +281,8 @@ class FilesPluginTest extends TestCase {
}
public function testGetPropertiesStorageNotAvailable(): void {
- /** @var File|\PHPUnit\Framework\MockObject\MockObject $node */
- $node = $this->createTestNode('\OCA\DAV\Connector\Sabre\File');
+ /** @var File&MockObject $node */
+ $node = $this->createTestNode(File::class);
$propFind = new PropFind(
'/dummyPath',
@@ -325,9 +306,7 @@ class FilesPluginTest extends TestCase {
public function testGetPublicPermissions(): void {
/** @var IRequest&MockObject */
- $request = $this->getMockBuilder(IRequest::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $request = $this->createMock(IRequest::class);
$this->plugin = new FilesPlugin(
$this->tree,
$this->config,
@@ -348,8 +327,8 @@ class FilesPluginTest extends TestCase {
0
);
- /** @var File|\PHPUnit\Framework\MockObject\MockObject $node */
- $node = $this->createTestNode('\OCA\DAV\Connector\Sabre\File');
+ /** @var File&MockObject $node */
+ $node = $this->createTestNode(File::class);
$node->expects($this->any())
->method('getDavPermissions')
->willReturn('DWCKMSR');
@@ -363,8 +342,8 @@ class FilesPluginTest extends TestCase {
}
public function testGetPropertiesForDirectory(): void {
- /** @var Directory|\PHPUnit\Framework\MockObject\MockObject $node */
- $node = $this->createTestNode('\OCA\DAV\Connector\Sabre\Directory');
+ /** @var Directory&MockObject $node */
+ $node = $this->createTestNode(Directory::class);
$propFind = new PropFind(
'/dummyPath',
@@ -398,10 +377,8 @@ class FilesPluginTest extends TestCase {
}
public function testGetPropertiesForRootDirectory(): void {
- /** @var Directory|\PHPUnit\Framework\MockObject\MockObject $node */
- $node = $this->getMockBuilder(Directory::class)
- ->disableOriginalConstructor()
- ->getMock();
+ /** @var Directory&MockObject $node */
+ $node = $this->createMock(Directory::class);
$node->expects($this->any())->method('getPath')->willReturn('/');
$fileInfo = $this->createMock(FileInfo::class);
@@ -433,10 +410,8 @@ class FilesPluginTest extends TestCase {
// No read permissions can be caused by files access control.
// But we still want to load the directory list, so this is okay for us.
// $this->expectException(\Sabre\DAV\Exception\NotFound::class);
- /** @var Directory|\PHPUnit\Framework\MockObject\MockObject $node */
- $node = $this->getMockBuilder(Directory::class)
- ->disableOriginalConstructor()
- ->getMock();
+ /** @var Directory&MockObject $node */
+ $node = $this->createMock(Directory::class);
$node->expects($this->any())->method('getPath')->willReturn('/');
$fileInfo = $this->createMock(FileInfo::class);
@@ -465,7 +440,7 @@ class FilesPluginTest extends TestCase {
}
public function testUpdateProps(): void {
- $node = $this->createTestNode('\OCA\DAV\Connector\Sabre\File');
+ $node = $this->createTestNode(File::class);
$testDate = 'Fri, 13 Feb 2015 00:01:02 GMT';
$testCreationDate = '2007-08-31T16:47+00:00';
@@ -549,16 +524,12 @@ class FilesPluginTest extends TestCase {
$this->expectException(\Sabre\DAV\Exception\Forbidden::class);
$this->expectExceptionMessage('FolderA/test.txt cannot be deleted');
- $fileInfoFolderATestTXT = $this->getMockBuilder(FileInfo::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $fileInfoFolderATestTXT = $this->createMock(FileInfo::class);
$fileInfoFolderATestTXT->expects($this->once())
->method('isDeletable')
->willReturn(false);
- $node = $this->getMockBuilder(Node::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $node = $this->createMock(Node::class);
$node->expects($this->atLeastOnce())
->method('getFileInfo')
->willReturn($fileInfoFolderATestTXT);
@@ -571,16 +542,12 @@ class FilesPluginTest extends TestCase {
}
public function testMoveSrcDeletable(): void {
- $fileInfoFolderATestTXT = $this->getMockBuilder(FileInfo::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $fileInfoFolderATestTXT = $this->createMock(FileInfo::class);
$fileInfoFolderATestTXT->expects($this->once())
->method('isDeletable')
->willReturn(true);
- $node = $this->getMockBuilder(Node::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $node = $this->createMock(Node::class);
$node->expects($this->atLeastOnce())
->method('getFileInfo')
->willReturn($fileInfoFolderATestTXT);
@@ -596,9 +563,7 @@ class FilesPluginTest extends TestCase {
$this->expectException(\Sabre\DAV\Exception\NotFound::class);
$this->expectExceptionMessage('FolderA/test.txt does not exist');
- $node = $this->getMockBuilder(Node::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $node = $this->createMock(Node::class);
$node->expects($this->atLeastOnce())
->method('getFileInfo')
->willReturn(null);
@@ -674,7 +639,7 @@ class FilesPluginTest extends TestCase {
$this->plugin->checkCopy('FolderA/test.txt', 'invalid\\path.txt');
}
- public function downloadHeadersProvider() {
+ public static function downloadHeadersProvider(): array {
return [
[
false,
@@ -690,22 +655,16 @@ class FilesPluginTest extends TestCase {
/**
* @dataProvider downloadHeadersProvider
*/
- public function testDownloadHeaders($isClumsyAgent, $contentDispositionHeader): void {
- $request = $this->getMockBuilder(RequestInterface::class)
- ->disableOriginalConstructor()
- ->getMock();
- $response = $this->getMockBuilder(ResponseInterface::class)
- ->disableOriginalConstructor()
- ->getMock();
+ public function testDownloadHeaders(bool $isClumsyAgent, string $contentDispositionHeader): void {
+ $request = $this->createMock(RequestInterface::class);
+ $response = $this->createMock(ResponseInterface::class);
$request
->expects($this->once())
->method('getPath')
->willReturn('test/somefile.xml');
- $node = $this->getMockBuilder(File::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $node = $this->createMock(File::class);
$node
->expects($this->once())
->method('getName')
@@ -722,20 +681,24 @@ class FilesPluginTest extends TestCase {
->method('isUserAgent')
->willReturn($isClumsyAgent);
+ $calls = [
+ ['Content-Disposition', $contentDispositionHeader],
+ ['X-Accel-Buffering', 'no'],
+ ];
$response
- ->expects($this->exactly(2))
+ ->expects($this->exactly(count($calls)))
->method('addHeader')
- ->withConsecutive(
- ['Content-Disposition', $contentDispositionHeader],
- ['X-Accel-Buffering', 'no']
- );
+ ->willReturnCallback(function () use (&$calls) {
+ $expected = array_shift($calls);
+ $this->assertSame($expected, func_get_args());
+ });
$this->plugin->httpGet($request, $response);
}
public function testHasPreview(): void {
- /** @var Directory|\PHPUnit\Framework\MockObject\MockObject $node */
- $node = $this->createTestNode('\OCA\DAV\Connector\Sabre\Directory');
+ /** @var Directory&MockObject $node */
+ $node = $this->createTestNode(Directory::class);
$propFind = new PropFind(
'/dummyPath',
diff --git a/apps/dav/tests/unit/Connector/Sabre/FilesReportPluginTest.php b/apps/dav/tests/unit/Connector/Sabre/FilesReportPluginTest.php
index 6a9372ca3fd..e6cfb1f67b2 100644
--- a/apps/dav/tests/unit/Connector/Sabre/FilesReportPluginTest.php
+++ b/apps/dav/tests/unit/Connector/Sabre/FilesReportPluginTest.php
@@ -1,5 +1,6 @@
<?php
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -31,6 +32,7 @@ use OCP\SystemTag\ISystemTagObjectMapper;
use OCP\SystemTag\TagNotFoundException;
use PHPUnit\Framework\MockObject\MockObject;
use Sabre\DAV\INode;
+use Sabre\DAV\Server;
use Sabre\DAV\Tree;
use Sabre\HTTP\ResponseInterface;
@@ -52,15 +54,11 @@ class FilesReportPluginTest extends \Test\TestCase {
protected function setUp(): void {
parent::setUp();
- $this->tree = $this->getMockBuilder(Tree::class)
- ->disableOriginalConstructor()
- ->getMock();
- $this->view = $this->getMockBuilder(View::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $this->tree = $this->createMock(Tree::class);
+ $this->view = $this->createMock(View::class);
- $this->server = $this->getMockBuilder('\Sabre\DAV\Server')
+ $this->server = $this->getMockBuilder(Server::class)
->setConstructorArgs([$this->tree])
->onlyMethods(['getRequestUri', 'getBaseUri'])
->getMock();
@@ -69,22 +67,10 @@ class FilesReportPluginTest extends \Test\TestCase {
->method('getBaseUri')
->willReturn('http://example.com/owncloud/remote.php/dav');
- $this->groupManager = $this->getMockBuilder(IGroupManager::class)
- ->disableOriginalConstructor()
- ->getMock();
-
- $this->userFolder = $this->getMockBuilder(Folder::class)
- ->disableOriginalConstructor()
- ->getMock();
-
- $this->previewManager = $this->getMockBuilder(IPreview::class)
- ->disableOriginalConstructor()
- ->getMock();
-
- $this->appManager = $this->getMockBuilder(IAppManager::class)
- ->disableOriginalConstructor()
- ->getMock();
-
+ $this->groupManager = $this->createMock(IGroupManager::class);
+ $this->userFolder = $this->createMock(Folder::class);
+ $this->previewManager = $this->createMock(IPreview::class);
+ $this->appManager = $this->createMock(IAppManager::class);
$this->tagManager = $this->createMock(ISystemTagManager::class);
$this->tagMapper = $this->createMock(ISystemTagObjectMapper::class);
$this->userSession = $this->createMock(IUserSession::class);
@@ -95,9 +81,7 @@ class FilesReportPluginTest extends \Test\TestCase {
->with('files')
->willReturn($this->privateTags);
- $user = $this->getMockBuilder(IUser::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $user = $this->createMock(IUser::class);
$user->expects($this->any())
->method('getUID')
->willReturn('testuser');
@@ -124,11 +108,7 @@ class FilesReportPluginTest extends \Test\TestCase {
$this->tree->expects($this->any())
->method('getNodeForPath')
->with('/' . $path)
- ->willReturn(
- $this->getMockBuilder(INode::class)
- ->disableOriginalConstructor()
- ->getMock()
- );
+ ->willReturn($this->createMock(INode::class));
$this->server->expects($this->any())
->method('getRequestUri')
@@ -182,16 +162,12 @@ class FilesReportPluginTest extends \Test\TestCase {
->method('isAdmin')
->willReturn(true);
- $reportTargetNode = $this->getMockBuilder(Directory::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $reportTargetNode = $this->createMock(Directory::class);
$reportTargetNode->expects($this->any())
->method('getPath')
->willReturn('');
- $response = $this->getMockBuilder(ResponseInterface::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $response = $this->createMock(ResponseInterface::class);
$response->expects($this->once())
->method('setHeader')
@@ -240,14 +216,10 @@ class FilesReportPluginTest extends \Test\TestCase {
$this->userFolder->expects($this->exactly(2))
->method('searchBySystemTag')
- ->withConsecutive(
- ['OneTwoThree'],
- ['FourFiveSix'],
- )
- ->willReturnOnConsecutiveCalls(
- [$filesNode1],
- [$filesNode2],
- );
+ ->willReturnMap([
+ ['OneTwoThree', 'testuser', 0, 0, [$filesNode1]],
+ ['FourFiveSix', 'testuser', 0, 0, [$filesNode2]],
+ ]);
$this->server->expects($this->any())
->method('getRequestUri')
@@ -259,74 +231,56 @@ class FilesReportPluginTest extends \Test\TestCase {
}
public function testFindNodesByFileIdsRoot(): void {
- $filesNode1 = $this->getMockBuilder(Folder::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $filesNode1 = $this->createMock(Folder::class);
$filesNode1->expects($this->once())
->method('getName')
->willReturn('first node');
- $filesNode2 = $this->getMockBuilder(File::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $filesNode2 = $this->createMock(File::class);
$filesNode2->expects($this->once())
->method('getName')
->willReturn('second node');
- $reportTargetNode = $this->getMockBuilder(Directory::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $reportTargetNode = $this->createMock(Directory::class);
$reportTargetNode->expects($this->any())
->method('getPath')
->willReturn('/');
$this->userFolder->expects($this->exactly(2))
->method('getFirstNodeById')
- ->withConsecutive(
- ['111'],
- ['222'],
- )
- ->willReturnOnConsecutiveCalls(
- $filesNode1,
- $filesNode2,
- );
+ ->willReturnMap([
+ [111, $filesNode1],
+ [222, $filesNode2],
+ ]);
/** @var Directory&MockObject $reportTargetNode */
$result = $this->plugin->findNodesByFileIds($reportTargetNode, ['111', '222']);
$this->assertCount(2, $result);
- $this->assertInstanceOf('\OCA\DAV\Connector\Sabre\Directory', $result[0]);
+ $this->assertInstanceOf(Directory::class, $result[0]);
$this->assertEquals('first node', $result[0]->getName());
- $this->assertInstanceOf('\OCA\DAV\Connector\Sabre\File', $result[1]);
+ $this->assertInstanceOf(\OCA\DAV\Connector\Sabre\File::class, $result[1]);
$this->assertEquals('second node', $result[1]->getName());
}
public function testFindNodesByFileIdsSubDir(): void {
- $filesNode1 = $this->getMockBuilder(Folder::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $filesNode1 = $this->createMock(Folder::class);
$filesNode1->expects($this->once())
->method('getName')
->willReturn('first node');
- $filesNode2 = $this->getMockBuilder(File::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $filesNode2 = $this->createMock(File::class);
$filesNode2->expects($this->once())
->method('getName')
->willReturn('second node');
- $reportTargetNode = $this->getMockBuilder(Directory::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $reportTargetNode = $this->createMock(Directory::class);
$reportTargetNode->expects($this->any())
->method('getPath')
->willReturn('/sub1/sub2');
- $subNode = $this->getMockBuilder(Folder::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $subNode = $this->createMock(Folder::class);
$this->userFolder->expects($this->once())
->method('get')
@@ -335,22 +289,18 @@ class FilesReportPluginTest extends \Test\TestCase {
$subNode->expects($this->exactly(2))
->method('getFirstNodeById')
- ->withConsecutive(
- ['111'],
- ['222'],
- )
- ->willReturnOnConsecutiveCalls(
- $filesNode1,
- $filesNode2,
- );
+ ->willReturnMap([
+ [111, $filesNode1],
+ [222, $filesNode2],
+ ]);
/** @var Directory&MockObject $reportTargetNode */
$result = $this->plugin->findNodesByFileIds($reportTargetNode, ['111', '222']);
$this->assertCount(2, $result);
- $this->assertInstanceOf('\OCA\DAV\Connector\Sabre\Directory', $result[0]);
+ $this->assertInstanceOf(Directory::class, $result[0]);
$this->assertEquals('first node', $result[0]->getName());
- $this->assertInstanceOf('\OCA\DAV\Connector\Sabre\File', $result[1]);
+ $this->assertInstanceOf(\OCA\DAV\Connector\Sabre\File::class, $result[1]);
$this->assertEquals('second node', $result[1]->getName());
}
@@ -360,12 +310,8 @@ class FilesReportPluginTest extends \Test\TestCase {
$fileInfo = $this->createMock(FileInfo::class);
$fileInfo->method('isReadable')->willReturn(true);
- $node1 = $this->getMockBuilder(Directory::class)
- ->disableOriginalConstructor()
- ->getMock();
- $node2 = $this->getMockBuilder(\OCA\DAV\Connector\Sabre\File::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $node1 = $this->createMock(Directory::class);
+ $node2 = $this->createMock(\OCA\DAV\Connector\Sabre\File::class);
$node1->expects($this->once())
->method('getInternalFileId')
@@ -385,10 +331,7 @@ class FilesReportPluginTest extends \Test\TestCase {
->willReturn('/sub/node2');
$node2->method('getFileInfo')->willReturn($fileInfo);
- $config = $this->getMockBuilder(IConfig::class)
- ->disableOriginalConstructor()
- ->getMock();
-
+ $config = $this->createMock(IConfig::class);
$validator = $this->createMock(IFilenameValidator::class);
$accountManager = $this->createMock(IAccountManager::class);
@@ -461,7 +404,7 @@ class FilesReportPluginTest extends \Test\TestCase {
->with('OneTwoThree')
->willReturn([$filesNode1, $filesNode2]);
- $this->assertEquals([$filesNode1, $filesNode2], $this->invokePrivate($this->plugin, 'processFilterRulesForFileNodes', [$rules, 0, 0]));
+ $this->assertEquals([$filesNode1, $filesNode2], self::invokePrivate($this->plugin, 'processFilterRulesForFileNodes', [$rules, 0, 0]));
}
public function testProcessFilterRulesAndCondition(): void {
@@ -513,21 +456,17 @@ class FilesReportPluginTest extends \Test\TestCase {
$this->userFolder->expects($this->exactly(2))
->method('searchBySystemTag')
- ->withConsecutive(
- ['OneTwoThree'],
- ['FourFiveSix'],
- )
- ->willReturnOnConsecutiveCalls(
- [$filesNode1, $filesNode2],
- [$filesNode2, $filesNode3],
- );
+ ->willReturnMap([
+ ['OneTwoThree', 'testuser', 0, 0, [$filesNode1, $filesNode2]],
+ ['FourFiveSix', 'testuser', 0, 0, [$filesNode2, $filesNode3]],
+ ]);
$rules = [
['name' => '{http://owncloud.org/ns}systemtag', 'value' => '123'],
['name' => '{http://owncloud.org/ns}systemtag', 'value' => '456'],
];
- $this->assertEquals([$filesNode2], array_values($this->invokePrivate($this->plugin, 'processFilterRulesForFileNodes', [$rules, null, null])));
+ $this->assertEquals([$filesNode2], array_values(self::invokePrivate($this->plugin, 'processFilterRulesForFileNodes', [$rules, null, null])));
}
public function testProcessFilterRulesAndConditionWithOneEmptyResult(): void {
@@ -572,21 +511,17 @@ class FilesReportPluginTest extends \Test\TestCase {
$this->userFolder->expects($this->exactly(2))
->method('searchBySystemTag')
- ->withConsecutive(
- ['OneTwoThree'],
- ['FourFiveSix'],
- )
- ->willReturnOnConsecutiveCalls(
- [$filesNode1, $filesNode2],
- [],
- );
+ ->willReturnMap([
+ ['OneTwoThree', 'testuser', 0, 0, [$filesNode1, $filesNode2]],
+ ['FourFiveSix', 'testuser', 0, 0, []],
+ ]);
$rules = [
['name' => '{http://owncloud.org/ns}systemtag', 'value' => '123'],
['name' => '{http://owncloud.org/ns}systemtag', 'value' => '456'],
];
- $this->assertEquals([], $this->invokePrivate($this->plugin, 'processFilterRulesForFileNodes', [$rules, null, null]));
+ $this->assertEquals([], self::invokePrivate($this->plugin, 'processFilterRulesForFileNodes', [$rules, null, null]));
}
public function testProcessFilterRulesAndConditionWithFirstEmptyResult(): void {
@@ -631,18 +566,16 @@ class FilesReportPluginTest extends \Test\TestCase {
$this->userFolder->expects($this->once())
->method('searchBySystemTag')
- ->with('OneTwoThree')
- ->willReturnOnConsecutiveCalls(
- [],
- [$filesNode1, $filesNode2],
- );
+ ->willReturnMap([
+ ['OneTwoThree', 'testuser', 0, 0, []],
+ ]);
$rules = [
['name' => '{http://owncloud.org/ns}systemtag', 'value' => '123'],
['name' => '{http://owncloud.org/ns}systemtag', 'value' => '456'],
];
- $this->assertEquals([], $this->invokePrivate($this->plugin, 'processFilterRulesForFileNodes', [$rules, null, null]));
+ $this->assertEquals([], self::invokePrivate($this->plugin, 'processFilterRulesForFileNodes', [$rules, null, null]));
}
public function testProcessFilterRulesAndConditionWithEmptyMidResult(): void {
@@ -689,7 +622,7 @@ class FilesReportPluginTest extends \Test\TestCase {
$tag789 = $this->createMock(ISystemTag::class);
$tag789->expects($this->any())
->method('getName')
- ->willReturn('SevenEightNein');
+ ->willReturn('SevenEightNine');
$tag789->expects($this->any())
->method('isUserVisible')
->willReturn(true);
@@ -701,12 +634,10 @@ class FilesReportPluginTest extends \Test\TestCase {
$this->userFolder->expects($this->exactly(2))
->method('searchBySystemTag')
- ->withConsecutive(['OneTwoThree'], ['FourFiveSix'], ['SevenEightNein'])
- ->willReturnOnConsecutiveCalls(
- [$filesNode1, $filesNode2],
- [$filesNode3],
- [$filesNode1, $filesNode2],
- );
+ ->willReturnMap([
+ ['OneTwoThree', 'testuser', 0, 0, [$filesNode1, $filesNode2]],
+ ['FourFiveSix', 'testuser', 0, 0, [$filesNode3]],
+ ]);
$rules = [
['name' => '{http://owncloud.org/ns}systemtag', 'value' => '123'],
@@ -714,7 +645,7 @@ class FilesReportPluginTest extends \Test\TestCase {
['name' => '{http://owncloud.org/ns}systemtag', 'value' => '789'],
];
- $this->assertEquals([], array_values($this->invokePrivate($this->plugin, 'processFilterRulesForFileNodes', [$rules, null, null])));
+ $this->assertEquals([], array_values(self::invokePrivate($this->plugin, 'processFilterRulesForFileNodes', [$rules, null, null])));
}
public function testProcessFilterRulesInvisibleTagAsAdmin(): void {
@@ -766,18 +697,17 @@ class FilesReportPluginTest extends \Test\TestCase {
$this->userFolder->expects($this->exactly(2))
->method('searchBySystemTag')
- ->withConsecutive(['OneTwoThree'], ['FourFiveSix'])
- ->willReturnOnConsecutiveCalls(
- [$filesNode1, $filesNode2],
- [$filesNode2, $filesNode3],
- );
+ ->willReturnMap([
+ ['OneTwoThree', 'testuser', 0, 0, [$filesNode1, $filesNode2]],
+ ['FourFiveSix', 'testuser', 0, 0, [$filesNode2, $filesNode3]],
+ ]);
$rules = [
['name' => '{http://owncloud.org/ns}systemtag', 'value' => '123'],
['name' => '{http://owncloud.org/ns}systemtag', 'value' => '456'],
];
- $this->assertEquals([$filesNode2], array_values($this->invokePrivate($this->plugin, 'processFilterRulesForFileNodes', [$rules, null, null])));
+ $this->assertEquals([$filesNode2], array_values(self::invokePrivate($this->plugin, 'processFilterRulesForFileNodes', [$rules, null, null])));
}
@@ -816,7 +746,7 @@ class FilesReportPluginTest extends \Test\TestCase {
['name' => '{http://owncloud.org/ns}systemtag', 'value' => '456'],
];
- $this->invokePrivate($this->plugin, 'processFilterRulesForFileNodes', [$rules, null, null]);
+ self::invokePrivate($this->plugin, 'processFilterRulesForFileNodes', [$rules, null, null]);
}
public function testProcessFilterRulesVisibleTagAsUser(): void {
@@ -881,18 +811,17 @@ class FilesReportPluginTest extends \Test\TestCase {
// main assertion: only user visible tags are being passed through.
$this->userFolder->expects($this->exactly(2))
->method('searchBySystemTag')
- ->withConsecutive(['OneTwoThree'], ['FourFiveSix'])
- ->willReturnOnConsecutiveCalls(
- [$filesNode1, $filesNode2],
- [$filesNode2, $filesNode3],
- );
+ ->willReturnMap([
+ ['OneTwoThree', 'testuser', 0, 0, [$filesNode1, $filesNode2]],
+ ['FourFiveSix', 'testuser', 0, 0, [$filesNode2, $filesNode3]],
+ ]);
$rules = [
['name' => '{http://owncloud.org/ns}systemtag', 'value' => '123'],
['name' => '{http://owncloud.org/ns}systemtag', 'value' => '456'],
];
- $this->assertEquals([$filesNode2], array_values($this->invokePrivate($this->plugin, 'processFilterRulesForFileNodes', [$rules, null, null])));
+ $this->assertEquals([$filesNode2], array_values(self::invokePrivate($this->plugin, 'processFilterRulesForFileNodes', [$rules, null, null])));
}
public function testProcessFavoriteFilter(): void {
@@ -904,10 +833,10 @@ class FilesReportPluginTest extends \Test\TestCase {
->method('getFavorites')
->willReturn(['456', '789']);
- $this->assertEquals(['456', '789'], array_values($this->invokePrivate($this->plugin, 'processFilterRulesForFileIDs', [$rules])));
+ $this->assertEquals(['456', '789'], array_values(self::invokePrivate($this->plugin, 'processFilterRulesForFileIDs', [$rules])));
}
- public function filesBaseUriProvider() {
+ public static function filesBaseUriProvider(): array {
return [
['', '', ''],
['files/username', '', '/files/username'],
@@ -920,7 +849,7 @@ class FilesReportPluginTest extends \Test\TestCase {
/**
* @dataProvider filesBaseUriProvider
*/
- public function testFilesBaseUri($uri, $reportPath, $expectedUri): void {
- $this->assertEquals($expectedUri, $this->invokePrivate($this->plugin, 'getFilesBaseUri', [$uri, $reportPath]));
+ public function testFilesBaseUri(string $uri, string $reportPath, string $expectedUri): void {
+ $this->assertEquals($expectedUri, self::invokePrivate($this->plugin, 'getFilesBaseUri', [$uri, $reportPath]));
}
}
diff --git a/apps/dav/tests/unit/Connector/Sabre/MaintenancePluginTest.php b/apps/dav/tests/unit/Connector/Sabre/MaintenancePluginTest.php
index 9ecc49222e9..bc1d50ac41f 100644
--- a/apps/dav/tests/unit/Connector/Sabre/MaintenancePluginTest.php
+++ b/apps/dav/tests/unit/Connector/Sabre/MaintenancePluginTest.php
@@ -1,5 +1,6 @@
<?php
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -10,6 +11,7 @@ namespace OCA\DAV\Tests\unit\Connector\Sabre;
use OCA\DAV\Connector\Sabre\MaintenancePlugin;
use OCP\IConfig;
use OCP\IL10N;
+use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
/**
@@ -18,18 +20,15 @@ use Test\TestCase;
* @package OCA\DAV\Tests\unit\Connector\Sabre
*/
class MaintenancePluginTest extends TestCase {
- /** @var IConfig */
- private $config;
- /** @var \PHPUnit\Framework\MockObject\Builder\InvocationMocker|\PHPUnit_Framework_MockObject_Builder_InvocationMocker|IL10N */
- private $l10n;
- /** @var MaintenancePlugin */
- private $maintenancePlugin;
+ private IConfig&MockObject $config;
+ private IL10N&MockObject $l10n;
+ private MaintenancePlugin $maintenancePlugin;
protected function setUp(): void {
parent::setUp();
- $this->config = $this->getMockBuilder(IConfig::class)->getMock();
- $this->l10n = $this->getMockBuilder(IL10N::class)->getMock();
+ $this->config = $this->createMock(IConfig::class);
+ $this->l10n = $this->createMock(IL10N::class);
$this->maintenancePlugin = new MaintenancePlugin($this->config, $this->l10n);
}
diff --git a/apps/dav/tests/unit/Connector/Sabre/NodeTest.php b/apps/dav/tests/unit/Connector/Sabre/NodeTest.php
index 04cd60fbdaa..3dea5cf281b 100644
--- a/apps/dav/tests/unit/Connector/Sabre/NodeTest.php
+++ b/apps/dav/tests/unit/Connector/Sabre/NodeTest.php
@@ -1,5 +1,6 @@
<?php
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -32,7 +33,7 @@ use PHPUnit\Framework\MockObject\MockObject;
* @package OCA\DAV\Tests\unit\Connector\Sabre
*/
class NodeTest extends \Test\TestCase {
- public function davPermissionsProvider() {
+ public static function davPermissionsProvider(): array {
return [
[Constants::PERMISSION_ALL, 'file', false, Constants::PERMISSION_ALL, false, 'test', 'RGDNVW'],
[Constants::PERMISSION_ALL, 'dir', false, Constants::PERMISSION_ALL, false, 'test', 'RGDNVCK'],
@@ -53,7 +54,7 @@ class NodeTest extends \Test\TestCase {
/**
* @dataProvider davPermissionsProvider
*/
- public function testDavPermissions($permissions, $type, $shared, $shareRootPermissions, $mounted, $internalPath, $expected): void {
+ public function testDavPermissions(int $permissions, string $type, bool $shared, int $shareRootPermissions, bool $mounted, string $internalPath, string $expected): void {
$info = $this->getMockBuilder(FileInfo::class)
->disableOriginalConstructor()
->onlyMethods(['getPermissions', 'isShared', 'isMounted', 'getType', 'getInternalPath', 'getStorage', 'getMountPoint'])
@@ -94,15 +95,13 @@ class NodeTest extends \Test\TestCase {
}
$info->method('getStorage')
->willReturn($storage);
- $view = $this->getMockBuilder(View::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $view = $this->createMock(View::class);
$node = new File($view, $info);
$this->assertEquals($expected, $node->getDavPermissions());
}
- public function sharePermissionsProvider() {
+ public static function sharePermissionsProvider(): array {
return [
[\OCP\Files\FileInfo::TYPE_FILE, null, 1, 1],
[\OCP\Files\FileInfo::TYPE_FILE, null, 3, 3],
@@ -145,18 +144,14 @@ class NodeTest extends \Test\TestCase {
/**
* @dataProvider sharePermissionsProvider
*/
- public function testSharePermissions($type, $user, $permissions, $expected): void {
- $storage = $this->getMockBuilder(IStorage::class)
- ->disableOriginalConstructor()
- ->getMock();
+ public function testSharePermissions(string $type, ?string $user, int $permissions, int $expected): void {
+ $storage = $this->createMock(IStorage::class);
$storage->method('getPermissions')->willReturn($permissions);
- $mountpoint = $this->getMockBuilder(IMountPoint::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $mountpoint = $this->createMock(IMountPoint::class);
$mountpoint->method('getMountPoint')->willReturn('myPath');
- $shareManager = $this->getMockBuilder(IManager::class)->disableOriginalConstructor()->getMock();
- $share = $this->getMockBuilder(IShare::class)->disableOriginalConstructor()->getMock();
+ $shareManager = $this->createMock(IManager::class);
+ $share = $this->createMock(IShare::class);
if ($user === null) {
$shareManager->expects($this->never())->method('getShareByToken');
@@ -169,7 +164,7 @@ class NodeTest extends \Test\TestCase {
$info = $this->getMockBuilder(FileInfo::class)
->disableOriginalConstructor()
- ->setMethods(['getStorage', 'getType', 'getMountPoint', 'getPermissions'])
+ ->onlyMethods(['getStorage', 'getType', 'getMountPoint', 'getPermissions'])
->getMock();
$info->method('getStorage')->willReturn($storage);
@@ -177,9 +172,7 @@ class NodeTest extends \Test\TestCase {
$info->method('getMountPoint')->willReturn($mountpoint);
$info->method('getPermissions')->willReturn($permissions);
- $view = $this->getMockBuilder(View::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $view = $this->createMock(View::class);
$node = new File($view, $info);
$this->invokePrivate($node, 'shareManager', [$shareManager]);
@@ -189,11 +182,11 @@ class NodeTest extends \Test\TestCase {
public function testShareAttributes(): void {
$storage = $this->getMockBuilder(SharedStorage::class)
->disableOriginalConstructor()
- ->setMethods(['getShare'])
+ ->onlyMethods(['getShare'])
->getMock();
- $shareManager = $this->getMockBuilder(IManager::class)->disableOriginalConstructor()->getMock();
- $share = $this->getMockBuilder(IShare::class)->disableOriginalConstructor()->getMock();
+ $shareManager = $this->createMock(IManager::class);
+ $share = $this->createMock(IShare::class);
$storage->expects($this->once())
->method('getShare')
@@ -214,9 +207,7 @@ class NodeTest extends \Test\TestCase {
$info->method('getType')->willReturn(FileInfo::TYPE_FOLDER);
/** @var View&MockObject $view */
- $view = $this->getMockBuilder(View::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $view = $this->createMock(View::class);
$node = new File($view, $info);
$this->invokePrivate($node, 'shareManager', [$shareManager]);
@@ -224,11 +215,8 @@ class NodeTest extends \Test\TestCase {
}
public function testShareAttributesNonShare(): void {
- $storage = $this->getMockBuilder(IStorage::class)
- ->disableOriginalConstructor()
- ->getMock();
-
- $shareManager = $this->getMockBuilder(IManager::class)->disableOriginalConstructor()->getMock();
+ $storage = $this->createMock(IStorage::class);
+ $shareManager = $this->createMock(IManager::class);
/** @var Folder&MockObject */
$info = $this->getMockBuilder(Folder::class)
@@ -240,16 +228,14 @@ class NodeTest extends \Test\TestCase {
$info->method('getType')->willReturn(FileInfo::TYPE_FOLDER);
/** @var View&MockObject */
- $view = $this->getMockBuilder(View::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $view = $this->createMock(View::class);
$node = new File($view, $info);
$this->invokePrivate($node, 'shareManager', [$shareManager]);
$this->assertEquals([], $node->getShareAttributes());
}
- public function sanitizeMtimeProvider() {
+ public static function sanitizeMtimeProvider(): array {
return [
[123456789, 123456789],
['987654321', 987654321],
@@ -259,7 +245,7 @@ class NodeTest extends \Test\TestCase {
/**
* @dataProvider sanitizeMtimeProvider
*/
- public function testSanitizeMtime($mtime, $expected): void {
+ public function testSanitizeMtime(string|int $mtime, int $expected): void {
$view = $this->getMockBuilder(View::class)
->disableOriginalConstructor()
->getMock();
@@ -272,7 +258,7 @@ class NodeTest extends \Test\TestCase {
$this->assertEquals($expected, $result);
}
- public function invalidSanitizeMtimeProvider() {
+ public static function invalidSanitizeMtimeProvider(): array {
return [
[-1337], [0], ['abcdef'], ['-1337'], ['0'], [12321], [24 * 60 * 60 - 1],
];
@@ -281,17 +267,13 @@ class NodeTest extends \Test\TestCase {
/**
* @dataProvider invalidSanitizeMtimeProvider
*/
- public function testInvalidSanitizeMtime($mtime): void {
+ public function testInvalidSanitizeMtime(int|string $mtime): void {
$this->expectException(\InvalidArgumentException::class);
- $view = $this->getMockBuilder(View::class)
- ->disableOriginalConstructor()
- ->getMock();
- $info = $this->getMockBuilder(FileInfo::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $view = $this->createMock(View::class);
+ $info = $this->createMock(FileInfo::class);
$node = new File($view, $info);
- $result = $this->invokePrivate($node, 'sanitizeMtime', [$mtime]);
+ self::invokePrivate($node, 'sanitizeMtime', [$mtime]);
}
}
diff --git a/apps/dav/tests/unit/Connector/Sabre/ObjectTreeTest.php b/apps/dav/tests/unit/Connector/Sabre/ObjectTreeTest.php
index 393f3c72c20..4a5937e365b 100644
--- a/apps/dav/tests/unit/Connector/Sabre/ObjectTreeTest.php
+++ b/apps/dav/tests/unit/Connector/Sabre/ObjectTreeTest.php
@@ -1,5 +1,6 @@
<?php
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -27,7 +28,7 @@ use OCP\Files\Mount\IMountManager;
* @package OCA\DAV\Tests\Unit\Connector\Sabre
*/
class ObjectTreeTest extends \Test\TestCase {
- public function copyDataProvider() {
+ public static function copyDataProvider(): array {
return [
// copy into same dir
['a', 'b', ''],
@@ -41,7 +42,7 @@ class ObjectTreeTest extends \Test\TestCase {
/**
* @dataProvider copyDataProvider
*/
- public function testCopy($sourcePath, $targetPath, $targetParent): void {
+ public function testCopy(string $sourcePath, string $targetPath, string $targetParent): void {
$view = $this->createMock(View::class);
$view->expects($this->once())
->method('verifyPath')
@@ -67,7 +68,7 @@ class ObjectTreeTest extends \Test\TestCase {
$rootDir = new Directory($view, $info);
$objectTree = $this->getMockBuilder(ObjectTree::class)
- ->setMethods(['nodeExists', 'getNodeForPath'])
+ ->onlyMethods(['nodeExists', 'getNodeForPath'])
->setConstructorArgs([$rootDir, $view])
->getMock();
@@ -110,7 +111,7 @@ class ObjectTreeTest extends \Test\TestCase {
$rootDir = new Directory($view, $info);
$objectTree = $this->getMockBuilder(ObjectTree::class)
- ->setMethods(['nodeExists', 'getNodeForPath'])
+ ->onlyMethods(['nodeExists', 'getNodeForPath'])
->setConstructorArgs([$rootDir, $view])
->getMock();
@@ -127,23 +128,15 @@ class ObjectTreeTest extends \Test\TestCase {
* @dataProvider nodeForPathProvider
*/
public function testGetNodeForPath(
- $inputFileName,
- $fileInfoQueryPath,
- $outputFileName,
- $type,
+ string $inputFileName,
+ string $fileInfoQueryPath,
+ string $outputFileName,
+ string $type,
): void {
- $rootNode = $this->getMockBuilder(Directory::class)
- ->disableOriginalConstructor()
- ->getMock();
- $mountManager = $this->getMockBuilder(Manager::class)
- ->disableOriginalConstructor()
- ->getMock();
- $view = $this->getMockBuilder(View::class)
- ->disableOriginalConstructor()
- ->getMock();
- $fileInfo = $this->getMockBuilder(FileInfo::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $rootNode = $this->createMock(Directory::class);
+ $mountManager = $this->createMock(Manager::class);
+ $view = $this->createMock(View::class);
+ $fileInfo = $this->createMock(FileInfo::class);
$fileInfo->method('getType')
->willReturn($type);
$fileInfo->method('getName')
@@ -164,13 +157,13 @@ class ObjectTreeTest extends \Test\TestCase {
$this->assertEquals($outputFileName, $node->getName());
if ($type === 'file') {
- $this->assertTrue($node instanceof File);
+ $this->assertInstanceOf(File::class, $node);
} else {
- $this->assertTrue($node instanceof Directory);
+ $this->assertInstanceOf(Directory::class, $node);
}
}
- public function nodeForPathProvider() {
+ public static function nodeForPathProvider(): array {
return [
// regular file
[
@@ -213,7 +206,7 @@ class ObjectTreeTest extends \Test\TestCase {
$storage = new Temporary([]);
$view = $this->getMockBuilder(View::class)
- ->setMethods(['resolvePath'])
+ ->onlyMethods(['resolvePath'])
->getMock();
$view->expects($this->once())
->method('resolvePath')
@@ -221,9 +214,7 @@ class ObjectTreeTest extends \Test\TestCase {
return [$storage, ltrim($path, '/')];
});
- $rootNode = $this->getMockBuilder(Directory::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $rootNode = $this->createMock(Directory::class);
$mountManager = $this->createMock(IMountManager::class);
$tree = new ObjectTree();
@@ -239,7 +230,7 @@ class ObjectTreeTest extends \Test\TestCase {
$storage = new Temporary([]);
$view = $this->getMockBuilder(View::class)
- ->setMethods(['resolvePath'])
+ ->onlyMethods(['resolvePath'])
->getMock();
$view->expects($this->any())
->method('resolvePath')
@@ -247,9 +238,7 @@ class ObjectTreeTest extends \Test\TestCase {
return [$storage, ltrim($path, '/')];
});
- $rootNode = $this->getMockBuilder(Directory::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $rootNode = $this->createMock(Directory::class);
$mountManager = $this->createMock(IMountManager::class);
$tree = new ObjectTree();
diff --git a/apps/dav/tests/unit/Connector/Sabre/PrincipalTest.php b/apps/dav/tests/unit/Connector/Sabre/PrincipalTest.php
index 30e2c995d18..087bbd66107 100644
--- a/apps/dav/tests/unit/Connector/Sabre/PrincipalTest.php
+++ b/apps/dav/tests/unit/Connector/Sabre/PrincipalTest.php
@@ -1,4 +1,6 @@
<?php
+
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -30,38 +32,21 @@ use Sabre\DAV\PropPatch;
use Test\TestCase;
class PrincipalTest extends TestCase {
- /** @var IUserManager | MockObject */
- private $userManager;
-
- /** @var Principal */
- private $connector;
-
- /** @var IGroupManager | MockObject */
- private $groupManager;
-
- /** @var IAccountManager|MockObject */
- private $accountManager;
-
- /** @var IManager | MockObject */
- private $shareManager;
-
- /** @var IUserSession | MockObject */
- private $userSession;
-
- /** @var IAppManager | MockObject */
- private $appManager;
-
- /** @var ProxyMapper | MockObject */
- private $proxyMapper;
-
- /** @var KnownUserService|MockObject */
- private $knownUserService;
- /** @var IConfig | MockObject */
- private $config;
- /** @var IFactory|MockObject */
- private $languageFactory;
+ private IUserManager&MockObject $userManager;
+ private IGroupManager&MockObject $groupManager;
+ private IAccountManager&MockObject $accountManager;
+ private IManager&MockObject $shareManager;
+ private IUserSession&MockObject $userSession;
+ private IAppManager&MockObject $appManager;
+ private ProxyMapper&MockObject $proxyMapper;
+ private KnownUserService&MockObject $knownUserService;
+ private IConfig&MockObject $config;
+ private IFactory&MockObject $languageFactory;
+ private Principal $connector;
protected function setUp(): void {
+ parent::setUp();
+
$this->userManager = $this->createMock(IUserManager::class);
$this->groupManager = $this->createMock(IGroupManager::class);
$this->accountManager = $this->createMock(IAccountManager::class);
@@ -85,7 +70,6 @@ class PrincipalTest extends TestCase {
$this->config,
$this->languageFactory
);
- parent::setUp();
}
public function testGetPrincipalsByPrefixWithoutPrefix(): void {
@@ -125,13 +109,14 @@ class PrincipalTest extends TestCase {
$this->languageFactory
->expects($this->exactly(2))
->method('getUserLanguage')
- ->withConsecutive([$fooUser], [$barUser])
- ->willReturnOnConsecutiveCalls('de', 'en');
+ ->willReturnMap([
+ [$fooUser, 'de'],
+ [$barUser, 'en'],
+ ]);
$fooAccountPropertyCollection = $this->createMock(IAccountPropertyCollection::class);
$fooAccountPropertyCollection->expects($this->once())
->method('getProperties')
- ->with()
->willReturn([]);
$fooAccount = $this->createMock(IAccount::class);
$fooAccount->expects($this->once())
@@ -142,18 +127,15 @@ class PrincipalTest extends TestCase {
$emailPropertyOne = $this->createMock(IAccountProperty::class);
$emailPropertyOne->expects($this->once())
->method('getValue')
- ->with()
->willReturn('alias@nextcloud.com');
$emailPropertyTwo = $this->createMock(IAccountProperty::class);
$emailPropertyTwo->expects($this->once())
->method('getValue')
- ->with()
->willReturn('alias2@nextcloud.com');
$barAccountPropertyCollection = $this->createMock(IAccountPropertyCollection::class);
$barAccountPropertyCollection->expects($this->once())
->method('getProperties')
- ->with()
->willReturn([$emailPropertyOne, $emailPropertyTwo]);
$barAccount = $this->createMock(IAccount::class);
$barAccount->expects($this->once())
@@ -164,8 +146,10 @@ class PrincipalTest extends TestCase {
$this->accountManager
->expects($this->exactly(2))
->method('getAccount')
- ->withConsecutive([$fooUser], [$barUser])
- ->willReturnOnConsecutiveCalls($fooAccount, $barAccount);
+ ->willReturnMap([
+ [$fooUser, $fooAccount],
+ [$barUser, $barAccount],
+ ]);
$expectedResponse = [
0 => [
@@ -482,7 +466,7 @@ class PrincipalTest extends TestCase {
/**
* @dataProvider searchPrincipalsDataProvider
*/
- public function testSearchPrincipals($sharingEnabled, $groupsOnly, $test, $result): void {
+ public function testSearchPrincipals(bool $sharingEnabled, bool $groupsOnly, string $test, array $result): void {
$this->shareManager->expects($this->once())
->method('shareAPIEnabled')
->willReturn($sharingEnabled);
@@ -556,7 +540,7 @@ class PrincipalTest extends TestCase {
'{DAV:}displayname' => 'User 12'], $test));
}
- public function searchPrincipalsDataProvider(): array {
+ public static function searchPrincipalsDataProvider(): array {
return [
[true, false, 'allof', ['principals/users/user3']],
[true, false, 'anyof', ['principals/users/user2', 'principals/users/user3', 'principals/users/user4']],
@@ -845,7 +829,7 @@ class PrincipalTest extends TestCase {
/**
* @dataProvider findByUriWithGroupRestrictionDataProvider
*/
- public function testFindByUriWithGroupRestriction($uri, $email, $expects): void {
+ public function testFindByUriWithGroupRestriction(string $uri, string $email, ?string $expects): void {
$this->shareManager->expects($this->once())
->method('shareApiEnabled')
->willReturn(true);
@@ -872,31 +856,23 @@ class PrincipalTest extends TestCase {
if ($email === 'user2@foo.bar') {
$this->groupManager->expects($this->exactly(2))
->method('getUserGroupIds')
- ->withConsecutive(
- [$user],
- [$user2],
- )
- ->willReturnOnConsecutiveCalls(
- ['group1', 'group2'],
- ['group1', 'group3'],
- );
+ ->willReturnMap([
+ [$user, ['group1', 'group2']],
+ [$user2, ['group1', 'group3']],
+ ]);
} else {
$this->groupManager->expects($this->exactly(2))
->method('getUserGroupIds')
- ->withConsecutive(
- [$user],
- [$user3],
- )
- ->willReturnOnConsecutiveCalls(
- ['group1', 'group2'],
- ['group3', 'group3'],
- );
+ ->willReturnMap([
+ [$user, ['group1', 'group2']],
+ [$user3, ['group3', 'group3']],
+ ]);
}
$this->assertEquals($expects, $this->connector->findByUri($uri, 'principals/users'));
}
- public function findByUriWithGroupRestrictionDataProvider(): array {
+ public static function findByUriWithGroupRestrictionDataProvider(): array {
return [
['mailto:user2@foo.bar', 'user2@foo.bar', 'principals/users/user2'],
['mailto:user3@foo.bar', 'user3@foo.bar', null],
@@ -906,7 +882,7 @@ class PrincipalTest extends TestCase {
/**
* @dataProvider findByUriWithoutGroupRestrictionDataProvider
*/
- public function testFindByUriWithoutGroupRestriction($uri, $email, $expects): void {
+ public function testFindByUriWithoutGroupRestriction(string $uri, string $email, string $expects): void {
$this->shareManager->expects($this->once())
->method('shareApiEnabled')
->willReturn(true);
@@ -928,7 +904,7 @@ class PrincipalTest extends TestCase {
$this->assertEquals($expects, $this->connector->findByUri($uri, 'principals/users'));
}
- public function findByUriWithoutGroupRestrictionDataProvider(): array {
+ public static function findByUriWithoutGroupRestrictionDataProvider(): array {
return [
['mailto:user2@foo.bar', 'user2@foo.bar', 'principals/users/user2'],
['mailto:user3@foo.bar', 'user3@foo.bar', 'principals/users/user3'],
diff --git a/apps/dav/tests/unit/Connector/Sabre/PropfindCompressionPluginTest.php b/apps/dav/tests/unit/Connector/Sabre/PropfindCompressionPluginTest.php
index 42414ad6efb..e6f696ed160 100644
--- a/apps/dav/tests/unit/Connector/Sabre/PropfindCompressionPluginTest.php
+++ b/apps/dav/tests/unit/Connector/Sabre/PropfindCompressionPluginTest.php
@@ -14,8 +14,7 @@ use Sabre\HTTP\Response;
use Test\TestCase;
class PropfindCompressionPluginTest extends TestCase {
- /** @var PropfindCompressionPlugin */
- private $plugin;
+ private PropfindCompressionPlugin $plugin;
protected function setUp(): void {
parent::setUp();
diff --git a/apps/dav/tests/unit/Connector/Sabre/PublicAuthTest.php b/apps/dav/tests/unit/Connector/Sabre/PublicAuthTest.php
index 67e7f6af675..2340890ae5a 100644
--- a/apps/dav/tests/unit/Connector/Sabre/PublicAuthTest.php
+++ b/apps/dav/tests/unit/Connector/Sabre/PublicAuthTest.php
@@ -1,5 +1,6 @@
<?php
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2022-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -30,12 +31,12 @@ class PublicAuthTest extends \Test\TestCase {
private ISession&MockObject $session;
private IRequest&MockObject $request;
private IManager&MockObject $shareManager;
- private PublicAuth $auth;
private IThrottler&MockObject $throttler;
private LoggerInterface&MockObject $logger;
private IURLGenerator&MockObject $urlGenerator;
+ private PublicAuth $auth;
- private string $oldUser;
+ private bool|string $oldUser;
protected function setUp(): void {
parent::setUp();
@@ -65,7 +66,9 @@ class PublicAuthTest extends \Test\TestCase {
// Set old user
\OC_User::setUserId($this->oldUser);
- \OC_Util::setupFS($this->oldUser);
+ if ($this->oldUser !== false) {
+ \OC_Util::setupFS($this->oldUser);
+ }
parent::tearDown();
}
@@ -74,7 +77,7 @@ class PublicAuthTest extends \Test\TestCase {
$this->request->method('getPathInfo')
->willReturn('/dav/files/GX9HSGQrGE');
- $result = $this->invokePrivate($this->auth, 'getToken');
+ $result = self::invokePrivate($this->auth, 'getToken');
$this->assertSame('GX9HSGQrGE', $result);
}
@@ -84,16 +87,14 @@ class PublicAuthTest extends \Test\TestCase {
->willReturn('/dav/files');
$this->expectException(\Sabre\DAV\Exception\NotFound::class);
- $this->invokePrivate($this->auth, 'getToken');
+ self::invokePrivate($this->auth, 'getToken');
}
public function testCheckTokenValidShare(): void {
$this->request->method('getPathInfo')
->willReturn('/dav/files/GX9HSGQrGE');
- $share = $this->getMockBuilder(IShare::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $share = $this->createMock(IShare::class);
$share->method('getPassword')->willReturn(null);
$this->shareManager->expects($this->once())
@@ -101,7 +102,7 @@ class PublicAuthTest extends \Test\TestCase {
->with('GX9HSGQrGE')
->willReturn($share);
- $result = $this->invokePrivate($this->auth, 'checkToken');
+ $result = self::invokePrivate($this->auth, 'checkToken');
$this->assertSame([true, 'principals/GX9HSGQrGE'], $result);
}
@@ -116,16 +117,14 @@ class PublicAuthTest extends \Test\TestCase {
->will($this->throwException(new ShareNotFound()));
$this->expectException(\Sabre\DAV\Exception\NotFound::class);
- $this->invokePrivate($this->auth, 'checkToken');
+ self::invokePrivate($this->auth, 'checkToken');
}
public function testCheckTokenAlreadyAuthenticated(): void {
$this->request->method('getPathInfo')
->willReturn('/dav/files/GX9HSGQrGE');
- $share = $this->getMockBuilder(IShare::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $share = $this->createMock(IShare::class);
$share->method('getShareType')->willReturn(42);
$this->shareManager->expects($this->once())
@@ -136,7 +135,7 @@ class PublicAuthTest extends \Test\TestCase {
$this->session->method('exists')->with('public_link_authenticated')->willReturn(true);
$this->session->method('get')->with('public_link_authenticated')->willReturn('42');
- $result = $this->invokePrivate($this->auth, 'checkToken');
+ $result = self::invokePrivate($this->auth, 'checkToken');
$this->assertSame([true, 'principals/GX9HSGQrGE'], $result);
}
@@ -144,9 +143,7 @@ class PublicAuthTest extends \Test\TestCase {
$this->request->method('getPathInfo')
->willReturn('/dav/files/GX9HSGQrGE');
- $share = $this->getMockBuilder(IShare::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $share = $this->createMock(IShare::class);
$share->method('getPassword')->willReturn('password');
$share->method('getShareType')->willReturn(42);
@@ -158,16 +155,14 @@ class PublicAuthTest extends \Test\TestCase {
$this->session->method('exists')->with('public_link_authenticated')->willReturn(false);
$this->expectException(\Sabre\DAV\Exception\NotAuthenticated::class);
- $this->invokePrivate($this->auth, 'checkToken');
+ self::invokePrivate($this->auth, 'checkToken');
}
public function testCheckTokenPasswordAuthenticatedWrongShare(): void {
$this->request->method('getPathInfo')
->willReturn('/dav/files/GX9HSGQrGE');
- $share = $this->getMockBuilder(IShare::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $share = $this->createMock(IShare::class);
$share->method('getPassword')->willReturn('password');
$share->method('getShareType')->willReturn(42);
@@ -180,7 +175,7 @@ class PublicAuthTest extends \Test\TestCase {
$this->session->method('get')->with('public_link_authenticated')->willReturn('43');
$this->expectException(\Sabre\DAV\Exception\NotAuthenticated::class);
- $this->invokePrivate($this->auth, 'checkToken');
+ self::invokePrivate($this->auth, 'checkToken');
}
public function testNoShare(): void {
@@ -192,7 +187,7 @@ class PublicAuthTest extends \Test\TestCase {
->with('GX9HSGQrGE')
->willThrowException(new ShareNotFound());
- $result = $this->invokePrivate($this->auth, 'validateUserPass', ['username', 'password']);
+ $result = self::invokePrivate($this->auth, 'validateUserPass', ['username', 'password']);
$this->assertFalse($result);
}
@@ -201,9 +196,7 @@ class PublicAuthTest extends \Test\TestCase {
$this->request->method('getPathInfo')
->willReturn('/dav/files/GX9HSGQrGE');
- $share = $this->getMockBuilder(IShare::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $share = $this->createMock(IShare::class);
$share->method('getPassword')->willReturn(null);
$this->shareManager->expects($this->once())
@@ -211,7 +204,7 @@ class PublicAuthTest extends \Test\TestCase {
->with('GX9HSGQrGE')
->willReturn($share);
- $result = $this->invokePrivate($this->auth, 'validateUserPass', ['username', 'password']);
+ $result = self::invokePrivate($this->auth, 'validateUserPass', ['username', 'password']);
$this->assertTrue($result);
}
@@ -220,9 +213,7 @@ class PublicAuthTest extends \Test\TestCase {
$this->request->method('getPathInfo')
->willReturn('/dav/files/GX9HSGQrGE');
- $share = $this->getMockBuilder(IShare::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $share = $this->createMock(IShare::class);
$share->method('getPassword')->willReturn('password');
$share->method('getShareType')->willReturn(42);
@@ -231,7 +222,7 @@ class PublicAuthTest extends \Test\TestCase {
->with('GX9HSGQrGE')
->willReturn($share);
- $result = $this->invokePrivate($this->auth, 'validateUserPass', ['username', 'password']);
+ $result = self::invokePrivate($this->auth, 'validateUserPass', ['username', 'password']);
$this->assertFalse($result);
}
@@ -241,9 +232,7 @@ class PublicAuthTest extends \Test\TestCase {
$this->request->method('getPathInfo')
->willReturn('/dav/files/GX9HSGQrGE');
- $share = $this->getMockBuilder(IShare::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $share = $this->createMock(IShare::class);
$share->method('getPassword')->willReturn('password');
$share->method('getShareType')->willReturn(IShare::TYPE_REMOTE);
@@ -252,7 +241,7 @@ class PublicAuthTest extends \Test\TestCase {
->with('GX9HSGQrGE')
->willReturn($share);
- $result = $this->invokePrivate($this->auth, 'validateUserPass', ['username', 'password']);
+ $result = self::invokePrivate($this->auth, 'validateUserPass', ['username', 'password']);
$this->assertTrue($result);
}
@@ -261,9 +250,7 @@ class PublicAuthTest extends \Test\TestCase {
$this->request->method('getPathInfo')
->willReturn('/dav/files/GX9HSGQrGE');
- $share = $this->getMockBuilder(IShare::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $share = $this->createMock(IShare::class);
$share->method('getPassword')->willReturn('password');
$share->method('getShareType')->willReturn(IShare::TYPE_LINK);
@@ -278,7 +265,7 @@ class PublicAuthTest extends \Test\TestCase {
$this->equalTo('password')
)->willReturn(true);
- $result = $this->invokePrivate($this->auth, 'validateUserPass', ['username', 'password']);
+ $result = self::invokePrivate($this->auth, 'validateUserPass', ['username', 'password']);
$this->assertTrue($result);
}
@@ -287,9 +274,7 @@ class PublicAuthTest extends \Test\TestCase {
$this->request->method('getPathInfo')
->willReturn('/dav/files/GX9HSGQrGE');
- $share = $this->getMockBuilder(IShare::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $share = $this->createMock(IShare::class);
$share->method('getPassword')->willReturn('password');
$share->method('getShareType')->willReturn(IShare::TYPE_EMAIL);
@@ -304,7 +289,7 @@ class PublicAuthTest extends \Test\TestCase {
$this->equalTo('password')
)->willReturn(true);
- $result = $this->invokePrivate($this->auth, 'validateUserPass', ['username', 'password']);
+ $result = self::invokePrivate($this->auth, 'validateUserPass', ['username', 'password']);
$this->assertTrue($result);
}
@@ -313,9 +298,7 @@ class PublicAuthTest extends \Test\TestCase {
$this->request->method('getPathInfo')
->willReturn('/dav/files/GX9HSGQrGE');
- $share = $this->getMockBuilder(IShare::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $share = $this->createMock(IShare::class);
$share->method('getPassword')->willReturn('password');
$share->method('getShareType')->willReturn(IShare::TYPE_LINK);
$share->method('getId')->willReturn('42');
@@ -335,7 +318,7 @@ class PublicAuthTest extends \Test\TestCase {
$this->session->method('exists')->with('public_link_authenticated')->willReturn(true);
$this->session->method('get')->with('public_link_authenticated')->willReturn('42');
- $result = $this->invokePrivate($this->auth, 'validateUserPass', ['username', 'password']);
+ $result = self::invokePrivate($this->auth, 'validateUserPass', ['username', 'password']);
$this->assertTrue($result);
}
@@ -344,9 +327,7 @@ class PublicAuthTest extends \Test\TestCase {
$this->request->method('getPathInfo')
->willReturn('/dav/files/GX9HSGQrGE');
- $share = $this->getMockBuilder(IShare::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $share = $this->createMock(IShare::class);
$share->method('getPassword')->willReturn('password');
$share->method('getShareType')->willReturn(IShare::TYPE_LINK);
$share->method('getId')->willReturn('42');
@@ -366,7 +347,7 @@ class PublicAuthTest extends \Test\TestCase {
$this->session->method('exists')->with('public_link_authenticated')->willReturn(true);
$this->session->method('get')->with('public_link_authenticated')->willReturn('43');
- $result = $this->invokePrivate($this->auth, 'validateUserPass', ['username', 'password']);
+ $result = self::invokePrivate($this->auth, 'validateUserPass', ['username', 'password']);
$this->assertFalse($result);
}
@@ -376,9 +357,7 @@ class PublicAuthTest extends \Test\TestCase {
$this->request->method('getPathInfo')
->willReturn('/dav/files/GX9HSGQrGE');
- $share = $this->getMockBuilder(IShare::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $share = $this->createMock(IShare::class);
$share->method('getPassword')->willReturn('password');
$share->method('getShareType')->willReturn(IShare::TYPE_EMAIL);
$share->method('getId')->willReturn('42');
@@ -398,7 +377,7 @@ class PublicAuthTest extends \Test\TestCase {
$this->session->method('exists')->with('public_link_authenticated')->willReturn(true);
$this->session->method('get')->with('public_link_authenticated')->willReturn('43');
- $result = $this->invokePrivate($this->auth, 'validateUserPass', ['username', 'password']);
+ $result = self::invokePrivate($this->auth, 'validateUserPass', ['username', 'password']);
$this->assertFalse($result);
}
diff --git a/apps/dav/tests/unit/Connector/Sabre/QuotaPluginTest.php b/apps/dav/tests/unit/Connector/Sabre/QuotaPluginTest.php
index c370e0fb0f7..a78a1a223c5 100644
--- a/apps/dav/tests/unit/Connector/Sabre/QuotaPluginTest.php
+++ b/apps/dav/tests/unit/Connector/Sabre/QuotaPluginTest.php
@@ -1,5 +1,6 @@
<?php
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2013-2016 ownCloud, Inc.
@@ -13,29 +14,23 @@ use OCP\Files\FileInfo;
use Test\TestCase;
class QuotaPluginTest extends TestCase {
- /** @var \Sabre\DAV\Server | \PHPUnit\Framework\MockObject\MockObject */
- private $server;
+ private \Sabre\DAV\Server $server;
- /** @var QuotaPlugin|\PHPUnit\Framework\MockObject\MockObject */
- private $plugin;
+ private QuotaPlugin $plugin;
- private function init($quota, $checkedPath = ''): void {
- $view = $this->buildFileViewMock($quota, $checkedPath);
+ private function init(int $quota, string $checkedPath = ''): void {
+ $view = $this->buildFileViewMock((string)$quota, $checkedPath);
$this->server = new \Sabre\DAV\Server();
- $this->plugin = $this->getMockBuilder(QuotaPlugin::class)
- ->setConstructorArgs([$view])
- ->setMethods(['getFileChunking'])
- ->getMock();
+ $this->plugin = new QuotaPlugin($view);
$this->plugin->initialize($this->server);
}
/**
* @dataProvider lengthProvider
*/
- public function testLength($expected, $headers): void {
+ public function testLength(?int $expected, array $headers): void {
$this->init(0);
- $this->plugin->expects($this->never())
- ->method('getFileChunking');
+
$this->server->httpRequest = new \Sabre\HTTP\Request('POST', 'dummy.file', $headers);
$length = $this->plugin->getLength();
$this->assertEquals($expected, $length);
@@ -44,10 +39,8 @@ class QuotaPluginTest extends TestCase {
/**
* @dataProvider quotaOkayProvider
*/
- public function testCheckQuota($quota, $headers): void {
+ public function testCheckQuota(int $quota, array $headers): void {
$this->init($quota);
- $this->plugin->expects($this->never())
- ->method('getFileChunking');
$this->server->httpRequest = new \Sabre\HTTP\Request('POST', 'dummy.file', $headers);
$result = $this->plugin->checkQuota('');
@@ -57,12 +50,10 @@ class QuotaPluginTest extends TestCase {
/**
* @dataProvider quotaExceededProvider
*/
- public function testCheckExceededQuota($quota, $headers): void {
+ public function testCheckExceededQuota(int $quota, array $headers): void {
$this->expectException(\Sabre\DAV\Exception\InsufficientStorage::class);
$this->init($quota);
- $this->plugin->expects($this->never())
- ->method('getFileChunking');
$this->server->httpRequest = new \Sabre\HTTP\Request('POST', 'dummy.file', $headers);
$this->plugin->checkQuota('');
@@ -71,17 +62,15 @@ class QuotaPluginTest extends TestCase {
/**
* @dataProvider quotaOkayProvider
*/
- public function testCheckQuotaOnPath($quota, $headers): void {
+ public function testCheckQuotaOnPath(int $quota, array $headers): void {
$this->init($quota, 'sub/test.txt');
- $this->plugin->expects($this->never())
- ->method('getFileChunking');
$this->server->httpRequest = new \Sabre\HTTP\Request('POST', 'dummy.file', $headers);
$result = $this->plugin->checkQuota('/sub/test.txt');
$this->assertTrue($result);
}
- public function quotaOkayProvider() {
+ public static function quotaOkayProvider(): array {
return [
[1024, []],
[1024, ['X-EXPECTED-ENTITY-LENGTH' => '1024']],
@@ -100,7 +89,7 @@ class QuotaPluginTest extends TestCase {
];
}
- public function quotaExceededProvider() {
+ public static function quotaExceededProvider(): array {
return [
[1023, ['X-EXPECTED-ENTITY-LENGTH' => '1024']],
[511, ['CONTENT-LENGTH' => '512']],
@@ -108,7 +97,7 @@ class QuotaPluginTest extends TestCase {
];
}
- public function lengthProvider() {
+ public static function lengthProvider(): array {
return [
[null, []],
[1024, ['X-EXPECTED-ENTITY-LENGTH' => '1024']],
@@ -124,7 +113,7 @@ class QuotaPluginTest extends TestCase {
];
}
- public function quotaChunkedOkProvider() {
+ public static function quotaChunkedOkProvider(): array {
return [
[1024, 0, ['X-EXPECTED-ENTITY-LENGTH' => '1024']],
[1024, 0, ['CONTENT-LENGTH' => '512']],
@@ -143,7 +132,7 @@ class QuotaPluginTest extends TestCase {
];
}
- public function quotaChunkedFailProvider() {
+ public static function quotaChunkedFailProvider(): array {
return [
[400, 0, ['X-EXPECTED-ENTITY-LENGTH' => '1024']],
[400, 0, ['CONTENT-LENGTH' => '512']],
@@ -155,15 +144,15 @@ class QuotaPluginTest extends TestCase {
];
}
- private function buildFileViewMock($quota, $checkedPath) {
- // mock filesysten
+ private function buildFileViewMock(string $quota, string $checkedPath): View {
+ // mock filesystem
$view = $this->getMockBuilder(View::class)
- ->setMethods(['free_space'])
+ ->onlyMethods(['free_space'])
->disableOriginalConstructor()
->getMock();
$view->expects($this->any())
->method('free_space')
- ->with($this->identicalTo($checkedPath))
+ ->with($checkedPath)
->willReturn($quota);
return $view;
diff --git a/apps/dav/tests/unit/Connector/Sabre/RequestTest/Auth.php b/apps/dav/tests/unit/Connector/Sabre/RequestTest/Auth.php
index 836766b366d..b01807d5bbb 100644
--- a/apps/dav/tests/unit/Connector/Sabre/RequestTest/Auth.php
+++ b/apps/dav/tests/unit/Connector/Sabre/RequestTest/Auth.php
@@ -1,5 +1,6 @@
<?php
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
diff --git a/apps/dav/tests/unit/Connector/Sabre/RequestTest/DeleteTest.php b/apps/dav/tests/unit/Connector/Sabre/RequestTest/DeleteTest.php
index e7f20fbadfa..c5c7e99c7e5 100644
--- a/apps/dav/tests/unit/Connector/Sabre/RequestTest/DeleteTest.php
+++ b/apps/dav/tests/unit/Connector/Sabre/RequestTest/DeleteTest.php
@@ -1,5 +1,6 @@
<?php
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -18,7 +19,7 @@ use OCP\AppFramework\Http;
*/
class DeleteTest extends RequestTestCase {
public function testBasicUpload(): void {
- $user = $this->getUniqueID();
+ $user = self::getUniqueID();
$view = $this->setupUser($user, 'pass');
$view->file_put_contents('foo.txt', 'asd');
@@ -29,7 +30,7 @@ class DeleteTest extends RequestTestCase {
$mount->getStorage()->unlink($mount->getInternalPath($internalPath));
// cache entry still exists
- $this->assertInstanceOf('\OCP\Files\FileInfo', $view->getFileInfo('foo.txt'));
+ $this->assertInstanceOf(\OCP\Files\FileInfo::class, $view->getFileInfo('foo.txt'));
$response = $this->request($view, $user, 'pass', 'DELETE', '/foo.txt');
diff --git a/apps/dav/tests/unit/Connector/Sabre/RequestTest/DownloadTest.php b/apps/dav/tests/unit/Connector/Sabre/RequestTest/DownloadTest.php
index bec4cd9967b..34171963ef0 100644
--- a/apps/dav/tests/unit/Connector/Sabre/RequestTest/DownloadTest.php
+++ b/apps/dav/tests/unit/Connector/Sabre/RequestTest/DownloadTest.php
@@ -1,5 +1,6 @@
<?php
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -19,7 +20,7 @@ use OCP\Lock\ILockingProvider;
*/
class DownloadTest extends RequestTestCase {
public function testDownload(): void {
- $user = $this->getUniqueID();
+ $user = self::getUniqueID();
$view = $this->setupUser($user, 'pass');
$view->file_put_contents('foo.txt', 'bar');
@@ -30,7 +31,7 @@ class DownloadTest extends RequestTestCase {
}
public function testDownloadWriteLocked(): void {
- $user = $this->getUniqueID();
+ $user = self::getUniqueID();
$view = $this->setupUser($user, 'pass');
$view->file_put_contents('foo.txt', 'bar');
@@ -42,7 +43,7 @@ class DownloadTest extends RequestTestCase {
}
public function testDownloadReadLocked(): void {
- $user = $this->getUniqueID();
+ $user = self::getUniqueID();
$view = $this->setupUser($user, 'pass');
$view->file_put_contents('foo.txt', 'bar');
diff --git a/apps/dav/tests/unit/Connector/Sabre/RequestTest/EncryptionMasterKeyUploadTest.php b/apps/dav/tests/unit/Connector/Sabre/RequestTest/EncryptionMasterKeyUploadTest.php
index 92d89d7753a..615490ddc92 100644
--- a/apps/dav/tests/unit/Connector/Sabre/RequestTest/EncryptionMasterKeyUploadTest.php
+++ b/apps/dav/tests/unit/Connector/Sabre/RequestTest/EncryptionMasterKeyUploadTest.php
@@ -1,5 +1,6 @@
<?php
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -23,7 +24,7 @@ use Test\Traits\EncryptionTrait;
class EncryptionMasterKeyUploadTest extends UploadTest {
use EncryptionTrait;
- protected function setupUser($name, $password) {
+ protected function setupUser($name, $password): View {
$this->createUser($name, $password);
$tmpFolder = Server::get(ITempManager::class)->getTemporaryFolder();
$this->registerMount($name, '\OC\Files\Storage\Local', '/' . $name, ['datadir' => $tmpFolder]);
diff --git a/apps/dav/tests/unit/Connector/Sabre/RequestTest/EncryptionUploadTest.php b/apps/dav/tests/unit/Connector/Sabre/RequestTest/EncryptionUploadTest.php
index 935ef6d9464..efa7bb54cf8 100644
--- a/apps/dav/tests/unit/Connector/Sabre/RequestTest/EncryptionUploadTest.php
+++ b/apps/dav/tests/unit/Connector/Sabre/RequestTest/EncryptionUploadTest.php
@@ -1,5 +1,6 @@
<?php
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -23,7 +24,7 @@ use Test\Traits\EncryptionTrait;
class EncryptionUploadTest extends UploadTest {
use EncryptionTrait;
- protected function setupUser($name, $password) {
+ protected function setupUser($name, $password): View {
$this->createUser($name, $password);
$tmpFolder = Server::get(ITempManager::class)->getTemporaryFolder();
$this->registerMount($name, '\OC\Files\Storage\Local', '/' . $name, ['datadir' => $tmpFolder]);
diff --git a/apps/dav/tests/unit/Connector/Sabre/RequestTest/ExceptionPlugin.php b/apps/dav/tests/unit/Connector/Sabre/RequestTest/ExceptionPlugin.php
index b1e68f9597b..0c53e4b1009 100644
--- a/apps/dav/tests/unit/Connector/Sabre/RequestTest/ExceptionPlugin.php
+++ b/apps/dav/tests/unit/Connector/Sabre/RequestTest/ExceptionPlugin.php
@@ -1,5 +1,6 @@
<?php
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
diff --git a/apps/dav/tests/unit/Connector/Sabre/RequestTest/PartFileInRootUploadTest.php b/apps/dav/tests/unit/Connector/Sabre/RequestTest/PartFileInRootUploadTest.php
index 5f3dc6f4e32..e6fa489fb24 100644
--- a/apps/dav/tests/unit/Connector/Sabre/RequestTest/PartFileInRootUploadTest.php
+++ b/apps/dav/tests/unit/Connector/Sabre/RequestTest/PartFileInRootUploadTest.php
@@ -21,9 +21,7 @@ use OCP\Server;
class PartFileInRootUploadTest extends UploadTest {
protected function setUp(): void {
$config = Server::get(IConfig::class);
- $mockConfig = $this->getMockBuilder(IConfig::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $mockConfig = $this->createMock(IConfig::class);
$mockConfig->expects($this->any())
->method('getSystemValue')
->willReturnCallback(function ($key, $default) use ($config) {
diff --git a/apps/dav/tests/unit/Connector/Sabre/RequestTest/RequestTestCase.php b/apps/dav/tests/unit/Connector/Sabre/RequestTest/RequestTestCase.php
index d02f1d76cac..404dc7fa5d7 100644
--- a/apps/dav/tests/unit/Connector/Sabre/RequestTest/RequestTestCase.php
+++ b/apps/dav/tests/unit/Connector/Sabre/RequestTest/RequestTestCase.php
@@ -1,5 +1,6 @@
<?php
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -20,6 +21,7 @@ use OCP\IRequestId;
use OCP\ITagManager;
use OCP\ITempManager;
use OCP\IUserSession;
+use OCP\L10N\IFactory;
use Psr\Log\LoggerInterface;
use Sabre\HTTP\Request;
use Test\TestCase;
@@ -29,11 +31,7 @@ use Test\Traits\UserTrait;
abstract class RequestTestCase extends TestCase {
use UserTrait;
use MountProviderTrait;
-
- /**
- * @var ServerFactory
- */
- protected $serverFactory;
+ protected ServerFactory $serverFactory;
protected function getStream($string) {
$stream = fopen('php://temp', 'r+');
@@ -52,20 +50,18 @@ abstract class RequestTestCase extends TestCase {
\OCP\Server::get(IUserSession::class),
\OCP\Server::get(IMountManager::class),
\OCP\Server::get(ITagManager::class),
- $this->getMockBuilder(IRequest::class)
- ->disableOriginalConstructor()
- ->getMock(),
+ $this->createMock(IRequest::class),
\OCP\Server::get(IPreview::class),
\OCP\Server::get(IEventDispatcher::class),
- \OC::$server->getL10N('dav')
+ \OCP\Server::get(IFactory::class)->get('dav'),
);
}
- protected function setupUser($name, $password) {
+ protected function setupUser($name, $password): View {
$this->createUser($name, $password);
$tmpFolder = \OCP\Server::get(ITempManager::class)->getTemporaryFolder();
$this->registerMount($name, '\OC\Files\Storage\Local', '/' . $name, ['datadir' => $tmpFolder]);
- $this->loginAsUser($name);
+ self::loginAsUser($name);
return new View('/' . $name . '/files');
}
diff --git a/apps/dav/tests/unit/Connector/Sabre/RequestTest/Sapi.php b/apps/dav/tests/unit/Connector/Sabre/RequestTest/Sapi.php
index f12c93468ff..08d774e56b8 100644
--- a/apps/dav/tests/unit/Connector/Sabre/RequestTest/Sapi.php
+++ b/apps/dav/tests/unit/Connector/Sabre/RequestTest/Sapi.php
@@ -1,5 +1,6 @@
<?php
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
diff --git a/apps/dav/tests/unit/Connector/Sabre/RequestTest/UploadTest.php b/apps/dav/tests/unit/Connector/Sabre/RequestTest/UploadTest.php
index 60decd4c846..5c6d0f03334 100644
--- a/apps/dav/tests/unit/Connector/Sabre/RequestTest/UploadTest.php
+++ b/apps/dav/tests/unit/Connector/Sabre/RequestTest/UploadTest.php
@@ -1,5 +1,6 @@
<?php
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -19,7 +20,7 @@ use OCP\Lock\ILockingProvider;
*/
class UploadTest extends RequestTestCase {
public function testBasicUpload(): void {
- $user = $this->getUniqueID();
+ $user = self::getUniqueID();
$view = $this->setupUser($user, 'pass');
$this->assertFalse($view->file_exists('foo.txt'));
@@ -35,7 +36,7 @@ class UploadTest extends RequestTestCase {
}
public function testUploadOverWrite(): void {
- $user = $this->getUniqueID();
+ $user = self::getUniqueID();
$view = $this->setupUser($user, 'pass');
$view->file_put_contents('foo.txt', 'foobar');
@@ -51,7 +52,7 @@ class UploadTest extends RequestTestCase {
}
public function testUploadOverWriteReadLocked(): void {
- $user = $this->getUniqueID();
+ $user = self::getUniqueID();
$view = $this->setupUser($user, 'pass');
$view->file_put_contents('foo.txt', 'bar');
@@ -63,7 +64,7 @@ class UploadTest extends RequestTestCase {
}
public function testUploadOverWriteWriteLocked(): void {
- $user = $this->getUniqueID();
+ $user = self::getUniqueID();
$view = $this->setupUser($user, 'pass');
$this->loginAsUser($user);
diff --git a/apps/dav/tests/unit/Connector/Sabre/SharesPluginTest.php b/apps/dav/tests/unit/Connector/Sabre/SharesPluginTest.php
index 97d3ba79046..00ac5b5543f 100644
--- a/apps/dav/tests/unit/Connector/Sabre/SharesPluginTest.php
+++ b/apps/dav/tests/unit/Connector/Sabre/SharesPluginTest.php
@@ -1,5 +1,6 @@
<?php
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -17,35 +18,17 @@ use OCP\IUser;
use OCP\IUserSession;
use OCP\Share\IManager;
use OCP\Share\IShare;
+use PHPUnit\Framework\MockObject\MockObject;
use Sabre\DAV\Tree;
class SharesPluginTest extends \Test\TestCase {
public const SHARETYPES_PROPERTYNAME = SharesPlugin::SHARETYPES_PROPERTYNAME;
- /**
- * @var \Sabre\DAV\Server
- */
- private $server;
-
- /**
- * @var \Sabre\DAV\Tree
- */
- private $tree;
-
- /**
- * @var \OCP\Share\IManager
- */
- private $shareManager;
-
- /**
- * @var Folder
- */
- private $userFolder;
-
- /**
- * @var SharesPlugin
- */
- private $plugin;
+ private \Sabre\DAV\Server $server;
+ private \Sabre\DAV\Tree&MockObject $tree;
+ private \OCP\Share\IManager&MockObject $shareManager;
+ private Folder&MockObject $userFolder;
+ private SharesPlugin $plugin;
protected function setUp(): void {
parent::setUp();
@@ -74,10 +57,8 @@ class SharesPluginTest extends \Test\TestCase {
/**
* @dataProvider sharesGetPropertiesDataProvider
*/
- public function testGetProperties($shareTypes): void {
- $sabreNode = $this->getMockBuilder(Node::class)
- ->disableOriginalConstructor()
- ->getMock();
+ public function testGetProperties(array $shareTypes): void {
+ $sabreNode = $this->createMock(Node::class);
$sabreNode->expects($this->any())
->method('getId')
->willReturn(123);
@@ -86,9 +67,7 @@ class SharesPluginTest extends \Test\TestCase {
->willReturn('/subdir');
// node API nodes
- $node = $this->getMockBuilder(Folder::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $node = $this->createMock(Folder::class);
$sabreNode->method('getNode')
->willReturn($node);
@@ -143,7 +122,7 @@ class SharesPluginTest extends \Test\TestCase {
/**
* @dataProvider sharesGetPropertiesDataProvider
*/
- public function testPreloadThenGetProperties($shareTypes): void {
+ public function testPreloadThenGetProperties(array $shareTypes): void {
$sabreNode1 = $this->createMock(File::class);
$sabreNode1->method('getId')
->willReturn(111);
@@ -182,7 +161,7 @@ class SharesPluginTest extends \Test\TestCase {
->willReturn($node2);
$dummyShares = array_map(function ($type) {
- $share = $this->getMockBuilder(IShare::class)->getMock();
+ $share = $this->createMock(IShare::class);
$share->expects($this->any())
->method('getShareType')
->willReturn($type);
@@ -268,7 +247,7 @@ class SharesPluginTest extends \Test\TestCase {
$this->assertEquals($shareTypes, $result[200][self::SHARETYPES_PROPERTYNAME]->getShareTypes());
}
- public function sharesGetPropertiesDataProvider() {
+ public static function sharesGetPropertiesDataProvider(): array {
return [
[[]],
[[IShare::TYPE_USER]],
@@ -287,9 +266,7 @@ class SharesPluginTest extends \Test\TestCase {
}
public function testGetPropertiesSkipChunks(): void {
- $sabreNode = $this->getMockBuilder(UploadFile::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $sabreNode = $this->createMock(UploadFile::class);
$propFind = new \Sabre\DAV\PropFind(
'/dummyPath',
diff --git a/apps/dav/tests/unit/Connector/Sabre/TagsPluginTest.php b/apps/dav/tests/unit/Connector/Sabre/TagsPluginTest.php
index 43c08a1a61c..bef508e08ca 100644
--- a/apps/dav/tests/unit/Connector/Sabre/TagsPluginTest.php
+++ b/apps/dav/tests/unit/Connector/Sabre/TagsPluginTest.php
@@ -1,5 +1,6 @@
<?php
+declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2014-2016 ownCloud, Inc.
@@ -18,6 +19,7 @@ use OCP\ITagManager;
use OCP\ITags;
use OCP\IUser;
use OCP\IUserSession;
+use PHPUnit\Framework\MockObject\MockObject;
use Sabre\DAV\Tree;
class TagsPluginTest extends \Test\TestCase {
@@ -25,61 +27,24 @@ class TagsPluginTest extends \Test\TestCase {
public const FAVORITE_PROPERTYNAME = TagsPlugin::FAVORITE_PROPERTYNAME;
public const TAG_FAVORITE = TagsPlugin::TAG_FAVORITE;
- /**
- * @var \Sabre\DAV\Server
- */
- private $server;
-
- /**
- * @var Tree
- */
- private $tree;
-
- /**
- * @var ITagManager
- */
- private $tagManager;
-
- /**
- * @var ITags
- */
- private $tagger;
-
- /**
- * @var IEventDispatcher
- */
- private $eventDispatcher;
-
- /**
- * @var IUserSession
- */
- private $userSession;
-
- /**
- * @var TagsPlugin
- */
- private $plugin;
+ private \Sabre\DAV\Server $server;
+ private Tree&MockObject $tree;
+ private ITagManager&MockObject $tagManager;
+ private ITags&MockObject $tagger;
+ private IEventDispatcher&MockObject $eventDispatcher;
+ private IUserSession&MockObject $userSession;
+ private TagsPlugin $plugin;
protected function setUp(): void {
parent::setUp();
+
$this->server = new \Sabre\DAV\Server();
- $this->tree = $this->getMockBuilder(Tree::class)
- ->disableOriginalConstructor()
- ->getMock();
- $this->tagger = $this->getMockBuilder(ITags::class)
- ->disableOriginalConstructor()
- ->getMock();
- $this->tagManager = $this->getMockBuilder(ITagManager::class)
- ->disableOriginalConstructor()
- ->getMock();
-
- $this->eventDispatcher = $this->getMockBuilder(IEventDispatcher::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $this->tree = $this->createMock(Tree::class);
+ $this->tagger = $this->createMock(ITags::class);
+ $this->tagManager = $this->createMock(ITagManager::class);
+ $this->eventDispatcher = $this->createMock(IEventDispatcher::class);
$user = $this->createMock(IUser::class);
- /**
- * @var IUserSession
- */
+
$this->userSession = $this->createMock(IUserSession::class);
$this->userSession->expects($this->any())
->method('getUser')
@@ -96,10 +61,8 @@ class TagsPluginTest extends \Test\TestCase {
/**
* @dataProvider tagsGetPropertiesDataProvider
*/
- public function testGetProperties($tags, $requestedProperties, $expectedProperties): void {
- $node = $this->getMockBuilder(Node::class)
- ->disableOriginalConstructor()
- ->getMock();
+ public function testGetProperties(array $tags, array $requestedProperties, array $expectedProperties): void {
+ $node = $this->createMock(Node::class);
$node->expects($this->any())
->method('getId')
->willReturn(123);
@@ -135,16 +98,12 @@ class TagsPluginTest extends \Test\TestCase {
/**
* @dataProvider tagsGetPropertiesDataProvider
*/
- public function testPreloadThenGetProperties($tags, $requestedProperties, $expectedProperties): void {
- $node1 = $this->getMockBuilder(File::class)
- ->disableOriginalConstructor()
- ->getMock();
+ public function testPreloadThenGetProperties(array $tags, array $requestedProperties, array $expectedProperties): void {
+ $node1 = $this->createMock(File::class);
$node1->expects($this->any())
->method('getId')
->willReturn(111);
- $node2 = $this->getMockBuilder(File::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $node2 = $this->createMock(File::class);
$node2->expects($this->any())
->method('getId')
->willReturn(222);
@@ -157,9 +116,7 @@ class TagsPluginTest extends \Test\TestCase {
$expectedCallCount = 1;
}
- $node = $this->getMockBuilder(Directory::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $node = $this->createMock(Directory::class);
$node->expects($this->any())
->method('getId')
->willReturn(123);
@@ -214,7 +171,7 @@ class TagsPluginTest extends \Test\TestCase {
$this->assertEquals($expectedProperties, $result);
}
- public function tagsGetPropertiesDataProvider() {
+ public static function tagsGetPropertiesDataProvider(): array {
return [
// request both, receive both
[
@@ -270,9 +227,7 @@ class TagsPluginTest extends \Test\TestCase {
}
public function testGetPropertiesSkipChunks(): void {
- $sabreNode = $this->getMockBuilder(UploadFile::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $sabreNode = $this->createMock(UploadFile::class);
$propFind = new \Sabre\DAV\PropFind(
'/dummyPath',
@@ -292,9 +247,7 @@ class TagsPluginTest extends \Test\TestCase {
public function testUpdateTags(): void {
// this test will replace the existing tags "tagremove" with "tag1" and "tag2"
// and keep "tagkeep"
- $node = $this->getMockBuilder(Node::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $node = $this->createMock(Node::class);
$node->expects($this->any())
->method('getId')
->willReturn(123);
@@ -310,12 +263,16 @@ class TagsPluginTest extends \Test\TestCase {
->willReturn([123 => ['tagkeep', 'tagremove', self::TAG_FAVORITE]]);
// then tag as tag1 and tag2
- $this->tagger->expects($this->exactly(2))
+ $calls = [
+ [123, 'tag1'],
+ [123, 'tag2'],
+ ];
+ $this->tagger->expects($this->exactly(count($calls)))
->method('tagAs')
- ->withConsecutive(
- [123, 'tag1'],
- [123, 'tag2'],
- );
+ ->willReturnCallback(function () use (&$calls) {
+ $expected = array_shift($calls);
+ $this->assertEquals($expected, func_get_args());
+ });
// it will untag tag3
$this->tagger->expects($this->once())
@@ -339,13 +296,11 @@ class TagsPluginTest extends \Test\TestCase {
$result = $propPatch->getResult();
$this->assertEquals(200, $result[self::TAGS_PROPERTYNAME]);
- $this->assertFalse(isset($result[self::FAVORITE_PROPERTYNAME]));
+ $this->assertArrayNotHasKey(self::FAVORITE_PROPERTYNAME, $result);
}
public function testUpdateTagsFromScratch(): void {
- $node = $this->getMockBuilder(Node::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $node = $this->createMock(Node::class);
$node->expects($this->any())
->method('getId')
->willReturn(123);
@@ -361,12 +316,16 @@ class TagsPluginTest extends \Test\TestCase {
->willReturn([]);
// then tag as tag1 and tag2
- $this->tagger->expects($this->exactly(2))
+ $calls = [
+ [123, 'tag1'],
+ [123, 'tag2'],
+ ];
+ $this->tagger->expects($this->exactly(count($calls)))
->method('tagAs')
- ->withConsecutive(
- [123, 'tag1'],
- [123, 'tag2'],
- );
+ ->willReturnCallback(function () use (&$calls) {
+ $expected = array_shift($calls);
+ $this->assertEquals($expected, func_get_args());
+ });
// properties to set
$propPatch = new \Sabre\DAV\PropPatch([
@@ -385,15 +344,13 @@ class TagsPluginTest extends \Test\TestCase {
$result = $propPatch->getResult();
$this->assertEquals(200, $result[self::TAGS_PROPERTYNAME]);
- $this->assertFalse(false, isset($result[self::FAVORITE_PROPERTYNAME]));
+ $this->assertArrayNotHasKey(self::FAVORITE_PROPERTYNAME, $result);
}
public function testUpdateFav(): void {
// this test will replace the existing tags "tagremove" with "tag1" and "tag2"
// and keep "tagkeep"
- $node = $this->getMockBuilder(Node::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $node = $this->createMock(Node::class);
$node->expects($this->any())
->method('getId')
->willReturn(123);
@@ -424,8 +381,8 @@ class TagsPluginTest extends \Test\TestCase {
$this->assertEmpty($propPatch->getRemainingMutations());
$result = $propPatch->getResult();
- $this->assertFalse(false, isset($result[self::TAGS_PROPERTYNAME]));
- $this->assertEquals(200, isset($result[self::FAVORITE_PROPERTYNAME]));
+ $this->assertArrayNotHasKey(self::TAGS_PROPERTYNAME, $result);
+ $this->assertEquals(200, $result[self::FAVORITE_PROPERTYNAME]);
// unfavorite now
// set favorite tag
@@ -449,7 +406,7 @@ class TagsPluginTest extends \Test\TestCase {
$this->assertEmpty($propPatch->getRemainingMutations());
$result = $propPatch->getResult();
- $this->assertFalse(false, isset($result[self::TAGS_PROPERTYNAME]));
- $this->assertEquals(200, isset($result[self::FAVORITE_PROPERTYNAME]));
+ $this->assertArrayNotHasKey(self::TAGS_PROPERTYNAME, $result);
+ $this->assertEquals(200, $result[self::FAVORITE_PROPERTYNAME]);
}
}