|
46 | 46 | use Google\ApiCore\ServerStream; |
47 | 47 | use Google\ApiCore\Testing\MockRequest; |
48 | 48 | use Google\ApiCore\Testing\MockRequestBody; |
| 49 | +use Google\ApiCore\Testing\MockResponse; |
49 | 50 | use Google\ApiCore\Transport\GrpcFallbackTransport; |
50 | 51 | use Google\ApiCore\Transport\GrpcTransport; |
51 | 52 | use Google\ApiCore\Transport\RestTransport; |
@@ -271,6 +272,59 @@ public function testStartApiCallOperation() |
271 | 272 | $this->assertEquals($expectedResponse, $response); |
272 | 273 | } |
273 | 274 |
|
| 275 | + public function testStartApiCallCustomOperation() |
| 276 | + { |
| 277 | + $header = AgentHeader::buildAgentHeader([]); |
| 278 | + $retrySettings = $this->getMockBuilder(RetrySettings::class) |
| 279 | + ->disableOriginalConstructor() |
| 280 | + ->getMock(); |
| 281 | + |
| 282 | + $longRunningDescriptors = [ |
| 283 | + 'callType' => Call::LONGRUNNING_CALL, |
| 284 | + 'responseType' => 'Google\ApiCore\Testing\MockResponse', |
| 285 | + 'longRunning' => [ |
| 286 | + 'operationReturnType' => 'operationType', |
| 287 | + 'metadataReturnType' => 'metadataType', |
| 288 | + 'initialPollDelayMillis' => 100, |
| 289 | + 'pollDelayMultiplier' => 1.0, |
| 290 | + 'maxPollDelayMillis' => 200, |
| 291 | + 'totalPollTimeoutMillis' => 300, |
| 292 | + ] |
| 293 | + ]; |
| 294 | + $expectedPromise = new FulfilledPromise(new MockResponse()); |
| 295 | + $transport = $this->getMockBuilder(TransportInterface::class)->getMock(); |
| 296 | + $transport->expects($this->once()) |
| 297 | + ->method('startUnaryCall') |
| 298 | + ->will($this->returnValue($expectedPromise)); |
| 299 | + $credentialsWrapper = CredentialsWrapper::build([]); |
| 300 | + $client = new GapicClientTraitOperationsStub(); |
| 301 | + $client->set('transport', $transport); |
| 302 | + $client->set('credentialsWrapper', $credentialsWrapper); |
| 303 | + $client->set('agentHeader', $header); |
| 304 | + $client->set('retrySettings', ['method' => $retrySettings]); |
| 305 | + $client->set('descriptors', ['method' => $longRunningDescriptors]); |
| 306 | + $operationsClient = $this->getMockBuilder(OperationsClient::class) |
| 307 | + ->disableOriginalConstructor() |
| 308 | + ->setMethodsExcept(['validate']) |
| 309 | + ->getMock(); |
| 310 | + $client->set('operationsClient', $operationsClient); |
| 311 | + |
| 312 | + $request = new MockRequest(); |
| 313 | + $response = $client->call('startApiCall', [ |
| 314 | + 'method', |
| 315 | + /* interfaceName */ null, |
| 316 | + $request, |
| 317 | + ])->wait(); |
| 318 | + |
| 319 | + $expectedResponse = new OperationResponse( |
| 320 | + '', |
| 321 | + $operationsClient, |
| 322 | + $longRunningDescriptors['longRunning'] + ['lastProtoResponse' => new MockResponse()] |
| 323 | + ); |
| 324 | + |
| 325 | + $this->assertEquals($expectedResponse, $response); |
| 326 | + } |
| 327 | + |
274 | 328 | /** |
275 | 329 | * @dataProvider startApiCallExceptions |
276 | 330 | */ |
@@ -339,7 +393,7 @@ public function testStartApiCallUnary() |
339 | 393 | ->getMock(); |
340 | 394 | $unaryDescriptors = [ |
341 | 395 | 'callType' => Call::UNARY_CALL, |
342 | | - 'responseType' => 'Google\Longrunning\Operation::class' |
| 396 | + 'responseType' => 'Google\Longrunning\Operation' |
343 | 397 | ]; |
344 | 398 | $expectedPromise = new FulfilledPromise(new Operation()); |
345 | 399 | $transport = $this->getMockBuilder(TransportInterface::class)->getMock(); |
@@ -370,7 +424,7 @@ public function testStartApiCallPaged() |
370 | 424 | ->getMock(); |
371 | 425 | $pagedDescriptors = [ |
372 | 426 | 'callType' => Call::PAGINATED_CALL, |
373 | | - 'responseType' => 'Google\Longrunning\ListOperationsResponse::class', |
| 427 | + 'responseType' => 'Google\Longrunning\ListOperationsResponse', |
374 | 428 | 'pageStreaming' => [ |
375 | 429 | 'requestPageTokenGetMethod' => 'getPageToken', |
376 | 430 | 'requestPageTokenSetMethod' => 'setPageToken', |
|
0 commit comments