Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: [Datastore] Upgrade to V2 #7179

Open
wants to merge 55 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
0baef28
feat!: [Datastore] Upgrade to PHP v2
yash30201 Mar 26, 2024
7215b2e
Enable Gapic Client support for Request Handler.
yash30201 Mar 26, 2024
237531f
Add credentials wrapper support in DatastoreClient
yash30201 Mar 26, 2024
cac76f1
Add request handler and serializer in DatastoreClient
yash30201 Mar 26, 2024
f39189f
Update Resource classes to add serializer and requesthandler in their…
yash30201 Mar 26, 2024
be2533c
Update snippet and unit tests to add request handler and serializer.
yash30201 Mar 26, 2024
d06abf7
Update beginTransaction and allocateIds rpc + unit + snippet tests
yash30201 Mar 31, 2024
cee1539
Update lookup rpc + unit + snippet tests
yash30201 Apr 1, 2024
927d510
Update RunQuery rpc + unit + snippet tests
yash30201 Apr 3, 2024
c9d2186
Update RunAggregationQuery rpc + unit + snippet tests
yash30201 Apr 3, 2024
82716bd
Update Commit rpc + unit + snippet tests
yash30201 Apr 3, 2024
fcdcf9b
Update Rollback rpc + unit + snippet tests
yash30201 Apr 3, 2024
4c32fc9
Remove all connection classes and references
yash30201 Apr 3, 2024
0596f27
Remove old gapic files and class aliases
yash30201 Apr 4, 2024
fa9e30a
Fix unit test failures
yash30201 Apr 4, 2024
e6fa30a
Fix PHP style checks
yash30201 Apr 4, 2024
2d01ea6
Fix aggregation query snippet test
yash30201 Apr 4, 2024
e098d66
Add MIGRATION.md
yash30201 Apr 4, 2024
2196aa2
Update documentation for DatastoreClient
yash30201 Apr 4, 2024
bf2c50b
Increase minimum core version to 1.55
yash30201 Apr 4, 2024
d6e2823
Mark `Operation` as internal
yash30201 Apr 4, 2024
6a03125
Merge branch 'main' into datastore-php-v2
yash30201 Apr 4, 2024
af549dd
Increase minimum core version to 1.57 (to be version)
yash30201 Apr 4, 2024
170d590
Fix emulator tests
yash30201 Apr 5, 2024
8e43aab
Self iteration
yash30201 Apr 5, 2024
9cf8493
Merge branch 'main' into datastore-php-v2
yash30201 May 6, 2024
fad4022
Iteration 1
yash30201 May 6, 2024
d45178c
fix(Spanner):Properly remove redundant keys from request options
yash30201 May 7, 2024
14fc795
pr iteration
yash30201 May 7, 2024
b9f0661
Add comments
yash30201 May 7, 2024
c6275bd
fix(Datastore):Properly remove redundant keys from request options
yash30201 May 7, 2024
81655e1
chore(Datastore): Update Composer version to use the upcoming latest.
yash30201 May 7, 2024
7e1dfa3
chore(Datastore): Update Composer version to use the upcoming latest.
yash30201 May 7, 2024
8c5a721
Merge branch 'main' into datastore-tryout-1
yash30201 May 7, 2024
b49d34e
Merge branch 'main' into datastore-php-v2
yash30201 May 7, 2024
2f33be4
Merge branch 'datastore-php-v2' of https://github.com/yash30201/googl…
yash30201 May 7, 2024
4c29341
chore(Datastore): Enhance readability of RunQuery and RunAggregationQ…
yash30201 May 7, 2024
dd24b76
Merge branch 'datastore-php-v2' into datastore-tryout-1
yash30201 May 7, 2024
d9b1b0b
Merge pull request #6 from yash30201/datastore-tryout-1
yash30201 May 7, 2024
2de6d58
Enhance Commit API readability
yash30201 May 7, 2024
b49f2db
Enhance Commit API readability
yash30201 May 7, 2024
0ab053d
Remove all nester level conversions
yash30201 May 7, 2024
4040d1c
Remove all nested level `decodeMessage` calls
yash30201 May 7, 2024
7d6ba8d
fix multidb tests
yash30201 May 7, 2024
9546293
Merge branch 'datastore-php-v2' of https://github.com/yash30201/googl…
yash30201 May 7, 2024
38a9e7d
Remove old GAPIC files
yash30201 May 9, 2024
8f5db18
Refactor SnippetTest::DatastoreClientTest
yash30201 May 9, 2024
2e9a749
Refactor Snippet::DatastoreSessionHandlerTest
yash30201 May 9, 2024
c0e2644
Update snippet tests part 1
yash30201 May 9, 2024
87ff887
Refactor all the remaining unit and snippets tests
yash30201 May 10, 2024
1e3e27f
php-cs-fix
yash30201 May 10, 2024
15747c8
Merge pull request #9 from googleapis/datastore-php-v2-patch
yash30201 May 10, 2024
df7ca4f
Merge branch 'main' into datastore-php-v2
yash30201 May 13, 2024
b2b0754
nit: Pr feedback
yash30201 May 13, 2024
b6130fc
nit: Remove GAPIC_KEYS const
yash30201 May 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@ keys/
.testing
.split
__pycache__

# VS Code local workspace settings
.vscode
1 change: 1 addition & 0 deletions Core/src/GrpcTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
namespace Google\Cloud\Core;

use Google\Auth\GetUniverseDomainInterface;
use Google\ApiCore\ArrayTrait;
use Google\ApiCore\CredentialsWrapper;
use Google\Cloud\Core\Exception\NotFoundException;
use Google\Cloud\Core\Exception\ServiceException;
Expand Down
95 changes: 91 additions & 4 deletions Core/src/Testing/DatastoreOperationRefreshTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@

namespace Google\Cloud\Core\Testing;

use Google\Cloud\Datastore\Connection\ConnectionInterface;
use Google\ApiCore\Serializer;
use Google\Cloud\Core\RequestHandler;
use Google\Cloud\Datastore\EntityMapper;
use Google\Cloud\Datastore\Operation;
use Google\Cloud\Datastore\V1\Client\DatastoreClient;
use Prophecy\Argument;

/**
* Refresh Datastore operation class
Expand All @@ -33,7 +36,7 @@ trait DatastoreOperationRefreshTrait
* Refresh the operation property of a given stubbed class.
*
* @param mixed $stub
* @param ConnectionInterface $connection
* @param RequestHandler $requestHandler
* @param array $options {
* Configuration Options
*
Expand All @@ -43,7 +46,7 @@ trait DatastoreOperationRefreshTrait
* }
* @return mixed
*/
public function refreshOperation($stub, ConnectionInterface $connection, array $options = [])
public function refreshOperation($stub, RequestHandler $requestHandler, array $options = [])
{
$options += [
'projectId' => null,
Expand All @@ -57,13 +60,97 @@ public function refreshOperation($stub, ConnectionInterface $connection, array $
$options['returnInt64AsObject']
);

$serializer = new Serializer([], [
'google.protobuf.Value' => function ($v) {
return $this->flattenValue($v);
},
'google.protobuf.Timestamp' => function ($v) {
return $this->formatTimestampFromApi($v);
}
], [], [
'google.protobuf.Timestamp' => function ($v) {
if (is_string($v)) {
$dt = new \DateTime($v);
return ['seconds' => $dt->format('U')];
}
return $v;
}
]);

$stub->___setProperty('operation', new Operation(
$connection,
$requestHandler,
$serializer,
yash30201 marked this conversation as resolved.
Show resolved Hide resolved
$options['projectId'],
$options['returnInt64AsObject'],
$mapper
));

return $stub;
}

/**
* Helper method for Unit and Snippet test classes. This mocks the
* $requestHandler class property present in the Test Class with
* given arguments.
*
* @param string $methodName The method name to mock in RequestHandler::sendRequest
* @param array<string, mixed> $params The parameters to look for in the
* array equivalent of rpc request.
* @param mixed $returnValue The value to be returned by sendRequest mock.
* @param null|int $shouldBeCalledTimes Adds a shouldBeCalled prophecy. Defaults to `null`, implying nothing is added.
* [
* `0` => `shouldBeCalled`,
* Non zero positive integer $x => `shouldBeCalledTimes($x)`
* ]
*/
private function mockSendRequest($methodName, $params, $returnValue, $shouldBeCalledTimes = null)
yash30201 marked this conversation as resolved.
Show resolved Hide resolved
{
if (isset($this->serializer)) {
$serializer = $this->serializer;
} else {
$serializer = new Serializer([], [
'google.protobuf.Value' => function ($v) {
return $this->flattenValue($v);
},
'google.protobuf.Timestamp' => function ($v) {
return $this->formatTimestampFromApi($v);
}
], [], [
'google.protobuf.Timestamp' => function ($v) {
if (is_string($v)) {
$dt = new \DateTime($v);
return ['seconds' => $dt->format('U')];
}
return $v;
}
]);
}

$prophecy = $this->requestHandler->sendRequest(
DatastoreClient::class,
$methodName,
Argument::that(function ($arg) use ($methodName, $params, $serializer) {
$requestName = ucfirst($methodName . 'Request');
$x = explode('\\', get_class($arg));
$argName = end($x);

if ($requestName != $argName) {
return false;
}
$data = $serializer->encodeMessage($arg);
return array_replace_recursive($data, $params) == $data;
}),
Argument::cetera()
);

if (!is_null($shouldBeCalledTimes)) {
if ($shouldBeCalledTimes == 0) {
yash30201 marked this conversation as resolved.
Show resolved Hide resolved
$prophecy->shouldBeCalled();
} else {
$prophecy->shouldBeCalledTimes($shouldBeCalledTimes);
}
}

$prophecy->willReturn($returnValue);
}
}
62 changes: 0 additions & 62 deletions Datastore/src/Connection/ConnectionInterface.php

This file was deleted.

Loading
Loading