Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
54 changes: 8 additions & 46 deletions Core/src/Testing/DatastoreOperationRefreshTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
*/
trait DatastoreOperationRefreshTrait
{
private static Serializer $_serializer;

/**
* Refresh the operation property of a given stubbed class.
*
Expand Down Expand Up @@ -74,59 +76,19 @@ public function refreshOperation($stub, RequestHandler $requestHandler, array $o
}

/**
* 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)`
* ]
* @return Serializer
*/
private function mockSendRequest($methodName, $params, $returnValue, $shouldBeCalledTimes = null)
private function getSerializer()
{
$serializer = $this->getSerializer();

$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) {
$prophecy->shouldBeCalled();
} else {
$prophecy->shouldBeCalledTimes($shouldBeCalledTimes);
}
if (isset(self::$_serializer)) {
return self::$_serializer;
}

$prophecy->willReturn($returnValue);
}

private function getSerializer()
{
if (isset($this->serializer)) {
return $this->serializer;
return self::$_serializer = $this->serializer;
}

return new Serializer([], [
return self::$_serializer = new Serializer([], [
'google.protobuf.Value' => function ($v) {
return $this->flattenValue($v);
},
Expand Down
34 changes: 0 additions & 34 deletions Datastore/src/V1/DatastoreClient.php

This file was deleted.

164 changes: 0 additions & 164 deletions Datastore/src/V1/DatastoreGrpcClient.php

This file was deleted.

Loading