diff --git a/SilMock/Google/Http/Batch.php b/SilMock/Google/Http/Batch.php new file mode 100644 index 0000000..74cb9f2 --- /dev/null +++ b/SilMock/Google/Http/Batch.php @@ -0,0 +1,18 @@ +batch[$key] = $result; + } + + public function execute() + { + return $this->batch; + } +} diff --git a/SilMock/Google/Service/Directory.php b/SilMock/Google/Service/Directory.php index 9d3be51..7be0cc3 100644 --- a/SilMock/Google/Service/Directory.php +++ b/SilMock/Google/Service/Directory.php @@ -2,6 +2,8 @@ namespace SilMock\Google\Service; +use Google\Client; +use SilMock\Google\Http\Batch; use SilMock\Google\Service\Directory\Asps; use SilMock\Google\Service\Directory\Resource\Groups; use SilMock\Google\Service\Directory\Resource\Members; @@ -10,6 +12,7 @@ use SilMock\Google\Service\Directory\UsersAliasesResource; use SilMock\Google\Service\Directory\UsersResource; use SilMock\Google\Service\Directory\VerificationCodesResource; +use Webmozart\Assert\Assert; class Directory { @@ -21,7 +24,8 @@ class Directory public $users_aliases; public $verificationCodes; public $twoStepVerification; - + public Client $client; + /** * Sets the users and users_aliases properties to be instances of * the corresponding mock classes. @@ -39,5 +43,17 @@ public function __construct($client, ?string $dbFile = null) $this->users_aliases = new UsersAliasesResource($dbFile); $this->verificationCodes = new VerificationCodesResource($dbFile); $this->twoStepVerification = new TwoStepVerification($dbFile); + $this->client = new Client(); + Assert::notEmpty($client, 'Expecting a client to be passed!'); + } + + public function getClient() + { + return $this->client; + } + + public function createBatch() + { + return new Batch(); } } diff --git a/SilMock/Google/Service/Directory/Resource/Members.php b/SilMock/Google/Service/Directory/Resource/Members.php index f0b8ddb..b6c4084 100644 --- a/SilMock/Google/Service/Directory/Resource/Members.php +++ b/SilMock/Google/Service/Directory/Resource/Members.php @@ -69,8 +69,8 @@ public function listMembers($groupKey, $optParams = []) $this->validateGroupExists($groupKey); $pageSize = $optParams['pageSize'] ?? 10; $pageToken = $optParams['pageToken'] ?? 0; - $query = $optParams['query'] ?? null; - $expectedRoles = $this->extractRoles($query); + $roles = $optParams['roles'] ?? null; + $expectedRoles = $this->extractRoles($roles); $members = new GoogleDirectory_Members(); $directoryMemberRecords = $this->getRecords(); $memberCounter = 0; @@ -81,8 +81,8 @@ public function listMembers($groupKey, $optParams = []) && $memberCounter >= ($pageToken * $pageSize) // Matches the subsection of all the members && (empty($expectedRoles) || in_array($memberData['member']['role'], $expectedRoles)) // Matches role ) { - $memberCounter = $memberCounter + 1; - $this->addToMembers($memberData, $members); + $memberCounter = $memberCounter + 1; + $this->addToMembers($memberData, $members); } $currentMembers = $members->getMembers(); $currentResultSize = count($currentMembers); @@ -98,17 +98,11 @@ public function listMembers($groupKey, $optParams = []) return $members; } - protected function extractRoles(?string $query): array + protected function extractRoles(?string $roles): array { - if (! empty($query) && str_contains($query, 'roles')) { - $roleSegmentStart = substr($query, strpos($query, 'roles')); - $roleSegmentEnd = strrpos($roleSegmentStart, ' '); - if ($roleSegmentEnd === false) { - $roleSegmentEnd = strlen($roleSegmentStart); - } - $roleSegment = trim(substr($roleSegmentStart, 0, $roleSegmentEnd)); - $roleValue = substr($roleSegment, 6); // roles= is 0-5 - $expectedRoles = explode(',', $roleValue); + if (! empty($roles)) { + $allExpectedRoles = explode(',', $roles); + $expectedRoles = array_map(function ($role) { return mb_strtoupper(trim($role)); }, $allExpectedRoles); } else { $expectedRoles = []; } diff --git a/SilMock/tests/Google/Http/BatchTest.php b/SilMock/tests/Google/Http/BatchTest.php new file mode 100644 index 0000000..9f55b5c --- /dev/null +++ b/SilMock/tests/Google/Http/BatchTest.php @@ -0,0 +1,24 @@ +add('RESULT', 'key'); + $results = $batch->execute(); + $expected = [ + 'key' => 'RESULT', + ]; + Assert::assertEquals($expected, $results); + } +} diff --git a/SilMock/tests/Google/Service/Directory/Resource/MembersTest.php b/SilMock/tests/Google/Service/Directory/Resource/MembersTest.php index e43cc4f..f05fcdf 100644 --- a/SilMock/tests/Google/Service/Directory/Resource/MembersTest.php +++ b/SilMock/tests/Google/Service/Directory/Resource/MembersTest.php @@ -98,7 +98,7 @@ public function testListMembersOnlyMember() $members = $mockGoogleServiceDirectory->members->listMembers( $groupEmailAddress, [ - 'query' => 'roles=MEMBER' + 'roles' => 'MEMBER' ] ); } catch (Exception $exception) { @@ -119,7 +119,7 @@ public function testListMembersOnlyOwner() $members = $mockGoogleServiceDirectory->members->listMembers( $groupEmailAddress, [ - 'query' => 'roles=OWNER' + 'roles' => 'OWNER' ] ); } catch (Exception $exception) { diff --git a/SilMock/tests/Google/Service/DirectoryTest.php b/SilMock/tests/Google/Service/DirectoryTest.php index e8295c4..9897a9f 100644 --- a/SilMock/tests/Google/Service/DirectoryTest.php +++ b/SilMock/tests/Google/Service/DirectoryTest.php @@ -2,9 +2,12 @@ namespace SilMock\tests\Google\Service; +use Google\Client; +use Google\Service\Directory\Alias as Google_Service_Directory_Alias; +use Google\Service\Directory\User as Google_Service_Directory_User; +use PHPUnit\Framework\Assert; use PHPUnit\Framework\TestCase; -use Google_Service_Directory_Alias; -use Google_Service_Directory_User; +use SilMock\Google\Http\Batch; use SilMock\Google\Service\Directory; use SilMock\Google\Service\Directory\ObjectUtils; use SilMock\DataStore\Sqlite\SqliteUtils; @@ -43,6 +46,12 @@ public function getProperties($object, $propKeys = null): array return $outArray; } + public function testCreateBatch() + { + $batch = new Batch(); + self::assertInstanceOf(Batch::class, $batch); + } + public function testDirectory() { $expectedKeys = [ @@ -54,7 +63,7 @@ public function testDirectory() ]; $errorMessage = " *** Directory was not initialized properly"; - $directory = new Directory('whatever', $this->dataFile); + $directory = new Directory('anyclient', $this->dataFile); $directoryAsJson = json_encode($directory); $directoryInfo = json_decode($directoryAsJson, true); @@ -64,6 +73,13 @@ public function testDirectory() } } + public function testGetClient() + { + $dir = new Directory('anyclient', $this->dataFile); + $client = $dir->getClient(); + Assert::assertInstanceOf(Client::class, $client); + } + public function testUsersInsert() { $newUser = $this->setupSampleUser($this->dataFile); diff --git a/composer.json b/composer.json index a83ada3..637d069 100644 --- a/composer.json +++ b/composer.json @@ -27,7 +27,8 @@ "ext-mbstring": "*", "ext-pdo": "*", "google/apiclient": "^v2.15.0", - "google/apiclient-services": "^v0.312.0" + "google/apiclient-services": "^v0.312.0", + "webmozart/assert": "1.11.0" }, "require-dev": { "phpunit/phpunit": "^9.0", diff --git a/composer.lock b/composer.lock index 69b83b3..9fe2de9 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": "a79c34fc19f24150faf0f514f23a5274", + "content-hash": "7e5c29f633db0a2bd3ea5e0e775e9592", "packages": [ { "name": "firebase/php-jwt", @@ -184,16 +184,16 @@ }, { "name": "google/auth", - "version": "v1.39.0", + "version": "v1.40.0", "source": { "type": "git", "url": "https://github.com/googleapis/google-auth-library-php.git", - "reference": "23e8e696d87f8d7dfefbd347ca1c99ce17ecb368" + "reference": "bff9f2d01677e71a98394b5ac981b99523df5178" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/googleapis/google-auth-library-php/zipball/23e8e696d87f8d7dfefbd347ca1c99ce17ecb368", - "reference": "23e8e696d87f8d7dfefbd347ca1c99ce17ecb368", + "url": "https://api.github.com/repos/googleapis/google-auth-library-php/zipball/bff9f2d01677e71a98394b5ac981b99523df5178", + "reference": "bff9f2d01677e71a98394b5ac981b99523df5178", "shasum": "" }, "require": { @@ -238,9 +238,9 @@ "support": { "docs": "https://googleapis.github.io/google-auth-library-php/main/", "issues": "https://github.com/googleapis/google-auth-library-php/issues", - "source": "https://github.com/googleapis/google-auth-library-php/tree/v1.39.0" + "source": "https://github.com/googleapis/google-auth-library-php/tree/v1.40.0" }, - "time": "2024-05-02T16:03:51+00:00" + "time": "2024-05-31T19:16:15+00:00" }, { "name": "guzzlehttp/guzzle", @@ -671,24 +671,24 @@ }, { "name": "paragonie/constant_time_encoding", - "version": "v2.7.0", + "version": "v3.0.0", "source": { "type": "git", "url": "https://github.com/paragonie/constant_time_encoding.git", - "reference": "52a0d99e69f56b9ec27ace92ba56897fe6993105" + "reference": "df1e7fde177501eee2037dd159cf04f5f301a512" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/paragonie/constant_time_encoding/zipball/52a0d99e69f56b9ec27ace92ba56897fe6993105", - "reference": "52a0d99e69f56b9ec27ace92ba56897fe6993105", + "url": "https://api.github.com/repos/paragonie/constant_time_encoding/zipball/df1e7fde177501eee2037dd159cf04f5f301a512", + "reference": "df1e7fde177501eee2037dd159cf04f5f301a512", "shasum": "" }, "require": { - "php": "^7|^8" + "php": "^8" }, "require-dev": { - "phpunit/phpunit": "^6|^7|^8|^9", - "vimeo/psalm": "^1|^2|^3|^4" + "phpunit/phpunit": "^9", + "vimeo/psalm": "^4|^5" }, "type": "library", "autoload": { @@ -734,7 +734,7 @@ "issues": "https://github.com/paragonie/constant_time_encoding/issues", "source": "https://github.com/paragonie/constant_time_encoding" }, - "time": "2024-05-08T12:18:48+00:00" + "time": "2024-05-08T12:36:18+00:00" }, { "name": "paragonie/random_compat", @@ -788,20 +788,20 @@ }, { "name": "phpseclib/phpseclib", - "version": "3.0.37", + "version": "3.0.38", "source": { "type": "git", "url": "https://github.com/phpseclib/phpseclib.git", - "reference": "cfa2013d0f68c062055180dd4328cc8b9d1f30b8" + "reference": "b18b8788e51156c4dd97b7f220a31149a0052067" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpseclib/phpseclib/zipball/cfa2013d0f68c062055180dd4328cc8b9d1f30b8", - "reference": "cfa2013d0f68c062055180dd4328cc8b9d1f30b8", + "url": "https://api.github.com/repos/phpseclib/phpseclib/zipball/b18b8788e51156c4dd97b7f220a31149a0052067", + "reference": "b18b8788e51156c4dd97b7f220a31149a0052067", "shasum": "" }, "require": { - "paragonie/constant_time_encoding": "^1|^2", + "paragonie/constant_time_encoding": "^1|^2|^3", "paragonie/random_compat": "^1.4|^2.0|^9.99.99", "php": ">=5.6.1" }, @@ -878,7 +878,7 @@ ], "support": { "issues": "https://github.com/phpseclib/phpseclib/issues", - "source": "https://github.com/phpseclib/phpseclib/tree/3.0.37" + "source": "https://github.com/phpseclib/phpseclib/tree/3.0.38" }, "funding": [ { @@ -894,7 +894,7 @@ "type": "tidelift" } ], - "time": "2024-03-03T02:14:58+00:00" + "time": "2024-06-17T10:11:32+00:00" }, { "name": "psr/cache", @@ -1265,6 +1265,64 @@ } ], "time": "2024-04-18T09:32:20+00:00" + }, + { + "name": "webmozart/assert", + "version": "1.11.0", + "source": { + "type": "git", + "url": "https://github.com/webmozarts/assert.git", + "reference": "11cb2199493b2f8a3b53e7f19068fc6aac760991" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/webmozarts/assert/zipball/11cb2199493b2f8a3b53e7f19068fc6aac760991", + "reference": "11cb2199493b2f8a3b53e7f19068fc6aac760991", + "shasum": "" + }, + "require": { + "ext-ctype": "*", + "php": "^7.2 || ^8.0" + }, + "conflict": { + "phpstan/phpstan": "<0.12.20", + "vimeo/psalm": "<4.6.1 || 4.6.2" + }, + "require-dev": { + "phpunit/phpunit": "^8.5.13" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.10-dev" + } + }, + "autoload": { + "psr-4": { + "Webmozart\\Assert\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Bernhard Schussek", + "email": "bschussek@gmail.com" + } + ], + "description": "Assertions to validate method input/output with nice error messages.", + "keywords": [ + "assert", + "check", + "validate" + ], + "support": { + "issues": "https://github.com/webmozarts/assert/issues", + "source": "https://github.com/webmozarts/assert/tree/1.11.0" + }, + "time": "2022-06-03T18:03:27+00:00" } ], "packages-dev": [ @@ -1340,16 +1398,16 @@ }, { "name": "myclabs/deep-copy", - "version": "1.11.1", + "version": "1.12.0", "source": { "type": "git", "url": "https://github.com/myclabs/DeepCopy.git", - "reference": "7284c22080590fb39f2ffa3e9057f10a4ddd0e0c" + "reference": "3a6b9a42cd8f8771bd4295d13e1423fa7f3d942c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/7284c22080590fb39f2ffa3e9057f10a4ddd0e0c", - "reference": "7284c22080590fb39f2ffa3e9057f10a4ddd0e0c", + "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/3a6b9a42cd8f8771bd4295d13e1423fa7f3d942c", + "reference": "3a6b9a42cd8f8771bd4295d13e1423fa7f3d942c", "shasum": "" }, "require": { @@ -1357,11 +1415,12 @@ }, "conflict": { "doctrine/collections": "<1.6.8", - "doctrine/common": "<2.13.3 || >=3,<3.2.2" + "doctrine/common": "<2.13.3 || >=3 <3.2.2" }, "require-dev": { "doctrine/collections": "^1.6.8", "doctrine/common": "^2.13.3 || ^3.2.2", + "phpspec/prophecy": "^1.10", "phpunit/phpunit": "^7.5.20 || ^8.5.23 || ^9.5.13" }, "type": "library", @@ -1387,7 +1446,7 @@ ], "support": { "issues": "https://github.com/myclabs/DeepCopy/issues", - "source": "https://github.com/myclabs/DeepCopy/tree/1.11.1" + "source": "https://github.com/myclabs/DeepCopy/tree/1.12.0" }, "funding": [ { @@ -1395,7 +1454,7 @@ "type": "tidelift" } ], - "time": "2023-03-08T13:26:56+00:00" + "time": "2024-06-12T14:39:25+00:00" }, { "name": "nikic/php-parser",