Skip to content

Commit 648a98e

Browse files
committed
Create specific exceptions
When the group does or does not exist, that may cause an exception.
1 parent f02cde7 commit 648a98e

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

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

+4-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
use Google\Service\Directory\Groups as GoogleDirectory_Groups;
88
use Google\Service\Directory\Alias as GoogleDirectory_GroupAlias;
99
use Google\Service\Groupssettings\Groups as GoogleGroupsSettings_Group;
10+
use SilMock\exceptions\GroupAlreadyExistsException;
11+
use SilMock\exceptions\GroupDoesNotExistException;
1012
use SilMock\Google\Service\DbClass;
1113
use SilMock\Google\Service\Directory\ObjectUtils;
1214
use SilMock\Google\Service\Groupssettings\Resource\Groups as MockGroupssettings_ResourceGroups;
@@ -92,7 +94,7 @@ public function insert(GoogleDirectory_Group $postBody, $optParams = [])
9294
$groupSettings->setWhoCanViewGroup('ALL_MEMBERS_CAN_VIEW');
9395
$mockGroupSettings->insert($groupSettings);
9496
} else {
95-
throw new Exception(
97+
throw new GroupAlreadyExistsException(
9698
"Cannot group.insert an existing group: " . $postBody->getEmail()
9799
);
98100
}
@@ -166,7 +168,7 @@ protected function isNewGroup(string $groupKey): bool
166168
public function update(string $groupKey, GoogleDirectory_Group $postBody, $optParams = []): GoogleDirectory_Group
167169
{
168170
if ($this->isNewGroup($postBody->getEmail())) {
169-
throw new Exception("Group '{$groupKey}' does not exist.");
171+
throw new GroupDoesNotExistException("Group '{$groupKey}' does not exist.");
170172
}
171173
$group = $this->get($groupKey);
172174

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
namespace SilMock\exceptions;
4+
5+
use Exception;
6+
7+
class GroupAlreadyExistsException extends Exception
8+
{
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
namespace SilMock\exceptions;
4+
5+
use Exception;
6+
7+
class GroupDoesNotExistException extends Exception
8+
{
9+
}

0 commit comments

Comments
 (0)