From 2d04470af24c03119bd19e88b7b06909a1d01ff4 Mon Sep 17 00:00:00 2001 From: Artur Neumann Date: Fri, 22 Dec 2023 11:14:07 +0545 Subject: [PATCH] restrict invite requests to a single receiver --- src/OcisResource.php | 53 ++++--- .../Owncloud/OcisPhpSdk/OcisResourceTest.php | 4 +- .../Owncloud/OcisPhpSdk/OcisTest.php | 6 +- .../OcisPhpSdk/ResourceInviteTest.php | 133 +++++------------- .../OcisPhpSdk/ShareCreatedModifyTest.php | 28 ++-- .../OcisPhpSdk/ShareGetShareByMeTest.php | 4 +- .../OcisPhpSdk/ResourceInviteTest.php | 41 ++---- 7 files changed, 94 insertions(+), 175 deletions(-) diff --git a/src/OcisResource.php b/src/OcisResource.php index ceb819f5..80178764 100644 --- a/src/OcisResource.php +++ b/src/OcisResource.php @@ -11,6 +11,7 @@ use OpenAPI\Client\Model\DriveItemInvite; use OpenAPI\Client\Model\DriveRecipient; use OpenAPI\Client\Model\OdataError; +use OpenAPI\Client\Model\Permission; use OpenAPI\Client\Model\SharingLinkType; use Owncloud\OcisPhpSdk\Exception\BadRequestException; use Owncloud\OcisPhpSdk\Exception\ExceptionHelper; @@ -175,13 +176,13 @@ public function getRoles(): array } /** - * Invite one or multiple people(user/group) to the resource. + * Invite a user or group to the resource. * Every recipient will result in an own ShareCreated object in the returned array. * - * @param array $recipients + * @param User|Group $recipient * @param SharingRole $role * @param \DateTimeImmutable|null $expiration - * @return array + * @return ShareCreated * @throws BadRequestException * @throws ForbiddenException * @throws HttpException @@ -190,18 +191,16 @@ public function getRoles(): array * @throws UnauthorizedException * @throws InternalServerErrorException */ - public function invite($recipients, SharingRole $role, ?\DateTimeImmutable $expiration = null): array + public function invite($recipient, SharingRole $role, ?\DateTimeImmutable $expiration = null): ShareCreated { $driveItemInviteData = []; $driveItemInviteData['recipients'] = []; - foreach ($recipients as $recipient) { - $recipientData = []; - $recipientData['object_id'] = $recipient->getId(); - if ($recipient instanceof Group) { - $recipientData['at_libre_graph_recipient_type'] = "group"; - } - $driveItemInviteData['recipients'][] = new DriveRecipient($recipientData); + $recipientData = []; + $recipientData['object_id'] = $recipient->getId(); + if ($recipient instanceof Group) { + $recipientData['at_libre_graph_recipient_type'] = "group"; } + $driveItemInviteData['recipients'][] = new DriveRecipient($recipientData); $driveItemInviteData['roles'] = [$role->getId()]; if ($expiration !== null) { $expirationMutable = \DateTime::createFromImmutable($expiration); @@ -231,27 +230,25 @@ public function invite($recipients, SharingRole $role, ?\DateTimeImmutable $expi "invite returned an OdataError - " . $permissions->getError() ); } - if ($permissions->getValue() === null) { + $permissionsValue = $permissions->getValue(); + if ( + $permissionsValue === null || + !array_key_exists(0, $permissionsValue) || + !($permissionsValue[0] instanceof Permission) + ) { throw new InvalidResponseException( - "invite returned 'null' where an array of permissions were expected" + "invite returned invalid data " . print_r($permissionsValue, true) ); } - /** - * @var array $shares - */ - $shares = []; - foreach ($permissions->getValue() as $permission) { - $shares[] = new ShareCreated( - $permission, - $this->getId(), - $this->getSpaceId(), - $this->connectionConfig, - $this->serviceUrl, - $this->accessToken - ); - } - return $shares; + return new ShareCreated( + $permissionsValue[0], + $this->getId(), + $this->getSpaceId(), + $this->connectionConfig, + $this->serviceUrl, + $this->accessToken + ); } /** diff --git a/tests/integration/Owncloud/OcisPhpSdk/OcisResourceTest.php b/tests/integration/Owncloud/OcisPhpSdk/OcisResourceTest.php index 376d25fa..64682a9c 100644 --- a/tests/integration/Owncloud/OcisPhpSdk/OcisResourceTest.php +++ b/tests/integration/Owncloud/OcisPhpSdk/OcisResourceTest.php @@ -72,7 +72,7 @@ private function share(string $receiverName, string $roleName, string $resourceN foreach ($resources as $resource) { if ($resource->getName() === $resourceName) { $role = $this->getRoleByName($resource, $roleName); - $resource->invite([$receiver], $role); + $resource->invite($receiver, $role); break; } } @@ -265,7 +265,7 @@ public function testUploadFileNoPermission(): void foreach ($resources as $resource) { if ($resource->getName() === 'subfolder') { $role = $this->getRoleByName($resource, 'Viewer'); - $resource->invite([$einstein], $role); + $resource->invite($einstein, $role); break; } } diff --git a/tests/integration/Owncloud/OcisPhpSdk/OcisTest.php b/tests/integration/Owncloud/OcisPhpSdk/OcisTest.php index 82dfe5c3..60ce92b6 100644 --- a/tests/integration/Owncloud/OcisPhpSdk/OcisTest.php +++ b/tests/integration/Owncloud/OcisPhpSdk/OcisTest.php @@ -66,7 +66,7 @@ public function testGetMyDrives(): void "manager role not found " ); } - $sharedResource->invite([$marie], $managerRole); + $sharedResource->invite($marie, $managerRole); $marieDrive = $marieOcis->getMyDrives(); $this->assertContainsOnlyInstancesOf(Drive::class, $marieDrive); @@ -125,7 +125,7 @@ public function testGetAllDrives(): void "manager role not found " ); } - $sharedResource->invite([$katherine], $managerRole); + $sharedResource->invite($katherine, $managerRole); $drives = $adminOcis->getAllDrives(); foreach ($drives as $drive) { @@ -220,7 +220,7 @@ public function testGetAllDrivesType(DriveType $driveType): void ); } - $sharedResource->invite([$katherine], $managerRole); + $sharedResource->invite($katherine, $managerRole); } $drives = $adminOcis->getAllDrives( diff --git a/tests/integration/Owncloud/OcisPhpSdk/ResourceInviteTest.php b/tests/integration/Owncloud/OcisPhpSdk/ResourceInviteTest.php index c6c1a08e..fbebaf2c 100644 --- a/tests/integration/Owncloud/OcisPhpSdk/ResourceInviteTest.php +++ b/tests/integration/Owncloud/OcisPhpSdk/ResourceInviteTest.php @@ -77,9 +77,9 @@ public function setUp(): void public function testInviteUser(): void { - $shares = $this->fileToShare->invite([$this->einstein], $this->viewerRole); - $this->assertCount(1, $shares); - $this->assertNull($shares[0]->getExpiration()); + $share = $this->fileToShare->invite($this->einstein, $this->viewerRole); + $this->assertNull($share->getExpiration()); + $this->assertSame($this->fileToShare->getId(), $share->getResourceId()); $receivedShares = $this->einsteinOcis->getSharedWithMe(); $this->assertCount(1, $receivedShares); $this->assertSame($this->fileToShare->getName(), $receivedShares[0]->getName()); @@ -87,27 +87,14 @@ public function testInviteUser(): void public function testInviteAnotherUser(): void { - $this->fileToShare->invite([$this->einstein], $this->viewerRole); - $shares = $this->fileToShare->invite([$this->marie], $this->viewerRole); - $this->assertCount(1, $shares); + $this->fileToShare->invite($this->einstein, $this->viewerRole); + $share = $this->fileToShare->invite($this->marie, $this->viewerRole); + $this->assertSame($this->fileToShare->getId(), $share->getResourceId()); $receivedShares = $this->marieOcis->getSharedWithMe(); $this->assertCount(1, $receivedShares); $this->assertSame($this->fileToShare->getName(), $receivedShares[0]->getName()); } - public function testInviteMultipleUsersAtOnce(): void - { - $shares = $this->fileToShare->invite([$this->einstein,$this->marie], $this->viewerRole); - $this->assertCount(2, $shares); - $receivedShares = $this->marieOcis->getSharedWithMe(); - $this->assertCount(1, $receivedShares); - $this->assertSame($this->fileToShare->getName(), $receivedShares[0]->getName()); - - $receivedShares = $this->einsteinOcis->getSharedWithMe(); - $this->assertCount(1, $receivedShares); - $this->assertSame($this->fileToShare->getName(), $receivedShares[0]->getName()); - } - public function testInviteGroup(): void { $philosophyHatersGroup = $this->ocis->createGroup( @@ -116,62 +103,20 @@ public function testInviteGroup(): void ); $this->createdGroups = [$philosophyHatersGroup]; $philosophyHatersGroup->addUser($this->einstein); - $shares = $this->fileToShare->invite([$philosophyHatersGroup], $this->viewerRole); - $this->assertCount(1, $shares); + $share = $this->fileToShare->invite($philosophyHatersGroup, $this->viewerRole); + $this->assertSame($this->fileToShare->getId(), $share->getResourceId()); $receivedShares = $this->einsteinOcis->getSharedWithMe(); $this->assertCount(1, $receivedShares); $this->assertSame($this->fileToShare->getName(), $receivedShares[0]->getName()); } - public function testInviteGroupAndUserOfTheGroup(): void - { - $philosophyHatersGroup = $this->ocis->createGroup( - 'philosophyhaters', - 'philosophy haters group' - ); - $this->createdGroups = [$philosophyHatersGroup]; - $philosophyHatersGroup->addUser($this->einstein); - $shares = $this->fileToShare->invite([$philosophyHatersGroup, $this->einstein], $this->viewerRole); - $this->assertCount(2, $shares); - $receivedShares = $this->einsteinOcis->getSharedWithMe(); - $this->assertCount(2, $receivedShares); - $this->assertSame($this->fileToShare->getName(), $receivedShares[0]->getName()); - $this->assertSame($this->fileToShare->getName(), $receivedShares[1]->getName()); - } - - public function testInviteMultipleGroups(): void - { - $philosophyHatersGroup = $this->ocis->createGroup( - 'philosophyhaters', - 'philosophy haters group' - ); - $physicsLoversGroup = $this->ocis->createGroup( - 'physicslovers', - 'physics lovers group' - ); - $this->createdGroups = [$philosophyHatersGroup, $physicsLoversGroup]; - $philosophyHatersGroup->addUser($this->einstein); - $physicsLoversGroup->addUser($this->einstein); - $physicsLoversGroup->addUser($this->marie); - $shares = $this->fileToShare->invite([$physicsLoversGroup, $philosophyHatersGroup], $this->viewerRole); - $this->assertCount(2, $shares); - $receivedShares = $this->einsteinOcis->getSharedWithMe(); - $this->assertCount(2, $receivedShares); - $this->assertSame($this->fileToShare->getName(), $receivedShares[0]->getName()); - $this->assertSame($this->fileToShare->getName(), $receivedShares[1]->getName()); - - $receivedShares = $this->marieOcis->getSharedWithMe(); - $this->assertCount(1, $receivedShares); - $this->assertSame($this->fileToShare->getName(), $receivedShares[0]->getName()); - } - public function testInviteSameUserAgain(): void { $this->markTestSkipped('https://github.com/owncloud/ocis/issues/7842'); // @phpstan-ignore-next-line because the test is skipped $this->expectException(ForbiddenException::class); - $this->fileToShare->invite([$this->einstein], $this->viewerRole); - $this->fileToShare->invite([$this->einstein], $this->viewerRole); + $this->fileToShare->invite($this->einstein, $this->viewerRole); + $this->fileToShare->invite($this->einstein, $this->viewerRole); } public function testInviteSameUserAgainWithDifferentRole(): void @@ -179,15 +124,16 @@ public function testInviteSameUserAgainWithDifferentRole(): void $this->markTestSkipped('https://github.com/owncloud/ocis/issues/7842'); // @phpstan-ignore-next-line because the test is skipped $this->expectException(ForbiddenException::class); - $this->fileToShare->invite([$this->einstein], $this->viewerRole); - $this->fileToShare->invite([$this->einstein], $this->managerRole); + $this->fileToShare->invite($this->einstein, $this->viewerRole); + $this->fileToShare->invite($this->einstein, $this->managerRole); } public function testInviteWithExpiry(): void { $tomorrow = new \DateTimeImmutable('tomorrow'); - $shares = $this->fileToShare->invite([$this->einstein], $this->viewerRole, $tomorrow); - $this->assertCount(1, $shares); + $share = $this->fileToShare->invite($this->einstein, $this->viewerRole, $tomorrow); + $this->assertInstanceOf(\DateTimeImmutable::class, $share->getExpiration()); + $this->assertSame($tomorrow->getTimestamp(), $share->getExpiration()->getTimestamp()); $createdShares = $this->ocis->getSharedByMe(); $this->assertCount(1, $createdShares); $this->assertInstanceOf(\DateTimeImmutable::class, $createdShares[0]->getExpiration()); @@ -198,14 +144,17 @@ public function testInviteWithPastExpiry(): void { $this->expectException(BadRequestException::class); $yesterday = new \DateTimeImmutable('yesterday'); - $this->fileToShare->invite([$this->einstein], $this->viewerRole, $yesterday); + $this->fileToShare->invite($this->einstein, $this->viewerRole, $yesterday); } public function testInviteWithExpiryTimezone(): void { $expiry = new \DateTimeImmutable('2060-01-01 12:00:00', new \DateTimeZone('Europe/Kyiv')); - $shares = $this->fileToShare->invite([$this->marie], $this->viewerRole, $expiry); - $this->assertCount(1, $shares); + $share = $this->fileToShare->invite($this->marie, $this->viewerRole, $expiry); + $this->assertInstanceOf(\DateTimeImmutable::class, $share->getExpiration()); + // The returned expiry is in UTC timezone (2 hours earlier than the expiry time in Kyiv) + $this->assertSame("Thu, 01 Jan 2060 10:00:00 +0000", $share->getExpiration()->format('r')); + $this->assertSame("Z", $share->getExpiration()->getTimezone()->getName()); $createdShares = $this->ocis->getSharedByMe(); $this->assertCount(1, $createdShares); $this->assertInstanceOf(\DateTimeImmutable::class, $createdShares[0]->getExpiration()); @@ -222,21 +171,13 @@ public function testGetReceiversOfShareCreatedByInvite(): void ); $this->createdGroups = [$philosophyHatersGroup]; $philosophyHatersGroup->addUser($this->einstein); - $shares = $this->fileToShare->invite( - [$this->einstein, $this->marie, $philosophyHatersGroup], - $this->viewerRole - ); - $this->assertCount(3, $shares); - for($i = 0; $i < 3; $i++) { - $this->assertThat( - $shares[$i]->getReceiver()->getDisplayName(), - $this->logicalOr( - $this->equalTo("philosophyhaters"), - $this->equalTo("Marie Curie"), - $this->equalTo("Albert Einstein") - ) - ); - } + $shares = []; + $shares[] = $this->fileToShare->invite($this->einstein, $this->viewerRole); + $shares[] = $this->fileToShare->invite($this->marie, $this->viewerRole); + $shares[] = $this->fileToShare->invite($philosophyHatersGroup, $this->viewerRole); + $this->assertSame("Albert Einstein", $shares[0]->getReceiver()->getDisplayName()); + $this->assertSame("Marie Curie", $shares[1]->getReceiver()->getDisplayName()); + $this->assertSame("philosophyhaters", $shares[2]->getReceiver()->getDisplayName()); } public function testGetReceiversOfShareReturnedBySharedByMe(): void @@ -247,14 +188,12 @@ public function testGetReceiversOfShareReturnedBySharedByMe(): void ); $this->createdGroups = [$philosophyHatersGroup]; $philosophyHatersGroup->addUser($this->einstein); - $this->fileToShare->invite( - [$this->einstein, $this->marie, $philosophyHatersGroup], - $this->viewerRole - ); - $this->folderToShare->invite( - [$this->einstein, $this->marie, $philosophyHatersGroup], - $this->viewerRole - ); + $this->fileToShare->invite($this->einstein, $this->viewerRole); + $this->fileToShare->invite($this->marie, $this->viewerRole); + $this->fileToShare->invite($philosophyHatersGroup, $this->viewerRole); + $this->folderToShare->invite($this->einstein, $this->viewerRole); + $this->folderToShare->invite($this->marie, $this->viewerRole); + $this->folderToShare->invite($philosophyHatersGroup, $this->viewerRole); $shares = $this->ocis->getSharedByMe(); $this->assertCount(6, $shares); for($i = 0; $i < 6; $i++) { @@ -281,13 +220,13 @@ public function testGetReceiversOfShareReturnedBySharedByMe(): void public function testInviteUserToAReceivedShare(): void { - $this->fileToShare->invite([$this->einstein], $this->managerRole); + $this->fileToShare->invite($this->einstein, $this->managerRole); /** * @var ShareReceived $receivedShare */ $receivedShare = $this->einsteinOcis->getSharedWithMe()[0]; $resource = $this->einsteinOcis->getResourceById($receivedShare->getRemoteItemId()); - $resource->invite([$this->marie], $this->viewerRole); + $resource->invite($this->marie, $this->viewerRole); /** * @var ShareReceived $receivedShare */ diff --git a/tests/integration/Owncloud/OcisPhpSdk/ShareCreatedModifyTest.php b/tests/integration/Owncloud/OcisPhpSdk/ShareCreatedModifyTest.php index 3094122c..fa947c26 100644 --- a/tests/integration/Owncloud/OcisPhpSdk/ShareCreatedModifyTest.php +++ b/tests/integration/Owncloud/OcisPhpSdk/ShareCreatedModifyTest.php @@ -58,7 +58,8 @@ public function setUp(): void public function testDeleteIndividualShare(): void { - $this->fileToShare->invite([$this->einstein, $this->marie], $this->viewerRole); + $this->fileToShare->invite($this->einstein, $this->viewerRole); + $this->fileToShare->invite($this->marie, $this->viewerRole); $shares = $this->ocis->getSharedByMe(); foreach ($shares as $share) { $this->assertInstanceOf(ShareCreated::class, $share); @@ -76,17 +77,19 @@ public function testDeleteIndividualShare(): void public function testDeleteGroupShare(): void { $philosophyHatersGroup = $this->ocis->createGroup( - 'philosophyhaters', + 'philosophy-haters', 'philosophy haters group' ); $this->createdGroups = [$philosophyHatersGroup]; $philosophyHatersGroup->addUser($this->einstein); - $this->fileToShare->invite([$this->einstein, $philosophyHatersGroup, $this->marie], $this->viewerRole); + $this->fileToShare->invite($this->einstein, $this->viewerRole); + $this->fileToShare->invite($philosophyHatersGroup, $this->viewerRole); + $this->fileToShare->invite($this->marie, $this->viewerRole); $shares = $this->ocis->getSharedByMe(); foreach ($shares as $share) { $this->assertInstanceOf(ShareCreated::class, $share); - if ($share->getReceiver()->getDisplayName() === 'philosophyhaters') { + if ($share->getReceiver()->getDisplayName() === 'philosophy-haters') { $share->delete(); break; } @@ -101,7 +104,8 @@ public function testDeleteAnAlreadyDeletedShare(): void $this->markTestSkipped('https://github.com/owncloud/ocis/issues/7872'); // @phpstan-ignore-next-line because the test is skipped $this->expectException(NotFoundException::class); - $this->fileToShare->invite([$this->einstein, $this->marie], $this->viewerRole); + $this->fileToShare->invite($this->einstein, $this->viewerRole); + $this->fileToShare->invite($this->marie, $this->viewerRole); $shares = $this->ocis->getSharedByMe(); $shares[0]->delete(); $shares[0]->delete(); @@ -132,15 +136,15 @@ public function testSetExpirationDateOnObjectFromInvite(): void $this->markTestSkipped('Not implemented yet in oCIS, see https://github.com/owncloud/ocis/issues/6993'); // @phpstan-ignore-next-line because the test is skipped $this->expectException(NotFoundException::class); - $sharesFromInvite = $this->fileToShare->invite([$this->einstein], $this->viewerRole); + $shareFromInvite = $this->fileToShare->invite($this->einstein, $this->viewerRole); $tomorrow = new \DateTimeImmutable('tomorrow'); - $sharesFromInvite[0]->setExpiration($tomorrow); + $shareFromInvite->setExpiration($tomorrow); $sharedByMeShares = $this->ocis->getSharedByMe(); - $this->assertInstanceOf(\DateTimeImmutable::class, $sharesFromInvite[0]->getExpiration()); - $this->assertSame($tomorrow->getTimestamp(), $sharesFromInvite[0]->getExpiration()->getTimestamp()); - $this->assertInstanceOf(\DateTimeImmutable::class, $sharedByMeShares[0]->getExpiration()); - $this->assertSame($tomorrow->getTimestamp(), $sharedByMeShares[0]->getExpiration()->getTimestamp()); + $this->assertInstanceOf(\DateTimeImmutable::class, $shareFromInvite->getExpiration()); + $this->assertSame($tomorrow->getTimestamp(), $shareFromInvite->getExpiration()->getTimestamp()); + $this->assertInstanceOf(\DateTimeImmutable::class, $shareFromInvite->getExpiration()); + $this->assertSame($tomorrow->getTimestamp(), $shareFromInvite->getExpiration()->getTimestamp()); } public function testSetExpirationDateOnObjectFromSharedByMe(): void @@ -148,7 +152,7 @@ public function testSetExpirationDateOnObjectFromSharedByMe(): void $this->markTestSkipped('Not implemented yet in oCIS, see https://github.com/owncloud/ocis/issues/6993'); // @phpstan-ignore-next-line because the test is skipped $this->expectException(NotFoundException::class); - $this->fileToShare->invite([$this->einstein], $this->viewerRole); + $this->fileToShare->invite($this->einstein, $this->viewerRole); $tomorrow = new \DateTimeImmutable('tomorrow'); $sharedByMeShares = $this->ocis->getSharedByMe(); $sharedByMeShares[0]->setExpiration($tomorrow); diff --git a/tests/integration/Owncloud/OcisPhpSdk/ShareGetShareByMeTest.php b/tests/integration/Owncloud/OcisPhpSdk/ShareGetShareByMeTest.php index 68eb25d9..a5999a34 100644 --- a/tests/integration/Owncloud/OcisPhpSdk/ShareGetShareByMeTest.php +++ b/tests/integration/Owncloud/OcisPhpSdk/ShareGetShareByMeTest.php @@ -62,7 +62,7 @@ public function setUp(): void public function testGetShareByMe(): void { - $this->sharedResource->invite([$this->einstein], $this->editorRole); + $this->sharedResource->invite($this->einstein, $this->editorRole); $myShare = $this->ocis->getSharedByMe(); $this->assertInstanceOf(ShareCreated::class, $myShare[0]); $this->assertEquals('Albert Einstein', $myShare[0]->getReceiver()->getDisplayName()); @@ -86,7 +86,7 @@ public function testGetShareLinkByMe(): void public function testGetShareAndShareLinkByMe(): void { - $this->sharedResource->invite([$this->einstein], $this->editorRole); + $this->sharedResource->invite($this->einstein, $this->editorRole); $this->sharedResource->createSharingLink( SharingLinkType::VIEW, new \DateTimeImmutable('2023-12-31 01:02:03.456789'), diff --git a/tests/unit/Owncloud/OcisPhpSdk/ResourceInviteTest.php b/tests/unit/Owncloud/OcisPhpSdk/ResourceInviteTest.php index d9e88d81..e3a3c8cd 100644 --- a/tests/unit/Owncloud/OcisPhpSdk/ResourceInviteTest.php +++ b/tests/unit/Owncloud/OcisPhpSdk/ResourceInviteTest.php @@ -46,7 +46,7 @@ public function inviteDataProvider(): array return [ // invite for a single recipient [ - [$einstein], + $einstein, null, new DriveItemInvite( [ @@ -61,32 +61,9 @@ public function inviteDataProvider(): array ] ) ], - // invite a user and a group - [ - [$einstein, $smartPeopleGroup], - null, - new DriveItemInvite( - [ - 'recipients' => [ - new DriveRecipient( - [ - 'object_id' => 'uuid-of-einstein', - ] - ), - new DriveRecipient( - [ - 'object_id' => 'uuid-of-smart-people-group', - 'at_libre_graph_recipient_type' => 'group', - ] - ), - ], - 'roles' => ['uuid-of-the-role'], - ] - ) - ], // set expiry time [ - [$smartPeopleGroup], + $smartPeopleGroup, new \DateTimeImmutable('2022-12-31 01:02:03.456789'), new DriveItemInvite( [ @@ -105,7 +82,7 @@ public function inviteDataProvider(): array ], // set expiry time, with conversion to UTC/Z timezone [ - [$einstein], + $einstein, new \DateTimeImmutable('2021-01-01 17:45:43.123456', new \DateTimeZone('Asia/Kathmandu')), new DriveItemInvite( [ @@ -126,10 +103,12 @@ public function inviteDataProvider(): array /** * @dataProvider inviteDataProvider - * @param array $recipients */ - public function testInvite($recipients, ?\DateTimeImmutable $expiration, DriveItemInvite $expectedInviteData): void - { + public function testInvite( + User|Group $recipient, + ?\DateTimeImmutable $expiration, + DriveItemInvite $expectedInviteData + ): void { $permission = $this->createMock(Permission::class); $permission->method('getId') ->willReturn('uuid-of-the-permission'); @@ -167,7 +146,7 @@ public function testInvite($recipients, ?\DateTimeImmutable $expiration, DriveIt ); $role = new SharingRole($openAPIRole); - $result = $resource->invite($recipients, $role, $expiration); - $this->assertContainsOnly(ShareCreated::class, $result); + $result = $resource->invite($recipient, $role, $expiration); + $this->assertInstanceOf(ShareCreated::class, $result); } }