diff --git a/Dockerfile b/Dockerfile index cd1c394..41bb2a5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,28 +1,60 @@ FROM php:8.2-apache +RUN useradd nonroot LABEL maintainer="Mark Tompsett " ENV REFRESHED_AT 2023-07-12 # Make sure apt has current list/updates +USER root RUN apt-get update -y \ # Fix timezone stuff from hanging. && echo "America/New_York" > /etc/timezone \ - && apt-get install -y tzdata \ + && apt-get install -y --no-install-recommends tzdata \ && apt-get upgrade -y \ # Install - && apt-get install -y \ + && apt-get install -y --no-install-recommends \ # things needed for GoogleMock objects sqlite3 \ # some basics unzip wget zip \ # Clean up to reduce docker image size && apt-get clean \ - && rm -rf /var/lib/apt/lists/* + && rm -rf /var/lib/apt/lists/* \ +# Make sure the directory we'll mount and reference is there + && mkdir -p /data -RUN mkdir -p /data +USER nonroot WORKDIR /data -COPY ./ /data +COPY actions-services.yml /data +COPY composer-install.sh /data +COPY composer.json /data +COPY composer.lock /data +COPY docker-compose.yml /data +COPY Dockerfile /data +COPY LICENSE /data +COPY Makefile /data +COPY README.md /data +COPY run-tests.sh /data +COPY .travis.yml /data +COPY SilMock/ /data/SilMock -RUN cd /data && ./composer-install.sh -RUN mv /data/composer.phar /usr/bin/composer +USER root +# Make sure the development test files exist and have writable permissions +RUN touch /data/SilMock/DataStore/Sqlite/Test1_Google_Service_Data.db && \ + touch /data/SilMock/DataStore/Sqlite/Test2_Google_Service_Data.db && \ + touch /data/SilMock/DataStore/Sqlite/Test3_Google_Service_Data.db && \ + touch /data/SilMock/DataStore/Sqlite/Test4_Google_Service_Data.db && \ + touch /data/SilMock/DataStore/Sqlite/Test5_Google_Service_Data.db && \ + touch /data/SilMock/tests/.phpunit.result.cache && \ + chown -R nonroot:root /data && \ + chmod 664 /data/SilMock/DataStore/Sqlite/Test1_Google_Service_Data.db && \ + chmod 664 /data/SilMock/DataStore/Sqlite/Test2_Google_Service_Data.db && \ + chmod 664 /data/SilMock/DataStore/Sqlite/Test3_Google_Service_Data.db && \ + chmod 664 /data/SilMock/DataStore/Sqlite/Test4_Google_Service_Data.db && \ + chmod 664 /data/SilMock/DataStore/Sqlite/Test5_Google_Service_Data.db && \ + chmod 664 /data/SilMock/tests/.phpunit.result.cache + +WORKDIR /data +RUN ./composer-install.sh && mv /data/composer.phar /usr/bin/composer +USER nonroot RUN /usr/bin/composer install diff --git a/README.md b/README.md index d8f1255..80d5ef3 100644 --- a/README.md +++ b/README.md @@ -182,3 +182,5 @@ Examples $aliases = $dir->users_aliases->listUsersAliases($users_email); $alias = $dir->users_aliases->delete($users_email, $alias); + +### DEVELOPER'S NOTE: Releases should include updating the version in composer.json to match \ No newline at end of file diff --git a/SilMock/Google/Service/Directory/Resource/Groups.php b/SilMock/Google/Service/Directory/Resource/Groups.php index 8721d5c..df15d67 100644 --- a/SilMock/Google/Service/Directory/Resource/Groups.php +++ b/SilMock/Google/Service/Directory/Resource/Groups.php @@ -7,6 +7,8 @@ use Google\Service\Directory\Groups as GoogleDirectory_Groups; use Google\Service\Directory\Alias as GoogleDirectory_GroupAlias; use Google\Service\Groupssettings\Groups as GoogleGroupsSettings_Group; +use SilMock\exceptions\GroupAlreadyExistsException; +use SilMock\exceptions\GroupDoesNotExistException; use SilMock\Google\Service\DbClass; use SilMock\Google\Service\Directory\ObjectUtils; use SilMock\Google\Service\Groupssettings\Resource\Groups as MockGroupssettings_ResourceGroups; @@ -92,7 +94,7 @@ public function insert(GoogleDirectory_Group $postBody, $optParams = []) $groupSettings->setWhoCanViewGroup('ALL_MEMBERS_CAN_VIEW'); $mockGroupSettings->insert($groupSettings); } else { - throw new Exception( + throw new GroupAlreadyExistsException( "Cannot group.insert an existing group: " . $postBody->getEmail() ); } @@ -166,7 +168,7 @@ protected function isNewGroup(string $groupKey): bool public function update(string $groupKey, GoogleDirectory_Group $postBody, $optParams = []): GoogleDirectory_Group { if ($this->isNewGroup($postBody->getEmail())) { - throw new Exception("Group '{$groupKey}' does not exist."); + throw new GroupDoesNotExistException("Group '{$groupKey}' does not exist."); } $group = $this->get($groupKey); diff --git a/SilMock/Google/Service/Directory/UsersResource.php b/SilMock/Google/Service/Directory/UsersResource.php index 13ea6db..228c02c 100644 --- a/SilMock/Google/Service/Directory/UsersResource.php +++ b/SilMock/Google/Service/Directory/UsersResource.php @@ -293,7 +293,7 @@ public function update($userKey, $postBody) $newAlias->kind = "personal"; $newAlias->primaryEmail = $postBody->primaryEmail; - $insertedAlias = $usersAliases->insertAssumingUserExists($newAlias); + $usersAliases->insertAssumingUserExists($newAlias); } } @@ -451,10 +451,6 @@ private function doesUserMatch($entry, $query = '') ) ); } - if (mb_strpos($checkValue, $value) === 0) { - return true; - } else { - return false; - } + return mb_strpos($checkValue, $value) === 0; } } diff --git a/SilMock/Google/Service/Gmail/Resource/UsersSettingsDelegates.php b/SilMock/Google/Service/Gmail/Resource/UsersSettingsDelegates.php index b646c99..86b8093 100644 --- a/SilMock/Google/Service/Gmail/Resource/UsersSettingsDelegates.php +++ b/SilMock/Google/Service/Gmail/Resource/UsersSettingsDelegates.php @@ -122,7 +122,7 @@ protected function assertIsValidDelegateEmail($delegateEmail) */ protected function isValidEmailAddress($email) { - return (filter_var($email, FILTER_VALIDATE_EMAIL) !== false); + return filter_var($email, FILTER_VALIDATE_EMAIL) !== false; } public function get($userId, $delegateEmail, $optParams = array()) diff --git a/SilMock/Google/Service/Gmail/Resource/UsersSettingsForwardingAddresses.php b/SilMock/Google/Service/Gmail/Resource/UsersSettingsForwardingAddresses.php index 0867b3f..e7cd102 100644 --- a/SilMock/Google/Service/Gmail/Resource/UsersSettingsForwardingAddresses.php +++ b/SilMock/Google/Service/Gmail/Resource/UsersSettingsForwardingAddresses.php @@ -42,7 +42,7 @@ protected function assertIsValidDelegateEmail($delegateEmail) */ protected function isValidEmailAddress(string $email): bool { - return (filter_var($email, FILTER_VALIDATE_EMAIL) !== false); + return filter_var($email, FILTER_VALIDATE_EMAIL) !== false; } /** diff --git a/SilMock/Google/Service/Groupssettings/Resource/Groups.php b/SilMock/Google/Service/Groupssettings/Resource/Groups.php index debf86e..34353da 100644 --- a/SilMock/Google/Service/Groupssettings/Resource/Groups.php +++ b/SilMock/Google/Service/Groupssettings/Resource/Groups.php @@ -4,6 +4,7 @@ use Exception; use Google\Service\Groupssettings\Groups as GoogleGroupsSettings_Groups; +use SilMock\exceptions\GroupSettingsDoNotExistException; use SilMock\Google\Service\DbClass; use SilMock\Google\Service\Directory\ObjectUtils; @@ -35,7 +36,7 @@ public function delete(string $groupKey) protected function doGroupsSettingsExist(string $groupKey): bool { $groupsSettings = $this->get($groupKey); - return ($groupsSettings !== null); + return $groupsSettings !== null; } public function get(string $groupKey): ?GoogleGroupsSettings_Groups @@ -79,7 +80,7 @@ public function update( $optParams = [] ): GoogleGroupsSettings_Groups { if (! $this->doGroupsSettingsExist($postBody->getEmail())) { - throw new Exception("Group Settings for '{$groupKey}' does not exist."); + throw new GroupSettingsDoNotExistException("Group Settings for '{$groupKey}' does not exist."); } $groupsSettings = $this->get($groupKey); diff --git a/SilMock/exceptions/GroupAlreadyExistsException.php b/SilMock/exceptions/GroupAlreadyExistsException.php new file mode 100644 index 0000000..9f189e7 --- /dev/null +++ b/SilMock/exceptions/GroupAlreadyExistsException.php @@ -0,0 +1,9 @@ +getMessage() ) ); @@ -71,7 +72,7 @@ public function testUpdate() } catch (Exception $exception) { self::fail( sprintf( - 'Was expecting the groups.insert method to function, but got: %s', + self::GROUP_INSERT_FAILURE_TEMPLATE, $exception->getMessage() ) ); @@ -104,7 +105,7 @@ protected function deleteTestSetup() } catch (Exception $exception) { self::fail( sprintf( - 'Was expecting the groups.insert method to function, but got: %s', + self::GROUP_INSERT_FAILURE_TEMPLATE, $exception->getMessage() ) ); diff --git a/SilMock/tests/Google/Service/Groupsettings/GroupsettingsTest.php b/SilMock/tests/Google/Service/Groupsettings/GroupsettingsTest.php index 87bcf61..ae08785 100644 --- a/SilMock/tests/Google/Service/Groupsettings/GroupsettingsTest.php +++ b/SilMock/tests/Google/Service/Groupsettings/GroupsettingsTest.php @@ -17,8 +17,9 @@ public function testGet() $mockGroupsSettings = new MockGroupsSettings_ResourceGroups($this->dataFile); $groupsSettings = $mockGroupsSettings->get(self::GROUP_EMAIL_ADDRESS); self::assertNotNull($groupsSettings, 'Expecting group settings to exist'); - self::assertTrue( - $groupsSettings->getEmail() === self::GROUP_EMAIL_ADDRESS, + self::assertSame( + $groupsSettings->getEmail(), + self::GROUP_EMAIL_ADDRESS, sprintf( 'Was expecting the groupsSettings.get method to return a match for the group: %s', json_encode($groupsSettings, JSON_PRETTY_PRINT) diff --git a/composer.json b/composer.json index f5eff69..f286ca3 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "silinternational/google-api-php-client-mock", - "version": "2.15.2", + "version": "2.15.3", "description": "Attempting to create an intelligent mock of the Google API PHP Client for unit and functional testing.", "type": "library", "keywords": [ diff --git a/composer.lock b/composer.lock index 7f203e0..fc2c497 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "96d986eb6c122fd2fc7116d4d22be086", + "content-hash": "c611b88ab8dfbe32432f711980fd313c", "packages": [ { "name": "firebase/php-jwt",