diff --git a/tests/lib/Share20/DefaultShareProviderTest.php b/tests/lib/Share20/DefaultShareProviderTest.php index 6ef00721a7..ae9ad47b9a 100644 --- a/tests/lib/Share20/DefaultShareProviderTest.php +++ b/tests/lib/Share20/DefaultShareProviderTest.php @@ -22,11 +22,16 @@ namespace Test\Share20; use OC\Share20\Exception\ProviderException; use OCP\DB\QueryBuilder\IQueryBuilder; +use OCP\Files\File; +use OCP\Files\Folder; use OCP\IDBConnection; +use OCP\IGroup; +use OCP\IUser; use OCP\IUserManager; use OCP\IGroupManager; use OCP\Files\IRootFolder; use OC\Share20\DefaultShareProvider; +use OCP\Share\IShare; /** * Class DefaultShareProviderTest @@ -53,9 +58,9 @@ class DefaultShareProviderTest extends \Test\TestCase { public function setUp() { $this->dbConn = \OC::$server->getDatabaseConnection(); - $this->userManager = $this->getMock('OCP\IUserManager'); - $this->groupManager = $this->getMock('OCP\IGroupManager'); - $this->rootFolder = $this->getMock('OCP\Files\IRootFolder'); + $this->userManager = $this->createMock(IUserManager::class); + $this->groupManager = $this->createMock(IGroupManager::class); + $this->rootFolder = $this->createMock(IRootFolder::class); $this->userManager->expects($this->any())->method('userExists')->willReturn(true); @@ -136,13 +141,13 @@ class DefaultShareProviderTest extends \Test\TestCase { $id = $qb->getLastInsertId(); - $sharedBy = $this->getMock('OCP\IUser'); + $sharedBy = $this->createMock(IUser::class); $sharedBy->method('getUID')->willReturn('sharedBy'); - $shareOwner = $this->getMock('OCP\IUser'); + $shareOwner = $this->createMock(IUser::class); $shareOwner->method('getUID')->willReturn('shareOwner'); - $ownerPath = $this->getMock('\OCP\Files\File'); - $shareOwnerFolder = $this->getMock('\OCP\Files\Folder'); + $ownerPath = $this->createMock(File::class); + $shareOwnerFolder = $this->createMock(Folder::class); $shareOwnerFolder->method('getById')->with(42)->willReturn([$ownerPath]); $this->rootFolder @@ -218,9 +223,9 @@ class DefaultShareProviderTest extends \Test\TestCase { $id = $qb->getLastInsertId(); - $ownerPath = $this->getMock('\OCP\Files\File'); + $ownerPath = $this->createMock(File::class); - $shareOwnerFolder = $this->getMock('\OCP\Files\Folder'); + $shareOwnerFolder = $this->createMock(Folder::class); $shareOwnerFolder->method('getById')->with(42)->willReturn([$ownerPath]); $this->rootFolder @@ -263,8 +268,8 @@ class DefaultShareProviderTest extends \Test\TestCase { // Get the id $id = $qb->getLastInsertId(); - $ownerPath = $this->getMock('\OCP\Files\Folder'); - $shareOwnerFolder = $this->getMock('\OCP\Files\Folder'); + $ownerPath = $this->createMock(Folder::class); + $shareOwnerFolder = $this->createMock(Folder::class); $shareOwnerFolder->method('getById')->with(42)->willReturn([$ownerPath]); $this->rootFolder @@ -291,15 +296,15 @@ class DefaultShareProviderTest extends \Test\TestCase { $id = $this->addShareToDB(\OCP\Share::SHARE_TYPE_GROUP, 'group0', 'user0', 'user0', 'file', 42, 'myTarget', 31, null, null); $this->addShareToDB(2, 'user1', 'user0', 'user0', 'file', 42, 'userTarget', 0, null, null, $id); - $user0 = $this->getMock('OCP\IUser'); + $user0 = $this->createMock(IUser::class); $user0->method('getUID')->willReturn('user0'); - $user1 = $this->getMock('OCP\IUser'); + $user1 = $this->createMock(IUser::class); $user1->method('getUID')->willReturn('user1'); - $group0 = $this->getMock('OCP\IGroup'); + $group0 = $this->createMock(IGroup::class); $group0->method('inGroup')->with($user1)->willReturn(true); - $node = $this->getMock('\OCP\Files\Folder'); + $node = $this->createMock(Folder::class); $node->method('getId')->willReturn(42); $this->rootFolder->method('getUserFolder')->with('user0')->will($this->returnSelf()); @@ -345,8 +350,8 @@ class DefaultShareProviderTest extends \Test\TestCase { $id = $qb->getLastInsertId(); - $ownerPath = $this->getMock('\OCP\Files\Folder'); - $shareOwnerFolder = $this->getMock('\OCP\Files\Folder'); + $ownerPath = $this->createMock(Folder::class); + $shareOwnerFolder = $this->createMock(Folder::class); $shareOwnerFolder->method('getById')->with(42)->willReturn([$ownerPath]); $this->rootFolder @@ -385,7 +390,7 @@ class DefaultShareProviderTest extends \Test\TestCase { $id = $qb->getLastInsertId(); - $share = $this->getMock('OCP\Share\IShare'); + $share = $this->createMock(IShare::class); $share->method('getId')->willReturn($id); $provider = $this->getMockBuilder('OC\Share20\DefaultShareProvider') @@ -473,7 +478,7 @@ class DefaultShareProviderTest extends \Test\TestCase { ]); $this->assertEquals(1, $qb->execute()); - $share = $this->getMock('OCP\Share\IShare'); + $share = $this->createMock(IShare::class); $share->method('getId')->willReturn($id); $share->method('getShareType')->willReturn(\OCP\Share::SHARE_TYPE_GROUP); @@ -548,8 +553,8 @@ class DefaultShareProviderTest extends \Test\TestCase { ]); $qb->execute(); - $ownerPath = $this->getMock('\OCP\Files\Folder'); - $ownerFolder = $this->getMock('\OCP\Files\Folder'); + $ownerPath = $this->createMock(Folder::class); + $ownerFolder = $this->createMock(Folder::class); $ownerFolder->method('getById')->willReturn([$ownerPath]); $this->rootFolder @@ -558,7 +563,7 @@ class DefaultShareProviderTest extends \Test\TestCase { ['shareOwner', $ownerFolder], ])); - $share = $this->getMock('\OCP\Share\IShare'); + $share = $this->createMock(IShare::class); $share->method('getId')->willReturn($id); $children = $this->provider->getChildren($share); @@ -591,15 +596,15 @@ class DefaultShareProviderTest extends \Test\TestCase { public function testCreateUserShare() { $share = new \OC\Share20\Share($this->rootFolder, $this->userManager); - $shareOwner = $this->getMock('OCP\IUser'); + $shareOwner = $this->createMock(IUser::class); $shareOwner->method('getUID')->WillReturn('shareOwner'); - $path = $this->getMock('\OCP\Files\File'); + $path = $this->createMock(File::class); $path->method('getId')->willReturn(100); $path->method('getOwner')->willReturn($shareOwner); - $ownerFolder = $this->getMock('OCP\Files\Folder'); - $userFolder = $this->getMock('OCP\Files\Folder'); + $ownerFolder = $this->createMock(Folder::class); + $userFolder = $this->createMock(Folder::class); $this->rootFolder ->method('getUserFolder') ->will($this->returnValueMap([ @@ -639,15 +644,15 @@ class DefaultShareProviderTest extends \Test\TestCase { public function testCreateGroupShare() { $share = new \OC\Share20\Share($this->rootFolder, $this->userManager); - $shareOwner = $this->getMock('\OCP\IUser'); + $shareOwner = $this->createMock(IUser::class); $shareOwner->method('getUID')->willReturn('shareOwner'); - $path = $this->getMock('\OCP\Files\Folder'); + $path = $this->createMock(Folder::class); $path->method('getId')->willReturn(100); $path->method('getOwner')->willReturn($shareOwner); - $ownerFolder = $this->getMock('OCP\Files\Folder'); - $userFolder = $this->getMock('OCP\Files\Folder'); + $ownerFolder = $this->createMock(Folder::class); + $userFolder = $this->createMock(Folder::class); $this->rootFolder ->method('getUserFolder') ->will($this->returnValueMap([ @@ -687,15 +692,15 @@ class DefaultShareProviderTest extends \Test\TestCase { public function testCreateLinkShare() { $share = new \OC\Share20\Share($this->rootFolder, $this->userManager); - $shareOwner = $this->getMock('\OCP\IUser'); + $shareOwner = $this->createMock(IUser::class); $shareOwner->method('getUID')->willReturn('shareOwner'); - $path = $this->getMock('\OCP\Files\Folder'); + $path = $this->createMock(Folder::class); $path->method('getId')->willReturn(100); $path->method('getOwner')->willReturn($shareOwner); - $ownerFolder = $this->getMock('OCP\Files\Folder'); - $userFolder = $this->getMock('OCP\Files\Folder'); + $ownerFolder = $this->createMock(Folder::class); + $userFolder = $this->createMock(Folder::class); $this->rootFolder ->method('getUserFolder') ->will($this->returnValueMap([ @@ -755,7 +760,7 @@ class DefaultShareProviderTest extends \Test\TestCase { $qb->execute(); $id = $qb->getLastInsertId(); - $file = $this->getMock('\OCP\Files\File'); + $file = $this->createMock(File::class); $this->rootFolder->method('getUserFolder')->with('shareOwner')->will($this->returnSelf()); $this->rootFolder->method('getById')->with(42)->willReturn([$file]); @@ -806,7 +811,7 @@ class DefaultShareProviderTest extends \Test\TestCase { ]); $this->assertEquals(1, $qb->execute()); - $file = $this->getMock('\OCP\Files\File'); + $file = $this->createMock(File::class); $this->rootFolder->method('getUserFolder')->with('shareOwner')->will($this->returnSelf()); $this->rootFolder->method('getById')->with(42)->willReturn([$file]); @@ -853,20 +858,20 @@ class DefaultShareProviderTest extends \Test\TestCase { $groups = []; foreach(range(0, 100) as $i) { - $group = $this->getMock('\OCP\IGroup'); + $group = $this->createMock(IGroup::class); $group->method('getGID')->willReturn('group'.$i); $groups[] = $group; } - $group = $this->getMock('\OCP\IGroup'); + $group = $this->createMock(IGroup::class); $group->method('getGID')->willReturn('sharedWith'); $groups[] = $group; - $user = $this->getMock('\OCP\IUser'); + $user = $this->createMock(IUser::class); $user->method('getUID')->willReturn('sharedWith'); - $owner = $this->getMock('\OCP\IUser'); + $owner = $this->createMock(IUser::class); $owner->method('getUID')->willReturn('shareOwner'); - $initiator = $this->getMock('\OCP\IUser'); + $initiator = $this->createMock(IUser::class); $initiator->method('getUID')->willReturn('sharedBy'); $this->userManager->method('get')->willReturnMap([ @@ -877,7 +882,7 @@ class DefaultShareProviderTest extends \Test\TestCase { $this->groupManager->method('getUserGroups')->with($user)->willReturn($groups); $this->groupManager->method('get')->with('sharedWith')->willReturn($group); - $file = $this->getMock('\OCP\Files\File'); + $file = $this->createMock(File::class); $this->rootFolder->method('getUserFolder')->with('shareOwner')->will($this->returnSelf()); $this->rootFolder->method('getById')->with(42)->willReturn([$file]); @@ -944,15 +949,15 @@ class DefaultShareProviderTest extends \Test\TestCase { ]); $this->assertEquals(1, $qb->execute()); - $group = $this->getMock('\OCP\IGroup'); + $group = $this->createMock(IGroup::class); $group->method('getGID')->willReturn('sharedWith'); $groups = [$group]; - $user = $this->getMock('\OCP\IUser'); + $user = $this->createMock(IUser::class); $user->method('getUID')->willReturn('user'); - $owner = $this->getMock('\OCP\IUser'); + $owner = $this->createMock(IUser::class); $owner->method('getUID')->willReturn('shareOwner'); - $initiator = $this->getMock('\OCP\IUser'); + $initiator = $this->createMock(IUser::class); $initiator->method('getUID')->willReturn('sharedBy'); $this->userManager->method('get')->willReturnMap([ @@ -963,7 +968,7 @@ class DefaultShareProviderTest extends \Test\TestCase { $this->groupManager->method('getUserGroups')->with($user)->willReturn($groups); $this->groupManager->method('get')->with('sharedWith')->willReturn($group); - $file = $this->getMock('\OCP\Files\File'); + $file = $this->createMock(File::class); $this->rootFolder->method('getUserFolder')->with('shareOwner')->will($this->returnSelf()); $this->rootFolder->method('getById')->with(42)->willReturn([$file]); @@ -986,9 +991,9 @@ class DefaultShareProviderTest extends \Test\TestCase { $id = $this->addShareToDB(\OCP\Share::SHARE_TYPE_USER, 'user0', 'user1', 'user1', 'file', 43, 'myTarget', 31, null, null, null); - $user0 = $this->getMock('\OCP\IUser'); + $user0 = $this->createMock(IUser::class); $user0->method('getUID')->willReturn('user0'); - $user1 = $this->getMock('\OCP\IUser'); + $user1 = $this->createMock(IUser::class); $user1->method('getUID')->willReturn('user1'); $this->userManager->method('get')->willReturnMap([ @@ -996,7 +1001,7 @@ class DefaultShareProviderTest extends \Test\TestCase { ['user1', $user1], ]); - $file = $this->getMock('\OCP\Files\File'); + $file = $this->createMock(File::class); $file->method('getId')->willReturn(43); $this->rootFolder->method('getUserFolder')->with('user1')->will($this->returnSelf()); $this->rootFolder->method('getById')->with(43)->willReturn([$file]); @@ -1019,9 +1024,9 @@ class DefaultShareProviderTest extends \Test\TestCase { $id = $this->addShareToDB(\OCP\Share::SHARE_TYPE_GROUP, 'group0', 'user1', 'user1', 'file', 43, 'myTarget', 31, null, null, null); - $user0 = $this->getMock('\OCP\IUser'); + $user0 = $this->createMock(IUser::class); $user0->method('getUID')->willReturn('user0'); - $user1 = $this->getMock('\OCP\IUser'); + $user1 = $this->createMock(IUser::class); $user1->method('getUID')->willReturn('user1'); $this->userManager->method('get')->willReturnMap([ @@ -1029,13 +1034,13 @@ class DefaultShareProviderTest extends \Test\TestCase { ['user1', $user1], ]); - $group0 = $this->getMock('\OCP\IGroup'); + $group0 = $this->createMock(IGroup::class); $group0->method('getGID')->willReturn('group0'); $this->groupManager->method('get')->with('group0')->willReturn($group0); $this->groupManager->method('getUserGroups')->with($user0)->willReturn([$group0]); - $node = $this->getMock('\OCP\Files\Folder'); + $node = $this->createMock(Folder::class); $node->method('getId')->willReturn(43); $this->rootFolder->method('getUserFolder')->with('user1')->will($this->returnSelf()); $this->rootFolder->method('getById')->with(43)->willReturn([$node]); @@ -1083,7 +1088,7 @@ class DefaultShareProviderTest extends \Test\TestCase { ]); $this->assertEquals(1, $qb->execute()); - $file = $this->getMock('\OCP\Files\File'); + $file = $this->createMock(File::class); $this->rootFolder->method('getUserFolder')->with('shareOwner')->will($this->returnSelf()); $this->rootFolder->method('getById')->with(42)->willReturn([$file]); @@ -1131,7 +1136,7 @@ class DefaultShareProviderTest extends \Test\TestCase { ]); $this->assertEquals(1, $qb->execute()); - $file = $this->getMock('\OCP\Files\File'); + $file = $this->createMock(File::class); $file->method('getId')->willReturn(42); $this->rootFolder->method('getUserFolder')->with('shareOwner')->will($this->returnSelf()); $this->rootFolder->method('getById')->with(42)->willReturn([$file]); @@ -1180,7 +1185,7 @@ class DefaultShareProviderTest extends \Test\TestCase { $this->assertEquals(1, $qb->execute()); $id2 = $qb->getLastInsertId(); - $file = $this->getMock('\OCP\Files\File'); + $file = $this->createMock(File::class); $file->method('getId')->willReturn(42); $this->rootFolder->method('getUserFolder')->with('shareOwner')->will($this->returnSelf()); $this->rootFolder->method('getById')->with(42)->willReturn([$file]); @@ -1223,21 +1228,21 @@ class DefaultShareProviderTest extends \Test\TestCase { $this->assertEquals(1, $stmt); $id = $qb->getLastInsertId(); - $user1 = $this->getMock('\OCP\IUser'); + $user1 = $this->createMock(IUser::class); $user1->method('getUID')->willReturn('user1'); - $user2 = $this->getMock('\OCP\IUser'); + $user2 = $this->createMock(IUser::class); $user2->method('getUID')->willReturn('user2'); $this->userManager->method('get')->will($this->returnValueMap([ ['user1', $user1], ['user2', $user2], ])); - $group = $this->getMock('\OCP\IGroup'); + $group = $this->createMock(IGroup::class); $group->method('getGID')->willReturn('group'); $group->method('inGroup')->with($user2)->willReturn(true); $this->groupManager->method('get')->with('group')->willReturn($group); - $file = $this->getMock('\OCP\Files\File'); + $file = $this->createMock(File::class); $file->method('getId')->willReturn(1); $this->rootFolder->method('getUserFolder')->with('user1')->will($this->returnSelf()); @@ -1294,21 +1299,21 @@ class DefaultShareProviderTest extends \Test\TestCase { ])->execute(); $this->assertEquals(1, $stmt); - $user1 = $this->getMock('\OCP\IUser'); + $user1 = $this->createMock(IUser::class); $user1->method('getUID')->willReturn('user1'); - $user2 = $this->getMock('\OCP\IUser'); + $user2 = $this->createMock(IUser::class); $user2->method('getUID')->willReturn('user2'); $this->userManager->method('get')->will($this->returnValueMap([ ['user1', $user1], ['user2', $user2], ])); - $group = $this->getMock('\OCP\IGroup'); + $group = $this->createMock(IGroup::class); $group->method('getGID')->willReturn('group'); $group->method('inGroup')->with($user2)->willReturn(true); $this->groupManager->method('get')->with('group')->willReturn($group); - $file = $this->getMock('\OCP\Files\File'); + $file = $this->createMock(File::class); $file->method('getId')->willReturn(1); $this->rootFolder->method('getUserFolder')->with('user1')->will($this->returnSelf()); @@ -1354,21 +1359,21 @@ class DefaultShareProviderTest extends \Test\TestCase { $this->assertEquals(1, $stmt); $id = $qb->getLastInsertId(); - $user1 = $this->getMock('\OCP\IUser'); + $user1 = $this->createMock(IUser::class); $user1->method('getUID')->willReturn('user1'); - $user2 = $this->getMock('\OCP\IUser'); + $user2 = $this->createMock(IUser::class); $user2->method('getUID')->willReturn('user2'); $this->userManager->method('get')->will($this->returnValueMap([ ['user1', $user1], ['user2', $user2], ])); - $group = $this->getMock('\OCP\IGroup'); + $group = $this->createMock(IGroup::class); $group->method('getGID')->willReturn('group'); $group->method('inGroup')->with($user2)->willReturn(false); $this->groupManager->method('get')->with('group')->willReturn($group); - $file = $this->getMock('\OCP\Files\File'); + $file = $this->createMock(File::class); $file->method('getId')->willReturn(1); $this->rootFolder->method('getUserFolder')->with('user1')->will($this->returnSelf()); @@ -1395,16 +1400,16 @@ class DefaultShareProviderTest extends \Test\TestCase { $this->assertEquals(1, $stmt); $id = $qb->getLastInsertId(); - $user1 = $this->getMock('\OCP\IUser'); + $user1 = $this->createMock(IUser::class); $user1->method('getUID')->willReturn('user1'); - $user2 = $this->getMock('\OCP\IUser'); + $user2 = $this->createMock(IUser::class); $user2->method('getUID')->willReturn('user2'); $this->userManager->method('get')->will($this->returnValueMap([ ['user1', $user1], ['user2', $user2], ])); - $file = $this->getMock('\OCP\Files\File'); + $file = $this->createMock(File::class); $file->method('getId')->willReturn(1); $this->rootFolder->method('getUserFolder')->with('user1')->will($this->returnSelf()); @@ -1446,17 +1451,17 @@ class DefaultShareProviderTest extends \Test\TestCase { $this->assertEquals(1, $stmt); $id = $qb->getLastInsertId(); - $user1 = $this->getMock('\OCP\IUser'); + $user1 = $this->createMock(IUser::class); $user1->method('getUID')->willReturn('user1'); - $user2 = $this->getMock('\OCP\IUser'); + $user2 = $this->createMock(IUser::class); $user2->method('getUID')->willReturn('user2'); - $user3 = $this->getMock('\OCP\IUser'); + $user3 = $this->createMock(IUser::class); $this->userManager->method('get')->will($this->returnValueMap([ ['user1', $user1], ['user2', $user2], ])); - $file = $this->getMock('\OCP\Files\File'); + $file = $this->createMock(File::class); $file->method('getId')->willReturn(1); $this->rootFolder->method('getUserFolder')->with('user1')->will($this->returnSelf()); @@ -1487,13 +1492,13 @@ class DefaultShareProviderTest extends \Test\TestCase { $this->assertEquals(1, $stmt); $id = $qb->getLastInsertId(); - $user1 = $this->getMock('\OCP\IUser'); + $user1 = $this->createMock(IUser::class); $user1->method('getUID')->willReturn('user1'); $this->userManager->method('get')->will($this->returnValueMap([ ['user1', $user1], ])); - $file = $this->getMock('\OCP\Files\File'); + $file = $this->createMock(File::class); $file->method('getId')->willReturn(1); $this->rootFolder->method('getUserFolder')->with('user1')->will($this->returnSelf()); @@ -1510,7 +1515,7 @@ class DefaultShareProviderTest extends \Test\TestCase { $users = []; for($i = 0; $i < 6; $i++) { - $user = $this->getMock('\OCP\IUser'); + $user = $this->createMock(IUser::class); $user->method('getUID')->willReturn('user'.$i); $users['user'.$i] = $user; } @@ -1521,14 +1526,14 @@ class DefaultShareProviderTest extends \Test\TestCase { }) ); - $file1 = $this->getMock('\OCP\Files\File'); + $file1 = $this->createMock(File::class); $file1->method('getId')->willReturn(42); - $file2 = $this->getMock('\OCP\Files\File'); + $file2 = $this->createMock(File::class); $file2->method('getId')->willReturn(43); - $folder1 = $this->getMock('\OCP\Files\Folder'); + $folder1 = $this->createMock(Folder::class); $folder1->method('getById')->with(42)->willReturn([$file1]); - $folder2 = $this->getMock('\OCP\Files\Folder'); + $folder2 = $this->createMock(Folder::class); $folder2->method('getById')->with(43)->willReturn([$file2]); $this->rootFolder->method('getUserFolder')->will($this->returnValueMap([ @@ -1559,7 +1564,7 @@ class DefaultShareProviderTest extends \Test\TestCase { $users = []; for($i = 0; $i < 6; $i++) { - $user = $this->getMock('\OCP\IUser'); + $user = $this->createMock(IUser::class); $user->method('getUID')->willReturn('user'.$i); $users['user'.$i] = $user; } @@ -1570,14 +1575,14 @@ class DefaultShareProviderTest extends \Test\TestCase { }) ); - $file1 = $this->getMock('\OCP\Files\File'); + $file1 = $this->createMock(File::class); $file1->method('getId')->willReturn(42); - $file2 = $this->getMock('\OCP\Files\File'); + $file2 = $this->createMock(File::class); $file2->method('getId')->willReturn(43); - $folder1 = $this->getMock('\OCP\Files\Folder'); + $folder1 = $this->createMock(Folder::class); $folder1->method('getById')->with(42)->willReturn([$file1]); - $folder2 = $this->getMock('\OCP\Files\Folder'); + $folder2 = $this->createMock(Folder::class); $folder2->method('getById')->with(43)->willReturn([$file2]); $this->rootFolder->method('getUserFolder')->will($this->returnValueMap([ @@ -1608,7 +1613,7 @@ class DefaultShareProviderTest extends \Test\TestCase { $users = []; for($i = 0; $i < 6; $i++) { - $user = $this->getMock('\OCP\IUser'); + $user = $this->createMock(IUser::class); $user->method('getUID')->willReturn('user'.$i); $users['user'.$i] = $user; } @@ -1619,14 +1624,14 @@ class DefaultShareProviderTest extends \Test\TestCase { }) ); - $file1 = $this->getMock('\OCP\Files\File'); + $file1 = $this->createMock(File::class); $file1->method('getId')->willReturn(42); - $file2 = $this->getMock('\OCP\Files\File'); + $file2 = $this->createMock(File::class); $file2->method('getId')->willReturn(43); - $folder1 = $this->getMock('\OCP\Files\Folder'); + $folder1 = $this->createMock(Folder::class); $folder1->method('getById')->with(42)->willReturn([$file1]); - $folder2 = $this->getMock('\OCP\Files\Folder'); + $folder2 = $this->createMock(Folder::class); $folder2->method('getById')->with(43)->willReturn([$file2]); $this->rootFolder->method('getUserFolder')->will($this->returnValueMap([ @@ -1657,7 +1662,7 @@ class DefaultShareProviderTest extends \Test\TestCase { $users = []; for($i = 0; $i < 6; $i++) { - $user = $this->getMock('\OCP\IUser'); + $user = $this->createMock(IUser::class); $user->method('getUID')->willReturn('user'.$i); $users['user'.$i] = $user; } @@ -1670,7 +1675,7 @@ class DefaultShareProviderTest extends \Test\TestCase { $groups = []; for($i = 0; $i < 2; $i++) { - $group = $this->getMock('\OCP\IGroup'); + $group = $this->createMock(IGroup::class); $group->method('getGID')->willReturn('group'.$i); $groups['group'.$i] = $group; } @@ -1681,14 +1686,14 @@ class DefaultShareProviderTest extends \Test\TestCase { }) ); - $file1 = $this->getMock('\OCP\Files\File'); + $file1 = $this->createMock(File::class); $file1->method('getId')->willReturn(42); - $file2 = $this->getMock('\OCP\Files\File'); + $file2 = $this->createMock(File::class); $file2->method('getId')->willReturn(43); - $folder1 = $this->getMock('\OCP\Files\Folder'); + $folder1 = $this->createMock(Folder::class); $folder1->method('getById')->with(42)->willReturn([$file1]); - $folder2 = $this->getMock('\OCP\Files\Folder'); + $folder2 = $this->createMock(Folder::class); $folder2->method('getById')->with(43)->willReturn([$file2]); $this->rootFolder->method('getUserFolder')->will($this->returnValueMap([ @@ -1726,7 +1731,7 @@ class DefaultShareProviderTest extends \Test\TestCase { $users = []; for($i = 0; $i < 6; $i++) { - $user = $this->getMock('\OCP\IUser'); + $user = $this->createMock(IUser::class); $user->method('getUID')->willReturn('user'.$i); $users['user'.$i] = $user; } @@ -1739,7 +1744,7 @@ class DefaultShareProviderTest extends \Test\TestCase { $groups = []; for($i = 0; $i < 2; $i++) { - $group = $this->getMock('\OCP\IGroup'); + $group = $this->createMock(IGroup::class); $group->method('getGID')->willReturn('group'.$i); $groups['group'.$i] = $group; } @@ -1750,14 +1755,14 @@ class DefaultShareProviderTest extends \Test\TestCase { }) ); - $file1 = $this->getMock('\OCP\Files\File'); + $file1 = $this->createMock(File::class); $file1->method('getId')->willReturn(42); - $file2 = $this->getMock('\OCP\Files\File'); + $file2 = $this->createMock(File::class); $file2->method('getId')->willReturn(43); - $folder1 = $this->getMock('\OCP\Files\Folder'); + $folder1 = $this->createMock(Folder::class); $folder1->method('getById')->with(42)->willReturn([$file1]); - $folder2 = $this->getMock('\OCP\Files\Folder'); + $folder2 = $this->createMock(Folder::class); $folder2->method('getById')->with(43)->willReturn([$file2]); $this->rootFolder->method('getUserFolder')->will($this->returnValueMap([ @@ -1809,9 +1814,9 @@ class DefaultShareProviderTest extends \Test\TestCase { $id = $this->addShareToDB(\OCP\Share::SHARE_TYPE_USER, 'user0', 'user1', 'user1', 'file', 42, 'mytaret', 31, null, null); - $user0 = $this->getMock('\OCP\IUser'); + $user0 = $this->createMock(IUser::class); $user0->method('getUID')->willReturn('user0'); - $user1 = $this->getMock('\OCP\IUser'); + $user1 = $this->createMock(IUser::class); $user1->method('getUID')->willReturn('user1'); $this->userManager->method('get')->will($this->returnValueMap([ @@ -1819,7 +1824,7 @@ class DefaultShareProviderTest extends \Test\TestCase { ['user1', $user1], ])); - $file = $this->getMock('\OCP\Files\File'); + $file = $this->createMock(File::class); $file->method('getId')->willReturn(42); $this->rootFolder->method('getUserFolder')->with('user1')->will($this->returnSelf()); @@ -1838,12 +1843,12 @@ class DefaultShareProviderTest extends \Test\TestCase { $id = $this->addShareToDB(\OCP\Share::SHARE_TYPE_GROUP, 'group0', 'user1', 'user1', 'file', 42, 'mytaret', 31, null, null); - $user0 = $this->getMock('\OCP\IUser'); + $user0 = $this->createMock(IUser::class); $user0->method('getUID')->willReturn('user0'); - $user1 = $this->getMock('\OCP\IUser'); + $user1 = $this->createMock(IUser::class); $user1->method('getUID')->willReturn('user1'); - $group0 = $this->getMock('\OCP\IGroup'); + $group0 = $this->createMock(IGroup::class); $group0->method('getGID')->willReturn('group0'); $group0->method('inGroup')->with($user0)->willReturn(true); @@ -1854,7 +1859,7 @@ class DefaultShareProviderTest extends \Test\TestCase { ['user1', $user1], ])); - $folder = $this->getMock('\OCP\Files\Folder'); + $folder = $this->createMock(Folder::class); $folder->method('getId')->willReturn(42); $this->rootFolder->method('getUserFolder')->with('user1')->will($this->returnSelf()); diff --git a/tests/lib/Share20/ManagerTest.php b/tests/lib/Share20/ManagerTest.php index 689e47d8c5..16ad1b07f8 100644 --- a/tests/lib/Share20/ManagerTest.php +++ b/tests/lib/Share20/ManagerTest.php @@ -20,8 +20,16 @@ */ namespace Test\Share20; +use OC\Files\Mount\MoveableMount; use OC\HintException; +use OCP\Files\File; +use OCP\Files\Folder; use OCP\Files\IRootFolder; +use OCP\Files\Mount\IMountPoint; +use OCP\Files\Node; +use OCP\Files\Storage; +use OCP\IGroup; +use OCP\IUser; use OCP\IUserManager; use OCP\Share\Exceptions\ShareNotFound; use OCP\Share\IProviderFactory; @@ -78,17 +86,17 @@ class ManagerTest extends \Test\TestCase { public function setUp() { - $this->logger = $this->getMock('\OCP\ILogger'); - $this->config = $this->getMock('\OCP\IConfig'); - $this->secureRandom = $this->getMock('\OCP\Security\ISecureRandom'); - $this->hasher = $this->getMock('\OCP\Security\IHasher'); - $this->mountManager = $this->getMock('\OCP\Files\Mount\IMountManager'); - $this->groupManager = $this->getMock('\OCP\IGroupManager'); - $this->userManager = $this->getMock('\OCP\IUserManager'); - $this->rootFolder = $this->getMock('\OCP\Files\IRootFolder'); - $this->eventDispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcher'); + $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 = $this->createMock(EventDispatcher::class); - $this->l = $this->getMock('\OCP\IL10N'); + $this->l = $this->createMock(IL10N::class); $this->l->method('t') ->will($this->returnCallback(function($text, $parameters = []) { return vsprintf($text, $parameters); @@ -149,10 +157,10 @@ class ManagerTest extends \Test\TestCase { } public function dataTestDelete() { - $user = $this->getMock('\OCP\IUser'); + $user = $this->createMock(IUser::class); $user->method('getUID')->willReturn('sharedWithUser'); - $group = $this->getMock('\OCP\IGroup'); + $group = $this->createMock(IGroup::class); $group->method('getGID')->willReturn('sharedWithGroup'); return [ @@ -171,7 +179,7 @@ class ManagerTest extends \Test\TestCase { ->setMethods(['getShareById', 'deleteChildren']) ->getMock(); - $path = $this->getMock('\OCP\Files\File'); + $path = $this->createMock(File::class); $path->method('getId')->willReturn(1); $share = $this->manager->newShare(); @@ -328,7 +336,7 @@ class ManagerTest extends \Test\TestCase { ->setMethods(['getShareById']) ->getMock(); - $path = $this->getMock('\OCP\Files\File'); + $path = $this->createMock(File::class); $path->method('getId')->willReturn(1); $share1 = $this->manager->newShare(); @@ -451,14 +459,14 @@ class ManagerTest extends \Test\TestCase { ->setMethods(['deleteShare']) ->getMock(); - $share = $this->getMock('\OCP\Share\IShare'); + $share = $this->createMock(IShare::class); $share->method('getShareType')->willReturn(\OCP\Share::SHARE_TYPE_USER); - $child1 = $this->getMock('\OCP\Share\IShare'); + $child1 = $this->createMock(IShare::class); $child1->method('getShareType')->willReturn(\OCP\Share::SHARE_TYPE_USER); - $child2 = $this->getMock('\OCP\Share\IShare'); + $child2 = $this->createMock(IShare::class); $child2->method('getShareType')->willReturn(\OCP\Share::SHARE_TYPE_USER); - $child3 = $this->getMock('\OCP\Share\IShare'); + $child3 = $this->createMock(IShare::class); $child3->method('getShareType')->willReturn(\OCP\Share::SHARE_TYPE_USER); $shares = [ @@ -487,7 +495,7 @@ class ManagerTest extends \Test\TestCase { } public function testGetShareById() { - $share = $this->getMock('\OCP\Share\IShare'); + $share = $this->createMock(IShare::class); $this->defaultProvider ->expects($this->once()) @@ -584,7 +592,7 @@ class ManagerTest extends \Test\TestCase { public function createShare($id, $type, $path, $sharedWith, $sharedBy, $shareOwner, $permissions, $expireDate = null, $password = null) { - $share = $this->getMock('\OCP\Share\IShare'); + $share = $this->createMock(IShare::class); $share->method('getShareType')->willReturn($type); $share->method('getSharedWith')->willReturn($sharedWith); @@ -603,8 +611,8 @@ class ManagerTest extends \Test\TestCase { $user2 = 'user1'; $group0 = 'group0'; - $file = $this->getMock('\OCP\Files\File'); - $node = $this->getMock('\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], @@ -633,7 +641,7 @@ class ManagerTest extends \Test\TestCase { [$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->getMock('\OCP\Files\Folder'); + $nonShareAble = $this->createMock(Folder::class); $nonShareAble->method('isShareable')->willReturn(false); $nonShareAble->method('getPath')->willReturn('path'); @@ -641,7 +649,7 @@ class ManagerTest extends \Test\TestCase { $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->getMock('\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'); @@ -650,14 +658,14 @@ class ManagerTest extends \Test\TestCase { $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->getMock('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->getMock('\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'); @@ -665,7 +673,7 @@ class ManagerTest extends \Test\TestCase { $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->getMock('\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'); @@ -674,7 +682,7 @@ class ManagerTest extends \Test\TestCase { $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->getMock('\OCP\Files\Folder'); + $allPermssions = $this->createMock(Folder::class); $allPermssions->method('isShareable')->willReturn(true); $allPermssions->method('getPermissions')->willReturn(\OCP\Constants::PERMISSION_ALL); @@ -706,7 +714,7 @@ class ManagerTest extends \Test\TestCase { ['group0', true], ])); - $userFolder = $this->getMock('\OCP\Files\Folder'); + $userFolder = $this->createMock(Folder::class); $userFolder->method('getPath')->willReturn('myrootfolder'); $this->rootFolder->method('getUserFolder')->willReturn($userFolder); @@ -737,7 +745,7 @@ class ManagerTest extends \Test\TestCase { ['user1', true], ])); - $userFolder = $this->getMock('\OCP\Files\Folder'); + $userFolder = $this->createMock(Folder::class); $userFolder->method('isSubNode')->with($userFolder)->willReturn(false); $this->rootFolder->method('getUserFolder')->willReturn($userFolder); @@ -1000,8 +1008,8 @@ class ManagerTest extends \Test\TestCase { public function testUserCreateChecksShareWithGroupMembersOnlyDifferentGroups() { $share = $this->manager->newShare(); - $sharedBy = $this->getMock('\OCP\IUser'); - $sharedWith = $this->getMock('\OCP\IUser'); + $sharedBy = $this->createMock(IUser::class); + $sharedWith = $this->createMock(IUser::class); $share->setSharedBy('sharedBy')->setSharedWith('sharedWith'); $this->groupManager @@ -1030,11 +1038,11 @@ class ManagerTest extends \Test\TestCase { public function testUserCreateChecksShareWithGroupMembersOnlySharedGroup() { $share = $this->manager->newShare(); - $sharedBy = $this->getMock('\OCP\IUser'); - $sharedWith = $this->getMock('\OCP\IUser'); + $sharedBy = $this->createMock(IUser::class); + $sharedWith = $this->createMock(IUser::class); $share->setSharedBy('sharedBy')->setSharedWith('sharedWith'); - $path = $this->getMock('\OCP\Files\Node'); + $path = $this->createMock(Node::class); $share->setNode($path); $this->groupManager @@ -1073,8 +1081,8 @@ class ManagerTest extends \Test\TestCase { $share = $this->manager->newShare(); $share2 = $this->manager->newShare(); - $sharedWith = $this->getMock('\OCP\IUser'); - $path = $this->getMock('\OCP\Files\Node'); + $sharedWith = $this->createMock(IUser::class); + $path = $this->createMock(Node::class); $share->setSharedWith('sharedWith')->setNode($path) ->setProviderId('foo')->setId('bar'); @@ -1097,12 +1105,12 @@ class ManagerTest extends \Test\TestCase { public function testUserCreateChecksIdenticalPathSharedViaGroup() { $share = $this->manager->newShare(); - $sharedWith = $this->getMock('\OCP\IUser'); + $sharedWith = $this->createMock(IUser::class); $sharedWith->method('getUID')->willReturn('sharedWith'); $this->userManager->method('get')->with('sharedWith')->willReturn($sharedWith); - $path = $this->getMock('\OCP\Files\Node'); + $path = $this->createMock(Node::class); $share->setSharedWith('sharedWith') ->setNode($path) @@ -1117,7 +1125,7 @@ class ManagerTest extends \Test\TestCase { ->setId('baz') ->setSharedWith('group'); - $group = $this->getMock('\OCP\IGroup'); + $group = $this->createMock(IGroup::class); $group->method('inGroup') ->with($sharedWith) ->willReturn(true); @@ -1134,8 +1142,8 @@ class ManagerTest extends \Test\TestCase { public function testUserCreateChecksIdenticalPathNotSharedWithUser() { $share = $this->manager->newShare(); - $sharedWith = $this->getMock('\OCP\IUser'); - $path = $this->getMock('\OCP\Files\Node'); + $sharedWith = $this->createMock(IUser::class); + $path = $this->createMock(Node::class); $share->setSharedWith('sharedWith') ->setNode($path) ->setShareOwner('shareOwner') @@ -1150,7 +1158,7 @@ class ManagerTest extends \Test\TestCase { ->setProviderId('foo') ->setId('baz'); - $group = $this->getMock('\OCP\IGroup'); + $group = $this->createMock(IGroup::class); $group->method('inGroup') ->with($sharedWith) ->willReturn(false); @@ -1190,8 +1198,8 @@ class ManagerTest extends \Test\TestCase { public function testGroupCreateChecksShareWithGroupMembersOnlyNotInGroup() { $share = $this->manager->newShare(); - $user = $this->getMock('\OCP\IUser'); - $group = $this->getMock('\OCP\IGroup'); + $user = $this->createMock(IUser::class); + $group = $this->createMock(IGroup::class); $share->setSharedBy('user')->setSharedWith('group'); $group->method('inGroup')->with($user)->willReturn(false); @@ -1212,8 +1220,8 @@ class ManagerTest extends \Test\TestCase { public function testGroupCreateChecksShareWithGroupMembersOnlyInGroup() { $share = $this->manager->newShare(); - $user = $this->getMock('\OCP\IUser'); - $group = $this->getMock('\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); @@ -1221,7 +1229,7 @@ class ManagerTest extends \Test\TestCase { $group->method('inGroup')->with($user)->willReturn(true); - $path = $this->getMock('\OCP\Files\Node'); + $path = $this->createMock(Node::class); $share->setNode($path); $this->defaultProvider->method('getSharesByPath') @@ -1245,7 +1253,7 @@ class ManagerTest extends \Test\TestCase { public function testGroupCreateChecksPathAlreadySharedWithSameGroup() { $share = $this->manager->newShare(); - $path = $this->getMock('\OCP\Files\Node'); + $path = $this->createMock(Node::class); $share->setSharedWith('sharedWith') ->setNode($path) ->setProviderId('foo') @@ -1274,7 +1282,7 @@ class ManagerTest extends \Test\TestCase { $share->setSharedWith('sharedWith'); - $path = $this->getMock('\OCP\Files\Node'); + $path = $this->createMock(Node::class); $share->setNode($path); $share2 = $this->manager->newShare(); @@ -1381,11 +1389,11 @@ class ManagerTest extends \Test\TestCase { * @expectedExceptionMessage Path contains files shared with you */ public function testPathCreateChecksContainsSharedMount() { - $path = $this->getMock('\OCP\Files\Folder'); + $path = $this->createMock(Folder::class); $path->method('getPath')->willReturn('path'); - $mount = $this->getMock('\OCP\Files\Mount\IMountPoint'); - $storage = $this->getMock('\OCP\Files\Storage'); + $mount = $this->createMock(IMountPoint::class); + $storage = $this->createMock(Storage::class); $mount->method('getStorage')->willReturn($storage); $storage->method('instanceOfStorage')->with('\OCA\Files_Sharing\ISharedStorage')->willReturn(true); @@ -1395,11 +1403,11 @@ class ManagerTest extends \Test\TestCase { } public function testPathCreateChecksContainsNoSharedMount() { - $path = $this->getMock('\OCP\Files\Folder'); + $path = $this->createMock(Folder::class); $path->method('getPath')->willReturn('path'); - $mount = $this->getMock('\OCP\Files\Mount\IMountPoint'); - $storage = $this->getMock('\OCP\Files\Storage'); + $mount = $this->createMock(IMountPoint::class); + $storage = $this->createMock(Storage::class); $mount->method('getStorage')->willReturn($storage); $storage->method('instanceOfStorage')->with('\OCA\Files_Sharing\ISharedStorage')->willReturn(false); @@ -1409,7 +1417,7 @@ class ManagerTest extends \Test\TestCase { } public function testPathCreateChecksContainsNoFolder() { - $path = $this->getMock('\OCP\Files\File'); + $path = $this->createMock(File::class); $this->invokePrivate($this->manager, 'pathCreateChecks', [$path]); } @@ -1454,7 +1462,7 @@ class ManagerTest extends \Test\TestCase { * @param bool $expected */ public function testIsSharingDisabledForUser($excludeGroups, $groupList, $setList, $groupIds, $expected) { - $user = $this->getMock('\OCP\IUser'); + $user = $this->createMock(IUser::class); $this->config->method('getAppValue') ->will($this->returnValueMap([ @@ -1535,11 +1543,11 @@ class ManagerTest extends \Test\TestCase { ->setMethods(['canShare', 'generalCreateChecks', 'userCreateChecks', 'pathCreateChecks']) ->getMock(); - $shareOwner = $this->getMock('\OCP\IUser'); + $shareOwner = $this->createMock(IUser::class); $shareOwner->method('getUID')->willReturn('shareOwner'); - $storage = $this->getMock('\OCP\Files\Storage'); - $path = $this->getMock('\OCP\Files\File'); + $storage = $this->createMock(Storage::class); + $path = $this->createMock(File::class); $path->method('getOwner')->willReturn($shareOwner); $path->method('getName')->willReturn('target'); $path->method('getStorage')->willReturn($storage); @@ -1588,11 +1596,11 @@ class ManagerTest extends \Test\TestCase { ->setMethods(['canShare', 'generalCreateChecks', 'groupCreateChecks', 'pathCreateChecks']) ->getMock(); - $shareOwner = $this->getMock('\OCP\IUser'); + $shareOwner = $this->createMock(IUser::class); $shareOwner->method('getUID')->willReturn('shareOwner'); - $storage = $this->getMock('\OCP\Files\Storage'); - $path = $this->getMock('\OCP\Files\File'); + $storage = $this->createMock(Storage::class); + $path = $this->createMock(File::class); $path->method('getOwner')->willReturn($shareOwner); $path->method('getName')->willReturn('target'); $path->method('getStorage')->willReturn($storage); @@ -1649,11 +1657,11 @@ class ManagerTest extends \Test\TestCase { ]) ->getMock(); - $shareOwner = $this->getMock('\OCP\IUser'); + $shareOwner = $this->createMock(IUser::class); $shareOwner->method('getUID')->willReturn('shareOwner'); - $storage = $this->getMock('\OCP\Files\Storage'); - $path = $this->getMock('\OCP\Files\File'); + $storage = $this->createMock(Storage::class); + $path = $this->createMock(File::class); $path->method('getOwner')->willReturn($shareOwner); $path->method('getName')->willReturn('target'); $path->method('getId')->willReturn(1); @@ -1775,11 +1783,11 @@ class ManagerTest extends \Test\TestCase { ]) ->getMock(); - $shareOwner = $this->getMock('\OCP\IUser'); + $shareOwner = $this->createMock(IUser::class); $shareOwner->method('getUID')->willReturn('shareOwner'); - $storage = $this->getMock('\OCP\Files\Storage'); - $path = $this->getMock('\OCP\Files\File'); + $storage = $this->createMock(Storage::class); + $path = $this->createMock(File::class); $path->method('getOwner')->willReturn($shareOwner); $path->method('getName')->willReturn('target'); $path->method('getStorage')->willReturn($storage); @@ -1831,28 +1839,28 @@ class ManagerTest extends \Test\TestCase { ->setMethods(['canShare', 'generalCreateChecks', 'userCreateChecks', 'pathCreateChecks']) ->getMock(); - $shareOwner = $this->getMock('\OCP\IUser'); + $shareOwner = $this->createMock(IUser::class); $shareOwner->method('getUID')->willReturn('shareOwner'); - $storage = $this->getMock('\OCP\Files\Storage'); + $storage = $this->createMock(Storage::class); $storage->method('instanceOfStorage') ->with('OCA\Files_Sharing\External\Storage') ->willReturn(true); - $storage2 = $this->getMock('\OCP\Files\Storage'); + $storage2 = $this->createMock(Storage::class); $storage2->method('instanceOfStorage') ->with('OCA\Files_Sharing\External\Storage') ->willReturn(false); - $path = $this->getMock('\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->getMock('\OCP\Files\Folder'); + $parent = $this->createMock(Folder::class); $parent->method('getStorage')->willReturn($storage); - $parentParent = $this->getMock('\OCP\Files\Folder'); + $parentParent = $this->createMock(Folder::class); $parentParent->method('getStorage')->willReturn($storage2); $parentParent->method('getOwner')->willReturn($shareOwner); @@ -1901,7 +1909,7 @@ class ManagerTest extends \Test\TestCase { public function testGetSharesBy() { $share = $this->manager->newShare(); - $node = $this->getMock('OCP\Files\Folder'); + $node = $this->createMock(Folder::class); $this->defaultProvider->expects($this->once()) ->method('getSharesBy') @@ -1962,7 +1970,7 @@ class ManagerTest extends \Test\TestCase { $shares2[] = clone $shares[$i]; } - $node = $this->getMock('OCP\Files\File'); + $node = $this->createMock(File::class); /* * Simulate the getSharesBy call. @@ -2002,7 +2010,7 @@ class ManagerTest extends \Test\TestCase { } public function testGetShareByToken() { - $factory = $this->getMock('\OCP\Share\IProviderFactory'); + $factory = $this->createMock(IProviderFactory::class); $manager = new Manager( $this->logger, @@ -2018,7 +2026,7 @@ class ManagerTest extends \Test\TestCase { $this->eventDispatcher ); - $share = $this->getMock('\OCP\Share\IShare'); + $share = $this->createMock(IShare::class); $factory->expects($this->once()) ->method('getProviderForType') @@ -2035,7 +2043,7 @@ class ManagerTest extends \Test\TestCase { } public function testGetShareByTokenWithException() { - $factory = $this->getMock('\OCP\Share\IProviderFactory'); + $factory = $this->createMock(IProviderFactory::class); $manager = new Manager( $this->logger, @@ -2051,7 +2059,7 @@ class ManagerTest extends \Test\TestCase { $this->eventDispatcher ); - $share = $this->getMock('\OCP\Share\IShare'); + $share = $this->createMock(IShare::class); $factory->expects($this->at(0)) ->method('getProviderForType') @@ -2137,13 +2145,13 @@ class ManagerTest extends \Test\TestCase { } public function testCheckPasswordNoLinkShare() { - $share = $this->getMock('\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->getMock('\OCP\Share\IShare'); + $share = $this->createMock(IShare::class); $share->method('getShareType')->willReturn(\OCP\Share::SHARE_TYPE_LINK); $this->assertFalse($this->manager->checkPassword($share, 'password')); @@ -2152,7 +2160,7 @@ class ManagerTest extends \Test\TestCase { } public function testCheckPasswordInvalidPassword() { - $share = $this->getMock('\OCP\Share\IShare'); + $share = $this->createMock(IShare::class); $share->method('getShareType')->willReturn(\OCP\Share::SHARE_TYPE_LINK); $share->method('getPassword')->willReturn('password'); @@ -2162,7 +2170,7 @@ class ManagerTest extends \Test\TestCase { } public function testCheckPasswordValidPassword() { - $share = $this->getMock('\OCP\Share\IShare'); + $share = $this->createMock(IShare::class); $share->method('getShareType')->willReturn(\OCP\Share::SHARE_TYPE_LINK); $share->method('getPassword')->willReturn('passwordHash'); @@ -2294,7 +2302,7 @@ class ManagerTest extends \Test\TestCase { ->setSharedWith('origUser') ->setPermissions(1); - $node = $this->getMock('\OCP\Files\File'); + $node = $this->createMock(File::class); $node->method('getId')->willReturn(100); $node->method('getPath')->willReturn('/newUser/files/myPath'); @@ -2357,7 +2365,7 @@ class ManagerTest extends \Test\TestCase { $manager->expects($this->once())->method('canShare')->willReturn(true); $manager->expects($this->once())->method('getShareById')->with('foo:42')->willReturn($originalShare); - $node = $this->getMock('\OCP\Files\File'); + $node = $this->createMock(File::class); $share = $this->manager->newShare(); $share->setProviderId('foo') @@ -2453,7 +2461,7 @@ class ManagerTest extends \Test\TestCase { $share = $this->manager->newShare(); $share->setShareType(\OCP\Share::SHARE_TYPE_LINK); - $recipient = $this->getMock('\OCP\IUser'); + $recipient = $this->createMock(IUser::class); $this->manager->moveShare($share, $recipient); } @@ -2492,10 +2500,10 @@ class ManagerTest extends \Test\TestCase { $share = $this->manager->newShare(); $share->setShareType(\OCP\Share::SHARE_TYPE_GROUP); - $sharedWith = $this->getMock('\OCP\IGroup'); + $sharedWith = $this->createMock(IGroup::class); $share->setSharedWith('shareWith'); - $recipient = $this->getMock('\OCP\IUser'); + $recipient = $this->createMock(IUser::class); $sharedWith->method('inGroup')->with($recipient)->willReturn(false); $this->groupManager->method('get')->with('shareWith')->willReturn($sharedWith); @@ -2510,10 +2518,10 @@ class ManagerTest extends \Test\TestCase { ->setId('42') ->setProviderId('foo'); - $group = $this->getMock('\OCP\IGroup'); + $group = $this->createMock(IGroup::class); $share->setSharedWith('group'); - $recipient = $this->getMock('\OCP\IUser'); + $recipient = $this->createMock(IUser::class); $group->method('inGroup')->with($recipient)->willReturn(true); $this->groupManager->method('get')->with('group')->willReturn($group);