Example #1
0
 public function testClientStreaming()
 {
     $num_iter = function () {
         for ($i = 0; $i < 7; $i++) {
             $num = new math\Num();
             $num->setNum($i);
             (yield $num);
         }
     };
     $call = self::$client->Sum($num_iter());
     list($response, $status) = $call->wait();
     $this->assertSame(21, $response->getNum());
     $this->assertSame(\Grpc\STATUS_OK, $status->code);
 }
Example #2
0
p("Running server streaming test:");
$limit = 7;
$fib_arg = new math\FibArgs();
$fib_arg->setLimit($limit);
$call = $client->Fib($fib_arg);
$result_array = iterator_to_array($call->responses());
$result = '';
foreach ($result_array as $num) {
    $result .= ' ' . $num->getNum();
}
p("The first {$limit} Fibonacci numbers are:" . $result);
p('');
p("Running client streaming test:");
$call = $client->Sum();
for ($i = 0; $i <= $limit; $i++) {
    $num = new math\Num();
    $num->setNum($i);
    $call->write($num);
}
list($response, $status) = $call->wait();
p(sprintf("The first %d positive integers sum to: %d", $limit, $response->getNum()));
p('');
p("Running bidi-streaming test:");
$call = $client->DivMany();
for ($i = 0; $i < 7; $i++) {
    $div_arg = new math\DivArgs();
    $dividend = 2 * $i + 1;
    $divisor = 3;
    $div_arg->setDividend($dividend);
    $div_arg->setDivisor($divisor);
    $call->write($div_arg);
 public function testClientStreaming()
 {
     $call = self::$client->Sum();
     $this->assertTrue(is_string($call->getPeer()));
     for ($i = 0; $i < 7; ++$i) {
         $num = new math\Num();
         $num->setNum($i);
         $call->write($num);
     }
     list($response, $status) = $call->wait();
     $this->assertSame(21, $response->getNum());
     $this->assertSame(\Grpc\STATUS_OK, $status->code);
 }