Skip to content

Commit 1a2f959

Browse files
authored
Merge pull request #94 from silinternational/develop
Release 2.7.0: Add groups.delete with testing
2 parents 3b9511f + 4d3ddca commit 1a2f959

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

SilMock/Google/Service/Directory/Resource/Groups.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,17 @@ public function __construct(?string $dbFile = null)
1515
parent::__construct($dbFile, 'directory', 'groups');
1616
}
1717

18+
public function delete(string $groupKey)
19+
{
20+
$groupRecords = $this->getRecords();
21+
foreach ($groupRecords as $groupRecord) {
22+
$groupRecordData = json_decode($groupRecord['data'], true);
23+
if ($groupRecordData['email'] === $groupKey) {
24+
$this->deleteRecordById($groupRecord['id']);
25+
}
26+
}
27+
}
28+
1829
public function get(string $groupKey): ?GoogleDirectory_Group
1930
{
2031
$mockGroupsObject = new Groups($this->dbFile);

SilMock/tests/Google/Service/Directory/Resource/GroupsTest.php

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,57 @@ public function testInsert()
3737
self::assertTrue($addedGroup instanceof GoogleDirectory_Group);
3838
}
3939

40+
public function testDelete()
41+
{
42+
// Set update a deletable email address
43+
$group = new GoogleDirectory_Group();
44+
$group->setEmail(self::GROUP_EMAIL_ADDRESS . 'delete');
45+
$group->setAliases([]);
46+
$group->setName('Sample Deletable Group');
47+
$group->setDescription('A Sample Deletable Group used for testing');
48+
49+
$mockGoogleServiceDirectory = new GoogleMock_Directory('anyclient', $this->dataFile);
50+
try {
51+
$addedGroup = $mockGoogleServiceDirectory->groups->insert($group);
52+
} catch (Exception $exception) {
53+
self::fail(
54+
sprintf(
55+
'Was expecting the groups.insert method to function, but got: %s',
56+
$exception->getMessage()
57+
)
58+
);
59+
}
60+
self::assertTrue($addedGroup instanceof GoogleDirectory_Group);
61+
62+
// Now try to delete it
63+
$mockGoogleServiceDirectory = new GoogleMock_Directory('anyclient', $this->dataFile);
64+
try {
65+
$mockGoogleServiceDirectory->groups->delete(self::GROUP_EMAIL_ADDRESS . 'delete');
66+
} catch (Exception $exception) {
67+
self::fail(
68+
sprintf(
69+
'Was expecting the groups.delete method to function, but got: %s',
70+
$exception->getMessage()
71+
)
72+
);
73+
}
74+
75+
try {
76+
$group = $mockGoogleServiceDirectory->groups->get(self::GROUP_EMAIL_ADDRESS . 'delete');
77+
self::assertNull(
78+
$group,
79+
'Was expecting the group to be deleted, but found something'
80+
);
81+
} catch (Exception $exception) {
82+
self::fail(
83+
sprintf(
84+
'Was expecting to confirm the group was deleted, but got: %s',
85+
$exception->getMessage()
86+
)
87+
);
88+
}
89+
}
90+
4091
public function testGet()
4192
{
4293
$mockGoogleServiceDirectory = new GoogleMock_Directory('anyclient', $this->dataFile);

0 commit comments

Comments
 (0)