PHP code example of beloys / stub-grpc

1. Go to this page and download the library: Download beloys/stub-grpc library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

beloys / stub-grpc example snippets


use Beloys\StubGrpc\StubGrpc;
use Grpc\Health\V1\HealthCheckResponse;
use Grpc\Health\V1\HealthCheckRequest;
use Grpc\Health\V1\HealthClient;

$mock = StubGrpc::make(HealthClient::class, [
    '/grpc.health.v1.Health/Check' => new HealthCheckResponse(['status' => HealthCheckResponse\ServingStatus::SERVING]),
]);

$mock = StubGrpc::make(HealthClient::class, [
    '/grpc.health.v1.Health/Check' => function(HealthCheckRequest $in){
        return [new HealthCheckResponse(), null];
    },
]);

$mock = (new StubGrpc(HealthClient::class))
  ->methodWillReturn('/cyberxpert.grpc.user.User/ViewByUuid', new HealthCheckResponse(), (object)['status' => 1])
  ->build();