class MockTransport implements TransportInterface

Traits

The MockStubTrait is used by generated mock stub classes which extent \Grpc\BaseStub (https://github.com/grpc/grpc/blob/master/src/php/lib/Grpc/BaseStub.php) It provides functionality to add responses, get received calls, and overrides the _simpleRequest method so that the elements of $responses are returned instead of making a call to the API.

Methods

__construct($deserialize = null)

No description

_simpleRequest(string $method, Message $argument, callable $deserialize, array $metadata = [], array $options = [])

Overrides the _simpleRequest method in \Grpc\BaseStub (https://github.com/grpc/grpc/blob/master/src/php/lib/Grpc/BaseStub.php) Returns a MockUnaryCall object that will return the first item from $responses

_clientStreamRequest(string $method, callable $deserialize, array $metadata = [], array $options = [])

Overrides the _clientStreamRequest method in \Grpc\BaseStub (https://github.com/grpc/grpc/blob/master/src/php/lib/Grpc/BaseStub.php) Returns a MockClientStreamingCall object that will return the first item from $responses

_serverStreamRequest(string $method, Message $argument, callable $deserialize, array $metadata = [], array $options = [])

Overrides the _serverStreamRequest method in \Grpc\BaseStub (https://github.com/grpc/grpc/blob/master/src/php/lib/Grpc/BaseStub.php) Returns a MockServerStreamingCall object that will stream items from $responses, and return a final status of $serverStreamingStatus.

_bidiRequest(string $method, callable $deserialize, array $metadata = [], array $options = [])

Overrides the _bidiRequest method in \Grpc\BaseStub (https://github.com/grpc/grpc/blob/master/src/php/lib/Grpc/BaseStub.php) Returns a MockBidiStreamingCall object that will stream items from $responses, and return a final status of $serverStreamingStatus.

static 
stripStatusFromResponses($responses)

No description

addResponse(Message $response, Status $status = null)

Add a response object, and an optional status, to the list of responses to be returned via _simpleRequest.

setStreamingStatus(Status $status)

Set the status object to be used when creating streaming calls.

popReceivedCalls()

Return a list of calls made to _simpleRequest, and clear $receivedFuncCalls.

int
getReceivedCallCount()

No description

mixed[]
popCallObjects()

No description

bool
isExhausted()

No description

static MockStubTrait
create(mixed $responseObject, $status = null, callable $deserialize = null)

No description

static MockStubTrait
createWithResponseSequence(mixed[] $sequence, callable $deserialize = null, Status $finalStatus = null)

Creates a sequence such that the responses are returned in order.

setAgentHeaderDescriptor($agentHeaderDescriptor)

No description

PromiseInterface
startUnaryCall(Call $call, array $options)

Returns a promise used to execute network requests.

startBidiStreamingCall(Call $call, array $options)

Starts a bidi streaming call.

startClientStreamingCall(Call $call, array $options)

Starts a client streaming call.

startServerStreamingCall(Call $call, array $options)

Starts a server streaming call.

__call($name, $arguments)

No description

close()

Closes the connection, if one exists.

Details

in MockStubTrait at line 52
__construct($deserialize = null)

Parameters

$deserialize

in MockStubTrait at line 68
MockUnaryCall _simpleRequest(string $method, Message $argument, callable $deserialize, array $metadata = [], array $options = [])

Overrides the _simpleRequest method in \Grpc\BaseStub (https://github.com/grpc/grpc/blob/master/src/php/lib/Grpc/BaseStub.php) Returns a MockUnaryCall object that will return the first item from $responses

Parameters

string $method The API method name to be called
Message $argument The request object to the API method
callable $deserialize A function to deserialize the response object
array $metadata
array $options

Return Value

MockUnaryCall

in MockStubTrait at line 98
MockClientStreamingCall _clientStreamRequest(string $method, callable $deserialize, array $metadata = [], array $options = [])

Overrides the _clientStreamRequest method in \Grpc\BaseStub (https://github.com/grpc/grpc/blob/master/src/php/lib/Grpc/BaseStub.php) Returns a MockClientStreamingCall object that will return the first item from $responses

Parameters

string $method The name of the method to call
callable $deserialize A function that deserializes the responses
array $metadata A metadata map to send to the server (optional)
array $options An array of options (optional)

Return Value

MockClientStreamingCall The active call object

in MockStubTrait at line 129
MockServerStreamingCall _serverStreamRequest(string $method, Message $argument, callable $deserialize, array $metadata = [], array $options = [])

Overrides the _serverStreamRequest method in \Grpc\BaseStub (https://github.com/grpc/grpc/blob/master/src/php/lib/Grpc/BaseStub.php) Returns a MockServerStreamingCall object that will stream items from $responses, and return a final status of $serverStreamingStatus.

Parameters

string $method The name of the method to call
Message $argument The argument to the method
callable $deserialize A function that deserializes the responses
array $metadata A metadata map to send to the server (optional)
array $options An array of options (optional)

Return Value

MockServerStreamingCall The active call object

in MockStubTrait at line 164
MockBidiStreamingCall _bidiRequest(string $method, callable $deserialize, array $metadata = [], array $options = [])

Overrides the _bidiRequest method in \Grpc\BaseStub (https://github.com/grpc/grpc/blob/master/src/php/lib/Grpc/BaseStub.php) Returns a MockBidiStreamingCall object that will stream items from $responses, and return a final status of $serverStreamingStatus.

Parameters

string $method The name of the method to call
callable $deserialize A function that deserializes the responses
array $metadata A metadata map to send to the server (optional)
array $options An array of options (optional)

Return Value

MockBidiStreamingCall The active call object

in MockStubTrait at line 179
static stripStatusFromResponses($responses)

Parameters

$responses

in MockStubTrait at line 195
addResponse(Message $response, Status $status = null)

Add a response object, and an optional status, to the list of responses to be returned via _simpleRequest.

Parameters

Message $response
Status $status

in MockStubTrait at line 212
setStreamingStatus(Status $status)

Set the status object to be used when creating streaming calls.

Parameters

Status $status

in MockStubTrait at line 222
ReceivedRequest[] popReceivedCalls()

Return a list of calls made to _simpleRequest, and clear $receivedFuncCalls.

Return Value

ReceivedRequest[] An array of received requests

in MockStubTrait at line 232
int getReceivedCallCount()

Return Value

int The number of calls received.

in MockStubTrait at line 240
mixed[] popCallObjects()

Return Value

mixed[] The call objects created by calls to the stub

in MockStubTrait at line 250
bool isExhausted()

Return Value

bool True if $receivedFuncCalls and $response are empty.

in MockStubTrait at line 262
static MockStubTrait create(mixed $responseObject, $status = null, callable $deserialize = null)

Parameters

mixed $responseObject
$status
callable $deserialize

Return Value

MockStubTrait An instance of the current class type.

in MockStubTrait at line 276
static MockStubTrait createWithResponseSequence(mixed[] $sequence, callable $deserialize = null, Status $finalStatus = null)

Creates a sequence such that the responses are returned in order.

Parameters

mixed[] $sequence
callable $deserialize
Status $finalStatus

Return Value

MockStubTrait An instance of the current class type.

at line 50
setAgentHeaderDescriptor($agentHeaderDescriptor)

Parameters

$agentHeaderDescriptor

at line 55
PromiseInterface startUnaryCall(Call $call, array $options)

Returns a promise used to execute network requests.

Parameters

Call $call
array $options

Return Value

PromiseInterface

at line 72
BidiStream startBidiStreamingCall(Call $call, array $options)

Starts a bidi streaming call.

Parameters

Call $call
array $options

Return Value

BidiStream

at line 79
ClientStream startClientStreamingCall(Call $call, array $options)

Starts a client streaming call.

Parameters

Call $call
array $options

Return Value

ClientStream

at line 86
ServerStream startServerStreamingCall(Call $call, array $options)

Starts a server streaming call.

Parameters

Call $call
array $options

Return Value

ServerStream

at line 93
__call($name, $arguments)

Parameters

$name
$arguments

at line 107
close()

Closes the connection, if one exists.