diff --git a/.github/workflows/phpunit-tests.yml b/.github/workflows/phpunit-tests.yml index d3f1c79..670baa8 100644 --- a/.github/workflows/phpunit-tests.yml +++ b/.github/workflows/phpunit-tests.yml @@ -5,7 +5,6 @@ on: env: BRANCH_NAME: ${{ github.head_ref || github.ref_name }} - DF_RUN_TOKEN: ${{ secrets.DF_RUN_TOKEN }} IMAGE_NAME: google-api-php-client-mock AWS_REGION: ${{ vars.AWS_REGION }} AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} @@ -19,4 +18,4 @@ jobs: - name: Checkout code uses: actions/checkout@v4 - name: Run unit tests - run: docker-compose -f actions-services.yml run --rm google-api-php-client-mock "./run-tests.sh" \ No newline at end of file + run: docker-compose -f actions-services.yml run --rm google-api-php-client-mock "./run-tests.sh" diff --git a/SilMock/Google/Service/Directory/Resource/Members.php b/SilMock/Google/Service/Directory/Resource/Members.php index b6c4084..156c8fa 100644 --- a/SilMock/Google/Service/Directory/Resource/Members.php +++ b/SilMock/Google/Service/Directory/Resource/Members.php @@ -15,6 +15,21 @@ public function __construct(?string $dbFile = null) parent::__construct($dbFile, 'directory', 'members'); } + public function delete(string $groupKey, string $memberKey) + { + $directoryMemberRecords = $this->getRecords(); + foreach ($directoryMemberRecords as $record) { + $decodedRecordData = json_decode($record['data'], true); + if ( + $decodedRecordData['groupKey'] === $groupKey + && $decodedRecordData['member']['email'] === $memberKey + ) { + $recordId = $record['id']; + $this->deleteRecordById($recordId); + } + } + } + public function get(string $groupKey, string $memberKey): GoogleDirectory_Member { $members = $this->listMembers($groupKey); diff --git a/SilMock/tests/Google/Service/Directory/Resource/MembersTest.php b/SilMock/tests/Google/Service/Directory/Resource/MembersTest.php index f05fcdf..b14ac41 100644 --- a/SilMock/tests/Google/Service/Directory/Resource/MembersTest.php +++ b/SilMock/tests/Google/Service/Directory/Resource/MembersTest.php @@ -81,7 +81,7 @@ public function testListMembersAll() try { $members = $mockGoogleServiceDirectory->members->listMembers($groupEmailAddress); } catch (Exception $exception) { - $this->failure($exception); + $this->failure($exception, 'listMembersAll'); } self::assertNotEmpty( $members->getMembers(), @@ -102,7 +102,7 @@ public function testListMembersOnlyMember() ] ); } catch (Exception $exception) { - $this->failure($exception); + $this->failure($exception, 'listMembersOnlyMember'); } self::assertNotEmpty( $members->getMembers(), @@ -123,7 +123,7 @@ public function testListMembersOnlyOwner() ] ); } catch (Exception $exception) { - $this->failure($exception); + $this->failure($exception, 'listMembersOnlyOwner'); } self::assertEmpty( $members->getMembers(), @@ -131,11 +131,58 @@ public function testListMembersOnlyOwner() ); } - protected function failure(Exception $exception): void + public function testDelete() + { + $mockGoogleServiceDirectory = new GoogleMock_Directory('anyclient', $this->dataFile); + $groupEmailAddress = 'sample_group@groups.example.com'; + $emailAddress = 'test@example.com'; + try { + $result = $mockGoogleServiceDirectory->members->hasMember( + $groupEmailAddress, + $emailAddress + ); + $hasMember = $result['isMember'] ?? false; + } catch (Exception $exception) { + self::fail( + $exception->getMessage() + ); + } + + if (! $hasMember) { + $member = new GoogleDirectory_Member(); + $member->setEmail($emailAddress); + $member->setRole('MEMBER'); + $mockGoogleServiceDirectory->members->insert($groupEmailAddress, $member); + } + $mockGoogleServiceDirectory->members->delete($groupEmailAddress, $emailAddress); + + try { + $result = $mockGoogleServiceDirectory->members->hasMember( + $groupEmailAddress, + 'test@example.com' + ); + $hasMember = $result['isMember'] ?? false; + } catch (Exception $exception) { + self::fail( + $exception->getMessage() + ); + } + self::assertFalse( + $hasMember, + sprintf( + 'Failed to delete %s from group %s', + $emailAddress, + $groupEmailAddress + ) + ); + } + + protected function failure(Exception $exception, string $function): void { self::fail( sprintf( - 'Was expecting the members.insert method to function, but got: %s', + 'Was expecting the %s method to function, but got: %s', + $function, $exception->getMessage() ) );