Comments (1)
Hi @Livijn
Thanks for filling the issue.
There is a way to mock responses for every API call using the transportOptions.restOptions.handler
configuration for REST, but the issue is that every response needs to be de-serialized into a relevant protobuf object.
Consider the batchAnnotateImages method of the ImageAnnotatorGapicClient.
This method returns an instance of the BatchAnnotateImagesResponse
class, so it expects the relevant data to be present in the mocked response.
Although, I can't speak for the use of the following snippet in production by any means, but the following did work for me:
$client = new ImageAnnotatorClient();
$requests = [];
// $batchResponse is an instance of the BatchAnnotateImagesResponse class
$batchResponse = $client->batchAnnotateImages($requests, [
'transportOptions' => [
'restOptions' => [
'handler' => function () {
// I am using the serializer here to easily convert the array to an instance of BatchAnnotateImagesResponse
$serializer = new Serializer();
$response = $serializer->decodeMessage(
new BatchAnnotateImagesResponse,
['responses' => [
['context' => ['uri' => 'https://google.com']]
]]);
return new Response(200, ['content-type' => 'application/json'], $obj->serializeToJsonString());
}
]
]
]);
foreach($batchResponse->getResponses() as $row) {
// $row is an instance of the Google\Cloud\Vision\V1\AnnotateImageResponse class
echo $row->getContext()->getUri(); // https://google.com
}
You can mock an empty array by just using $obj = new BatchAnnotateImagesResponse([])
. I don't know if that works for your testing, but this is the information I have.
Closing this issue for now, but please reopen this for more discussion.
from google-cloud-php.
Related Issues (20)
- GCP Secret Manager empty reply/broken pipe on Ubuntu 22 VM in PHP HOT 1
- Alpha AnalyticsData is missing `Client/AlphaAnalyticsDataClient.php` HOT 4
- Something went wrong, please try again or contact support with this ticket:65a29774bf47a65a29774bf47c65a29774bf47d HOT 1
- BigQuery Storage API basic example doesn't work HOT 4
- `BetaAnalyticsDataClient` is documented as deprecated HOT 1
- Segmentation Fault on exists HOT 2
- storage: Add Support for manual managed folders feature includeFolders
- Recapcha: Wrong score conversion
- logging php 500 Internal server error HOT 2
- storage: add soft delete feature
- Field "document" is a required field, but no value is found. HOT 1
- [Spanner] Randomly getting ServiceException: Request is missing required authentication credential. HOT 2
- storage: sometimes ResumableUploader crashes on resume() HOT 2
- Fatal Error in RequestHandler class with emulator without GRPC extension HOT 7
- ci: enable flakybot for test failure detection HOT 3
- Fatal error: Uncaught Error: Undefined class constant 'RETRY_HEADER_KEY' HOT 8
- Cohort report not returning expected values. HOT 1
- storage: Support Storage Control Quickstart HOT 2
- Feature Request: Move python dependency on "gcs-updater" to the backend
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from google-cloud-php.