From 641c663e080fd69624b6aa2ad7f716f52da36e41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Fri, 13 Jul 2018 12:13:16 +0200 Subject: [PATCH] Remove deprecated interface OCP\Files\Storage in favor of OCP\Files\Storage\IStorage --- apps/dav/lib/Connector/Sabre/File.php | 4 +- .../tests/unit/Connector/Sabre/FileTest.php | 2 +- .../tests/unit/Connector/Sabre/NodeTest.php | 27 +- apps/federation/tests/DbHandlerTest.php | 8 +- apps/files_sharing/lib/SharedStorage.php | 6 +- .../tests/API/Share20OCSTest.php | 465 +++++++++--------- .../files_sharing/tests/MountProviderTest.php | 34 +- .../files_sharing/tests/SharedStorageTest.php | 4 +- lib/private/Encryption/EncryptionWrapper.php | 4 +- .../Auth/Password/SessionCredentials.php | 2 +- lib/private/Files/External/PersonalMount.php | 2 +- .../Files/External/SessionStorageWrapper.php | 1 - .../Files/External/StorageModifierTrait.php | 6 +- .../Files/Meta/MetaFileVersionNode.php | 2 +- .../Files/ObjectStore/ObjectStoreStorage.php | 3 +- lib/private/Files/Storage/Common.php | 11 +- lib/private/Files/Storage/FailedStorage.php | 5 +- lib/private/Files/Storage/Local.php | 18 +- lib/private/Files/Storage/Storage.php | 3 +- lib/private/Files/Storage/StorageFactory.php | 5 +- .../Files/Storage/Wrapper/Availability.php | 5 +- .../Files/Storage/Wrapper/Encoding.php | 9 +- .../Files/Storage/Wrapper/Encryption.php | 14 +- lib/private/Files/Storage/Wrapper/Jail.php | 9 +- lib/private/Files/Storage/Wrapper/Quota.php | 9 +- lib/private/Files/Storage/Wrapper/Wrapper.php | 10 +- lib/private/Share20/Manager.php | 2 +- lib/private/legacy/util.php | 11 +- lib/public/Files/Node.php | 4 +- lib/public/Files/Storage.php | 459 ----------------- lib/public/Files/Storage/IStorage.php | 10 +- tests/lib/Files/Mount/MountPointTest.php | 22 +- tests/lib/Files/Node/NodeTest.php | 125 ++--- tests/lib/Files/Storage/Storage.php | 3 +- .../lib/Files/Storage/StorageFactoryTest.php | 17 +- .../Files/Storage/Wrapper/EncryptionTest.php | 89 ++-- tests/lib/Files/ViewTest.php | 5 +- tests/lib/Share20/ManagerTest.php | 270 +++++----- 38 files changed, 646 insertions(+), 1039 deletions(-) delete mode 100644 lib/public/Files/Storage.php diff --git a/apps/dav/lib/Connector/Sabre/File.php b/apps/dav/lib/Connector/Sabre/File.php index b591ead2bbdc..2e02dd07bb42 100644 --- a/apps/dav/lib/Connector/Sabre/File.php +++ b/apps/dav/lib/Connector/Sabre/File.php @@ -437,7 +437,7 @@ public function getDirectDownload() { if (\OCP\App::isEnabled('encryption')) { return []; } - /** @var \OCP\Files\Storage $storage */ + /** @var \OCP\Files\Storage\IStorage $storage */ list($storage, $internalPath) = $this->fileView->resolvePath($this->path); if ($storage === null) { return []; @@ -610,7 +610,7 @@ private static function isChecksumValid(Storage $storage, $path) { * or whether the file can be assembled/uploaded directly on the * target storage. * - * @param \OCP\Files\Storage $storage + * @param \OCP\Files\Storage\IStorage $storage * @return bool true if the storage needs part file handling */ private function needsPartFile($storage) { diff --git a/apps/dav/tests/unit/Connector/Sabre/FileTest.php b/apps/dav/tests/unit/Connector/Sabre/FileTest.php index 4e30f1813c6a..b8c1be742420 100644 --- a/apps/dav/tests/unit/Connector/Sabre/FileTest.php +++ b/apps/dav/tests/unit/Connector/Sabre/FileTest.php @@ -98,7 +98,7 @@ public function tearDown() { * @return \PHPUnit_Framework_MockObject_MockObject | Storage */ private function getMockStorage() { - $storage = $this->createMock(Storage::class); + $storage = $this->createMock(Storage\IStorage::class); $storage->expects($this->any()) ->method('getId') ->will($this->returnValue('home::someuser')); diff --git a/apps/dav/tests/unit/Connector/Sabre/NodeTest.php b/apps/dav/tests/unit/Connector/Sabre/NodeTest.php index 75917ce2420f..3c9cef7ab4d5 100644 --- a/apps/dav/tests/unit/Connector/Sabre/NodeTest.php +++ b/apps/dav/tests/unit/Connector/Sabre/NodeTest.php @@ -25,6 +25,13 @@ namespace OCA\DAV\Tests\unit\Connector\Sabre; +use OCP\Files\Storage\IStorage; +use OC\Files\View; +use OC\Files\FileInfo; +use OCP\Share\IShare; +use OCP\Share\IManager; +use OCP\Files\Mount\IMountPoint; + /** * Class NodeTest * @@ -50,7 +57,7 @@ public function davPermissionsProvider() { * @dataProvider davPermissionsProvider */ public function testDavPermissions($permissions, $type, $shared, $mounted, $expected) { - $info = $this->getMockBuilder('\OC\Files\FileInfo') + $info = $this->getMockBuilder(FileInfo::class) ->disableOriginalConstructor() ->setMethods(['getPermissions', 'isShared', 'isMounted', 'getType']) ->getMock(); @@ -66,7 +73,7 @@ public function testDavPermissions($permissions, $type, $shared, $mounted, $expe $info->expects($this->any()) ->method('getType') ->will($this->returnValue($type)); - $view = $this->createMock('\OC\Files\View'); + $view = $this->createMock(View::class); $node = new \OCA\DAV\Connector\Sabre\File($view, $info); $this->assertEquals($expected, $node->getDavPermissions()); @@ -116,13 +123,13 @@ public function sharePermissionsProvider() { * @dataProvider sharePermissionsProvider */ public function testSharePermissions($type, $user, $permissions, $expected) { - $storage = $this->createMock('\OCP\Files\Storage'); + $storage = $this->createMock(IStorage::class); $storage->method('getPermissions')->willReturn($permissions); - $mountpoint = $this->createMock('\OCP\Files\Mount\IMountPoint'); + $mountpoint = $this->createMock(IMountPoint::class); $mountpoint->method('getMountPoint')->willReturn('myPath'); - $shareManager = $this->getMockBuilder('OCP\Share\IManager')->disableOriginalConstructor()->getMock(); - $share = $this->getMockBuilder('OCP\Share\IShare')->disableOriginalConstructor()->getMock(); + $shareManager = $this->getMockBuilder(IManager::class)->disableOriginalConstructor()->getMock(); + $share = $this->getMockBuilder(IShare::class)->disableOriginalConstructor()->getMock(); if ($user === null) { $shareManager->expects($this->never())->method('getShareByToken'); @@ -133,7 +140,7 @@ public function testSharePermissions($type, $user, $permissions, $expected) { $share->expects($this->once())->method('getPermissions')->willReturn($permissions); } - $info = $this->getMockBuilder('\OC\Files\FileInfo') + $info = $this->getMockBuilder(FileInfo::class) ->disableOriginalConstructor() ->setMethods(['getStorage', 'getType', 'getMountPoint']) ->getMock(); @@ -142,7 +149,7 @@ public function testSharePermissions($type, $user, $permissions, $expected) { $info->method('getType')->willReturn($type); $info->method('getMountPoint')->willReturn($mountpoint); - $view = $this->createMock('\OC\Files\View'); + $view = $this->createMock(View::class); $node = new \OCA\DAV\Connector\Sabre\File($view, $info); $this->invokePrivate($node, 'shareManager', [$shareManager]); @@ -163,14 +170,14 @@ public function fileIdProvider() { * @dataProvider fileIdProvider */ public function testFileId($instanceid, $numericid, $fullid) { - $info = $this->getMockBuilder('\OC\Files\FileInfo') + $info = $this->getMockBuilder(FileInfo::class) ->disableOriginalConstructor() ->setMethods(['getId']) ->getMock(); $info->expects($this->any()) ->method('getId') ->will($this->returnValue($numericid)); - $view = $this->createMock('\OC\Files\View'); + $view = $this->createMock(View::class); \OC::$server->getSystemConfig()->setValue('instanceid', $instanceid); diff --git a/apps/federation/tests/DbHandlerTest.php b/apps/federation/tests/DbHandlerTest.php index 6b41c9ec6d11..c8825149ddcc 100644 --- a/apps/federation/tests/DbHandlerTest.php +++ b/apps/federation/tests/DbHandlerTest.php @@ -50,7 +50,7 @@ public function setUp() { parent::setUp(); $this->connection = \OC::$server->getDatabaseConnection(); - $this->il10n = $this->createMock('OCP\IL10N'); + $this->il10n = $this->createMock(IL10N::class); $this->dbHandler = new DbHandler( $this->connection, @@ -74,6 +74,7 @@ public function tearDown() { * @param string $url passed to the method * @param string $expectedUrl the url we expect to be written to the db * @param string $expectedHash the hash value we expect to be written to the db + * @throws \OC\HintException */ public function testAddServer($url, $expectedUrl, $expectedHash) { $id = $this->dbHandler->addServer($url); @@ -141,6 +142,7 @@ public function testGetAll() { * @param string $serverInTable * @param string $checkForServer * @param bool $expected + * @throws \OC\HintException */ public function testServerExists($serverInTable, $checkForServer, $expected) { $this->dbHandler->addServer($serverInTable); @@ -272,6 +274,10 @@ public function dataTestNormalizeUrl() { /** * @dataProvider providesAuth + * @param $expectedResult + * @param $user + * @param $password + * @throws \OC\HintException */ public function testAuth($expectedResult, $user, $password) { if ($expectedResult) { diff --git a/apps/files_sharing/lib/SharedStorage.php b/apps/files_sharing/lib/SharedStorage.php index 48bec47a0f2d..096435fedd1e 100644 --- a/apps/files_sharing/lib/SharedStorage.php +++ b/apps/files_sharing/lib/SharedStorage.php @@ -374,7 +374,7 @@ public function unshareStorage() { * @throws \OCP\Lock\LockedException */ public function acquireLock($path, $type, ILockingProvider $provider) { - /** @var \OCP\Files\Storage $targetStorage */ + /** @var \OCP\Files\Storage\IStorage $targetStorage */ list($targetStorage, $targetInternalPath) = $this->resolvePath($path); $targetStorage->acquireLock($targetInternalPath, $type, $provider); // lock the parent folders of the owner when locking the share as recipient @@ -390,7 +390,7 @@ public function acquireLock($path, $type, ILockingProvider $provider) { * @param \OCP\Lock\ILockingProvider $provider */ public function releaseLock($path, $type, ILockingProvider $provider) { - /** @var \OCP\Files\Storage $targetStorage */ + /** @var \OCP\Files\Storage\IStorage $targetStorage */ list($targetStorage, $targetInternalPath) = $this->resolvePath($path); $targetStorage->releaseLock($targetInternalPath, $type, $provider); // unlock the parent folders of the owner when unlocking the share as recipient @@ -406,7 +406,7 @@ public function releaseLock($path, $type, ILockingProvider $provider) { * @param \OCP\Lock\ILockingProvider $provider */ public function changeLock($path, $type, ILockingProvider $provider) { - /** @var \OCP\Files\Storage $targetStorage */ + /** @var \OCP\Files\Storage\IStorage $targetStorage */ list($targetStorage, $targetInternalPath) = $this->resolvePath($path); $targetStorage->changeLock($targetInternalPath, $type, $provider); } diff --git a/apps/files_sharing/tests/API/Share20OCSTest.php b/apps/files_sharing/tests/API/Share20OCSTest.php index 6bb73ebdb409..d75fb31a65b1 100644 --- a/apps/files_sharing/tests/API/Share20OCSTest.php +++ b/apps/files_sharing/tests/API/Share20OCSTest.php @@ -30,6 +30,7 @@ use OCA\Files_Sharing\SharingBlacklist; use OCP\Files\IRootFolder; use OCP\Files\NotFoundException; +use OCP\Files\Storage\IStorage; use OCP\IConfig; use OCP\IGroupManager; use OCP\IL10N; @@ -38,6 +39,7 @@ use OCP\IUser; use OCP\IGroup; use OCP\IUserManager; +use OCP\Lock\ILockingProvider; use OCP\Lock\LockedException; use OCP\Share; use Symfony\Component\EventDispatcher\EventDispatcher; @@ -46,6 +48,12 @@ use OCP\Files\Folder; use OCP\Files\Node; use OCP\Share\Exceptions\ShareNotFound; +use OCP\Share\IManager; +use OCP\Files\Cache\ICache; +use OCP\Files\File; +use OCA\Files_Sharing\External\Storage; +use OCP\Share\IShare; +use OC\Files\Cache\Cache; /** * Class Share20OCSTest @@ -70,6 +78,9 @@ class Share20OCSTest extends TestCase { /** @var IRootFolder | \PHPUnit_Framework_MockObject_MockObject */ private $rootFolder; + /** @var IConfig | \PHPUnit_Framework_MockObject_MockObject */ + private $config; + /** @var IURLGenerator */ private $urlGenerator; @@ -90,24 +101,24 @@ class Share20OCSTest extends TestCase { private $sharingBlacklist; protected function setUp() { - $this->shareManager = $this->getMockBuilder('OCP\Share\IManager') + $this->shareManager = $this->getMockBuilder(IManager::class) ->disableOriginalConstructor() ->getMock(); $this->shareManager ->expects($this->any()) ->method('shareApiEnabled') ->willReturn(true); - $this->groupManager = $this->createMock('OCP\IGroupManager'); - $this->userManager = $this->createMock('OCP\IUserManager'); - $this->request = $this->createMock('OCP\IRequest'); - $this->rootFolder = $this->createMock('OCP\Files\IRootFolder'); - $this->urlGenerator = $this->createMock('OCP\IURLGenerator'); - $this->currentUser = $this->createMock('OCP\IUser'); + $this->groupManager = $this->createMock(IGroupManager::class); + $this->userManager = $this->createMock(IUserManager::class); + $this->request = $this->createMock(IRequest::class); + $this->rootFolder = $this->createMock(IRootFolder::class); + $this->urlGenerator = $this->createMock(IURLGenerator::class); + $this->currentUser = $this->createMock(IUser::class); $this->currentUser->method('getUID')->willReturn('currentUser'); $this->userManager->expects($this->any())->method('userExists')->willReturn(true); - $this->l = $this->createMock('\OCP\IL10N'); + $this->l = $this->createMock(IL10N::class); $this->l->method('t') ->will($this->returnCallback(function ($text, $parameters = []) { return \vsprintf($text, $parameters); @@ -144,8 +155,11 @@ public function tearDown() { parent::tearDown(); } + /** + * @return Share20OCS | \PHPUnit_Framework_MockObject_MockObject + */ private function mockFormatShare() { - return $this->getMockBuilder(\OCA\Files_Sharing\API\Share20OCS::class) + return $this->getMockBuilder(Share20OCS::class) ->setConstructorArgs([ $this->shareManager, $this->groupManager, @@ -187,7 +201,7 @@ public function testDeleteShareShareNotFound() { ->method('getShareById') ->will($this->returnCallback(function ($id) { if ($id === 'ocinternal:42' || $id === 'ocFederatedSharing:42') { - throw new \OCP\Share\Exceptions\ShareNotFound(); + throw new ShareNotFound(); } else { throw new \Exception(); } @@ -195,12 +209,12 @@ public function testDeleteShareShareNotFound() { $this->shareManager->method('outgoingServer2ServerSharesAllowed')->willReturn(true); - $expected = new \OC\OCS\Result(null, 404, 'Wrong share ID, share doesn\'t exist'); + $expected = new Result(null, 404, 'Wrong share ID, share doesn\'t exist'); $this->assertEquals($expected, $this->ocs->deleteShare(42)); } public function testDeleteShare() { - $node = $this->createMock('\OCP\Files\File'); + $node = $this->createMock(File::class); $share = $this->newShare(); $share->setSharedBy($this->currentUser->getUID()) @@ -217,17 +231,17 @@ public function testDeleteShare() { $node->expects($this->once()) ->method('lock') - ->with(\OCP\Lock\ILockingProvider::LOCK_SHARED); + ->with(ILockingProvider::LOCK_SHARED); $node->expects($this->once()) ->method('unlock') - ->with(\OCP\Lock\ILockingProvider::LOCK_SHARED); + ->with(ILockingProvider::LOCK_SHARED); - $expected = new \OC\OCS\Result(); + $expected = new Result(); $this->assertEquals($expected, $this->ocs->deleteShare(42)); } public function testDeleteShareLocked() { - $node = $this->createMock('\OCP\Files\File'); + $node = $this->createMock(File::class); $share = $this->newShare(); $share->setSharedBy($this->currentUser->getUID()) @@ -244,13 +258,13 @@ public function testDeleteShareLocked() { $node->expects($this->once()) ->method('lock') - ->with(\OCP\Lock\ILockingProvider::LOCK_SHARED) + ->with(ILockingProvider::LOCK_SHARED) ->will($this->throwException(new LockedException('mypath'))); $node->expects($this->never()) ->method('unlock') - ->with(\OCP\Lock\ILockingProvider::LOCK_SHARED); + ->with(ILockingProvider::LOCK_SHARED); - $expected = new \OC\OCS\Result(null, 404, 'could not delete share'); + $expected = new Result(null, 404, 'could not delete share'); $this->assertEquals($expected, $this->ocs->deleteShare(42)); } @@ -272,7 +286,7 @@ public function testGetGetShareNotExists() { public function createShare($id, $shareType, $sharedWith, $sharedBy, $shareOwner, $path, $permissions, $shareTime, $expiration, $parent, $target, $mail_send, $token=null, $password=null, $name=null) { - $share = $this->createMock('\OCP\Share\IShare'); + $share = $this->createMock(IShare::class); $share->method('getId')->willReturn($id); $share->method('getShareType')->willReturn($shareType); $share->method('getSharedWith')->willReturn($sharedWith); @@ -302,28 +316,28 @@ public function createShare($id, $shareType, $sharedWith, $sharedBy, $shareOwner public function dataGetShare() { $data = []; - $cache = $this->getMockBuilder('OC\Files\Cache\Cache') + $cache = $this->getMockBuilder(Cache::class) ->disableOriginalConstructor() ->getMock(); $cache->method('getNumericStorageId')->willReturn(101); - $storage = $this->getMockBuilder('OC\Files\Storage\Storage') + $storage = $this->getMockBuilder(\OC\Files\Storage\Storage::class) ->disableOriginalConstructor() ->getMock(); $storage->method('getId')->willReturn('STORAGE'); $storage->method('getCache')->willReturn($cache); - $parentFolder = $this->createMock('OCP\Files\Folder'); + $parentFolder = $this->createMock(Folder::class); $parentFolder->method('getId')->willReturn(3); - $file = $this->createMock('OCP\Files\File'); + $file = $this->createMock(File::class); $file->method('getId')->willReturn(1); $file->method('getPath')->willReturn('file'); $file->method('getStorage')->willReturn($storage); $file->method('getParent')->willReturn($parentFolder); $file->method('getMimeType')->willReturn('myMimeType'); - $folder = $this->createMock('OCP\Files\Folder'); + $folder = $this->createMock(Folder::class); $folder->method('getId')->willReturn(2); $folder->method('getPath')->willReturn('folder'); $folder->method('getStorage')->willReturn($storage); @@ -470,7 +484,7 @@ public function dataGetShare() { * @dataProvider dataGetShare */ public function testGetShare(\OCP\Share\IShare $share, array $result) { - $ocs = $this->getMockBuilder('OCA\Files_Sharing\API\Share20OCS') + $ocs = $this->getMockBuilder(Share20OCS::class) ->setConstructorArgs([ $this->shareManager, $this->groupManager, @@ -495,7 +509,7 @@ public function testGetShare(\OCP\Share\IShare $share, array $result) { ->with($share->getFullId()) ->willReturn($share); - $userFolder = $this->createMock('OCP\Files\Folder'); + $userFolder = $this->createMock(Folder::class); $userFolder ->method('getRelativePath') ->will($this->returnArgument(0)); @@ -512,19 +526,19 @@ public function testGetShare(\OCP\Share\IShare $share, array $result) { ->method('linkToRouteAbsolute') ->willReturn('url'); - $initiator = $this->createMock('OCP\IUser'); + $initiator = $this->createMock(IUser::class); $initiator->method('getUID')->willReturn('initiatorId'); $initiator->method('getDisplayName')->willReturn('initiatorDisplay'); - $owner = $this->createMock('OCP\IUser'); + $owner = $this->createMock(IUser::class); $owner->method('getUID')->willReturn('ownerId'); $owner->method('getDisplayName')->willReturn('ownerDisplay'); - $user = $this->createMock('OCP\IUser'); + $user = $this->createMock(IUser::class); $user->method('getUID')->willReturn('userId'); $user->method('getDisplayName')->willReturn('userDisplay'); - $group = $this->createMock('OCP\IGroup'); + $group = $this->createMock(IGroup::class); $group->method('getGID')->willReturn('groupId'); $this->userManager->method('get')->will($this->returnValueMap([ @@ -536,7 +550,7 @@ public function testGetShare(\OCP\Share\IShare $share, array $result) { ['group', $group], ])); - $expected = new \OC\OCS\Result([$result]); + $expected = new Result([$result]); $this->assertEquals($expected->getData(), $ocs->getShare($share->getId())->getData()); } @@ -552,36 +566,36 @@ public function testGetShareInvalidNode() { ->with('ocinternal:42') ->willReturn($share); - $expected = new \OC\OCS\Result(null, 404, 'Wrong share ID, share doesn\'t exist'); + $expected = new Result(null, 404, 'Wrong share ID, share doesn\'t exist'); $this->assertEquals($expected->getMeta(), $this->ocs->getShare(42)->getMeta()); } public function testCanAccessShare() { - $share = $this->createMock('OCP\Share\IShare'); + $share = $this->createMock(IShare::class); $share->method('getShareOwner')->willReturn($this->currentUser->getUID()); $this->assertTrue($this->invokePrivate($this->ocs, 'canAccessShare', [$share])); - $share = $this->createMock('OCP\Share\IShare'); + $share = $this->createMock(IShare::class); $share->method('getSharedBy')->willReturn($this->currentUser->getUID()); $this->assertTrue($this->invokePrivate($this->ocs, 'canAccessShare', [$share])); - $share = $this->createMock('OCP\Share\IShare'); + $share = $this->createMock(IShare::class); $share->method('getShareType')->willReturn(Share::SHARE_TYPE_USER); $share->method('getSharedWith')->willReturn($this->currentUser->getUID()); $this->assertTrue($this->invokePrivate($this->ocs, 'canAccessShare', [$share])); - $share = $this->createMock('OCP\Share\IShare'); + $share = $this->createMock(IShare::class); $share->method('getShareType')->willReturn(Share::SHARE_TYPE_USER); - $share->method('getSharedWith')->willReturn($this->createMock('OCP\IUser')); + $share->method('getSharedWith')->willReturn($this->createMock(IUser::class)); $this->assertFalse($this->invokePrivate($this->ocs, 'canAccessShare', [$share])); - $share = $this->createMock('OCP\Share\IShare'); + $share = $this->createMock(IShare::class); $share->method('getShareType')->willReturn(Share::SHARE_TYPE_GROUP); $share->method('getSharedWith')->willReturn('group'); - $group = $this->createMock('OCP\IGroup'); + $group = $this->createMock(IGroup::class); $group->method('inGroup')->with($this->currentUser)->willReturn(true); - $group2 = $this->createMock('OCP\IGroup'); + $group2 = $this->createMock(IGroup::class); $group2->method('inGroup')->with($this->currentUser)->willReturn(false); $this->groupManager->method('get')->will($this->returnValueMap([ @@ -591,30 +605,30 @@ public function testCanAccessShare() { ])); $this->assertTrue($this->invokePrivate($this->ocs, 'canAccessShare', [$share])); - $share = $this->createMock('OCP\Share\IShare'); + $share = $this->createMock(IShare::class); $share->method('getShareType')->willReturn(Share::SHARE_TYPE_GROUP); $share->method('getSharedWith')->willReturn('group2'); $this->assertFalse($this->invokePrivate($this->ocs, 'canAccessShare', [$share])); // null group - $share = $this->createMock('OCP\Share\IShare'); + $share = $this->createMock(IShare::class); $share->method('getShareType')->willReturn(\OCP\Share::SHARE_TYPE_GROUP); $share->method('getSharedWith')->willReturn('groupnull'); $this->assertFalse($this->invokePrivate($this->ocs, 'canAccessShare', [$share])); - $share = $this->createMock('OCP\Share\IShare'); + $share = $this->createMock(IShare::class); $share->method('getShareType')->willReturn(Share::SHARE_TYPE_LINK); $this->assertFalse($this->invokePrivate($this->ocs, 'canAccessShare', [$share])); // should not happen ever again, but who knows... let's cover it - $share = $this->createMock('OCP\Share\IShare'); + $share = $this->createMock(IShare::class); $share->method('getShareType')->willReturn(Share::SHARE_TYPE_USER); $share->method('getState')->willReturn(Share::STATE_ACCEPTED); $share->method('getPermissions')->willReturn(0); $this->assertFalse($this->invokePrivate($this->ocs, 'canAccessShare', [$share])); // legacy zero permission entries from group sub-shares, let it pass - $share = $this->createMock('OCP\Share\IShare'); + $share = $this->createMock(IShare::class); $share->method('getShareType')->willReturn(Share::SHARE_TYPE_GROUP); $share->method('getSharedWith')->willReturn('group'); $share->method('getState')->willReturn(Share::STATE_REJECTED); @@ -623,7 +637,7 @@ public function testCanAccessShare() { } public function testCreateShareNoPath() { - $expected = new \OC\OCS\Result(null, 404, 'Please specify a file or folder path'); + $expected = new Result(null, 404, 'Please specify a file or folder path'); $result = $this->ocs->createShare(); @@ -638,7 +652,7 @@ public function testCreateShareInvalidPath() { ['path', null, 'invalid-path'], ])); - $userFolder = $this->createMock('\OCP\Files\Folder'); + $userFolder = $this->createMock(Folder::class); $this->rootFolder->expects($this->once()) ->method('getUserFolder') ->with('currentUser') @@ -649,7 +663,7 @@ public function testCreateShareInvalidPath() { ->with('invalid-path') ->will($this->throwException(new \OCP\Files\NotFoundException())); - $expected = new \OC\OCS\Result(null, 404, 'Wrong path, file/folder doesn\'t exist'); + $expected = new Result(null, 404, 'Wrong path, file/folder doesn\'t exist'); $result = $this->ocs->createShare(); @@ -668,13 +682,13 @@ public function testCreateShareInvalidPermissions() { ['permissions', null, 32], ])); - $userFolder = $this->createMock('\OCP\Files\Folder'); + $userFolder = $this->createMock(Folder::class); $this->rootFolder->expects($this->once()) ->method('getUserFolder') ->with('currentUser') ->willReturn($userFolder); - $path = $this->createMock('\OCP\Files\File'); + $path = $this->createMock(File::class); $userFolder->expects($this->once()) ->method('get') ->with('valid-path') @@ -682,9 +696,9 @@ public function testCreateShareInvalidPermissions() { $path->expects($this->once()) ->method('lock') - ->with(\OCP\Lock\ILockingProvider::LOCK_SHARED); + ->with(ILockingProvider::LOCK_SHARED); - $expected = new \OC\OCS\Result(null, 404, 'invalid permissions'); + $expected = new Result(null, 404, 'invalid permissions'); $result = $this->ocs->createShare(); @@ -703,13 +717,13 @@ public function testCreateShareZeroPermissions() { ['permissions', null, 0], ])); - $userFolder = $this->createMock('\OCP\Files\Folder'); + $userFolder = $this->createMock(Folder::class); $this->rootFolder->expects($this->once()) ->method('getUserFolder') ->with('currentUser') ->willReturn($userFolder); - $path = $this->createMock('\OCP\Files\File'); + $path = $this->createMock(File::class); $userFolder->expects($this->once()) ->method('get') ->with('valid-path') @@ -717,9 +731,9 @@ public function testCreateShareZeroPermissions() { $path->expects($this->once()) ->method('lock') - ->with(\OCP\Lock\ILockingProvider::LOCK_SHARED); + ->with(ILockingProvider::LOCK_SHARED); - $expected = new \OC\OCS\Result(null, 400, 'Cannot remove all permissions'); + $expected = new Result(null, 400, 'Cannot remove all permissions'); $result = $this->ocs->createShare(); @@ -739,16 +753,16 @@ public function testCreateShareUserNoShareWith() { ['shareType', $this->any(), Share::SHARE_TYPE_USER], ])); - $userFolder = $this->createMock('\OCP\Files\Folder'); + $userFolder = $this->createMock(Folder::class); $this->rootFolder->expects($this->once()) ->method('getUserFolder') ->with('currentUser') ->willReturn($userFolder); - $path = $this->createMock('\OCP\Files\File'); - $storage = $this->createMock('OCP\Files\Storage'); + $path = $this->createMock(File::class); + $storage = $this->createMock(IStorage::class); $storage->method('instanceOfStorage') - ->with('OCA\Files_Sharing\External\Storage') + ->with(Storage::class) ->willReturn(false); $path->method('getStorage')->willReturn($storage); $userFolder->expects($this->once()) @@ -758,9 +772,9 @@ public function testCreateShareUserNoShareWith() { $path->expects($this->once()) ->method('lock') - ->with(\OCP\Lock\ILockingProvider::LOCK_SHARED); + ->with(ILockingProvider::LOCK_SHARED); - $expected = new \OC\OCS\Result(null, 404, 'Please specify a valid user'); + $expected = new Result(null, 404, 'Please specify a valid user'); $result = $this->ocs->createShare(); @@ -781,16 +795,16 @@ public function testCreateShareUserNoValidShareWith() { ['shareWith', $this->any(), 'invalidUser'], ])); - $userFolder = $this->createMock('\OCP\Files\Folder'); + $userFolder = $this->createMock(Folder::class); $this->rootFolder->expects($this->once()) ->method('getUserFolder') ->with('currentUser') ->willReturn($userFolder); - $path = $this->createMock('\OCP\Files\File'); - $storage = $this->createMock('OCP\Files\Storage'); + $path = $this->createMock(File::class); + $storage = $this->createMock(IStorage::class); $storage->method('instanceOfStorage') - ->with('OCA\Files_Sharing\External\Storage') + ->with(Storage::class) ->willReturn(false); $path->method('getStorage')->willReturn($storage); $userFolder->expects($this->once()) @@ -798,11 +812,11 @@ public function testCreateShareUserNoValidShareWith() { ->with('valid-path') ->willReturn($path); - $expected = new \OC\OCS\Result(null, 404, 'Please specify a valid user'); + $expected = new Result(null, 404, 'Please specify a valid user'); $path->expects($this->once()) ->method('lock') - ->with(\OCP\Lock\ILockingProvider::LOCK_SHARED); + ->with(ILockingProvider::LOCK_SHARED); $result = $this->ocs->createShare(); @@ -827,16 +841,16 @@ public function testCreateShareUser() { ['shareWith', null, 'validUser'], ])); - $userFolder = $this->createMock('\OCP\Files\Folder'); + $userFolder = $this->createMock(Folder::class); $this->rootFolder->expects($this->once()) ->method('getUserFolder') ->with('currentUser') ->willReturn($userFolder); - $path = $this->createMock('\OCP\Files\File'); - $storage = $this->createMock('OCP\Files\Storage'); + $path = $this->createMock(File::class); + $storage = $this->createMock(IStorage::class); $storage->method('instanceOfStorage') - ->with('OCA\Files_Sharing\External\Storage') + ->with(Storage::class) ->willReturn(false); $path->method('getStorage')->willReturn($storage); $userFolder->expects($this->once()) @@ -848,10 +862,10 @@ public function testCreateShareUser() { $path->expects($this->once()) ->method('lock') - ->with(\OCP\Lock\ILockingProvider::LOCK_SHARED); + ->with(ILockingProvider::LOCK_SHARED); $path->expects($this->once()) ->method('unlock') - ->with(\OCP\Lock\ILockingProvider::LOCK_SHARED); + ->with(ILockingProvider::LOCK_SHARED); $this->shareManager->method('createShare') ->with($this->callback(function (\OCP\Share\IShare $share) use ($path) { @@ -867,7 +881,7 @@ public function testCreateShareUser() { })) ->will($this->returnArgument(0)); - $expected = new \OC\OCS\Result(); + $expected = new Result(); $result = $ocs->createShare(); $this->assertEquals($expected->getMeta(), $result->getMeta()); @@ -888,16 +902,16 @@ public function testCreateShareGroupNoValidShareWith() { ['shareWith', $this->any(), 'invalidGroup'], ])); - $userFolder = $this->createMock('\OCP\Files\Folder'); + $userFolder = $this->createMock(Folder::class); $this->rootFolder->expects($this->once()) ->method('getUserFolder') ->with('currentUser') ->willReturn($userFolder); - $path = $this->createMock('\OCP\Files\File'); - $storage = $this->createMock('OCP\Files\Storage'); + $path = $this->createMock(File::class); + $storage = $this->createMock(IStorage::class); $storage->method('instanceOfStorage') - ->with('OCA\Files_Sharing\External\Storage') + ->with(Storage::class) ->willReturn(false); $path->method('getStorage')->willReturn($storage); $userFolder->expects($this->once()) @@ -905,11 +919,11 @@ public function testCreateShareGroupNoValidShareWith() { ->with('valid-path') ->willReturn($path); - $expected = new \OC\OCS\Result(null, 404, 'Please specify a valid user'); + $expected = new Result(null, 404, 'Please specify a valid user'); $path->expects($this->once()) ->method('lock') - ->with(\OCP\Lock\ILockingProvider::LOCK_SHARED); + ->with(ILockingProvider::LOCK_SHARED); $result = $this->ocs->createShare(); @@ -929,16 +943,16 @@ public function testCreateShareGroupBlacklisted() { ['shareWith', null, 'validGroup'], ])); - $userFolder = $this->createMock('\OCP\Files\Folder'); + $userFolder = $this->createMock(Folder::class); $this->rootFolder->expects($this->once()) ->method('getUserFolder') ->with('currentUser') ->willReturn($userFolder); - $path = $this->createMock('\OCP\Files\Folder'); - $storage = $this->createMock('OCP\Files\Storage'); + $path = $this->createMock(Folder::class); + $storage = $this->createMock(IStorage::class); $storage->method('instanceOfStorage') - ->with('OCA\Files_Sharing\External\Storage') + ->with(Storage::class) ->willReturn(false); $path->method('getStorage')->willReturn($storage); $userFolder->expects($this->once()) @@ -957,7 +971,7 @@ public function testCreateShareGroupBlacklisted() { $this->sharingBlacklist->method('isGroupBlacklisted')->willReturn(true); - $expected = new \OC\OCS\Result(null, 403, 'The group is blacklisted for sharing'); + $expected = new Result(null, 403, 'The group is blacklisted for sharing'); $result = $this->ocs->createShare(); @@ -980,16 +994,16 @@ public function testCreateShareGroup() { ['shareWith', null, 'validGroup'], ])); - $userFolder = $this->createMock('\OCP\Files\Folder'); + $userFolder = $this->createMock(Folder::class); $this->rootFolder->expects($this->once()) ->method('getUserFolder') ->with('currentUser') ->willReturn($userFolder); - $path = $this->createMock('\OCP\Files\Folder'); - $storage = $this->createMock('OCP\Files\Storage'); + $path = $this->createMock(Folder::class); + $storage = $this->createMock(IStorage::class); $storage->method('instanceOfStorage') - ->with('OCA\Files_Sharing\External\Storage') + ->with(Storage::class) ->willReturn(false); $path->method('getStorage')->willReturn($storage); $userFolder->expects($this->once()) @@ -1008,10 +1022,10 @@ public function testCreateShareGroup() { $path->expects($this->once()) ->method('lock') - ->with(\OCP\Lock\ILockingProvider::LOCK_SHARED); + ->with(ILockingProvider::LOCK_SHARED); $path->expects($this->once()) ->method('unlock') - ->with(\OCP\Lock\ILockingProvider::LOCK_SHARED); + ->with(ILockingProvider::LOCK_SHARED); $this->shareManager->method('createShare') ->with($this->callback(function (\OCP\Share\IShare $share) use ($path) { @@ -1025,7 +1039,7 @@ public function testCreateShareGroup() { $this->sharingBlacklist->method('isGroupBlacklisted')->willReturn(false); - $expected = new \OC\OCS\Result(); + $expected = new Result(); $result = $ocs->createShare(); $this->assertEquals($expected->getMeta(), $result->getMeta()); @@ -1045,16 +1059,16 @@ public function testCreateShareGroupNotAllowed() { ['shareWith', null, 'validGroup'], ])); - $userFolder = $this->createMock('\OCP\Files\Folder'); + $userFolder = $this->createMock(Folder::class); $this->rootFolder->expects($this->once()) ->method('getUserFolder') ->with('currentUser') ->willReturn($userFolder); - $path = $this->createMock('\OCP\Files\Folder'); - $storage = $this->createMock('OCP\Files\Storage'); + $path = $this->createMock(Folder::class); + $storage = $this->createMock(IStorage::class); $storage->method('instanceOfStorage') - ->with('OCA\Files_Sharing\External\Storage') + ->with(Storage::class) ->willReturn(false); $path->method('getStorage')->willReturn($storage); $userFolder->expects($this->once()) @@ -1068,7 +1082,7 @@ public function testCreateShareGroupNotAllowed() { ->method('allowGroupSharing') ->willReturn(false); - $expected = new \OC\OCS\Result(null, 404, 'Group sharing is disabled by the administrator'); + $expected = new Result(null, 404, 'Group sharing is disabled by the administrator'); $result = $this->ocs->createShare(); @@ -1084,10 +1098,10 @@ public function testCreateShareLinkNoLinksAllowed() { ['shareType', '-1', Share::SHARE_TYPE_LINK], ])); - $path = $this->createMock('\OCP\Files\Folder'); - $storage = $this->createMock('OCP\Files\Storage'); + $path = $this->createMock(Folder::class); + $storage = $this->createMock(IStorage::class); $storage->method('instanceOfStorage') - ->with('OCA\Files_Sharing\External\Storage') + ->with(Storage::class) ->willReturn(false); $path->method('getStorage')->willReturn($storage); $this->rootFolder->method('getUserFolder')->with($this->currentUser->getUID())->will($this->returnSelf()); @@ -1095,7 +1109,7 @@ public function testCreateShareLinkNoLinksAllowed() { $this->shareManager->method('newShare')->willReturn(\OC::$server->getShareManager()->newShare()); - $expected = new \OC\OCS\Result(null, 404, 'Public link sharing is disabled by the administrator'); + $expected = new Result(null, 404, 'Public link sharing is disabled by the administrator'); $result = $this->ocs->createShare(); $this->assertEquals($expected->getMeta(), $result->getMeta()); @@ -1111,10 +1125,10 @@ public function testCreateShareLinkNoPublicUpload() { ['publicUpload', null, 'true'], ])); - $path = $this->createMock('\OCP\Files\Folder'); - $storage = $this->createMock('OCP\Files\Storage'); + $path = $this->createMock(Folder::class); + $storage = $this->createMock(IStorage::class); $storage->method('instanceOfStorage') - ->with('OCA\Files_Sharing\External\Storage') + ->with(Storage::class) ->willReturn(false); $path->method('getStorage')->willReturn($storage); $this->rootFolder->method('getUserFolder')->with($this->currentUser->getUID())->will($this->returnSelf()); @@ -1123,7 +1137,7 @@ public function testCreateShareLinkNoPublicUpload() { $this->shareManager->method('newShare')->willReturn(\OC::$server->getShareManager()->newShare()); $this->shareManager->method('shareApiAllowLinks')->willReturn(true); - $expected = new \OC\OCS\Result(null, 403, 'Public upload disabled by the administrator'); + $expected = new Result(null, 403, 'Public upload disabled by the administrator'); $result = $this->ocs->createShare(); $this->assertEquals($expected->getMeta(), $result->getMeta()); @@ -1139,10 +1153,10 @@ public function testCreateShareLinkPublicUploadFile() { ['publicUpload', null, 'true'], ])); - $path = $this->createMock('\OCP\Files\File'); - $storage = $this->createMock('OCP\Files\Storage'); + $path = $this->createMock(File::class); + $storage = $this->createMock(IStorage::class); $storage->method('instanceOfStorage') - ->with('OCA\Files_Sharing\External\Storage') + ->with(Storage::class) ->willReturn(false); $path->method('getStorage')->willReturn($storage); $this->rootFolder->method('getUserFolder')->with($this->currentUser->getUID())->will($this->returnSelf()); @@ -1152,7 +1166,7 @@ public function testCreateShareLinkPublicUploadFile() { $this->shareManager->method('shareApiAllowLinks')->willReturn(true); $this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true); - $expected = new \OC\OCS\Result(null, 404, 'Public upload is only possible for publicly shared folders'); + $expected = new Result(null, 404, 'Public upload is only possible for publicly shared folders'); $result = $this->ocs->createShare(); $this->assertEquals($expected->getMeta(), $result->getMeta()); @@ -1172,10 +1186,10 @@ public function testCreateShareLinkPublicUploadFolder() { ['password', '', ''], ])); - $path = $this->createMock('\OCP\Files\Folder'); - $storage = $this->createMock('OCP\Files\Storage'); + $path = $this->createMock(Folder::class); + $storage = $this->createMock(IStorage::class); $storage->method('instanceOfStorage') - ->with('OCA\Files_Sharing\External\Storage') + ->with(Storage::class) ->willReturn(false); $path->method('getStorage')->willReturn($storage); $this->rootFolder->method('getUserFolder')->with($this->currentUser->getUID())->will($this->returnSelf()); @@ -1196,7 +1210,7 @@ public function testCreateShareLinkPublicUploadFolder() { }) )->will($this->returnArgument(0)); - $expected = new \OC\OCS\Result(null); + $expected = new Result(null); $result = $ocs->createShare(); $this->assertEquals($expected->getMeta(), $result->getMeta()); @@ -1216,10 +1230,10 @@ public function testCreateShareLinkReadWritePermissions() { ['password', '', ''], ])); - $path = $this->createMock('\OCP\Files\Folder'); - $storage = $this->createMock('OCP\Files\Storage'); + $path = $this->createMock(Folder::class); + $storage = $this->createMock(IStorage::class); $storage->method('instanceOfStorage') - ->with('OCA\Files_Sharing\External\Storage') + ->with(Storage::class) ->willReturn(false); $path->method('getStorage')->willReturn($storage); $this->rootFolder->method('getUserFolder')->with($this->currentUser->getUID())->will($this->returnSelf()); @@ -1240,7 +1254,7 @@ public function testCreateShareLinkReadWritePermissions() { }) )->will($this->returnArgument(0)); - $expected = new \OC\OCS\Result(null); + $expected = new Result(null); $result = $ocs->createShare(); $this->assertEquals($expected->getMeta(), $result->getMeta()); @@ -1260,10 +1274,10 @@ public function testCreateShareLinkCreateOnlyFolder() { ['password', '', ''], ])); - $path = $this->createMock('\OCP\Files\Folder'); - $storage = $this->createMock('OCP\Files\Storage'); + $path = $this->createMock(Folder::class); + $storage = $this->createMock(IStorage::class); $storage->method('instanceOfStorage') - ->with('OCA\Files_Sharing\External\Storage') + ->with(Storage::class) ->willReturn(false); $path->method('getStorage')->willReturn($storage); $this->rootFolder->method('getUserFolder')->with($this->currentUser->getUID())->will($this->returnSelf()); @@ -1284,7 +1298,7 @@ public function testCreateShareLinkCreateOnlyFolder() { }) )->will($this->returnArgument(0)); - $expected = new \OC\OCS\Result(null); + $expected = new Result(null); $result = $ocs->createShare(); $this->assertEquals($expected->getMeta(), $result->getMeta()); @@ -1304,10 +1318,10 @@ public function testCreateShareLinkCreateOnlyFolderPublicUploadDisabled() { ['password', '', ''], ])); - $path = $this->createMock('\OCP\Files\Folder'); - $storage = $this->createMock('OCP\Files\Storage'); + $path = $this->createMock(Folder::class); + $storage = $this->createMock(IStorage::class); $storage->method('instanceOfStorage') - ->with('OCA\Files_Sharing\External\Storage') + ->with(Storage::class) ->willReturn(false); $path->method('getStorage')->willReturn($storage); $this->rootFolder->method('getUserFolder')->with($this->currentUser->getUID())->will($this->returnSelf()); @@ -1317,7 +1331,7 @@ public function testCreateShareLinkCreateOnlyFolderPublicUploadDisabled() { $this->shareManager->method('shareApiAllowLinks')->willReturn(true); $this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(false); - $expected = new \OC\OCS\Result(null, 403, 'Public upload disabled by the administrator'); + $expected = new Result(null, 403, 'Public upload disabled by the administrator'); $result = $ocs->createShare(); $this->assertEquals($expected->getMeta(), $result->getMeta()); @@ -1336,10 +1350,10 @@ public function testCreateShareLinkDefaultPerms() { ['password', '', ''], ])); - $path = $this->createMock('\OCP\Files\Folder'); - $storage = $this->createMock('OCP\Files\Storage'); + $path = $this->createMock(Folder::class); + $storage = $this->createMock(IStorage::class); $storage->method('instanceOfStorage') - ->with('OCA\Files_Sharing\External\Storage') + ->with(Storage::class) ->willReturn(false); $path->method('getStorage')->willReturn($storage); $this->rootFolder->method('getUserFolder')->with($this->currentUser->getUID())->will($this->returnSelf()); @@ -1360,7 +1374,7 @@ public function testCreateShareLinkDefaultPerms() { }) )->will($this->returnArgument(0)); - $expected = new \OC\OCS\Result(null); + $expected = new Result(null); $result = $ocs->createShare(); $this->assertEquals($expected->getMeta(), $result->getMeta()); @@ -1380,10 +1394,10 @@ public function testCreateShareLinkPassword() { ['password', '', 'password'], ])); - $path = $this->createMock('\OCP\Files\Folder'); - $storage = $this->createMock('OCP\Files\Storage'); + $path = $this->createMock(Folder::class); + $storage = $this->createMock(IStorage::class); $storage->method('instanceOfStorage') - ->with('OCA\Files_Sharing\External\Storage') + ->with(Storage::class) ->willReturn(false); $path->method('getStorage')->willReturn($storage); $this->rootFolder->method('getUserFolder')->with($this->currentUser->getUID())->will($this->returnSelf()); @@ -1404,7 +1418,7 @@ public function testCreateShareLinkPassword() { }) )->will($this->returnArgument(0)); - $expected = new \OC\OCS\Result(null); + $expected = new Result(null); $result = $ocs->createShare(); $this->assertEquals($expected->getMeta(), $result->getMeta()); @@ -1424,10 +1438,10 @@ public function testCreateShareValidExpireDate() { ['password', '', ''], ])); - $path = $this->createMock('\OCP\Files\Folder'); - $storage = $this->createMock('OCP\Files\Storage'); + $path = $this->createMock(Folder::class); + $storage = $this->createMock(IStorage::class); $storage->method('instanceOfStorage') - ->with('OCA\Files_Sharing\External\Storage') + ->with(Storage::class) ->willReturn(false); $path->method('getStorage')->willReturn($storage); $this->rootFolder->method('getUserFolder')->with($this->currentUser->getUID())->will($this->returnSelf()); @@ -1451,7 +1465,7 @@ public function testCreateShareValidExpireDate() { }) )->will($this->returnArgument(0)); - $expected = new \OC\OCS\Result(null); + $expected = new Result(null); $result = $ocs->createShare(); $this->assertEquals($expected->getMeta(), $result->getMeta()); @@ -1471,10 +1485,10 @@ public function testCreateShareInvalidExpireDate() { ['password', '', ''], ])); - $path = $this->createMock('\OCP\Files\Folder'); - $storage = $this->createMock('OCP\Files\Storage'); + $path = $this->createMock(Folder::class); + $storage = $this->createMock(IStorage::class); $storage->method('instanceOfStorage') - ->with('OCA\Files_Sharing\External\Storage') + ->with(Storage::class) ->willReturn(false); $path->method('getStorage')->willReturn($storage); $this->rootFolder->method('getUserFolder')->with($this->currentUser->getUID())->will($this->returnSelf()); @@ -1484,7 +1498,7 @@ public function testCreateShareInvalidExpireDate() { $this->shareManager->method('shareApiAllowLinks')->willReturn(true); $this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true); - $expected = new \OC\OCS\Result(null, 404, 'Invalid date, date format must be YYYY-MM-DD'); + $expected = new Result(null, 404, 'Invalid date, date format must be YYYY-MM-DD'); $result = $ocs->createShare(); $this->assertEquals($expected->getMeta(), $result->getMeta()); @@ -1510,16 +1524,16 @@ public function testCreateReshareOfFederatedMountNoDeletePermissions() { ['shareWith', null, 'validUser'], ])); - $userFolder = $this->createMock('\OCP\Files\Folder'); + $userFolder = $this->createMock(Folder::class); $this->rootFolder->expects($this->once()) ->method('getUserFolder') ->with('currentUser') ->willReturn($userFolder); - $path = $this->createMock('\OCP\Files\Folder'); - $storage = $this->createMock('OCP\Files\Storage'); + $path = $this->createMock(Folder::class); + $storage = $this->createMock(IStorage::class); $storage->method('instanceOfStorage') - ->with('OCA\Files_Sharing\External\Storage') + ->with(Storage::class) ->willReturn(true); $path->method('getStorage')->willReturn($storage); $path->method('getPermissions')->willReturn(\OCP\Constants::PERMISSION_READ); @@ -1542,17 +1556,17 @@ public function testCreateReshareOfFederatedMountNoDeletePermissions() { } public function testUpdateShareCantAccess() { - $node = $this->createMock('\OCP\Files\Folder'); + $node = $this->createMock(Folder::class); $share = $this->newShare(); $share->setNode($node); $node->expects($this->once()) ->method('lock') - ->with(\OCP\Lock\ILockingProvider::LOCK_SHARED); + ->with(ILockingProvider::LOCK_SHARED); $this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share); - $expected = new \OC\OCS\Result(null, 404, 'Wrong share ID, share doesn\'t exist'); + $expected = new Result(null, 404, 'Wrong share ID, share doesn\'t exist'); $result = $this->ocs->updateShare(42); $this->assertEquals($expected->getMeta(), $result->getMeta()); @@ -1560,7 +1574,7 @@ public function testUpdateShareCantAccess() { } public function testUpdateNoParametersLink() { - $node = $this->createMock('\OCP\Files\Folder'); + $node = $this->createMock(Folder::class); $share = $this->newShare(); $share->setPermissions(\OCP\Constants::PERMISSION_ALL) ->setSharedBy($this->currentUser->getUID()) @@ -1569,11 +1583,11 @@ public function testUpdateNoParametersLink() { $node->expects($this->once()) ->method('lock') - ->with(\OCP\Lock\ILockingProvider::LOCK_SHARED); + ->with(ILockingProvider::LOCK_SHARED); $this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share); - $expected = new \OC\OCS\Result(null, 400, 'Wrong or no update parameter given'); + $expected = new Result(null, 400, 'Wrong or no update parameter given'); $result = $this->ocs->updateShare(42); $this->assertEquals($expected->getMeta(), $result->getMeta()); @@ -1581,7 +1595,7 @@ public function testUpdateNoParametersLink() { } public function testUpdateNoParametersOther() { - $node = $this->createMock('\OCP\Files\Folder'); + $node = $this->createMock(Folder::class); $share = $this->newShare(); $share->setPermissions(\OCP\Constants::PERMISSION_ALL) ->setSharedBy($this->currentUser->getUID()) @@ -1590,11 +1604,11 @@ public function testUpdateNoParametersOther() { $node->expects($this->once()) ->method('lock') - ->with(\OCP\Lock\ILockingProvider::LOCK_SHARED); + ->with(ILockingProvider::LOCK_SHARED); $this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share); - $expected = new \OC\OCS\Result(null, 400, 'Wrong or no update parameter given'); + $expected = new Result(null, 400, 'Wrong or no update parameter given'); $result = $this->ocs->updateShare(42); $this->assertEquals($expected->getMeta(), $result->getMeta()); @@ -1604,7 +1618,7 @@ public function testUpdateNoParametersOther() { public function testUpdateLinkShareClear() { $ocs = $this->mockFormatShare(); - $node = $this->createMock('\OCP\Files\Folder'); + $node = $this->createMock(Folder::class); $share = $this->newShare(); $share->setPermissions(\OCP\Constants::PERMISSION_ALL) ->setSharedBy($this->currentUser->getUID()) @@ -1617,10 +1631,10 @@ public function testUpdateLinkShareClear() { $node->expects($this->once()) ->method('lock') - ->with(\OCP\Lock\ILockingProvider::LOCK_SHARED); + ->with(ILockingProvider::LOCK_SHARED); $node->expects($this->once()) ->method('unlock') - ->with(\OCP\Lock\ILockingProvider::LOCK_SHARED); + ->with(ILockingProvider::LOCK_SHARED); $this->request ->method('getParam') @@ -1640,7 +1654,7 @@ public function testUpdateLinkShareClear() { }) )->will($this->returnArgument(0)); - $expected = new \OC\OCS\Result(null); + $expected = new Result(null); $result = $ocs->updateShare(42); $this->assertEquals($expected->getMeta(), $result->getMeta()); @@ -1650,7 +1664,7 @@ public function testUpdateLinkShareClear() { public function testUpdateLinkShareSet() { $ocs = $this->mockFormatShare(); - $folder = $this->createMock('\OCP\Files\Folder'); + $folder = $this->createMock(Folder::class); $share = \OC::$server->getShareManager()->newShare(); $share->setPermissions(\OCP\Constants::PERMISSION_ALL) @@ -1681,7 +1695,7 @@ public function testUpdateLinkShareSet() { }) )->will($this->returnArgument(0)); - $expected = new \OC\OCS\Result(null); + $expected = new Result(null); $result = $ocs->updateShare(42); $this->assertEquals($expected->getMeta(), $result->getMeta()); @@ -1694,7 +1708,7 @@ public function testUpdateLinkShareSet() { public function testUpdateLinkShareEnablePublicUpload($params) { $ocs = $this->mockFormatShare(); - $folder = $this->createMock('\OCP\Files\Folder'); + $folder = $this->createMock(Folder::class); $share = \OC::$server->getShareManager()->newShare(); $share->setPermissions(\OCP\Constants::PERMISSION_ALL) @@ -1720,7 +1734,7 @@ public function testUpdateLinkShareEnablePublicUpload($params) { }) )->will($this->returnArgument(0)); - $expected = new \OC\OCS\Result(null); + $expected = new Result(null); $result = $ocs->updateShare(42); $this->assertEquals($expected->getMeta(), $result->getMeta()); @@ -1730,7 +1744,7 @@ public function testUpdateLinkShareEnablePublicUpload($params) { public function testUpdateLinkShareInvalidDate() { $ocs = $this->mockFormatShare(); - $folder = $this->createMock('\OCP\Files\Folder'); + $folder = $this->createMock(Folder::class); $share = \OC::$server->getShareManager()->newShare(); $share->setPermissions(\OCP\Constants::PERMISSION_ALL) @@ -1749,7 +1763,7 @@ public function testUpdateLinkShareInvalidDate() { $this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share); $this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true); - $expected = new \OC\OCS\Result(null, 400, 'Invalid date. Format must be YYYY-MM-DD'); + $expected = new Result(null, 400, 'Invalid date. Format must be YYYY-MM-DD'); $result = $ocs->updateShare(42); $this->assertEquals($expected->getMeta(), $result->getMeta()); @@ -1782,7 +1796,7 @@ public function publicUploadParamsProvider() { public function testUpdateLinkSharePublicUploadNotAllowed($params) { $ocs = $this->mockFormatShare(); - $folder = $this->createMock('\OCP\Files\Folder'); + $folder = $this->createMock(Folder::class); $share = \OC::$server->getShareManager()->newShare(); $share->setPermissions(\OCP\Constants::PERMISSION_ALL) @@ -1797,7 +1811,7 @@ public function testUpdateLinkSharePublicUploadNotAllowed($params) { $this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share); $this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(false); - $expected = new \OC\OCS\Result(null, 403, 'Public upload disabled by the administrator'); + $expected = new Result(null, 403, 'Public upload disabled by the administrator'); $result = $ocs->updateShare(42); $this->assertEquals($expected->getMeta(), $result->getMeta()); @@ -1807,7 +1821,7 @@ public function testUpdateLinkSharePublicUploadNotAllowed($params) { public function testUpdateLinkSharePublicUploadOnFile() { $ocs = $this->mockFormatShare(); - $file = $this->createMock('\OCP\Files\File'); + $file = $this->createMock(File::class); $share = \OC::$server->getShareManager()->newShare(); $share->setPermissions(\OCP\Constants::PERMISSION_ALL) @@ -1826,7 +1840,7 @@ public function testUpdateLinkSharePublicUploadOnFile() { $this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share); $this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true); - $expected = new \OC\OCS\Result(null, 400, 'Public upload is only possible for publicly shared folders'); + $expected = new Result(null, 400, 'Public upload is only possible for publicly shared folders'); $result = $ocs->updateShare(42); $this->assertEquals($expected->getMeta(), $result->getMeta()); @@ -1839,7 +1853,7 @@ public function testUpdateLinkSharePasswordDoesNotChangeOther() { $date = new \DateTime('2000-01-01'); $date->setTime(0, 0, 0); - $node = $this->createMock('\OCP\Files\File'); + $node = $this->createMock(File::class); $share = $this->newShare(); $share->setPermissions(\OCP\Constants::PERMISSION_ALL) ->setSharedBy($this->currentUser->getUID()) @@ -1851,10 +1865,10 @@ public function testUpdateLinkSharePasswordDoesNotChangeOther() { $node->expects($this->once()) ->method('lock') - ->with(\OCP\Lock\ILockingProvider::LOCK_SHARED); + ->with(ILockingProvider::LOCK_SHARED); $node->expects($this->once()) ->method('unlock') - ->with(\OCP\Lock\ILockingProvider::LOCK_SHARED); + ->with(ILockingProvider::LOCK_SHARED); $this->request ->method('getParam') @@ -1872,7 +1886,7 @@ public function testUpdateLinkSharePasswordDoesNotChangeOther() { }) )->will($this->returnArgument(0)); - $expected = new \OC\OCS\Result(null); + $expected = new Result(null); $result = $ocs->updateShare(42); $this->assertEquals($expected->getMeta(), $result->getMeta()); @@ -1882,7 +1896,7 @@ public function testUpdateLinkSharePasswordDoesNotChangeOther() { public function testUpdateLinkShareExpireDateDoesNotChangeOther() { $ocs = $this->mockFormatShare(); - $node = $this->createMock('\OCP\Files\File'); + $node = $this->createMock(File::class); $share = $this->newShare(); $share->setPermissions(\OCP\Constants::PERMISSION_ALL) ->setSharedBy($this->currentUser->getUID()) @@ -1900,10 +1914,10 @@ public function testUpdateLinkShareExpireDateDoesNotChangeOther() { $node->expects($this->once()) ->method('lock') - ->with(\OCP\Lock\ILockingProvider::LOCK_SHARED); + ->with(ILockingProvider::LOCK_SHARED); $node->expects($this->once()) ->method('unlock') - ->with(\OCP\Lock\ILockingProvider::LOCK_SHARED); + ->with(ILockingProvider::LOCK_SHARED); $this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share); @@ -1918,7 +1932,7 @@ public function testUpdateLinkShareExpireDateDoesNotChangeOther() { }) )->will($this->returnArgument(0)); - $expected = new \OC\OCS\Result(null); + $expected = new Result(null); $result = $ocs->updateShare(42); $this->assertEquals($expected->getMeta(), $result->getMeta()); @@ -1930,7 +1944,7 @@ public function testUpdateLinkSharePublicUploadDoesNotChangeOther() { $date = new \DateTime('2000-01-01'); - $folder = $this->createMock('\OCP\Files\Folder'); + $folder = $this->createMock(Folder::class); $share = \OC::$server->getShareManager()->newShare(); $share->setPermissions(\OCP\Constants::PERMISSION_ALL) @@ -1959,7 +1973,7 @@ public function testUpdateLinkSharePublicUploadDoesNotChangeOther() { }) )->will($this->returnArgument(0)); - $expected = new \OC\OCS\Result(null); + $expected = new Result(null); $result = $ocs->updateShare(42); $this->assertEquals($expected->getMeta(), $result->getMeta()); @@ -1971,7 +1985,7 @@ public function testUpdateLinkSharePermissions() { $date = new \DateTime('2000-01-01'); - $folder = $this->createMock('\OCP\Files\Folder'); + $folder = $this->createMock(Folder::class); $share = \OC::$server->getShareManager()->newShare(); $share->setPermissions(\OCP\Constants::PERMISSION_ALL) @@ -2001,7 +2015,7 @@ public function testUpdateLinkSharePermissions() { $this->shareManager->method('getSharedWith')->willReturn([]); - $expected = new \OC\OCS\Result(null); + $expected = new Result(null); $result = $ocs->updateShare(42); $this->assertEquals($expected->getMeta(), $result->getMeta()); @@ -2011,7 +2025,7 @@ public function testUpdateLinkSharePermissions() { public function testUpdateLinkShareCreateOnly() { $ocs = $this->mockFormatShare(); - $folder = $this->createMock('\OCP\Files\Folder'); + $folder = $this->createMock(Folder::class); $share = \OC::$server->getShareManager()->newShare(); $share->setPermissions(\OCP\Constants::PERMISSION_ALL) @@ -2037,7 +2051,7 @@ public function testUpdateLinkShareCreateOnly() { $this->shareManager->method('getSharedWith')->willReturn([]); - $expected = new \OC\OCS\Result(null); + $expected = new Result(null); $result = $ocs->updateShare(42); $this->assertEquals($expected->getMeta(), $result->getMeta()); @@ -2049,7 +2063,7 @@ public function testUpdateLinkShareInvalidPermissions() { $date = new \DateTime('2000-01-01'); - $folder = $this->createMock('\OCP\Files\Folder'); + $folder = $this->createMock(Folder::class); $share = \OC::$server->getShareManager()->newShare(); $share->setPermissions(\OCP\Constants::PERMISSION_ALL) @@ -2069,7 +2083,7 @@ public function testUpdateLinkShareInvalidPermissions() { $this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share); $this->shareManager->method('shareApiLinkAllowPublicUpload')->willReturn(true); - $expected = new \OC\OCS\Result(null, 400, 'Can\'t change permissions for public share links'); + $expected = new Result(null, 400, 'Can\'t change permissions for public share links'); $result = $ocs->updateShare(42); $this->assertEquals($expected->getMeta(), $result->getMeta()); @@ -2079,7 +2093,7 @@ public function testUpdateLinkShareInvalidPermissions() { public function testUpdateShareZeroPermissions() { $ocs = $this->mockFormatShare(); - $folder = $this->createMock('\OCP\Files\Folder'); + $folder = $this->createMock(Folder::class); $share = \OC::$server->getShareManager()->newShare(); $share->setPermissions(\OCP\Constants::PERMISSION_ALL) @@ -2098,7 +2112,7 @@ public function testUpdateShareZeroPermissions() { $this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share); - $expected = new \OC\OCS\Result(null, 400, 'Cannot remove all permissions'); + $expected = new Result(null, 400, 'Cannot remove all permissions'); $result = $ocs->updateShare(42); $this->assertEquals($expected->getMeta(), $result->getMeta()); @@ -2108,7 +2122,7 @@ public function testUpdateShareZeroPermissions() { public function testUpdateOtherPermissions() { $ocs = $this->mockFormatShare(); - $file = $this->createMock('\OCP\Files\File'); + $file = $this->createMock(File::class); $share = \OC::$server->getShareManager()->newShare(); $share->setPermissions(\OCP\Constants::PERMISSION_ALL) @@ -2133,7 +2147,7 @@ public function testUpdateOtherPermissions() { $this->shareManager->method('getSharedWith')->willReturn([]); - $expected = new \OC\OCS\Result(null); + $expected = new Result(null); $result = $ocs->updateShare(42); $this->assertEquals($expected->getMeta(), $result->getMeta()); @@ -2145,7 +2159,7 @@ public function testUpdateShareCannotIncreasePermissions() { $date = new \DateTime('2000-01-01'); - $folder = $this->createMock('\OCP\Files\Folder'); + $folder = $this->createMock(Folder::class); $share = \OC::$server->getShareManager()->newShare(); $share @@ -2186,7 +2200,7 @@ public function testUpdateShareCannotIncreasePermissions() { $this->shareManager->expects($this->never())->method('updateShare'); - $expected = new \OC\OCS\Result(null, 404, 'Cannot increase permissions'); + $expected = new Result(null, 404, 'Cannot increase permissions'); $result = $ocs->updateShare(42); $this->assertEquals($expected->getMeta(), $result->getMeta()); @@ -2201,7 +2215,7 @@ public function testUpdateShareCannotIncreasePermissionsPublicLink($params) { $date = new \DateTime('2000-01-01'); - $folder = $this->createMock('\OCP\Files\Folder'); + $folder = $this->createMock(Folder::class); $share = \OC::$server->getShareManager()->newShare(); $share @@ -2239,7 +2253,7 @@ public function testUpdateShareCannotIncreasePermissionsPublicLink($params) { $this->shareManager->expects($this->never())->method('updateShare'); - $expected = new \OC\OCS\Result(null, 404, 'Cannot increase permissions'); + $expected = new Result(null, 404, 'Cannot increase permissions'); $result = $ocs->updateShare(43); $this->assertEquals($expected->getMeta(), $result->getMeta()); @@ -2251,7 +2265,7 @@ public function testUpdateShareCanIncreasePermissionsIfOwner() { $date = new \DateTime('2000-01-01'); - $folder = $this->createMock('\OCP\Files\Folder'); + $folder = $this->createMock(Folder::class); $share = \OC::$server->getShareManager()->newShare(); $share @@ -2283,7 +2297,7 @@ public function testUpdateShareCanIncreasePermissionsIfOwner() { $this->shareManager->method('getShareById')->with('ocinternal:42')->willReturn($share); - $this->shareManager->expects($this->any(0)) + $this->shareManager->expects($this->any()) ->method('getSharedWith') ->will($this->returnValueMap([ ['currentUser', Share::SHARE_TYPE_USER, $share->getNode(), -1, 0, []], @@ -2295,7 +2309,7 @@ public function testUpdateShareCanIncreasePermissionsIfOwner() { ->with($share) ->willReturn($share); - $expected = new \OC\OCS\Result(); + $expected = new Result(); $result = $ocs->updateShare(42); $this->assertEquals($expected->getMeta(), $result->getMeta()); @@ -2307,7 +2321,7 @@ public function testUpdateLinkShareNameAlone() { $date = new \DateTime('2000-01-01'); - $folder = $this->createMock('\OCP\Files\Folder'); + $folder = $this->createMock(Folder::class); $share = \OC::$server->getShareManager()->newShare(); $share->setPermissions(\OCP\Constants::PERMISSION_READ) @@ -2332,7 +2346,7 @@ public function testUpdateLinkShareNameAlone() { $this->shareManager->method('getSharedWith')->willReturn([]); - $expected = new \OC\OCS\Result(null); + $expected = new Result(null); $result = $ocs->updateShare(42); $this->assertEquals($expected->getMeta(), $result->getMeta()); @@ -2344,7 +2358,7 @@ public function testUpdateLinkShareKeepNameWhenNotSpecified() { $date = new \DateTime('2000-01-01'); - $folder = $this->createMock('\OCP\Files\Folder'); + $folder = $this->createMock(Folder::class); $share = \OC::$server->getShareManager()->newShare(); $share->setPermissions(\OCP\Constants::PERMISSION_READ) @@ -2371,7 +2385,7 @@ public function testUpdateLinkShareKeepNameWhenNotSpecified() { $this->shareManager->method('getSharedWith')->willReturn([]); - $expected = new \OC\OCS\Result(null); + $expected = new Result(null); $result = $ocs->updateShare(42); $this->assertEquals($expected->getMeta(), $result->getMeta()); @@ -2379,9 +2393,9 @@ public function testUpdateLinkShareKeepNameWhenNotSpecified() { } private function getMockFileFolder() { - $file = $this->createMock('\OCP\Files\File'); - $folder = $this->createMock('\OCP\Files\Folder'); - $parent = $this->createMock('\OCP\Files\Folder'); + $file = $this->createMock(File::class); + $folder = $this->createMock(Folder::class); + $parent = $this->createMock(Folder::class); $file->method('getMimeType')->willReturn('myMimeType'); $folder->method('getMimeType')->willReturn('myFolderMimeType'); @@ -2396,9 +2410,9 @@ private function getMockFileFolder() { $file->method('getParent')->willReturn($parent); $folder->method('getParent')->willReturn($parent); - $cache = $this->createMock('OCP\Files\Cache\ICache'); + $cache = $this->createMock(ICache::class); $cache->method('getNumericStorageId')->willReturn(100); - $storage = $this->createMock('\OCP\Files\Storage'); + $storage = $this->createMock(IStorage::class); $storage->method('getId')->willReturn('storageId'); $storage->method('getCache')->willReturn($cache); @@ -2410,11 +2424,11 @@ private function getMockFileFolder() { public function dataFormatShare() { list($file, $folder) = $this->getMockFileFolder(); - $owner = $this->createMock('\OCP\IUser'); + $owner = $this->createMock(IUser::class); $owner->method('getDisplayName')->willReturn('ownerDN'); - $initiator = $this->createMock('\OCP\IUser'); + $initiator = $this->createMock(IUser::class); $initiator->method('getDisplayName')->willReturn('initiatorDN'); - $recipient = $this->createMock('\OCP\IUser'); + $recipient = $this->createMock(IUser::class); $recipient->method('getDisplayName')->willReturn('recipientDN'); $result = []; @@ -2719,11 +2733,12 @@ public function dataFormatShare() { * @param \OCP\Share\IShare $share * @param array $users * @param $exception + * @throws NotFoundException */ public function testFormatShare(array $expects, \OCP\Share\IShare $share, array $users, $exception) { $this->userManager->method('get')->will($this->returnValueMap($users)); - $recipientGroup = $this->createMock('\OCP\IGroup'); + $recipientGroup = $this->createMock(IGroup::class); $recipientGroup->method('getDisplayName')->willReturn('recipientGroupDisplayName'); $this->groupManager->method('get')->will($this->returnValueMap([ ['recipientGroup', $recipientGroup], @@ -2760,7 +2775,7 @@ public function testFormatShare(array $expects, \OCP\Share\IShare $share, array * @return Share20OCS */ public function getOcsDisabledAPI() { - $shareManager = $this->getMockBuilder('OCP\Share\IManager') + $shareManager = $this->getMockBuilder(IManager::class) ->disableOriginalConstructor() ->getMock(); $shareManager @@ -2787,7 +2802,7 @@ public function getOcsDisabledAPI() { public function testGetShareApiDisabled() { $ocs = $this->getOcsDisabledAPI(); - $expected = new \OC\OCS\Result(null, 404, 'Share API is disabled'); + $expected = new Result(null, 404, 'Share API is disabled'); $result = $ocs->getShare('my:id'); $this->assertEquals($expected, $result); @@ -2796,7 +2811,7 @@ public function testGetShareApiDisabled() { public function testDeleteShareApiDisabled() { $ocs = $this->getOcsDisabledAPI(); - $expected = new \OC\OCS\Result(null, 404, 'Share API is disabled'); + $expected = new Result(null, 404, 'Share API is disabled'); $result = $ocs->deleteShare('my:id'); $this->assertEquals($expected, $result); @@ -2805,7 +2820,7 @@ public function testDeleteShareApiDisabled() { public function testCreateShareApiDisabled() { $ocs = $this->getOcsDisabledAPI(); - $expected = new \OC\OCS\Result(null, 404, 'Share API is disabled'); + $expected = new Result(null, 404, 'Share API is disabled'); $result = $ocs->createShare(); $this->assertEquals($expected, $result); @@ -2814,7 +2829,7 @@ public function testCreateShareApiDisabled() { public function testGetSharesApiDisabled() { $ocs = $this->getOcsDisabledAPI(); - $expected = new \OC\OCS\Result(); + $expected = new Result(); $result = $ocs->getShares(); $this->assertEquals($expected, $result); @@ -2823,7 +2838,7 @@ public function testGetSharesApiDisabled() { public function testUpdateShareApiDisabled() { $ocs = $this->getOcsDisabledAPI(); - $expected = new \OC\OCS\Result(null, 404, 'Share API is disabled'); + $expected = new Result(null, 404, 'Share API is disabled'); $result = $ocs->updateShare('my:id'); $this->assertEquals($expected, $result); @@ -3055,7 +3070,7 @@ public function testGetSharesSharedWithMe($requestedPath, $stateFilter) { $groupShareNonOwner->setShareType(\OCP\Share::SHARE_TYPE_GROUP); $groupShareNonOwner->setPermissions(\OCP\Constants::PERMISSION_ALL); - $group = $this->createMock('OCP\IGroup'); + $group = $this->createMock(IGroup::class); $group->method('inGroup')->with($this->currentUser)->willReturn(true); $this->groupManager->method('get')->with('group1')->willReturn($group); @@ -3145,7 +3160,7 @@ public function testAcceptRejectShare($method, $target, $targetExists, $expected ->method('updateShareForRecipient') ->with($userShare, 'currentUser'); - $userFolder = $this->createMock('OCP\Files\Folder'); + $userFolder = $this->createMock(Folder::class); if ($method === 'acceptShare') { // deduplicate $userFolder->expects($this->at(0)) @@ -3279,7 +3294,7 @@ public function testAcceptRejectShareMultiple($method, $target, $targetExists, $ ->method('updateShareForRecipient') ->withConsecutive($userShare, $groupShare); - $userFolder = $this->createMock('OCP\Files\Folder'); + $userFolder = $this->createMock(Folder::class); if ($method === 'acceptShare') { // deduplicate $userFolder->expects($this->at(0)) @@ -3344,7 +3359,7 @@ public function testAcceptRejectShareMultiple($method, $target, $targetExists, $ public function testAcceptRejectShareApiDisabled($method, $target, $targetExists, $expectedState) { $ocs = $this->getOcsDisabledAPI(); - $expected = new \OC\OCS\Result(null, 404, 'Share API is disabled'); + $expected = new Result(null, 404, 'Share API is disabled'); $result = $ocs->$method(123); $this->assertEquals($expected, $result); @@ -3382,7 +3397,7 @@ public function testAcceptRejectShareInvalidId($method, $target, $targetExists, $this->shareManager->expects($this->never()) ->method('updateShareForRecipient'); - $expected = new \OC\OCS\Result(null, 404, 'Wrong share ID, share doesn\'t exist'); + $expected = new Result(null, 404, 'Wrong share ID, share doesn\'t exist'); $result = $this->ocs->$method(123); $this->assertEquals($expected, $result); @@ -3403,7 +3418,7 @@ public function testAcceptRejectShareAccessDenied($method, $target, $targetExist $this->shareManager->expects($this->never()) ->method('updateShareForRecipient'); - $expected = new \OC\OCS\Result(null, 404, 'Wrong share ID, share doesn\'t exist'); + $expected = new Result(null, 404, 'Wrong share ID, share doesn\'t exist'); $result = $this->ocs->$method(123); $this->assertEquals($expected, $result); @@ -3425,7 +3440,7 @@ public function testAcceptRejectShareAccessNotRecipient($method, $target, $targe $userShare->setShareOwner('currentUser'); - $expected = new \OC\OCS\Result(null, 403, 'Only recipient can change accepted state'); + $expected = new Result(null, 403, 'Only recipient can change accepted state'); $result = $this->ocs->$method(123); $this->assertEquals($expected, $result); @@ -3460,7 +3475,7 @@ public function testAcceptRejectShareOperationError($method, $target, $targetExi ['currentUser', Share::SHARE_TYPE_GROUP, $userShare->getNode(), -1, 0, []] ])); - $userFolder = $this->createMock('OCP\Files\Folder'); + $userFolder = $this->createMock(Folder::class); if ($method === 'acceptShare') { $userFolder->expects($this->at(0)) ->method('nodeExists') @@ -3480,7 +3495,7 @@ public function testAcceptRejectShareOperationError($method, $target, $targetExi ->with($this->currentUser->getUID()) ->willReturn($userFolder); - $expected = new \OC\OCS\Result(null, 400, 'operation error'); + $expected = new Result(null, 400, 'operation error'); $result = $this->ocs->$method(123); $this->assertEquals($expected, $result); diff --git a/apps/files_sharing/tests/MountProviderTest.php b/apps/files_sharing/tests/MountProviderTest.php index 079d3923035d..5d5af9f95058 100644 --- a/apps/files_sharing/tests/MountProviderTest.php +++ b/apps/files_sharing/tests/MountProviderTest.php @@ -28,11 +28,16 @@ use OCP\ILogger; use OCP\IUser; use OCP\Share\IManager; +use OCA\Files_Sharing\SharedMount; +use OCP\IUserManager; +use OCP\Files\IRootFolder; +use OCP\Share\IShare; +use Test\TestCase; /** * @group DB */ -class MountProviderTest extends \Test\TestCase { +class MountProviderTest extends TestCase { /** @var MountProvider */ private $provider; @@ -55,17 +60,17 @@ class MountProviderTest extends \Test\TestCase { public function setUp() { parent::setUp(); - $this->config = $this->createMock('OCP\IConfig'); - $this->user = $this->createMock('OCP\IUser'); - $this->loader = $this->createMock('OCP\Files\Storage\IStorageFactory'); - $this->shareManager = $this->createMock('\OCP\Share\IManager'); - $this->logger = $this->createMock('\OCP\ILogger'); + $this->config = $this->createMock(IConfig::class); + $this->user = $this->createMock(IUser::class); + $this->loader = $this->createMock(IStorageFactory::class); + $this->shareManager = $this->createMock(IManager::class); + $this->logger = $this->createMock(ILogger::class); $this->provider = new MountProvider($this->config, $this->shareManager, $this->logger); } private function makeMockShare($id, $nodeId, $owner = 'user2', $target = null, $permissions = 31, $state = null) { - $share = $this->createMock('\OCP\Share\IShare'); + $share = $this->createMock(IShare::class); $share->expects($this->any()) ->method('getPermissions') ->will($this->returnValue($permissions)); @@ -105,8 +110,8 @@ private function makeMockShare($id, $nodeId, $owner = 'user2', $target = null, $ * - pending shares */ public function testExcludeShares() { - $rootFolder = $this->createMock('\OCP\Files\IRootFolder'); - $userManager = $this->createMock('\OCP\IUserManager'); + $rootFolder = $this->createMock(IRootFolder::class); + $userManager = $this->createMock(IUserManager::class); $userShares = [ $this->makeMockShare(1, 100, 'user2', '/share2', 0), @@ -143,8 +148,8 @@ public function testExcludeShares() { $mounts = $this->provider->getMountsForUser($this->user, $this->loader); $this->assertCount(2, $mounts); - $this->assertInstanceOf('OCA\Files_Sharing\SharedMount', $mounts[0]); - $this->assertInstanceOf('OCA\Files_Sharing\SharedMount', $mounts[1]); + $this->assertInstanceOf(SharedMount::class, $mounts[0]); + $this->assertInstanceOf(SharedMount::class, $mounts[1]); $mountedShare1 = $mounts[0]->getShare(); @@ -306,10 +311,11 @@ public function mergeSharesDataProvider() { * @param array $userShares array of user share specs * @param array $groupShares array of group share specs * @param array $expectedShares array of expected supershare specs + * @param bool $moveFails */ public function testMergeShares($userShares, $groupShares, $expectedShares, $moveFails = false) { - $rootFolder = $this->createMock('\OCP\Files\IRootFolder'); - $userManager = $this->createMock('\OCP\IUserManager'); + $rootFolder = $this->createMock(IRootFolder::class); + $userManager = $this->createMock(IUserManager::class); $userShares = \array_map(function ($shareSpec) { return $this->makeMockShare($shareSpec[0], $shareSpec[1], $shareSpec[2], $shareSpec[3], $shareSpec[4]); @@ -350,7 +356,7 @@ public function testMergeShares($userShares, $groupShares, $expectedShares, $mov foreach ($mounts as $index => $mount) { $expectedShare = $expectedShares[$index]; - $this->assertInstanceOf('OCA\Files_Sharing\SharedMount', $mount); + $this->assertInstanceOf(SharedMount::class, $mount); // supershare $share = $mount->getShare(); diff --git a/apps/files_sharing/tests/SharedStorageTest.php b/apps/files_sharing/tests/SharedStorageTest.php index 513fa61957d4..7b66dad6e12e 100644 --- a/apps/files_sharing/tests/SharedStorageTest.php +++ b/apps/files_sharing/tests/SharedStorageTest.php @@ -432,7 +432,7 @@ public function testCopyFromStorage() { $this->assertTrue($view->file_exists($this->folder)); /** - * @var \OCP\Files\Storage $sharedStorage + * @var \OCP\Files\Storage\IStorage $sharedStorage */ list($sharedStorage, ) = $view->resolvePath($this->folder); $this->assertTrue($sharedStorage->instanceOfStorage('OCA\Files_Sharing\ISharedStorage')); @@ -465,7 +465,7 @@ public function testMoveFromStorage() { $this->assertTrue($view->file_exists($this->folder)); /** - * @var \OCP\Files\Storage $sharedStorage + * @var \OCP\Files\Storage\IStorage $sharedStorage */ list($sharedStorage, ) = $view->resolvePath($this->folder); $this->assertTrue($sharedStorage->instanceOfStorage('OCA\Files_Sharing\ISharedStorage')); diff --git a/lib/private/Encryption/EncryptionWrapper.php b/lib/private/Encryption/EncryptionWrapper.php index d8c9156f684f..92d6a1a772f7 100644 --- a/lib/private/Encryption/EncryptionWrapper.php +++ b/lib/private/Encryption/EncryptionWrapper.php @@ -68,11 +68,11 @@ public function __construct(ArrayCache $arrayCache, * Wraps the given storage when it is not a shared storage * * @param string $mountPoint - * @param Storage $storage + * @param Storage\IStorage $storage * @param IMountPoint $mount * @return Encryption|Storage */ - public function wrapStorage($mountPoint, Storage $storage, IMountPoint $mount) { + public function wrapStorage($mountPoint, Storage\IStorage $storage, IMountPoint $mount) { $parameters = [ 'storage' => $storage, 'mountPoint' => $mountPoint, diff --git a/lib/private/Files/External/Auth/Password/SessionCredentials.php b/lib/private/Files/External/Auth/Password/SessionCredentials.php index ff4e0b875f3c..237285b3e321 100644 --- a/lib/private/Files/External/Auth/Password/SessionCredentials.php +++ b/lib/private/Files/External/Auth/Password/SessionCredentials.php @@ -79,7 +79,7 @@ public function manipulateStorageConfig(IStorageConfig &$storage, IUser $user = $storage->setBackendOption('password', $credentials['password']); } - public function wrapStorage(Storage $storage) { + public function wrapStorage(Storage\IStorage $storage) { return new SessionStorageWrapper(['storage' => $storage]); } } diff --git a/lib/private/Files/External/PersonalMount.php b/lib/private/Files/External/PersonalMount.php index 24f7ab6b9997..8d7a26b8cbf0 100644 --- a/lib/private/Files/External/PersonalMount.php +++ b/lib/private/Files/External/PersonalMount.php @@ -41,7 +41,7 @@ class PersonalMount extends MountPoint implements MoveableMount { /** * @param IUserStoragesService $storagesService * @param int $storageId - * @param \OCP\Files\Storage $storage + * @param \OCP\Files\Storage\IStorage $storage * @param string $mountpoint * @param array $arguments (optional) configuration for the storage backend * @param \OCP\Files\Storage\IStorageFactory $loader diff --git a/lib/private/Files/External/SessionStorageWrapper.php b/lib/private/Files/External/SessionStorageWrapper.php index 009f09e35b49..320a0ecc42d7 100644 --- a/lib/private/Files/External/SessionStorageWrapper.php +++ b/lib/private/Files/External/SessionStorageWrapper.php @@ -22,7 +22,6 @@ namespace OC\Files\External; -use \OCP\Files\Storage; use \OC\Files\Storage\Wrapper\PermissionsMask; use \OCP\Constants; diff --git a/lib/private/Files/External/StorageModifierTrait.php b/lib/private/Files/External/StorageModifierTrait.php index 68035bf22b88..416e5e82d06d 100644 --- a/lib/private/Files/External/StorageModifierTrait.php +++ b/lib/private/Files/External/StorageModifierTrait.php @@ -57,12 +57,12 @@ public function manipulateStorageConfig(IStorageConfig &$storage, IUser $user = /** * Wrap a Storage if necessary * - * @param Storage $storage - * @return Storage + * @param Storage\IStorage $storage + * @return Storage\IStorage * @throws InsufficientDataForMeaningfulAnswerException * @throws StorageNotAvailableException */ - public function wrapStorage(Storage $storage) { + public function wrapStorage(Storage\IStorage $storage) { return $storage; } } diff --git a/lib/private/Files/Meta/MetaFileVersionNode.php b/lib/private/Files/Meta/MetaFileVersionNode.php index 94cc0ac9734d..2367343683fa 100644 --- a/lib/private/Files/Meta/MetaFileVersionNode.php +++ b/lib/private/Files/Meta/MetaFileVersionNode.php @@ -65,7 +65,7 @@ class MetaFileVersionNode extends AbstractFile implements IPreviewNode, IProvide */ public function __construct(MetaVersionCollection $parent, IRootFolder $root, - array $version, Storage $storage, $internalPath) { + array $version, Storage\IStorage $storage, $internalPath) { $this->parent = $parent; $this->versionId = $version['version']; $this->versionInfo = $version; diff --git a/lib/private/Files/ObjectStore/ObjectStoreStorage.php b/lib/private/Files/ObjectStore/ObjectStoreStorage.php index b3b0cc0fd0e1..2e77f33595cc 100644 --- a/lib/private/Files/ObjectStore/ObjectStoreStorage.php +++ b/lib/private/Files/ObjectStore/ObjectStoreStorage.php @@ -30,6 +30,7 @@ use OCP\Files\NotFoundException; use OCP\Files\ObjectStore\IObjectStore; use OCP\Files\ObjectStore\IVersionedObjectStorage; +use OCP\Files\Storage\IStorage; class ObjectStoreStorage extends \OC\Files\Storage\Common { @@ -320,7 +321,7 @@ public function rename($source, $target) { return true; } - public function moveFromStorage(\OCP\Files\Storage $sourceStorage, $sourceInternalPath, $targetInternalPath) { + public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath) { if ($sourceStorage === $this) { return $this->copy($sourceInternalPath, $targetInternalPath); } diff --git a/lib/private/Files/Storage/Common.php b/lib/private/Files/Storage/Common.php index 8ab714e7aaa8..c729637c7518 100644 --- a/lib/private/Files/Storage/Common.php +++ b/lib/private/Files/Storage/Common.php @@ -51,6 +51,7 @@ use OCP\Files\InvalidPathException; use OCP\Files\ReservedWordException; use OCP\Files\Storage\ILockingStorage; +use OCP\Files\Storage\IStorage; use OCP\Files\Storage\IVersionedStorage; use OCP\Lock\ILockingProvider; @@ -547,13 +548,14 @@ public function getMountOption($name, $default = null) { } /** - * @param \OCP\Files\Storage $sourceStorage + * @param IStorage $sourceStorage * @param string $sourceInternalPath * @param string $targetInternalPath * @param bool $preserveMtime * @return bool + * @throws \OCP\Files\StorageNotAvailableException */ - public function copyFromStorage(\OCP\Files\Storage $sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime = false) { + public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime = false) { if ($sourceStorage === $this) { return $this->copy($sourceInternalPath, $targetInternalPath); } @@ -594,12 +596,13 @@ public function copyFromStorage(\OCP\Files\Storage $sourceStorage, $sourceIntern } /** - * @param \OCP\Files\Storage $sourceStorage + * @param IStorage $sourceStorage * @param string $sourceInternalPath * @param string $targetInternalPath * @return bool + * @throws \OCP\Files\StorageNotAvailableException */ - public function moveFromStorage(\OCP\Files\Storage $sourceStorage, $sourceInternalPath, $targetInternalPath) { + public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath) { if ($sourceStorage === $this) { return $this->rename($sourceInternalPath, $targetInternalPath); } diff --git a/lib/private/Files/Storage/FailedStorage.php b/lib/private/Files/Storage/FailedStorage.php index 58246c0d7af8..0b22822ccd50 100644 --- a/lib/private/Files/Storage/FailedStorage.php +++ b/lib/private/Files/Storage/FailedStorage.php @@ -24,6 +24,7 @@ namespace OC\Files\Storage; use OC\Files\Cache\FailedCache; +use OCP\Files\Storage\IStorage; use \OCP\Lock\ILockingProvider; use \OCP\Files\StorageNotAvailableException; @@ -182,11 +183,11 @@ public function verifyPath($path, $fileName) { return true; } - public function copyFromStorage(\OCP\Files\Storage $sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime = false) { + public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime = false) { throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); } - public function moveFromStorage(\OCP\Files\Storage $sourceStorage, $sourceInternalPath, $targetInternalPath) { + public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath) { throw new StorageNotAvailableException($this->e->getMessage(), $this->e->getCode(), $this->e); } diff --git a/lib/private/Files/Storage/Local.php b/lib/private/Files/Storage/Local.php index 5b577194bfb9..d512986246bc 100644 --- a/lib/private/Files/Storage/Local.php +++ b/lib/private/Files/Storage/Local.php @@ -37,6 +37,7 @@ namespace OC\Files\Storage; use OCP\Files\ForbiddenException; +use OCP\Files\Storage\IStorage; /** * for local filestore, we only have to map the paths @@ -314,10 +315,6 @@ public function free_space($path) { return $space; } - public function search($query) { - return $this->searchInDir($query); - } - public function getLocalFile($path) { return $this->getSourcePath($path); } @@ -357,6 +354,7 @@ protected function searchInDir($query, $dir = '') { * @param string $path * @param int $time * @return bool + * @throws \OCP\Files\StorageNotAvailableException */ public function hasUpdated($path, $time) { if ($this->file_exists($path)) { @@ -412,6 +410,7 @@ public function isLocal() { * * @param string $path * @return string + * @throws \OCP\Files\StorageNotAvailableException */ public function getETag($path) { if ($this->is_file($path)) { @@ -428,14 +427,15 @@ public function getETag($path) { } /** - * @param \OCP\Files\Storage $sourceStorage + * @param IStorage $sourceStorage * @param string $sourceInternalPath * @param string $targetInternalPath * @param bool $preserveMtime * @return bool * @throws ForbiddenException + * @throws \OCP\Files\StorageNotAvailableException */ - public function copyFromStorage(\OCP\Files\Storage $sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime = false) { + public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime = false) { if ($sourceStorage->instanceOfStorage(__CLASS__)) { /** * @var \OC\Files\Storage\Local $sourceStorage @@ -448,13 +448,13 @@ public function copyFromStorage(\OCP\Files\Storage $sourceStorage, $sourceIntern } /** - * @param \OCP\Files\Storage $sourceStorage + * @param \OCP\Files\Storage\IStorage $sourceStorage * @param string $sourceInternalPath * @param string $targetInternalPath * @return bool - * @throws \InvalidArgumentException + * @throws \OCP\Files\StorageNotAvailableException */ - public function moveFromStorage(\OCP\Files\Storage $sourceStorage, $sourceInternalPath, $targetInternalPath) { + public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath) { if ($sourceStorage->instanceOfStorage(__CLASS__)) { /** * @var \OC\Files\Storage\Local $sourceStorage diff --git a/lib/private/Files/Storage/Storage.php b/lib/private/Files/Storage/Storage.php index de39d00e9459..fb032dc1bec0 100644 --- a/lib/private/Files/Storage/Storage.php +++ b/lib/private/Files/Storage/Storage.php @@ -22,6 +22,7 @@ */ namespace OC\Files\Storage; +use OCP\Files\Storage\IStorage; use OCP\Lock\ILockingProvider; /** @@ -29,7 +30,7 @@ * * All paths passed to the storage are relative to the storage and should NOT have a leading slash. */ -interface Storage extends \OCP\Files\Storage { +interface Storage extends IStorage { /** * get a cache instance for the storage diff --git a/lib/private/Files/Storage/StorageFactory.php b/lib/private/Files/Storage/StorageFactory.php index dc08eb172a00..1cbc462b1348 100644 --- a/lib/private/Files/Storage/StorageFactory.php +++ b/lib/private/Files/Storage/StorageFactory.php @@ -25,6 +25,7 @@ namespace OC\Files\Storage; use OCP\Files\Mount\IMountPoint; +use OCP\Files\Storage\IStorage; use OCP\Files\Storage\IStorageFactory; class StorageFactory implements IStorageFactory { @@ -84,7 +85,7 @@ public function getInstance(IMountPoint $mountPoint, $class, $arguments) { /** * @param \OCP\Files\Mount\IMountPoint $mountPoint - * @param \OCP\Files\Storage $storage + * @param \OCP\Files\Storage\IStorage $storage * @return \OCP\Files\Storage */ public function wrap(IMountPoint $mountPoint, $storage) { @@ -98,7 +99,7 @@ public function wrap(IMountPoint $mountPoint, $storage) { }, $wrappers); foreach ($wrappers as $wrapper) { $storage = $wrapper($mountPoint->getMountPoint(), $storage, $mountPoint); - if (!($storage instanceof \OCP\Files\Storage)) { + if (!($storage instanceof IStorage)) { throw new \Exception('Invalid result from storage wrapper'); } } diff --git a/lib/private/Files/Storage/Wrapper/Availability.php b/lib/private/Files/Storage/Wrapper/Availability.php index b9bbc3b7ab39..a56d470e28f1 100644 --- a/lib/private/Files/Storage/Wrapper/Availability.php +++ b/lib/private/Files/Storage/Wrapper/Availability.php @@ -20,6 +20,7 @@ * */ namespace OC\Files\Storage\Wrapper; +use OCP\Files\Storage\IStorage; /** * Availability checker for storages @@ -431,7 +432,7 @@ public function getDirectDownload($path) { } /** {@inheritdoc} */ - public function copyFromStorage(\OCP\Files\Storage $sourceStorage, $sourceInternalPath, $targetInternalPath) { + public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath) { $this->checkAvailability(); try { return parent::copyFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath); @@ -442,7 +443,7 @@ public function copyFromStorage(\OCP\Files\Storage $sourceStorage, $sourceIntern } /** {@inheritdoc} */ - public function moveFromStorage(\OCP\Files\Storage $sourceStorage, $sourceInternalPath, $targetInternalPath) { + public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath) { $this->checkAvailability(); try { return parent::moveFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath); diff --git a/lib/private/Files/Storage/Wrapper/Encoding.php b/lib/private/Files/Storage/Wrapper/Encoding.php index 82e60e55f9f7..bd957691d7c1 100644 --- a/lib/private/Files/Storage/Wrapper/Encoding.php +++ b/lib/private/Files/Storage/Wrapper/Encoding.php @@ -21,6 +21,7 @@ namespace OC\Files\Storage\Wrapper; +use OCP\Files\Storage\IStorage; use OCP\ICache; use OC\Cache\CappedMemoryCache; @@ -482,12 +483,12 @@ public function getETag($path) { } /** - * @param \OCP\Files\Storage $sourceStorage + * @param \OCP\Files\Storage\IStorage $sourceStorage * @param string $sourceInternalPath * @param string $targetInternalPath * @return bool */ - public function copyFromStorage(\OCP\Files\Storage $sourceStorage, $sourceInternalPath, $targetInternalPath) { + public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath) { if ($sourceStorage === $this) { return $this->copy($sourceInternalPath, $this->findPathToUse($targetInternalPath)); } @@ -500,12 +501,12 @@ public function copyFromStorage(\OCP\Files\Storage $sourceStorage, $sourceIntern } /** - * @param \OCP\Files\Storage $sourceStorage + * @param \OCP\Files\Storage\IStorage $sourceStorage * @param string $sourceInternalPath * @param string $targetInternalPath * @return bool */ - public function moveFromStorage(\OCP\Files\Storage $sourceStorage, $sourceInternalPath, $targetInternalPath) { + public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath) { if ($sourceStorage === $this) { $result = $this->rename($sourceInternalPath, $this->findPathToUse($targetInternalPath)); if ($result) { diff --git a/lib/private/Files/Storage/Wrapper/Encryption.php b/lib/private/Files/Storage/Wrapper/Encryption.php index 7ea225660f50..426efc9a4bff 100644 --- a/lib/private/Files/Storage/Wrapper/Encryption.php +++ b/lib/private/Files/Storage/Wrapper/Encryption.php @@ -603,13 +603,14 @@ protected function fixUnencryptedSize($path, $size, $unencryptedSize) { } /** - * @param Storage $sourceStorage + * @param Storage\IStorage $sourceStorage * @param string $sourceInternalPath * @param string $targetInternalPath * @param bool $preserveMtime * @return bool + * @throws \Exception */ - public function moveFromStorage(Storage $sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime = true) { + public function moveFromStorage(Storage\IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime = true) { if ($sourceStorage === $this) { return $this->rename($sourceInternalPath, $targetInternalPath); } @@ -649,14 +650,15 @@ public static function setDisableWriteEncryption($isDisabled) { } /** - * @param Storage $sourceStorage + * @param Storage\IStorage $sourceStorage * @param string $sourceInternalPath * @param string $targetInternalPath * @param bool $preserveMtime * @param bool $isRename * @return bool + * @throws \Exception */ - public function copyFromStorage(Storage $sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime = false, $isRename = false) { + public function copyFromStorage(Storage\IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime = false, $isRename = false) { // TODO clean this up once the underlying moveFromStorage in OC\Files\Storage\Wrapper\Common is fixed: // - call $this->storage->copyFromStorage() instead of $this->copyBetweenStorage @@ -675,7 +677,7 @@ public function copyFromStorage(Storage $sourceStorage, $sourceInternalPath, $ta * @param string $targetInternalPath * @param bool $isRename */ - private function updateEncryptedVersion(Storage $sourceStorage, $sourceInternalPath, $targetInternalPath, $isRename) { + private function updateEncryptedVersion(Storage\IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath, $isRename) { $isEncrypted = $this->encryptionManager->isEnabled() && $this->mount->getOption('encrypt', true) ? 1 : 0; $cacheInformation = [ 'encrypted' => (bool)$isEncrypted, @@ -723,7 +725,7 @@ private function updateEncryptedVersion(Storage $sourceStorage, $sourceInternalP * @return bool * @throws \Exception */ - private function copyBetweenStorage(Storage $sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime, $isRename) { + private function copyBetweenStorage(Storage\IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime, $isRename) { // for versions we have nothing to do, because versions should always use the // key from the original file. Just create a 1:1 copy and done if ($this->isVersion($targetInternalPath) || diff --git a/lib/private/Files/Storage/Wrapper/Jail.php b/lib/private/Files/Storage/Wrapper/Jail.php index 5ab73b2f99b0..5595004dd0f4 100644 --- a/lib/private/Files/Storage/Wrapper/Jail.php +++ b/lib/private/Files/Storage/Wrapper/Jail.php @@ -25,6 +25,7 @@ namespace OC\Files\Storage\Wrapper; use OC\Files\Cache\Wrapper\CacheJail; +use OCP\Files\Storage\IStorage; use OCP\Lock\ILockingProvider; /** @@ -472,12 +473,12 @@ public function resolvePath($path) { } /** - * @param \OCP\Files\Storage $sourceStorage + * @param \OCP\Files\Storage\IStorage $sourceStorage * @param string $sourceInternalPath * @param string $targetInternalPath * @return bool */ - public function copyFromStorage(\OCP\Files\Storage $sourceStorage, $sourceInternalPath, $targetInternalPath) { + public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath) { if ($sourceStorage === $this) { return $this->copy($sourceInternalPath, $targetInternalPath); } @@ -485,12 +486,12 @@ public function copyFromStorage(\OCP\Files\Storage $sourceStorage, $sourceIntern } /** - * @param \OCP\Files\Storage $sourceStorage + * @param \OCP\Files\Storage\IStorage $sourceStorage * @param string $sourceInternalPath * @param string $targetInternalPath * @return bool */ - public function moveFromStorage(\OCP\Files\Storage $sourceStorage, $sourceInternalPath, $targetInternalPath) { + public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath) { if ($sourceStorage === $this) { return $this->rename($sourceInternalPath, $targetInternalPath); } diff --git a/lib/private/Files/Storage/Wrapper/Quota.php b/lib/private/Files/Storage/Wrapper/Quota.php index c7a1a577e643..9fd8b6b6c893 100644 --- a/lib/private/Files/Storage/Wrapper/Quota.php +++ b/lib/private/Files/Storage/Wrapper/Quota.php @@ -26,6 +26,7 @@ namespace OC\Files\Storage\Wrapper; use OCP\Files\Cache\ICacheEntry; +use OCP\Files\Storage\IStorage; class Quota extends Wrapper { @@ -169,12 +170,12 @@ private function isPartFile($path) { } /** - * @param \OCP\Files\Storage $sourceStorage + * @param \OCP\Files\Storage\IStorage $sourceStorage * @param string $sourceInternalPath * @param string $targetInternalPath * @return bool */ - public function copyFromStorage(\OCP\Files\Storage $sourceStorage, $sourceInternalPath, $targetInternalPath) { + public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath) { $free = $this->free_space(''); if ($free < 0 or $this->getSize($sourceInternalPath, $sourceStorage) < $free) { return $this->storage->copyFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath); @@ -184,12 +185,12 @@ public function copyFromStorage(\OCP\Files\Storage $sourceStorage, $sourceIntern } /** - * @param \OCP\Files\Storage $sourceStorage + * @param IStorage $sourceStorage * @param string $sourceInternalPath * @param string $targetInternalPath * @return bool */ - public function moveFromStorage(\OCP\Files\Storage $sourceStorage, $sourceInternalPath, $targetInternalPath) { + public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath) { $free = $this->free_space(''); if ($free < 0 or $this->getSize($sourceInternalPath, $sourceStorage) < $free) { return $this->storage->moveFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath); diff --git a/lib/private/Files/Storage/Wrapper/Wrapper.php b/lib/private/Files/Storage/Wrapper/Wrapper.php index 50cf0fad69e4..a052acea6202 100644 --- a/lib/private/Files/Storage/Wrapper/Wrapper.php +++ b/lib/private/Files/Storage/Wrapper/Wrapper.php @@ -28,6 +28,7 @@ use OCP\Files\InvalidPathException; use OCP\Files\Storage\ILockingStorage; +use OCP\Files\Storage\IStorage; use OCP\Lock\ILockingProvider; class Wrapper implements \OC\Files\Storage\Storage, ILockingStorage { @@ -541,12 +542,13 @@ public function verifyPath($path, $fileName) { } /** - * @param \OCP\Files\Storage $sourceStorage + * @param \OCP\Files\Storage\IStorage $sourceStorage * @param string $sourceInternalPath * @param string $targetInternalPath * @return bool + * @throws \OCP\Files\StorageNotAvailableException */ - public function copyFromStorage(\OCP\Files\Storage $sourceStorage, $sourceInternalPath, $targetInternalPath) { + public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath) { if ($sourceStorage === $this) { return $this->copy($sourceInternalPath, $targetInternalPath); } @@ -555,12 +557,12 @@ public function copyFromStorage(\OCP\Files\Storage $sourceStorage, $sourceIntern } /** - * @param \OCP\Files\Storage $sourceStorage + * @param IStorage $sourceStorage * @param string $sourceInternalPath * @param string $targetInternalPath * @return bool */ - public function moveFromStorage(\OCP\Files\Storage $sourceStorage, $sourceInternalPath, $targetInternalPath) { + public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath) { if ($sourceStorage === $this) { return $this->rename($sourceInternalPath, $targetInternalPath); } diff --git a/lib/private/Share20/Manager.php b/lib/private/Share20/Manager.php index 6f8a937cd5c7..a839295e06c8 100644 --- a/lib/private/Share20/Manager.php +++ b/lib/private/Share20/Manager.php @@ -529,7 +529,7 @@ protected function pathCreateChecks($path) { if ($path instanceof \OCP\Files\Folder) { $mounts = $this->mountManager->findIn($path->getPath()); foreach ($mounts as $mount) { - if ($mount->getStorage()->instanceOfStorage('\OCA\Files_Sharing\ISharedStorage')) { + if ($mount->getStorage()->instanceOfStorage('OCA\Files_Sharing\ISharedStorage')) { throw new \InvalidArgumentException('Path contains files shared with you'); } } diff --git a/lib/private/legacy/util.php b/lib/private/legacy/util.php index 5b4f96470157..b6cf36b87e50 100644 --- a/lib/private/legacy/util.php +++ b/lib/private/legacy/util.php @@ -58,8 +58,7 @@ use OCP\Authentication\Exceptions\AccountCheckException; use OCP\Files\NoReadAccessException; -use OCP\IConfig; -use OCP\IGroupManager; +use OCP\Files\Storage\IStorage; use OCP\IUser; class OC_Util { @@ -156,7 +155,7 @@ public static function setupFS($user = '') { \OC\Files\Filesystem::initMountManager(); \OC\Files\Filesystem::logWarningWhenAddingStorageWrapper(false); - \OC\Files\Filesystem::addStorageWrapper('mount_options', function ($mountPoint, \OCP\Files\Storage $storage, \OCP\Files\Mount\IMountPoint $mount) { + \OC\Files\Filesystem::addStorageWrapper('mount_options', function ($mountPoint, IStorage $storage, \OCP\Files\Mount\IMountPoint $mount) { if ($storage->instanceOfStorage('\OC\Files\Storage\Common')) { /** @var \OC\Files\Storage\Common $storage */ $storage->setMountOptions($mount->getOptions()); @@ -164,7 +163,7 @@ public static function setupFS($user = '') { return $storage; }); - \OC\Files\Filesystem::addStorageWrapper('enable_sharing', function ($mountPoint, \OCP\Files\Storage $storage, \OCP\Files\Mount\IMountPoint $mount) { + \OC\Files\Filesystem::addStorageWrapper('enable_sharing', function ($mountPoint, IStorage $storage, \OCP\Files\Mount\IMountPoint $mount) { if (!$mount->getOption('enable_sharing', true)) { return new \OC\Files\Storage\Wrapper\PermissionsMask([ 'storage' => $storage, @@ -183,7 +182,7 @@ public static function setupFS($user = '') { }); // install storage checksum wrapper - \OC\Files\Filesystem::addStorageWrapper('oc_checksum', function ($mountPoint, \OCP\Files\Storage\IStorage $storage) { + \OC\Files\Filesystem::addStorageWrapper('oc_checksum', function ($mountPoint, IStorage $storage) { if (!$storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage')) { return new \OC\Files\Storage\Wrapper\Checksum(['storage' => $storage]); } @@ -191,7 +190,7 @@ public static function setupFS($user = '') { return $storage; }, 1); - \OC\Files\Filesystem::addStorageWrapper('oc_encoding', function ($mountPoint, \OCP\Files\Storage $storage, \OCP\Files\Mount\IMountPoint $mount) { + \OC\Files\Filesystem::addStorageWrapper('oc_encoding', function ($mountPoint, IStorage $storage, \OCP\Files\Mount\IMountPoint $mount) { if ($mount->getOption('encoding_compatibility', false) && !$storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage') && !$storage->isLocal()) { return new \OC\Files\Storage\Wrapper\Encoding(['storage' => $storage]); } diff --git a/lib/public/Files/Node.php b/lib/public/Files/Node.php index c391095be404..52ad6183b548 100644 --- a/lib/public/Files/Node.php +++ b/lib/public/Files/Node.php @@ -32,6 +32,8 @@ // This means that they should be used by apps instead of the internal ownCloud classes namespace OCP\Files; +use OCP\Files\Storage\IStorage; + /** * Interface Node * @@ -79,7 +81,7 @@ public function touch($mtime = null); /** * Get the storage backend the file or folder is stored on * - * @return \OCP\Files\Storage + * @return IStorage * @throws \OCP\Files\NotFoundException * @since 6.0.0 */ diff --git a/lib/public/Files/Storage.php b/lib/public/Files/Storage.php deleted file mode 100644 index 8878119fc579..000000000000 --- a/lib/public/Files/Storage.php +++ /dev/null @@ -1,459 +0,0 @@ - - * @author Michael Roth - * @author Morris Jobke - * @author Robin Appelman - * @author Robin McCorkell - * @author Thomas Müller - * @author Vincent Petry - * - * @copyright Copyright (c) 2018, ownCloud GmbH - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License, version 3, - * along with this program. If not, see - * - */ - -/** - * Public interface of ownCloud for apps to use. - * Files/Storage interface - */ - -// use OCP namespace for all classes that are considered public. -// This means that they should be used by apps instead of the internal ownCloud classes -namespace OCP\Files; - -use OCP\Files\Storage\IStorage; -use OCP\Lock\ILockingProvider; - -/** - * Provide a common interface to all different storage options - * - * All paths passed to the storage are relative to the storage and should NOT have a leading slash. - * - * @since 6.0.0 - * @deprecated 9.0.0 use \OCP\Files\Storage\IStorage instead - */ -interface Storage extends IStorage { - /** - * $parameters is a free form array with the configuration options needed to construct the storage - * - * @param array $parameters - * @since 6.0.0 - */ - public function __construct($parameters); - - /** - * Get the identifier for the storage, - * the returned id should be the same for every storage object that is created with the same parameters - * and two storage objects with the same id should refer to two storages that display the same files. - * - * @return string - * @since 6.0.0 - */ - public function getId(); - - /** - * see http://php.net/manual/en/function.mkdir.php - * implementations need to implement a recursive mkdir - * - * @param string $path - * @return bool - * @since 6.0.0 - */ - public function mkdir($path); - - /** - * see http://php.net/manual/en/function.rmdir.php - * - * @param string $path - * @return bool - * @since 6.0.0 - */ - public function rmdir($path); - - /** - * see http://php.net/manual/en/function.opendir.php - * - * @param string $path - * @return resource|false - * @since 6.0.0 - */ - public function opendir($path); - - /** - * see http://php.net/manual/en/function.is-dir.php - * - * @param string $path - * @return bool - * @since 6.0.0 - */ - public function is_dir($path); - - /** - * see http://php.net/manual/en/function.is-file.php - * - * @param string $path - * @return bool - * @since 6.0.0 - */ - public function is_file($path); - - /** - * see http://php.net/manual/en/function.stat.php - * only the following keys are required in the result: size and mtime - * - * @param string $path - * @return array|false - * @since 6.0.0 - */ - public function stat($path); - - /** - * see http://php.net/manual/en/function.filetype.php - * - * @param string $path - * @return string|false - * @since 6.0.0 - */ - public function filetype($path); - - /** - * see http://php.net/manual/en/function.filesize.php - * The result for filesize when called on a folder is required to be 0 - * - * @param string $path - * @return int|false - * @since 6.0.0 - */ - public function filesize($path); - - /** - * check if a file can be created in $path - * - * @param string $path - * @return bool - * @since 6.0.0 - */ - public function isCreatable($path); - - /** - * check if a file can be read - * - * @param string $path - * @return bool - * @since 6.0.0 - */ - public function isReadable($path); - - /** - * check if a file can be written to - * - * @param string $path - * @return bool - * @since 6.0.0 - */ - public function isUpdatable($path); - - /** - * check if a file can be deleted - * - * @param string $path - * @return bool - * @since 6.0.0 - */ - public function isDeletable($path); - - /** - * check if a file can be shared - * - * @param string $path - * @return bool - * @since 6.0.0 - */ - public function isSharable($path); - - /** - * get the full permissions of a path. - * Should return a combination of the PERMISSION_ constants defined in lib/public/constants.php - * - * @param string $path - * @return int - * @since 6.0.0 - */ - public function getPermissions($path); - - /** - * see http://php.net/manual/en/function.file_exists.php - * - * @param string $path - * @return bool - * @since 6.0.0 - */ - public function file_exists($path); - - /** - * see http://php.net/manual/en/function.filemtime.php - * - * @param string $path - * @return int|false - * @since 6.0.0 - */ - public function filemtime($path); - - /** - * see http://php.net/manual/en/function.file_get_contents.php - * - * @param string $path - * @return string|false - * @since 6.0.0 - */ - public function file_get_contents($path); - - /** - * see http://php.net/manual/en/function.file_put_contents.php - * - * @param string $path - * @param string $data - * @return bool - * @since 6.0.0 - */ - public function file_put_contents($path, $data); - - /** - * see http://php.net/manual/en/function.unlink.php - * - * @param string $path - * @return bool - * @since 6.0.0 - */ - public function unlink($path); - - /** - * see http://php.net/manual/en/function.rename.php - * - * @param string $path1 - * @param string $path2 - * @return bool - * @since 6.0.0 - */ - public function rename($path1, $path2); - - /** - * see http://php.net/manual/en/function.copy.php - * - * @param string $path1 - * @param string $path2 - * @return bool - * @since 6.0.0 - */ - public function copy($path1, $path2); - - /** - * see http://php.net/manual/en/function.fopen.php - * - * @param string $path - * @param string $mode - * @return resource|false - * @since 6.0.0 - */ - public function fopen($path, $mode); - - /** - * get the mimetype for a file or folder - * The mimetype for a folder is required to be "httpd/unix-directory" - * - * @param string $path - * @return string|false - * @since 6.0.0 - */ - public function getMimeType($path); - - /** - * see http://php.net/manual/en/function.hash-file.php - * - * @param string $type - * @param string $path - * @param bool $raw - * @return string|false - * @since 6.0.0 - */ - public function hash($type, $path, $raw = false); - - /** - * see http://php.net/manual/en/function.free_space.php - * - * @param string $path - * @return int|false - * @since 6.0.0 - */ - public function free_space($path); - - /** - * search for occurrences of $query in file names - * - * @param string $query - * @return array|false - * @since 6.0.0 - */ - public function search($query); - - /** - * see http://php.net/manual/en/function.touch.php - * If the backend does not support the operation, false should be returned - * - * @param string $path - * @param int $mtime - * @return bool - * @since 6.0.0 - */ - public function touch($path, $mtime = null); - - /** - * get the path to a local version of the file. - * The local version of the file can be temporary and doesn't have to be persistent across requests - * - * @param string $path - * @return string|false - * @since 6.0.0 - */ - public function getLocalFile($path); - - /** - * check if a file or folder has been updated since $time - * - * @param string $path - * @param int $time - * @return bool - * @since 6.0.0 - * - * hasUpdated for folders should return at least true if a file inside the folder is add, removed or renamed. - * returning true for other changes in the folder is optional - */ - public function hasUpdated($path, $time); - - /** - * get the ETag for a file or folder - * - * @param string $path - * @return string|false - * @since 6.0.0 - */ - public function getETag($path); - - /** - * Returns whether the storage is local, which means that files - * are stored on the local filesystem instead of remotely. - * Calling getLocalFile() for local storages should always - * return the local files, whereas for non-local storages - * it might return a temporary file. - * - * @return bool true if the files are stored locally, false otherwise - * @since 7.0.0 - */ - public function isLocal(); - - /** - * Check if the storage is an instance of $class or is a wrapper for a storage that is an instance of $class - * - * @param string $class - * @return bool - * @since 7.0.0 - */ - public function instanceOfStorage($class); - - /** - * A custom storage implementation can return an url for direct download of a give file. - * - * For now the returned array can hold the parameter url - in future more attributes might follow. - * - * @param string $path - * @return array|false - * @since 8.0.0 - */ - public function getDirectDownload($path); - - /** - * @param string $path the path of the target folder - * @param string $fileName the name of the file itself - * @return void - * @throws InvalidPathException - * @since 8.1.0 - */ - public function verifyPath($path, $fileName); - - /** - * @param \OCP\Files\Storage $sourceStorage - * @param string $sourceInternalPath - * @param string $targetInternalPath - * @return bool - * @since 8.1.0 - */ - public function copyFromStorage(\OCP\Files\Storage $sourceStorage, $sourceInternalPath, $targetInternalPath); - - /** - * @param \OCP\Files\Storage $sourceStorage - * @param string $sourceInternalPath - * @param string $targetInternalPath - * @return bool - * @since 8.1.0 - */ - public function moveFromStorage(\OCP\Files\Storage $sourceStorage, $sourceInternalPath, $targetInternalPath); - - /** - * @param string $path The path of the file to acquire the lock for - * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE - * @param \OCP\Lock\ILockingProvider $provider - * @throws \OCP\Lock\LockedException - * @since 8.1.0 - */ - public function acquireLock($path, $type, ILockingProvider $provider); - - /** - * @param string $path The path of the file to acquire the lock for - * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE - * @param \OCP\Lock\ILockingProvider $provider - * @since 8.1.0 - */ - public function releaseLock($path, $type, ILockingProvider $provider); - - /** - * @param string $path The path of the file to change the lock for - * @param int $type \OCP\Lock\ILockingProvider::LOCK_SHARED or \OCP\Lock\ILockingProvider::LOCK_EXCLUSIVE - * @param \OCP\Lock\ILockingProvider $provider - * @throws \OCP\Lock\LockedException - * @since 8.1.0 - */ - public function changeLock($path, $type, ILockingProvider $provider); - - /** - * Test a storage for availability - * - * @since 8.2.0 - * @return bool - */ - public function test(); - - /** - * @since 8.2.0 - * @return array [ available, last_checked ] - */ - public function getAvailability(); - - /** - * @since 8.2.0 - * @param bool $isAvailable - */ - public function setAvailability($isAvailable); -} diff --git a/lib/public/Files/Storage/IStorage.php b/lib/public/Files/Storage/IStorage.php index 123a1ebdd419..f96b443d3cb7 100644 --- a/lib/public/Files/Storage/IStorage.php +++ b/lib/public/Files/Storage/IStorage.php @@ -414,24 +414,22 @@ public function getDirectDownload($path); public function verifyPath($path, $fileName); /** - * @param \OCP\Files\Storage $sourceStorage + * @param IStorage $sourceStorage * @param string $sourceInternalPath * @param string $targetInternalPath * @return bool - * @throws StorageNotAvailableException if the storage is temporarily not available * @since 9.0.0 */ - public function copyFromStorage(\OCP\Files\Storage $sourceStorage, $sourceInternalPath, $targetInternalPath); + public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath); /** - * @param \OCP\Files\Storage $sourceStorage + * @param IStorage $sourceStorage * @param string $sourceInternalPath * @param string $targetInternalPath * @return bool - * @throws StorageNotAvailableException if the storage is temporarily not available * @since 9.0.0 */ - public function moveFromStorage(\OCP\Files\Storage $sourceStorage, $sourceInternalPath, $targetInternalPath); + public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath); /** * Test a storage for availability diff --git a/tests/lib/Files/Mount/MountPointTest.php b/tests/lib/Files/Mount/MountPointTest.php index 11930da7f677..6cfe8a0eb6ed 100644 --- a/tests/lib/Files/Mount/MountPointTest.php +++ b/tests/lib/Files/Mount/MountPointTest.php @@ -8,14 +8,18 @@ namespace Test\Files\Mount; +use OCP\Files\Storage\IStorage; +use OCP\Files\Storage\IStorageFactory; +use OC\Files\Cache\Cache; + class MountPointTest extends \Test\TestCase { public function testGetStorage() { - $cache = $this->createMock('\OC\Files\Cache\Cache'); + $cache = $this->createMock(Cache::class); $cache->expects($this->once()) ->method('getId') ->will($this->returnValue(123)); - $storage = $this->createMock('\OCP\Files\Storage'); + $storage = $this->createMock(IStorage::class); $storage->expects($this->once()) ->method('getId') ->will($this->returnValue('home:12345')); @@ -23,14 +27,14 @@ public function testGetStorage() { ->method('getCache') ->will($this->returnValue($cache)); - $loader = $this->createMock('\OCP\Files\Storage\IStorageFactory'); + $loader = $this->createMock(IStorageFactory::class); $loader->expects($this->once()) ->method('getInstance') ->will($this->returnValue($storage)); $mountPoint = new \OC\Files\Mount\MountPoint( // just use this because a real class is needed - '\Test\Files\Mount\MountPointTest', + MountPointTest::class, '/mountpoint', null, $loader @@ -46,7 +50,7 @@ public function testGetStorage() { } public function testInvalidStorage() { - $loader = $this->createMock('\OCP\Files\Storage\IStorageFactory'); + $loader = $this->createMock(IStorageFactory::class); $loader->expects($this->once()) ->method('getInstance') ->will($this->throwException(new \Exception('Test storage init exception'))); @@ -58,7 +62,7 @@ public function testInvalidStorage() { $mountPoint = new \OC\Files\Mount\MountPoint( // just use this because a real class is needed - '\Test\Files\Mount\MountPointTest', + MountPointTest::class, '/mountpoint', null, $loader @@ -82,19 +86,19 @@ public function testInvalidStorage() { } public function testGetRootIdNullCache() { - $storage = $this->createMock('\OCP\Files\Storage'); + $storage = $this->createMock(IStorage::class); $storage->expects($this->any()) ->method('getCache') ->will($this->returnValue(null)); - $loader = $this->createMock('\OCP\Files\Storage\IStorageFactory'); + $loader = $this->createMock(IStorageFactory::class); $loader->expects($this->once()) ->method('getInstance') ->will($this->returnValue($storage)); $mountPoint = new \OC\Files\Mount\MountPoint( // just use this because a real class is needed - '\Test\Files\Mount\MountPointTest', + MountPointTest::class, '/mountpoint', null, $loader diff --git a/tests/lib/Files/Node/NodeTest.php b/tests/lib/Files/Node/NodeTest.php index c69ecee9fff6..c48dcb8b36e0 100644 --- a/tests/lib/Files/Node/NodeTest.php +++ b/tests/lib/Files/Node/NodeTest.php @@ -11,8 +11,13 @@ use OC\Files\FileInfo; use OCP\Constants; use OCP\Files\NotFoundException; +use OCP\Files\Storage\IStorage; use OCP\IUser; use Test\TestCase; +use OC\Files\Node\Root; +use OC\Files\View; +use OC\Files\Storage\Storage; +use OC\Files\Mount\Manager; /** * Class NodeTest @@ -31,7 +36,7 @@ protected function setUp() { abstract protected function createTestNode($root, $view, $path); protected function getMockStorage() { - $storage = $this->createMock('\OCP\Files\Storage'); + $storage = $this->createMock(IStorage::class); $storage->expects($this->any()) ->method('getId') ->will($this->returnValue('home::someuser')); @@ -46,9 +51,9 @@ public function testDelete() { /** * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view */ - $view = $this->createMock('\OC\Files\View'); + $view = $this->createMock(View::class); - $root = $this->createMock('\OC\Files\Node\Root'); + $root = $this->createMock(Root::class); $root->expects($this->exactly(2)) ->method('emit') ->will($this->returnValue(true)); @@ -99,11 +104,11 @@ public function testDeleteHooks() { /** * @var \OC\Files\Mount\Manager $manager */ - $manager = $this->createMock('\OC\Files\Mount\Manager'); + $manager = $this->createMock(Manager::class); /** * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view */ - $view = $this->createMock('\OC\Files\View'); + $view = $this->createMock(View::class); $root = new \OC\Files\Node\Root($manager, $view, $this->user); $root->listen('\OC\Files', 'preDelete', $preListener); $root->listen('\OC\Files', 'postDelete', $postListener); @@ -135,8 +140,8 @@ public function testDeleteNotPermitted() { /** * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view */ - $view = $this->createMock('\OC\Files\View'); - $root = $this->createMock('\OC\Files\Node\Root'); + $view = $this->createMock(View::class); + $root = $this->createMock(Root::class); $root->expects($this->any()) ->method('getUser') @@ -155,8 +160,8 @@ public function testStat() { /** * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view */ - $view = $this->createMock('\OC\Files\View'); - $root = $this->createMock('\OC\Files\Node\Root'); + $view = $this->createMock(View::class); + $root = $this->createMock(Root::class); $root->expects($this->any()) ->method('getUser') ->will($this->returnValue($this->user)); @@ -182,8 +187,8 @@ public function testGetId() { /** * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view */ - $view = $this->createMock('\OC\Files\View'); - $root = $this->createMock('\OC\Files\Node\Root'); + $view = $this->createMock(View::class); + $root = $this->createMock(Root::class); $root->expects($this->any()) ->method('getUser') ->will($this->returnValue($this->user)); @@ -208,8 +213,8 @@ public function testGetSize() { /** * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view */ - $view = $this->createMock('\OC\Files\View'); - $root = $this->createMock('\OC\Files\Node\Root'); + $view = $this->createMock(View::class); + $root = $this->createMock(Root::class); $root->expects($this->any()) ->method('getUser') ->will($this->returnValue($this->user)); @@ -234,8 +239,8 @@ public function testGetEtag() { /** * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view */ - $view = $this->createMock('\OC\Files\View'); - $root = $this->createMock('\OC\Files\Node\Root'); + $view = $this->createMock(View::class); + $root = $this->createMock(Root::class); $root->expects($this->any()) ->method('getUser') ->will($this->returnValue($this->user)); @@ -260,8 +265,8 @@ public function testGetMTime() { /** * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view */ - $view = $this->createMock('\OC\Files\View'); - $root = $this->createMock('\OC\Files\Node\Root'); + $view = $this->createMock(View::class); + $root = $this->createMock(Root::class); $root->expects($this->any()) ->method('getUser') ->will($this->returnValue($this->user)); @@ -286,15 +291,15 @@ public function testGetStorage() { /** * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view */ - $view = $this->createMock('\OC\Files\View'); - $root = $this->createMock('\OC\Files\Node\Root'); + $view = $this->createMock(View::class); + $root = $this->createMock(Root::class); $root->expects($this->any()) ->method('getUser') ->will($this->returnValue($this->user)); /** * @var \OC\Files\Storage\Storage | \PHPUnit_Framework_MockObject_MockObject $storage */ - $storage = $this->createMock('\OC\Files\Storage\Storage'); + $storage = $this->createMock(Storage::class); $view->expects($this->once()) ->method('resolvePath') @@ -309,8 +314,8 @@ public function testGetPath() { /** * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view */ - $view = $this->createMock('\OC\Files\View'); - $root = $this->createMock('\OC\Files\Node\Root'); + $view = $this->createMock(View::class); + $root = $this->createMock(Root::class); $root->expects($this->any()) ->method('getUser') ->will($this->returnValue($this->user)); @@ -323,15 +328,15 @@ public function testGetInternalPath() { /** * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view */ - $view = $this->createMock('\OC\Files\View'); - $root = $this->createMock('\OC\Files\Node\Root'); + $view = $this->createMock(View::class); + $root = $this->createMock(Root::class); $root->expects($this->any()) ->method('getUser') ->will($this->returnValue($this->user)); /** * @var \OC\Files\Storage\Storage | \PHPUnit_Framework_MockObject_MockObject $storage */ - $storage = $this->createMock('\OC\Files\Storage\Storage'); + $storage = $this->createMock(Storage::class); $view->expects($this->once()) ->method('resolvePath') @@ -346,8 +351,8 @@ public function testGetName() { /** * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view */ - $view = $this->createMock('\OC\Files\View'); - $root = $this->createMock('\OC\Files\Node\Root'); + $view = $this->createMock(View::class); + $root = $this->createMock(Root::class); $root->expects($this->any()) ->method('getUser') ->will($this->returnValue($this->user)); @@ -360,8 +365,8 @@ public function testTouchSetMTime() { /** * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view */ - $view = $this->createMock('\OC\Files\View'); - $root = $this->createMock('\OC\Files\Node\Root'); + $view = $this->createMock(View::class); + $root = $this->createMock(Root::class); $root->expects($this->any()) ->method('getUser') ->will($this->returnValue($this->user)); @@ -405,11 +410,11 @@ public function testTouchHooks() { /** * @var \OC\Files\Mount\Manager $manager */ - $manager = $this->createMock('\OC\Files\Mount\Manager'); + $manager = $this->createMock(Manager::class); /** * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view */ - $view = $this->createMock('\OC\Files\View'); + $view = $this->createMock(View::class); $root = new \OC\Files\Node\Root($manager, $view, $this->user); $root->listen('\OC\Files', 'preTouch', $preListener); $root->listen('\OC\Files', 'postTouch', $postListener); @@ -441,8 +446,8 @@ public function testTouchNotPermitted() { /** * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view */ - $view = $this->createMock('\OC\Files\View'); - $root = $this->createMock('\OC\Files\Node\Root'); + $view = $this->createMock(View::class); + $root = $this->createMock(Root::class); $root->expects($this->any()) ->method('getUser') ->will($this->returnValue($this->user)); @@ -463,8 +468,8 @@ public function testInvalidPath() { /** * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view */ - $view = $this->createMock('\OC\Files\View'); - $root = $this->createMock('\OC\Files\Node\Root'); + $view = $this->createMock(View::class); + $root = $this->createMock(Root::class); $node = $this->createTestNode($root, $view, '/../foo'); $node->getFileInfo(); @@ -474,8 +479,8 @@ public function testCopySameStorage() { /** * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view */ - $view = $this->createMock('\OC\Files\View'); - $root = $this->createMock('\OC\Files\Node\Root'); + $view = $this->createMock(View::class); + $root = $this->createMock(Root::class); $view->expects($this->any()) ->method('copy') @@ -509,12 +514,12 @@ public function testCopyNotPermitted() { /** * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view */ - $view = $this->createMock('\OC\Files\View'); - $root = $this->createMock('\OC\Files\Node\Root'); + $view = $this->createMock(View::class); + $root = $this->createMock(Root::class); /** * @var \OC\Files\Storage\Storage | \PHPUnit_Framework_MockObject_MockObject $storage */ - $storage = $this->createMock('\OC\Files\Storage\Storage'); + $storage = $this->createMock(Storage::class); $root->expects($this->never()) ->method('getMount'); @@ -545,8 +550,8 @@ public function testCopyNoParent() { /** * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view */ - $view = $this->createMock('\OC\Files\View'); - $root = $this->createMock('\OC\Files\Node\Root'); + $view = $this->createMock(View::class); + $root = $this->createMock(Root::class); $view->expects($this->never()) ->method('copy'); @@ -568,8 +573,8 @@ public function testCopyParentIsFile() { /** * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view */ - $view = $this->createMock('\OC\Files\View'); - $root = $this->createMock('\OC\Files\Node\Root'); + $view = $this->createMock(View::class); + $root = $this->createMock(Root::class); $view->expects($this->never()) ->method('copy'); @@ -590,8 +595,8 @@ public function testMoveSameStorage() { /** * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view */ - $view = $this->createMock('\OC\Files\View'); - $root = $this->createMock('\OC\Files\Node\Root'); + $view = $this->createMock(View::class); + $root = $this->createMock(Root::class); $view->expects($this->any()) ->method('rename') @@ -631,12 +636,12 @@ public function testMoveCopyHooks($operationMethod, $viewMethod, $preHookName, $ /** * @var \OC\Files\Mount\Manager $manager */ - $manager = $this->createMock('\OC\Files\Mount\Manager'); + $manager = $this->createMock(Manager::class); /** * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view */ - $view = $this->createMock('\OC\Files\View'); - $root = $this->getMockBuilder('\OC\Files\Node\Root') + $view = $this->createMock(View::class); + $root = $this->getMockBuilder(Root::class) ->setConstructorArgs([$manager, $view, $this->user]) ->setMethods(['get']) ->getMock(); @@ -716,8 +721,8 @@ public function testMoveNotPermitted() { /** * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view */ - $view = $this->createMock('\OC\Files\View'); - $root = $this->createMock('\OC\Files\Node\Root'); + $view = $this->createMock(View::class); + $root = $this->createMock(Root::class); $view->expects($this->any()) ->method('getFileInfo') @@ -744,12 +749,12 @@ public function testMoveNoParent() { /** * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view */ - $view = $this->createMock('\OC\Files\View'); - $root = $this->createMock('\OC\Files\Node\Root'); + $view = $this->createMock(View::class); + $root = $this->createMock(Root::class); /** * @var \OC\Files\Storage\Storage | \PHPUnit_Framework_MockObject_MockObject $storage */ - $storage = $this->createMock('\OC\Files\Storage\Storage'); + $storage = $this->createMock(Storage::class); $storage->expects($this->never()) ->method('rename'); @@ -772,8 +777,8 @@ public function testMoveParentIsFile() { /** * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view */ - $view = $this->createMock('\OC\Files\View'); - $root = $this->createMock('\OC\Files\Node\Root'); + $view = $this->createMock(View::class); + $root = $this->createMock(Root::class); $view->expects($this->never()) ->method('rename'); @@ -796,8 +801,8 @@ public function testMoveFailed() { /** * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view */ - $view = $this->createMock('\OC\Files\View'); - $root = $this->createMock('\OC\Files\Node\Root'); + $view = $this->createMock(View::class); + $root = $this->createMock(Root::class); $view->expects($this->any()) ->method('rename') @@ -825,8 +830,8 @@ public function testCopyFailed() { /** * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view */ - $view = $this->createMock('\OC\Files\View'); - $root = $this->createMock('\OC\Files\Node\Root'); + $view = $this->createMock(View::class); + $root = $this->createMock(Root::class); $view->expects($this->any()) ->method('copy') diff --git a/tests/lib/Files/Storage/Storage.php b/tests/lib/Files/Storage/Storage.php index 50194f2ec261..5acaed47adf6 100644 --- a/tests/lib/Files/Storage/Storage.php +++ b/tests/lib/Files/Storage/Storage.php @@ -23,6 +23,7 @@ namespace Test\Files\Storage; use OC\Files\Cache\Watcher; +use OCP\Files\Storage\IStorage; abstract class Storage extends \Test\TestCase { /** @@ -566,7 +567,7 @@ public function testCopyOverWriteDirectoryOverFile() { } public function testInstanceOfStorage() { - $this->assertTrue($this->instance->instanceOfStorage('\OCP\Files\Storage')); + $this->assertTrue($this->instance->instanceOfStorage(IStorage::class)); $this->assertTrue($this->instance->instanceOfStorage(\get_class($this->instance))); $this->assertFalse($this->instance->instanceOfStorage('\OC')); } diff --git a/tests/lib/Files/Storage/StorageFactoryTest.php b/tests/lib/Files/Storage/StorageFactoryTest.php index 20b51cdda223..895d45a1e5c5 100644 --- a/tests/lib/Files/Storage/StorageFactoryTest.php +++ b/tests/lib/Files/Storage/StorageFactoryTest.php @@ -11,8 +11,9 @@ use OC\Files\Mount\MountPoint; use OC\Files\Storage\Wrapper\Wrapper; use OCP\Files\Mount\IMountPoint; -use OCP\Files\Storage as IStorage; +use OCP\Files\Storage\IStorage; use Test\TestCase; +use OC\Files\Storage\Temporary; class DummyWrapper extends Wrapper { public $data; @@ -28,31 +29,31 @@ public function __construct($arguments) { class StorageFactoryTest extends TestCase { public function testSimpleWrapper() { $instance = new \OC\Files\Storage\StorageFactory(); - $mount = new MountPoint('\OC\Files\Storage\Temporary', '/foo', [[]], $instance); + $mount = new MountPoint(Temporary::class, '/foo', [[]], $instance); $instance->addStorageWrapper('dummy', function ($mountPoint, IStorage $storage, IMountPoint $mount) { - $this->assertInstanceOf('\OC\Files\Storage\Temporary', $storage); + $this->assertInstanceOf(Temporary::class, $storage); $this->assertEquals('/foo/', $mount->getMountPoint()); $this->assertEquals('/foo/', $mountPoint); return new DummyWrapper(['storage' => $storage]); }); $wrapped = $mount->getStorage(); - $this->assertInstanceOf('\Test\Files\Storage\DummyWrapper', $wrapped); + $this->assertInstanceOf(DummyWrapper::class, $wrapped); } public function testRemoveWrapper() { $instance = new \OC\Files\Storage\StorageFactory(); - $mount = new MountPoint('\OC\Files\Storage\Temporary', '/foo', [[]], $instance); + $mount = new MountPoint(Temporary::class, '/foo', [[]], $instance); $instance->addStorageWrapper('dummy', function ($mountPoint, IStorage $storage) { return new DummyWrapper(['storage' => $storage]); }); $instance->removeStorageWrapper('dummy'); $wrapped = $mount->getStorage(); - $this->assertInstanceOf('\OC\Files\Storage\Temporary', $wrapped); + $this->assertInstanceOf(Temporary::class, $wrapped); } public function testWrapperPriority() { $instance = new \OC\Files\Storage\StorageFactory(); - $mount = new MountPoint('\OC\Files\Storage\Temporary', '/foo', [[]], $instance); + $mount = new MountPoint(Temporary::class, '/foo', [[]], $instance); $instance->addStorageWrapper('dummy1', function ($mountPoint, IStorage $storage) { return new DummyWrapper(['storage' => $storage, 'data' => 1]); }, 1); @@ -64,7 +65,7 @@ public function testWrapperPriority() { }, 50); /** @var \Test\Files\Storage\DummyWrapper $wrapped */ $wrapped = $mount->getStorage(); - $this->assertInstanceOf('\Test\Files\Storage\DummyWrapper', $wrapped); + $this->assertInstanceOf(DummyWrapper::class, $wrapped); $this->assertEquals(1, $wrapped->data);// lowest priority is applied last, called first $this->assertEquals(50, $wrapped->getWrapperStorage()->data); $this->assertEquals(100, $wrapped->getWrapperStorage()->getWrapperStorage()->data); diff --git a/tests/lib/Files/Storage/Wrapper/EncryptionTest.php b/tests/lib/Files/Storage/Wrapper/EncryptionTest.php index e27037622cd0..71035c708efe 100644 --- a/tests/lib/Files/Storage/Wrapper/EncryptionTest.php +++ b/tests/lib/Files/Storage/Wrapper/EncryptionTest.php @@ -6,7 +6,18 @@ use OC\Files\Storage\Temporary; use OC\Files\View; use OC\User\Manager; +use OCP\Files\Storage\IStorage; use Test\Files\Storage\Storage; +use OC\Files\Storage\Wrapper\Encryption; +use OC\Files\Cache\Cache; +use OCP\Files\Cache\ICache; +use OCP\Encryption\IEncryptionModule; +use OC\Files\Mount\MountPoint; +use OC\Encryption\Update; +use OC\Log; +use OC\Encryption\File; +use OCP\IConfig; +use OC\Memcache\ArrayCache; class EncryptionTest extends Storage { @@ -97,7 +108,7 @@ protected function setUp() { parent::setUp(); $mockModule = $this->buildMockModule(); - $this->encryptionManager = $this->getMockBuilder('\OC\Encryption\Manager') + $this->encryptionManager = $this->getMockBuilder(\OC\Encryption\Manager::class) ->disableOriginalConstructor() ->setMethods(['getEncryptionModule', 'isEnabled']) ->getMock(); @@ -105,17 +116,17 @@ protected function setUp() { ->method('getEncryptionModule') ->willReturn($mockModule); - $this->arrayCache = $this->createMock('OC\Memcache\ArrayCache'); - $this->config = $this->getMockBuilder('\OCP\IConfig') + $this->arrayCache = $this->createMock(ArrayCache::class); + $this->config = $this->getMockBuilder(IConfig::class) ->disableOriginalConstructor() ->getMock(); - $this->groupManager = $this->getMockBuilder('\OC\Group\Manager') + $this->groupManager = $this->getMockBuilder(\OC\Group\Manager::class) ->disableOriginalConstructor() ->getMock(); $userManager = $this->createMock(Manager::class); - $this->util = $this->getMockBuilder('\OC\Encryption\Util') + $this->util = $this->getMockBuilder(Util::class) ->setMethods(['getUidAndFilename', 'isFile', 'isExcluded']) ->setConstructorArgs([new View(), $userManager, $this->groupManager, $this->config, $this->arrayCache]) ->getMock(); @@ -125,23 +136,23 @@ protected function setUp() { return ['user1', $path]; }); - $this->file = $this->getMockBuilder('\OC\Encryption\File') + $this->file = $this->getMockBuilder(File::class) ->disableOriginalConstructor() ->setMethods(['getAccessList']) ->getMock(); $this->file->expects($this->any())->method('getAccessList')->willReturn([]); - $this->logger = $this->createMock('\OC\Log'); + $this->logger = $this->createMock(Log::class); $this->sourceStorage = new Temporary([]); - $this->keyStore = $this->getMockBuilder('\OC\Encryption\Keys\Storage') + $this->keyStore = $this->getMockBuilder(\OC\Encryption\Keys\Storage::class) ->disableOriginalConstructor()->getMock(); - $this->update = $this->getMockBuilder('\OC\Encryption\Update') + $this->update = $this->getMockBuilder(Update::class) ->disableOriginalConstructor()->getMock(); - $this->mount = $this->getMockBuilder('\OC\Files\Mount\MountPoint') + $this->mount = $this->getMockBuilder(MountPoint::class) ->disableOriginalConstructor() ->setMethods(['getOption']) ->getMock(); @@ -155,7 +166,7 @@ protected function setUp() { return true; }); - $this->cache = $this->getMockBuilder('\OC\Files\Cache\Cache') + $this->cache = $this->getMockBuilder(Cache::class) ->disableOriginalConstructor()->getMock(); $this->cache->expects($this->any()) ->method('get') @@ -163,11 +174,11 @@ protected function setUp() { return ['encrypted' => false, 'path' => $path]; }); - $this->mountManager = $this->getMockBuilder('\OC\Files\Mount\Manager') + $this->mountManager = $this->getMockBuilder(\OC\Files\Mount\Manager::class) ->disableOriginalConstructor()->getMock(); $this->mountManager->expects($this->any())->method('findByStorageId')->willReturn([]); - $this->instance = $this->getMockBuilder('\OC\Files\Storage\Wrapper\Encryption') + $this->instance = $this->getMockBuilder(Encryption::class) ->setConstructorArgs( [ [ @@ -201,7 +212,7 @@ protected function setUp() { * @return \PHPUnit_Framework_MockObject_MockObject */ protected function buildMockModule() { - $this->encryptionModule = $this->getMockBuilder('\OCP\Encryption\IEncryptionModule') + $this->encryptionModule = $this->getMockBuilder(IEncryptionModule::class) ->disableOriginalConstructor() ->setMethods(['getId', 'getDisplayName', 'begin', 'end', 'encrypt', 'decrypt', 'update', 'shouldEncrypt', 'getUnencryptedBlockSize', 'isReadable', 'encryptAll', 'prepareDecryptAll', 'isReadyForUser']) ->getMock(); @@ -230,10 +241,10 @@ protected function buildMockModule() { * @param array $expected */ public function testGetMetaData($path, $metaData, $encrypted, $unencryptedSizeSet, $storedUnencryptedSize, $expected) { - $sourceStorage = $this->getMockBuilder('\OC\Files\Storage\Storage') + $sourceStorage = $this->getMockBuilder(\OC\Files\Storage\Storage::class) ->disableOriginalConstructor()->getMock(); - $cache = $this->getMockBuilder('\OC\Files\Cache\Cache') + $cache = $this->getMockBuilder(Cache::class) ->disableOriginalConstructor()->getMock(); $cache->expects($this->any()) ->method('get') @@ -243,7 +254,7 @@ function ($path) use ($encrypted) { } ); - $this->instance = $this->getMockBuilder('\OC\Files\Storage\Wrapper\Encryption') + $this->instance = $this->getMockBuilder(Encryption::class) ->setConstructorArgs( [ [ @@ -262,7 +273,7 @@ function ($path) use ($encrypted) { $this->invokePrivate($this->instance, 'unencryptedSize', [[$path => $storedUnencryptedSize]]); } - $fileEntry = $this->getMockBuilder('\OC\Files\Cache\Cache') + $fileEntry = $this->getMockBuilder(Cache::class) ->disableOriginalConstructor()->getMock(); $sourceStorage->expects($this->once())->method('getMetaData')->with($path) ->willReturn($metaData); @@ -299,13 +310,13 @@ public function dataTestGetMetaData() { } public function testFilesize() { - $cache = $this->getMockBuilder('\OC\Files\Cache\Cache') + $cache = $this->getMockBuilder(Cache::class) ->disableOriginalConstructor()->getMock(); $cache->expects($this->any()) ->method('get') ->willReturn(['encrypted' => true, 'path' => '/test.txt', 'size' => 0, 'fileid' => 1]); - $this->instance = $this->getMockBuilder('\OC\Files\Storage\Wrapper\Encryption') + $this->instance = $this->getMockBuilder(Encryption::class) ->setConstructorArgs( [ [ @@ -338,10 +349,10 @@ public function testFilesize() { * @param int $expected */ public function testVerifyUnencryptedSize($encryptedSize, $unencryptedSize, $failure, $expected) { - $sourceStorage = $this->getMockBuilder('\OC\Files\Storage\Storage') + $sourceStorage = $this->getMockBuilder(\OC\Files\Storage\Storage::class) ->disableOriginalConstructor()->getMock(); - $this->instance = $this->getMockBuilder('\OC\Files\Storage\Wrapper\Encryption') + $this->instance = $this->getMockBuilder(Encryption::class) ->setConstructorArgs( [ [ @@ -456,10 +467,10 @@ public function testIsLocal() { * @param boolean $encryptionEnabled */ public function testRmdir($path, $rmdirResult, $isExcluded, $encryptionEnabled) { - $sourceStorage = $this->getMockBuilder('\OC\Files\Storage\Storage') + $sourceStorage = $this->getMockBuilder(\OC\Files\Storage\Storage::class) ->disableOriginalConstructor()->getMock(); - $util = $this->getMockBuilder('\OC\Encryption\Util')->disableOriginalConstructor()->getMock(); + $util = $this->getMockBuilder(Util::class)->disableOriginalConstructor()->getMock(); $sourceStorage->expects($this->once())->method('rmdir')->willReturn($rmdirResult); $util->expects($this->any())->method('isExcluded')-> willReturn($isExcluded); @@ -534,11 +545,11 @@ public function dataTestCopyKeys() { * @param string $strippedPath */ public function testGetHeader($path, $strippedPathExists, $strippedPath) { - $sourceStorage = $this->getMockBuilder('\OC\Files\Storage\Storage') + $sourceStorage = $this->getMockBuilder(\OC\Files\Storage\Storage::class) ->disableOriginalConstructor()->getMock(); $userManager = $this->createMock(Manager::class); - $util = $this->getMockBuilder('\OC\Encryption\Util') + $util = $this->getMockBuilder(Util::class) ->setConstructorArgs( [ new View(), @@ -549,7 +560,7 @@ public function testGetHeader($path, $strippedPathExists, $strippedPath) { ] )->getMock(); - $instance = $this->getMockBuilder('\OC\Files\Storage\Wrapper\Encryption') + $instance = $this->getMockBuilder(Encryption::class) ->setConstructorArgs( [ [ @@ -602,7 +613,7 @@ public function dataTestGetHeader() { * @dataProvider dataTestGetHeaderAddLegacyModule */ public function testGetHeaderAddLegacyModule($header, $isEncrypted, $exists, $expected) { - $sourceStorage = $this->getMockBuilder('\OC\Files\Storage\Storage') + $sourceStorage = $this->getMockBuilder(\OC\Files\Storage\Storage::class) ->disableOriginalConstructor()->getMock(); $sourceStorage->expects($this->once()) @@ -612,11 +623,11 @@ public function testGetHeaderAddLegacyModule($header, $isEncrypted, $exists, $ex }); $userManager = $this->createMock(Manager::class); - $util = $this->getMockBuilder('\OC\Encryption\Util') + $util = $this->getMockBuilder(Util::class) ->setConstructorArgs([new View(), $userManager, $this->groupManager, $this->config, $this->arrayCache]) ->getMock(); - $cache = $this->getMockBuilder('\OC\Files\Cache\Cache') + $cache = $this->getMockBuilder(Cache::class) ->disableOriginalConstructor()->getMock(); $cache->expects($this->any()) ->method('get') @@ -624,7 +635,7 @@ public function testGetHeaderAddLegacyModule($header, $isEncrypted, $exists, $ex return ['encrypted' => $isEncrypted, 'path' => $path]; }); - $instance = $this->getMockBuilder('\OC\Files\Storage\Wrapper\Encryption') + $instance = $this->getMockBuilder(Encryption::class) ->setConstructorArgs( [ [ @@ -707,7 +718,7 @@ public function dataCopyBetweenStorage() { } public function testCopyBetweenStorageMinimumEncryptedVersion() { - $storage2 = $this->getMockBuilder('OCP\Files\Storage') + $storage2 = $this->getMockBuilder(IStorage::class) ->disableOriginalConstructor() ->getMock(); @@ -720,7 +731,7 @@ public function testCopyBetweenStorageMinimumEncryptedVersion() { $temp = \OC::$server->getTempManager(); return \fopen($temp->getTemporaryFile(), $mode); }); - $cache = $this->createMock('\OCP\Files\Cache\ICache'); + $cache = $this->createMock(ICache::class); $cache->expects($this->once()) ->method('get') ->with($sourceInternalPath) @@ -756,7 +767,7 @@ public function testCopyBetweenStorageMinimumEncryptedVersion() { * @param bool $expectedEncrypted */ public function testCopyBetweenStorage($encryptionEnabled, $mountPointEncryptionEnabled, $expectedEncrypted) { - $storage2 = $this->getMockBuilder('OCP\Files\Storage') + $storage2 = $this->getMockBuilder(IStorage::class) ->disableOriginalConstructor() ->getMock(); @@ -770,7 +781,7 @@ public function testCopyBetweenStorage($encryptionEnabled, $mountPointEncryption return \fopen($temp->getTemporaryFile(), $mode); }); if ($expectedEncrypted) { - $cache = $this->createMock('\OCP\Files\Cache\ICache'); + $cache = $this->createMock(ICache::class); $cache->expects($this->once()) ->method('get') ->with($sourceInternalPath) @@ -817,21 +828,21 @@ public function testCopyBetweenStorage($encryptionEnabled, $mountPointEncryption * @param bool $encrypted */ public function testCopyBetweenStorageVersions($sourceInternalPath, $targetInternalPath, $copyResult, $encrypted) { - $sourceStorage = $this->getMockBuilder('OCP\Files\Storage') + $sourceStorage = $this->getMockBuilder(IStorage::class) ->disableOriginalConstructor() ->getMock(); - $targetStorage = $this->getMockBuilder('OCP\Files\Storage') + $targetStorage = $this->getMockBuilder(IStorage::class) ->disableOriginalConstructor() ->getMock(); - $cache = $this->getMockBuilder('\OC\Files\Cache\Cache') + $cache = $this->getMockBuilder(Cache::class) ->disableOriginalConstructor()->getMock(); $mountPoint = '/mountPoint'; /** @var \OC\Files\Storage\Wrapper\Encryption |\PHPUnit_Framework_MockObject_MockObject $instance */ - $instance = $this->getMockBuilder('\OC\Files\Storage\Wrapper\Encryption') + $instance = $this->getMockBuilder(Encryption::class) ->setConstructorArgs( [ [ diff --git a/tests/lib/Files/ViewTest.php b/tests/lib/Files/ViewTest.php index 1393c7788c9d..ab8a54307a20 100644 --- a/tests/lib/Files/ViewTest.php +++ b/tests/lib/Files/ViewTest.php @@ -15,6 +15,7 @@ use OC\Files\Storage\Temporary; use OC\Files\View; use OCP\Files\FileInfo; +use OCP\Files\Storage\IStorage; use OCP\Lock\ILockingProvider; use OCP\Util; use Symfony\Component\EventDispatcher\GenericEvent; @@ -30,11 +31,11 @@ public function touch($path, $mtime = null) { } class TemporaryNoCross extends Temporary { - public function copyFromStorage(\OCP\Files\Storage $sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime = false) { + public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime = false) { return Common::copyFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath, $preserveMtime); } - public function moveFromStorage(\OCP\Files\Storage $sourceStorage, $sourceInternalPath, $targetInternalPath) { + public function moveFromStorage(IStorage $sourceStorage, $sourceInternalPath, $targetInternalPath) { return Common::moveFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath); } } diff --git a/tests/lib/Share20/ManagerTest.php b/tests/lib/Share20/ManagerTest.php index 6e472333f478..4e409a707f1b 100644 --- a/tests/lib/Share20/ManagerTest.php +++ b/tests/lib/Share20/ManagerTest.php @@ -48,6 +48,11 @@ use Symfony\Component\EventDispatcher\EventDispatcher; use Symfony\Component\EventDispatcher\GenericEvent; use Test\Traits\UserTrait; +use OC\Share20\DefaultShareProvider; +use OCA\Files_Sharing\ISharedStorage; +use OCP\Files\Node; +use OCP\IGroup; +use OC\Files\Mount\MoveableMount; /** * Class ManagerTest @@ -60,7 +65,7 @@ class ManagerTest extends \Test\TestCase { /** @var Manager */ protected $manager; - /** @var ILogger */ + /** @var ILogger | \PHPUnit_Framework_MockObject_MockObject */ protected $logger; /** @var IConfig */ protected $config; @@ -74,36 +79,37 @@ class ManagerTest extends \Test\TestCase { protected $mountManager; /** @var IGroupManager */ protected $groupManager; - /** @var IL10N */ + /** @var IL10N | \PHPUnit_Framework_MockObject_MockObject */ protected $l; /** @var DummyFactory */ protected $factory; - /** @var IUserManager */ + /** @var IUserManager | \PHPUnit_Framework_MockObject_MockObject */ protected $userManager; /** @var IRootFolder | \PHPUnit_Framework_MockObject_MockObject */ protected $rootFolder; /** @var EventDispatcher */ protected $eventDispatcher; - /** @var View */ + /** @var View | \PHPUnit_Framework_MockObject_MockObject */ protected $view; + /** @var IDBConnection | \PHPUnit_Framework_MockObject_MockObject */ protected $connection; public function setUp() { parent::setUp(); - $this->logger = $this->createMock('\OCP\ILogger'); - $this->config = $this->createMock('\OCP\IConfig'); - $this->secureRandom = $this->createMock('\OCP\Security\ISecureRandom'); - $this->hasher = $this->createMock('\OCP\Security\IHasher'); - $this->mountManager = $this->createMock('\OCP\Files\Mount\IMountManager'); - $this->groupManager = $this->createMock('\OCP\IGroupManager'); - $this->userManager = $this->createMock('\OCP\IUserManager'); - $this->rootFolder = $this->createMock('\OCP\Files\IRootFolder'); + $this->logger = $this->createMock(ILogger::class); + $this->config = $this->createMock(IConfig::class); + $this->secureRandom = $this->createMock(ISecureRandom::class); + $this->hasher = $this->createMock(IHasher::class); + $this->mountManager = $this->createMock(IMountManager::class); + $this->groupManager = $this->createMock(IGroupManager::class); + $this->userManager = $this->createMock(IUserManager::class); + $this->rootFolder = $this->createMock(IRootFolder::class); $this->eventDispatcher = new EventDispatcher(); $this->view = $this->createMock(View::class); $this->connection = $this->createMock(IDBConnection::class); - $this->l = $this->createMock('\OCP\IL10N'); + $this->l = $this->createMock(IL10N::class); $this->l->method('t') ->will($this->returnCallback(function ($text, $parameters = []) { return \vsprintf($text, $parameters); @@ -127,7 +133,7 @@ public function setUp() { $this->connection ); - $this->defaultProvider = $this->getMockBuilder('\OC\Share20\DefaultShareProvider') + $this->defaultProvider = $this->getMockBuilder(DefaultShareProvider::class) ->disableOriginalConstructor() ->getMock(); $this->defaultProvider->method('identifier')->willReturn('default'); @@ -135,10 +141,10 @@ public function setUp() { } /** - * @return \PHPUnit_Framework_MockObject_MockBuilder + * @return Manager | \PHPUnit_Framework_MockObject_MockBuilder */ private function createManagerMock() { - return $this->getMockBuilder('\OC\Share20\Manager') + return $this->getMockBuilder(Manager::class) ->setConstructorArgs([ $this->logger, $this->config, @@ -166,10 +172,10 @@ public function testDeleteNoShareId() { } public function dataTestDelete() { - $user = $this->createMock('\OCP\IUser'); + $user = $this->createMock(IUser::class); $user->method('getUID')->willReturn('sharedWithUser'); - $group = $this->createMock('\OCP\IGroup'); + $group = $this->createMock(IGroup::class); $group->method('getGID')->willReturn('sharedWithGroup'); return [ @@ -188,7 +194,7 @@ public function testDelete($shareType, $sharedWith) { ->setMethods(['getShareById', 'deleteChildren']) ->getMock(); - $path = $this->createMock('\OCP\Files\File'); + $path = $this->createMock(File::class); $path->method('getId')->willReturn(1); $share = $this->manager->newShare(); @@ -208,8 +214,8 @@ public function testDelete($shareType, $sharedWith) { ->with($share); $hookListner = $this->getMockBuilder('Dummy')->setMethods(['pre', 'post'])->getMock(); - \OCP\Util::connectHook('OCP\Share', 'pre_unshare', $hookListner, 'pre'); - \OCP\Util::connectHook('OCP\Share', 'post_unshare', $hookListner, 'post'); + \OCP\Util::connectHook(\OCP\Share::class, 'pre_unshare', $hookListner, 'pre'); + \OCP\Util::connectHook(\OCP\Share::class, 'post_unshare', $hookListner, 'post'); $hookListnerExpectsPre = [ 'id' => 42, @@ -306,8 +312,8 @@ public function testDeleteLazyShare() { ->with($share); $hookListner = $this->getMockBuilder('Dummy')->setMethods(['pre', 'post'])->getMock(); - \OCP\Util::connectHook('OCP\Share', 'pre_unshare', $hookListner, 'pre'); - \OCP\Util::connectHook('OCP\Share', 'post_unshare', $hookListner, 'post'); + \OCP\Util::connectHook(\OCP\Share::class, 'pre_unshare', $hookListner, 'pre'); + \OCP\Util::connectHook(\OCP\Share::class, 'post_unshare', $hookListner, 'post'); $hookListnerExpectsPre = [ 'id' => 42, @@ -383,7 +389,7 @@ public function testDeleteNested() { ->setMethods(['getShareById']) ->getMock(); - $path = $this->createMock('\OCP\Files\File'); + $path = $this->createMock(File::class); $path->method('getId')->willReturn(1); $share1 = $this->manager->newShare(); @@ -427,8 +433,8 @@ public function testDeleteNested() { ->withConsecutive($share3, $share2, $share1); $hookListner = $this->getMockBuilder('Dummy')->setMethods(['pre', 'post'])->getMock(); - \OCP\Util::connectHook('OCP\Share', 'pre_unshare', $hookListner, 'pre'); - \OCP\Util::connectHook('OCP\Share', 'post_unshare', $hookListner, 'post'); + \OCP\Util::connectHook(\OCP\Share::class, 'pre_unshare', $hookListner, 'pre'); + \OCP\Util::connectHook(\OCP\Share::class, 'post_unshare', $hookListner, 'post'); $hookListnerExpectsPre = [ 'id' => 42, @@ -526,14 +532,14 @@ public function testDeleteChildren() { ->setMethods(['deleteShare']) ->getMock(); - $share = $this->createMock('\OCP\Share\IShare'); + $share = $this->createMock(IShare::class); $share->method('getShareType')->willReturn(\OCP\Share::SHARE_TYPE_USER); - $child1 = $this->createMock('\OCP\Share\IShare'); + $child1 = $this->createMock(IShare::class); $child1->method('getShareType')->willReturn(\OCP\Share::SHARE_TYPE_USER); - $child2 = $this->createMock('\OCP\Share\IShare'); + $child2 = $this->createMock(IShare::class); $child2->method('getShareType')->willReturn(\OCP\Share::SHARE_TYPE_USER); - $child3 = $this->createMock('\OCP\Share\IShare'); + $child3 = $this->createMock(IShare::class); $child3->method('getShareType')->willReturn(\OCP\Share::SHARE_TYPE_USER); $shares = [ @@ -562,7 +568,7 @@ public function testDeleteChildren() { } public function testGetShareById() { - $share = $this->createMock('\OCP\Share\IShare'); + $share = $this->createMock(IShare::class); $this->defaultProvider ->expects($this->once()) @@ -698,7 +704,7 @@ public function testVerifyPasswordHookFails() { public function createShare($id, $type, $path, $sharedWith, $sharedBy, $shareOwner, $permissions, $expireDate = null, $password = null) { - $share = $this->createMock('\OCP\Share\IShare'); + $share = $this->createMock(IShare::class); $share->method('getShareType')->willReturn($type); $share->method('getSharedWith')->willReturn($sharedWith); @@ -717,8 +723,8 @@ public function dataGeneralChecks() { $user2 = 'user1'; $group0 = 'group0'; - $file = $this->createMock('\OCP\Files\File'); - $node = $this->createMock('\OCP\Files\Node'); + $file = $this->createMock(File::class); + $node = $this->createMock(Node::class); $data = [ [$this->createShare(null, \OCP\Share::SHARE_TYPE_USER, $file, null, $user0, $user0, 31, null, null), 'SharedWith is not a valid user', true], @@ -747,7 +753,7 @@ public function dataGeneralChecks() { [$this->createShare(null, \OCP\Share::SHARE_TYPE_LINK, $node, null, $user0, $user0, 31, null, null), 'Path should be either a file or a folder', true], ]; - $nonShareAble = $this->createMock('\OCP\Files\Folder'); + $nonShareAble = $this->createMock(Folder::class); $nonShareAble->method('isShareable')->willReturn(false); $nonShareAble->method('getPath')->willReturn('path'); @@ -755,7 +761,7 @@ public function dataGeneralChecks() { $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_GROUP, $nonShareAble, $group0, $user0, $user0, 31, null, null), 'You are not allowed to share path', true]; $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_LINK, $nonShareAble, null, $user0, $user0, 31, null, null), 'You are not allowed to share path', true]; - $limitedPermssions = $this->createMock('\OCP\Files\File'); + $limitedPermssions = $this->createMock(File::class); $limitedPermssions->method('isShareable')->willReturn(true); $limitedPermssions->method('getPermissions')->willReturn(\OCP\Constants::PERMISSION_READ); $limitedPermssions->method('getPath')->willReturn('path'); @@ -764,14 +770,14 @@ public function dataGeneralChecks() { $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_GROUP, $limitedPermssions, $group0, $user0, $user0, null, null, null), 'A share requires permissions', true]; $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_LINK, $limitedPermssions, null, $user0, $user0, null, null, null), 'A share requires permissions', true]; - $mount = $this->createMock('OC\Files\Mount\MoveableMount'); + $mount = $this->createMock(MoveableMount::class); $limitedPermssions->method('getMountPoint')->willReturn($mount); $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_USER, $limitedPermssions, $user2, $user0, $user0, 31, null, null), 'Cannot increase permissions of path', true]; $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_GROUP, $limitedPermssions, $group0, $user0, $user0, 17, null, null), 'Cannot increase permissions of path', true]; $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_LINK, $limitedPermssions, null, $user0, $user0, 3, null, null), 'Cannot increase permissions of path', true]; - $nonMoveableMountPermssions = $this->createMock('\OCP\Files\Folder'); + $nonMoveableMountPermssions = $this->createMock(Folder::class); $nonMoveableMountPermssions->method('isShareable')->willReturn(true); $nonMoveableMountPermssions->method('getPermissions')->willReturn(\OCP\Constants::PERMISSION_READ); $nonMoveableMountPermssions->method('getPath')->willReturn('path'); @@ -779,7 +785,7 @@ public function dataGeneralChecks() { $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_USER, $nonMoveableMountPermssions, $user2, $user0, $user0, 11, null, null), 'Cannot increase permissions of path', false]; $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_GROUP, $nonMoveableMountPermssions, $group0, $user0, $user0, 11, null, null), 'Cannot increase permissions of path', false]; - $rootFolder = $this->createMock('\OCP\Files\Folder'); + $rootFolder = $this->createMock(Folder::class); $rootFolder->method('isShareable')->willReturn(true); $rootFolder->method('getPermissions')->willReturn(\OCP\Constants::PERMISSION_ALL); $rootFolder->method('getPath')->willReturn('myrootfolder'); @@ -788,7 +794,7 @@ public function dataGeneralChecks() { $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_GROUP, $rootFolder, $group0, $user0, $user0, 2, null, null), 'You can\'t share your root folder', true]; $data[] = [$this->createShare(null, \OCP\Share::SHARE_TYPE_LINK, $rootFolder, null, $user0, $user0, 16, null, null), 'You can\'t share your root folder', true]; - $allPermssions = $this->createMock('\OCP\Files\Folder'); + $allPermssions = $this->createMock(Folder::class); $allPermssions->method('isShareable')->willReturn(true); $allPermssions->method('getPermissions')->willReturn(\OCP\Constants::PERMISSION_ALL); @@ -817,7 +823,7 @@ public function testGeneralChecks($share, $exceptionMessage, $exception) { ['group0', true], ])); - $userFolder = $this->createMock('\OCP\Files\Folder'); + $userFolder = $this->createMock(Folder::class); $userFolder->method('getPath')->willReturn('myrootfolder'); $this->rootFolder->method('getUserFolder')->willReturn($userFolder); @@ -847,7 +853,7 @@ public function testGeneralCheckShareRoot() { ['user1', true], ])); - $userFolder = $this->createMock('\OCP\Files\Folder'); + $userFolder = $this->createMock(Folder::class); $userFolder->method('isSubNode')->with($userFolder)->willReturn(false); $this->rootFolder->method('getUserFolder')->willReturn($userFolder); @@ -1110,8 +1116,8 @@ public function testValidateExpirationDateExistingShareNoDefault() { public function testUserCreateChecksShareWithGroupMembersOnlyDifferentGroups() { $share = $this->manager->newShare(); - $sharedBy = $this->createMock('\OCP\IUser'); - $sharedWith = $this->createMock('\OCP\IUser'); + $sharedBy = $this->createMock(IUser::class); + $sharedWith = $this->createMock(IUser::class); $share->setSharedBy('sharedBy')->setSharedWith('sharedWith'); $this->groupManager @@ -1140,11 +1146,11 @@ public function testUserCreateChecksShareWithGroupMembersOnlyDifferentGroups() { public function testUserCreateChecksShareWithGroupMembersOnlySharedGroup() { $share = $this->manager->newShare(); - $sharedBy = $this->createMock('\OCP\IUser'); - $sharedWith = $this->createMock('\OCP\IUser'); + $sharedBy = $this->createMock(IUser::class); + $sharedWith = $this->createMock(IUser::class); $share->setSharedBy('sharedBy')->setSharedWith('sharedWith'); - $path = $this->createMock('\OCP\Files\Node'); + $path = $this->createMock(Node::class); $share->setNode($path); $this->groupManager @@ -1183,8 +1189,8 @@ public function testUserCreateChecksIdenticalShareExists() { $share = $this->manager->newShare(); $share2 = $this->manager->newShare(); - $sharedWith = $this->createMock('\OCP\IUser'); - $path = $this->createMock('\OCP\Files\Node'); + $sharedWith = $this->createMock(IUser::class); + $path = $this->createMock(Node::class); $share->setSharedWith('sharedWith')->setNode($path) ->setProviderId('foo')->setId('bar'); @@ -1207,12 +1213,12 @@ public function testUserCreateChecksIdenticalShareExists() { public function testUserCreateChecksIdenticalPathSharedViaGroup() { $share = $this->manager->newShare(); - $sharedWith = $this->createMock('\OCP\IUser'); + $sharedWith = $this->createMock(IUser::class); $sharedWith->method('getUID')->willReturn('sharedWith'); $this->userManager->method('get')->with('sharedWith')->willReturn($sharedWith); - $path = $this->createMock('\OCP\Files\Node'); + $path = $this->createMock(Node::class); $share->setSharedWith('sharedWith') ->setNode($path) @@ -1227,7 +1233,7 @@ public function testUserCreateChecksIdenticalPathSharedViaGroup() { ->setId('baz') ->setSharedWith('group'); - $group = $this->createMock('\OCP\IGroup'); + $group = $this->createMock(IGroup::class); $group->method('inGroup') ->with($sharedWith) ->willReturn(true); @@ -1277,8 +1283,8 @@ public function testUserCreateChecksIdenticalPathSharedViaDeletedGroup() { public function testUserCreateChecksIdenticalPathNotSharedWithUser() { $share = $this->manager->newShare(); - $sharedWith = $this->createMock('\OCP\IUser'); - $path = $this->createMock('\OCP\Files\Node'); + $sharedWith = $this->createMock(IUser::class); + $path = $this->createMock(Node::class); $share->setSharedWith('sharedWith') ->setNode($path) ->setShareOwner('shareOwner') @@ -1293,7 +1299,7 @@ public function testUserCreateChecksIdenticalPathNotSharedWithUser() { ->setProviderId('foo') ->setId('baz'); - $group = $this->createMock('\OCP\IGroup'); + $group = $this->createMock(IGroup::class); $group->method('inGroup') ->with($sharedWith) ->willReturn(false); @@ -1333,8 +1339,8 @@ public function testGroupCreateChecksShareWithGroupMembersGroupSharingNotAllowed public function testGroupCreateChecksShareWithGroupMembersOnlyNotInGroup() { $share = $this->manager->newShare(); - $user = $this->createMock('\OCP\IUser'); - $group = $this->createMock('\OCP\IGroup'); + $user = $this->createMock(IUser::class); + $group = $this->createMock(IGroup::class); $share->setSharedBy('user')->setSharedWith('group'); $group->method('inGroup')->with($user)->willReturn(false); @@ -1359,7 +1365,7 @@ public function testGroupCreateChecksShareWithGroupMembersOnlyNotInGroup() { public function testGroupCreateChecksShareWithGroupMembersOnlyNullGroup() { $share = $this->manager->newShare(); - $user = $this->createMock('\OCP\IUser'); + $user = $this->createMock(IUser::class); $share->setSharedBy('user')->setSharedWith('group'); $this->groupManager->method('get')->with('group')->willReturn(null); @@ -1378,8 +1384,8 @@ public function testGroupCreateChecksShareWithGroupMembersOnlyNullGroup() { public function testGroupCreateChecksShareWithGroupMembersOnlyInGroup() { $share = $this->manager->newShare(); - $user = $this->createMock('\OCP\IUser'); - $group = $this->createMock('\OCP\IGroup'); + $user = $this->createMock(IUser::class); + $group = $this->createMock(IGroup::class); $share->setSharedBy('user')->setSharedWith('group'); $this->userManager->method('get')->with('user')->willReturn($user); @@ -1387,7 +1393,7 @@ public function testGroupCreateChecksShareWithGroupMembersOnlyInGroup() { $group->method('inGroup')->with($user)->willReturn(true); - $path = $this->createMock('\OCP\Files\Node'); + $path = $this->createMock(Node::class); $share->setNode($path); $this->defaultProvider->method('getSharesByPath') @@ -1411,7 +1417,7 @@ public function testGroupCreateChecksShareWithGroupMembersOnlyInGroup() { public function testGroupCreateChecksPathAlreadySharedWithSameGroup() { $share = $this->manager->newShare(); - $path = $this->createMock('\OCP\Files\Node'); + $path = $this->createMock(Node::class); $share->setSharedWith('sharedWith') ->setNode($path) ->setProviderId('foo') @@ -1440,7 +1446,7 @@ public function testGroupCreateChecksPathAlreadySharedWithDifferentGroup() { $share->setSharedWith('sharedWith'); - $path = $this->createMock('\OCP\Files\Node'); + $path = $this->createMock(Node::class); $share->setNode($path); $share2 = $this->manager->newShare(); @@ -1547,13 +1553,13 @@ public function testLinkCreateChecksReadOnly() { * @expectedExceptionMessage Path contains files shared with you */ public function testPathCreateChecksContainsSharedMount() { - $path = $this->createMock('\OCP\Files\Folder'); + $path = $this->createMock(Folder::class); $path->method('getPath')->willReturn('path'); - $mount = $this->createMock('\OCP\Files\Mount\IMountPoint'); - $storage = $this->createMock('\OCP\Files\Storage'); + $mount = $this->createMock(IMountPoint::class); + $storage = $this->createMock(Storage\IStorage::class); $mount->method('getStorage')->willReturn($storage); - $storage->method('instanceOfStorage')->with('\OCA\Files_Sharing\ISharedStorage')->willReturn(true); + $storage->method('instanceOfStorage')->with(ISharedStorage::class)->willReturn(true); $this->mountManager->method('findIn')->with('path')->willReturn([$mount]); @@ -1561,13 +1567,13 @@ public function testPathCreateChecksContainsSharedMount() { } public function testPathCreateChecksContainsNoSharedMount() { - $path = $this->createMock('\OCP\Files\Folder'); + $path = $this->createMock(Folder::class); $path->method('getPath')->willReturn('path'); - $mount = $this->createMock('\OCP\Files\Mount\IMountPoint'); - $storage = $this->createMock('\OCP\Files\Storage'); + $mount = $this->createMock(IMountPoint::class); + $storage = $this->createMock(Storage\IStorage::class); $mount->method('getStorage')->willReturn($storage); - $storage->method('instanceOfStorage')->with('\OCA\Files_Sharing\ISharedStorage')->willReturn(false); + $storage->method('instanceOfStorage')->with(ISharedStorage::class)->willReturn(false); $this->mountManager->method('findIn')->with('path')->willReturn([$mount]); @@ -1575,7 +1581,7 @@ public function testPathCreateChecksContainsNoSharedMount() { } public function testPathCreateChecksContainsNoFolder() { - $path = $this->createMock('\OCP\Files\File'); + $path = $this->createMock(File::class); $this->invokePrivate($this->manager, 'pathCreateChecks', [$path]); } @@ -1620,7 +1626,7 @@ public function dataIsSharingDisabledForUser() { * @param bool $expected */ public function testIsSharingDisabledForUser($excludeGroups, $groupList, $setList, $groupIds, $expected) { - $user = $this->createMock('\OCP\IUser'); + $user = $this->createMock(IUser::class); $this->config->method('getAppValue') ->will($this->returnValueMap([ @@ -1780,8 +1786,8 @@ public function testTransferShare($sharetype) { ->with($share); $hookListnerUnshare = $this->getMockBuilder('Dummy')->setMethods(['pre', 'post'])->getMock(); - \OCP\Util::connectHook('OCP\Share', 'pre_unshare', $hookListnerUnshare, 'pre'); - \OCP\Util::connectHook('OCP\Share', 'post_unshare', $hookListnerUnshare, 'post'); + \OCP\Util::connectHook(\OCP\Share::class, 'pre_unshare', $hookListnerUnshare, 'pre'); + \OCP\Util::connectHook(\OCP\Share::class, 'post_unshare', $hookListnerUnshare, 'post'); $mountPoint = $this->createMock(IMountPoint::class); $this->mountManager->expects($this->once()) @@ -1801,7 +1807,7 @@ public function testTransferShare($sharetype) { $share->setSharedWith('differentUser@server.com'); } - $shareOwner = $this->createMock('\OCP\IUser'); + $shareOwner = $this->createMock(IUser::class); $shareOwner->method('getUID')->willReturn('user1'); $this->defaultProvider @@ -1814,7 +1820,7 @@ public function testTransferShare($sharetype) { return []; })); - $storage = $this->createMock(Storage::class); + $storage = $this->createMock(Storage\IStorage::class); $path = $this->createMock(File::class); $path->method('getOwner')->willReturn($shareOwner); $path->method('getName')->willReturn('test_share'); @@ -2052,11 +2058,11 @@ public function testCreateShareUser() { ->setMethods(['canShare', 'generalCreateChecks', 'userCreateChecks', 'pathCreateChecks']) ->getMock(); - $shareOwner = $this->createMock('\OCP\IUser'); + $shareOwner = $this->createMock(IUser::class); $shareOwner->method('getUID')->willReturn('shareOwner'); - $storage = $this->createMock('\OCP\Files\Storage'); - $path = $this->createMock('\OCP\Files\File'); + $storage = $this->createMock(Storage\IStorage::class); + $path = $this->createMock(File::class); $path->method('getOwner')->willReturn($shareOwner); $path->method('getName')->willReturn('target'); $path->method('getStorage')->willReturn($storage); @@ -2077,11 +2083,9 @@ public function testCreateShareUser() { $manager->expects($this->once()) ->method('generalCreateChecks') ->with($share); - ; $manager->expects($this->once()) ->method('userCreateChecks') ->with($share); - ; $manager->expects($this->once()) ->method('pathCreateChecks') ->with($path); @@ -2129,11 +2133,11 @@ public function testCreateShareGroup() { ->setMethods(['canShare', 'generalCreateChecks', 'groupCreateChecks', 'pathCreateChecks']) ->getMock(); - $shareOwner = $this->createMock('\OCP\IUser'); + $shareOwner = $this->createMock(IUser::class); $shareOwner->method('getUID')->willReturn('shareOwner'); - $storage = $this->createMock('\OCP\Files\Storage'); - $path = $this->createMock('\OCP\Files\File'); + $storage = $this->createMock(Storage\IStorage::class); + $path = $this->createMock(File::class); $path->method('getOwner')->willReturn($shareOwner); $path->method('getName')->willReturn('target'); $path->method('getStorage')->willReturn($storage); @@ -2154,11 +2158,9 @@ public function testCreateShareGroup() { $manager->expects($this->once()) ->method('generalCreateChecks') ->with($share); - ; $manager->expects($this->once()) ->method('groupCreateChecks') ->with($share); - ; $manager->expects($this->once()) ->method('pathCreateChecks') ->with($path); @@ -2214,11 +2216,11 @@ public function testCreateShareLink() { ]) ->getMock(); - $shareOwner = $this->createMock('\OCP\IUser'); + $shareOwner = $this->createMock(IUser::class); $shareOwner->method('getUID')->willReturn('shareOwner'); - $storage = $this->createMock('\OCP\Files\Storage'); - $path = $this->createMock('\OCP\Files\File'); + $storage = $this->createMock(Storage\IStorage::class); + $path = $this->createMock(File::class); $path->method('getOwner')->willReturn($shareOwner); $path->method('getName')->willReturn('target'); $path->method('getId')->willReturn(1); @@ -2241,11 +2243,9 @@ public function testCreateShareLink() { $manager->expects($this->once()) ->method('generalCreateChecks') ->with($share); - ; $manager->expects($this->once()) ->method('linkCreateChecks') ->with($share); - ; $manager->expects($this->once()) ->method('pathCreateChecks') ->with($path); @@ -2278,8 +2278,8 @@ public function testCreateShareLink() { })); $hookListner = $this->getMockBuilder('Dummy')->setMethods(['pre', 'post'])->getMock(); - \OCP\Util::connectHook('OCP\Share', 'pre_shared', $hookListner, 'pre'); - \OCP\Util::connectHook('OCP\Share', 'post_shared', $hookListner, 'post'); + \OCP\Util::connectHook(\OCP\Share::class, 'pre_shared', $hookListner, 'pre'); + \OCP\Util::connectHook(\OCP\Share::class, 'post_shared', $hookListner, 'post'); $hookListnerExpectsPre = [ 'itemType' => 'file', @@ -2365,11 +2365,11 @@ public function testCreateShareHookError() { ]) ->getMock(); - $shareOwner = $this->createMock('\OCP\IUser'); + $shareOwner = $this->createMock(IUser::class); $shareOwner->method('getUID')->willReturn('shareOwner'); - $storage = $this->createMock('\OCP\Files\Storage'); - $path = $this->createMock('\OCP\Files\File'); + $storage = $this->createMock(Storage\IStorage::class); + $path = $this->createMock(File::class); $path->method('getOwner')->willReturn($shareOwner); $path->method('getName')->willReturn('target'); $path->method('getStorage')->willReturn($storage); @@ -2390,11 +2390,9 @@ public function testCreateShareHookError() { $manager->expects($this->once()) ->method('generalCreateChecks') ->with($share); - ; $manager->expects($this->once()) ->method('userCreateChecks') ->with($share); - ; $manager->expects($this->once()) ->method('pathCreateChecks') ->with($path); @@ -2407,7 +2405,7 @@ public function testCreateShareHookError() { ->with('/target'); $hookListner = $this->getMockBuilder('Dummy')->setMethods(['pre'])->getMock(); - \OCP\Util::connectHook('OCP\Share', 'pre_shared', $hookListner, 'pre'); + \OCP\Util::connectHook(\OCP\Share::class, 'pre_shared', $hookListner, 'pre'); $hookListner->expects($this->once()) ->method('pre') ->will($this->returnCallback(function (array $data) { @@ -2423,28 +2421,28 @@ public function testCreateShareOfIncomingFederatedShare() { ->setMethods(['canShare', 'generalCreateChecks', 'userCreateChecks', 'pathCreateChecks']) ->getMock(); - $shareOwner = $this->createMock('\OCP\IUser'); + $shareOwner = $this->createMock(IUser::class); $shareOwner->method('getUID')->willReturn('shareOwner'); - $storage = $this->createMock('\OCP\Files\Storage'); + $storage = $this->createMock(Storage\IStorage::class); $storage->method('instanceOfStorage') - ->with('OCA\Files_Sharing\External\Storage') + ->with(\OCA\Files_Sharing\External\Storage::class) ->willReturn(true); - $storage2 = $this->createMock('\OCP\Files\Storage'); + $storage2 = $this->createMock(Storage\IStorage::class); $storage2->method('instanceOfStorage') - ->with('OCA\Files_Sharing\External\Storage') + ->with(\OCA\Files_Sharing\External\Storage::class) ->willReturn(false); - $path = $this->createMock('\OCP\Files\File'); + $path = $this->createMock(File::class); $path->expects($this->never())->method('getOwner'); $path->method('getName')->willReturn('target'); $path->method('getStorage')->willReturn($storage); - $parent = $this->createMock('\OCP\Files\Folder'); + $parent = $this->createMock(Folder::class); $parent->method('getStorage')->willReturn($storage); - $parentParent = $this->createMock('\OCP\Files\Folder'); + $parentParent = $this->createMock(Folder::class); $parentParent->method('getStorage')->willReturn($storage2); $parentParent->method('getOwner')->willReturn($shareOwner); @@ -2467,11 +2465,9 @@ public function testCreateShareOfIncomingFederatedShare() { $manager->expects($this->once()) ->method('generalCreateChecks') ->with($share); - ; $manager->expects($this->once()) ->method('userCreateChecks') ->with($share); - ; $manager->expects($this->once()) ->method('pathCreateChecks') ->with($path); @@ -2517,7 +2513,7 @@ function (GenericEvent $event) use (&$calledAfterShareCreate) { public function testGetAllSharesBy() { $share = $this->manager->newShare(); - $node = $this->createMock('OCP\Files\Folder'); + $node = $this->createMock(Folder::class); $node->expects($this->any()) ->method('getId') ->will($this->returnValue(0)); @@ -2525,7 +2521,7 @@ public function testGetAllSharesBy() { $nodes = [$node->getId()]; for ($i = 1; $i <= 201; $i++) { - $node = $this->createMock('OCP\Files\File'); + $node = $this->createMock(File::class); $node->expects($this->any()) ->method('getId') ->will($this->returnValue($i)); @@ -2563,7 +2559,7 @@ public function testGetAllSharesByExpiration() { $today = new \DateTime(); $shareExpired->method('getExpirationDate')->willReturn($today); - $node = $this->createMock('OCP\Files\Folder'); + $node = $this->createMock(Folder::class); $node->expects($this->any()) ->method('getId') ->will($this->returnValue(0)); @@ -2571,7 +2567,7 @@ public function testGetAllSharesByExpiration() { $nodes = [$node->getId()]; for ($i = 1; $i <= 201; $i++) { - $node = $this->createMock('OCP\Files\File'); + $node = $this->createMock(File::class); $node->expects($this->any()) ->method('getId') ->will($this->returnValue($i)); @@ -2615,7 +2611,7 @@ public function testGetAllSharesByException() { public function testGetSharesBy() { $share = $this->manager->newShare(); - $node = $this->createMock('OCP\Files\Folder'); + $node = $this->createMock(Folder::class); $this->defaultProvider->expects($this->once()) ->method('getSharesBy') @@ -2676,7 +2672,7 @@ public function testGetSharesByExpiredLinkShares() { $shares2[] = clone $shares[$i]; } - $node = $this->createMock('OCP\Files\File'); + $node = $this->createMock(File::class); /* * Simulate the getSharesBy call. @@ -2716,7 +2712,7 @@ public function testGetSharesByExpiredLinkShares() { } public function testGetShareByToken() { - $factory = $this->createMock('\OCP\Share\IProviderFactory'); + $factory = $this->createMock(IProviderFactory::class); $manager = new Manager( $this->logger, @@ -2734,7 +2730,7 @@ public function testGetShareByToken() { $this->connection ); - $share = $this->createMock('\OCP\Share\IShare'); + $share = $this->createMock(IShare::class); $factory->expects($this->once()) ->method('getProviderForType') @@ -2751,7 +2747,7 @@ public function testGetShareByToken() { } public function testGetShareByTokenWithException() { - $factory = $this->createMock('\OCP\Share\IProviderFactory'); + $factory = $this->createMock(IProviderFactory::class); $manager = new Manager( $this->logger, @@ -2769,7 +2765,7 @@ public function testGetShareByTokenWithException() { $this->connection ); - $share = $this->createMock('\OCP\Share\IShare'); + $share = $this->createMock(IShare::class); $factory->expects($this->at(0)) ->method('getProviderForType') @@ -2855,7 +2851,7 @@ public function testGetShareByTokenPublicSharingDisabled() { } public function testGetSharesByPath() { - $factory = $this->createMock('\OCP\Share\IProviderFactory'); + $factory = $this->createMock(IProviderFactory::class); $manager = new Manager( $this->logger, @@ -2873,11 +2869,11 @@ public function testGetSharesByPath() { $this->connection ); - $provider1 = $this->getMockBuilder('\OC\Share20\DefaultShareProvider') + $provider1 = $this->getMockBuilder(DefaultShareProvider::class) ->disableOriginalConstructor() ->getMock(); $provider1->method('identifier')->willReturn('provider1'); - $provider2 = $this->getMockBuilder('\OC\Share20\DefaultShareProvider') + $provider2 = $this->getMockBuilder(DefaultShareProvider::class) ->disableOriginalConstructor() ->getMock(); $provider2->method('identifier')->willReturn('provider2'); @@ -2899,7 +2895,7 @@ public function testGetSharesByPath() { $share3 = $this->manager->newShare(); $share3->setId(44); - $node = $this->createMock('\OCP\Files\Folder'); + $node = $this->createMock(Folder::class); $provider1->expects($this->once()) ->method('getSharesByPath') @@ -2913,13 +2909,13 @@ public function testGetSharesByPath() { } public function testCheckPasswordNoLinkShare() { - $share = $this->createMock('\OCP\Share\IShare'); + $share = $this->createMock(IShare::class); $share->method('getShareType')->willReturn(\OCP\Share::SHARE_TYPE_USER); $this->assertFalse($this->manager->checkPassword($share, 'password')); } public function testCheckPasswordNoPassword() { - $share = $this->createMock('\OCP\Share\IShare'); + $share = $this->createMock(IShare::class); $share->method('getShareType')->willReturn(\OCP\Share::SHARE_TYPE_LINK); $this->assertFalse($this->manager->checkPassword($share, 'password')); @@ -2928,7 +2924,7 @@ public function testCheckPasswordNoPassword() { } public function testCheckPasswordInvalidPassword() { - $share = $this->createMock('\OCP\Share\IShare'); + $share = $this->createMock(IShare::class); $share->method('getShareType')->willReturn(\OCP\Share::SHARE_TYPE_LINK); $share->method('getPassword')->willReturn('password'); @@ -2938,7 +2934,7 @@ public function testCheckPasswordInvalidPassword() { } public function testCheckPasswordValidPassword() { - $share = $this->createMock('\OCP\Share\IShare'); + $share = $this->createMock(IShare::class); $share->method('getShareType')->willReturn(\OCP\Share::SHARE_TYPE_LINK); $share->method('getPassword')->willReturn('passwordHash'); @@ -3069,7 +3065,7 @@ public function testUpdateShareUser() { ->setSharedWith('origUser') ->setPermissions(1); - $node = $this->createMock('\OCP\Files\File'); + $node = $this->createMock(File::class); $node->method('getId')->willReturn(100); $node->method('getPath')->willReturn('/newUser/files/myPath'); @@ -3092,14 +3088,14 @@ public function testUpdateShareUser() { ->willReturn($share); $hookListner = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock(); - \OCP\Util::connectHook('OCP\Share', 'post_set_expiration_date', $hookListner, 'post'); + \OCP\Util::connectHook(\OCP\Share::class, 'post_set_expiration_date', $hookListner, 'post'); $hookListner->expects($this->never())->method('post'); $this->rootFolder->method('getUserFolder')->with('newUser')->will($this->returnSelf()); $this->rootFolder->method('getRelativePath')->with('/newUser/files/myPath')->willReturn('/myPath'); $hookListner2 = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock(); - \OCP\Util::connectHook('OCP\Share', 'post_update_permissions', $hookListner2, 'post'); + \OCP\Util::connectHook(\OCP\Share::class, 'post_update_permissions', $hookListner2, 'post'); $hookListner2->expects($this->once())->method('post')->with([ 'itemType' => 'file', 'itemSource' => 100, @@ -3148,7 +3144,7 @@ public function testUpdateShareGroup() { $manager->expects($this->once())->method('canShare')->willReturn(true); $manager->expects($this->once())->method('getShareById')->with('foo:42')->willReturn($originalShare); - $node = $this->createMock('\OCP\Files\File'); + $node = $this->createMock(File::class); $share = $this->manager->newShare(); $share->setProviderId('foo') @@ -3165,11 +3161,11 @@ public function testUpdateShareGroup() { ->willReturn($share); $hookListner = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock(); - \OCP\Util::connectHook('OCP\Share', 'post_set_expiration_date', $hookListner, 'post'); + \OCP\Util::connectHook(\OCP\Share::class, 'post_set_expiration_date', $hookListner, 'post'); $hookListner->expects($this->never())->method('post'); $hookListner2 = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock(); - \OCP\Util::connectHook('OCP\Share', 'post_update_permissions', $hookListner2, 'post'); + \OCP\Util::connectHook(\OCP\Share::class, 'post_update_permissions', $hookListner2, 'post'); $hookListner2->expects($this->never())->method('post'); $manager->updateShare($share); @@ -3196,7 +3192,7 @@ public function testUpdateShareLink() { $tomorrow->setTime(0, 0, 0); $tomorrow->add(new \DateInterval('P1D')); - $file = $this->createMock('OCP\Files\File', [], [], 'File'); + $file = $this->createMock(File::class, [], [], 'File'); $file->method('getId')->willReturn(100); $share = $this->manager->newShare(); @@ -3221,7 +3217,7 @@ public function testUpdateShareLink() { ->willReturn($share); $hookListner = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock(); - \OCP\Util::connectHook('OCP\Share', 'post_set_expiration_date', $hookListner, 'post'); + \OCP\Util::connectHook(\OCP\Share::class, 'post_set_expiration_date', $hookListner, 'post'); $hookListner->expects($this->once())->method('post')->with([ 'itemType' => 'file', 'itemSource' => 100, @@ -3230,7 +3226,7 @@ public function testUpdateShareLink() { ]); $hookListner2 = $this->getMockBuilder('Dummy')->setMethods(['post'])->getMock(); - \OCP\Util::connectHook('OCP\Share', 'post_update_permissions', $hookListner2, 'post'); + \OCP\Util::connectHook(\OCP\Share::class, 'post_update_permissions', $hookListner2, 'post'); $hookListner2->expects($this->never())->method('post'); $calledAfterUpdate = [];