aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/php/tests/generated_code
diff options
context:
space:
mode:
authorGravatar vjpai <vpai@google.com>2015-11-02 09:22:10 -0800
committerGravatar vjpai <vpai@google.com>2015-11-02 09:22:10 -0800
commit11537dc71c2ceabf0a1e7f999f6c0e97f90c9f24 (patch)
tree988df3540106ca35309f2cfc8f91e14474e03564 /src/php/tests/generated_code
parent72a633213815f19ac04b51331287e3f7b075dcc1 (diff)
parent89ea0c78151b5bdc4c9236ae7100a7b97b32e499 (diff)
Merge remote-tracking branch 'upstream/master' into protosplit
Diffstat (limited to 'src/php/tests/generated_code')
-rw-r--r--src/php/tests/generated_code/AbstractGeneratedCodeTest.php384
-rwxr-xr-xsrc/php/tests/generated_code/GeneratedCodeTest.php19
-rw-r--r--src/php/tests/generated_code/GeneratedCodeWithCallbackTest.php34
-rw-r--r--src/php/tests/generated_code/math_client.php55
4 files changed, 264 insertions, 228 deletions
diff --git a/src/php/tests/generated_code/AbstractGeneratedCodeTest.php b/src/php/tests/generated_code/AbstractGeneratedCodeTest.php
index 1819e401f6..4a0bd6a1f1 100644
--- a/src/php/tests/generated_code/AbstractGeneratedCodeTest.php
+++ b/src/php/tests/generated_code/AbstractGeneratedCodeTest.php
@@ -31,184 +31,212 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
-require_once realpath(dirname(__FILE__) . '/../../vendor/autoload.php');
-require_once dirname(__FILE__) . '/math.php';
-
-abstract class AbstractGeneratedCodeTest extends PHPUnit_Framework_TestCase {
- /* These tests require that a server exporting the math service must be
- * running on $GRPC_TEST_HOST */
- protected static $client;
- protected static $timeout;
-
- public function testWaitForNotReady() {
- $this->assertFalse(self::$client->waitForReady(1));
- }
-
- public function testWaitForReady() {
- $this->assertTrue(self::$client->waitForReady(250000));
- }
-
- public function testAlreadyReady() {
- $this->assertTrue(self::$client->waitForReady(250000));
- $this->assertTrue(self::$client->waitForReady(100));
- }
-
- public function testGetTarget() {
- $this->assertTrue(is_string(self::$client->getTarget()));
- }
-
- /**
- * @expectedException InvalidArgumentException
- */
- public function testClose() {
- self::$client->close();
- $div_arg = new math\DivArgs();
- $call = self::$client->Div($div_arg);
- }
-
- /**
- * @expectedException InvalidArgumentException
- */
- public function testInvalidMetadata() {
- $div_arg = new math\DivArgs();
- $call = self::$client->Div($div_arg, array(' ' => 'abc123'));
- }
-
- public function testGetCallMetadata() {
- $div_arg = new math\DivArgs();
- $call = self::$client->Div($div_arg);
- $this->assertTrue(is_array($call->getMetadata()));
- }
-
- public function testTimeout() {
- $div_arg = new math\DivArgs();
- $call = self::$client->Div($div_arg, array('timeout' => 100));
- list($response, $status) = $call->wait();
- $this->assertSame(\Grpc\STATUS_DEADLINE_EXCEEDED, $status->code);
- }
-
- public function testCancel() {
- $div_arg = new math\DivArgs();
- $call = self::$client->Div($div_arg);
- $call->cancel();
- list($response, $status) = $call->wait();
- $this->assertSame(\Grpc\STATUS_CANCELLED, $status->code);
- }
-
- /**
- * @expectedException InvalidArgumentException
- */
- public function testInvalidMethodName() {
- $invalid_client = new DummyInvalidClient('host', array());
- $div_arg = new math\DivArgs();
- $invalid_client->InvalidUnaryCall($div_arg);
- }
-
- public function testWriteFlags() {
- $div_arg = new math\DivArgs();
- $div_arg->setDividend(7);
- $div_arg->setDivisor(4);
- $call = self::$client->Div($div_arg, array(), array('flags' => Grpc\WRITE_NO_COMPRESS));
- $this->assertTrue(is_string($call->getPeer()));
- list($response, $status) = $call->wait();
- $this->assertSame(1, $response->getQuotient());
- $this->assertSame(3, $response->getRemainder());
- $this->assertSame(\Grpc\STATUS_OK, $status->code);
- }
-
- public function testWriteFlagsServerStreaming() {
- $fib_arg = new math\FibArgs();
- $fib_arg->setLimit(7);
- $call = self::$client->Fib($fib_arg, array(), array('flags' => Grpc\WRITE_NO_COMPRESS));
- $result_array = iterator_to_array($call->responses());
- $status = $call->getStatus();
- $this->assertSame(\Grpc\STATUS_OK, $status->code);
- }
-
- public function testWriteFlagsClientStreaming() {
- $call = self::$client->Sum();
- $num = new math\Num();
- $num->setNum(1);
- $call->write($num, array('flags' => Grpc\WRITE_NO_COMPRESS));
- list($response, $status) = $call->wait();
- $this->assertSame(\Grpc\STATUS_OK, $status->code);
- }
-
- public function testWriteFlagsBidiStreaming() {
- $call = self::$client->DivMany();
- $div_arg = new math\DivArgs();
- $div_arg->setDividend(7);
- $div_arg->setDivisor(4);
- $call->write($div_arg, array('flags' => Grpc\WRITE_NO_COMPRESS));
- $response = $call->read();
- $call->writesDone();
- $status = $call->getStatus();
- $this->assertSame(\Grpc\STATUS_OK, $status->code);
- }
-
- public function testSimpleRequest() {
- $div_arg = new math\DivArgs();
- $div_arg->setDividend(7);
- $div_arg->setDivisor(4);
- $call = self::$client->Div($div_arg);
- $this->assertTrue(is_string($call->getPeer()));
- list($response, $status) = $call->wait();
- $this->assertSame(1, $response->getQuotient());
- $this->assertSame(3, $response->getRemainder());
- $this->assertSame(\Grpc\STATUS_OK, $status->code);
- }
-
- public function testServerStreaming() {
- $fib_arg = new math\FibArgs();
- $fib_arg->setLimit(7);
- $call = self::$client->Fib($fib_arg);
- $this->assertTrue(is_string($call->getPeer()));
- $result_array = iterator_to_array($call->responses());
- $extract_num = function($num){
- return $num->getNum();
- };
- $values = array_map($extract_num, $result_array);
- $this->assertSame([1, 1, 2, 3, 5, 8, 13], $values);
- $status = $call->getStatus();
- $this->assertSame(\Grpc\STATUS_OK, $status->code);
- }
-
- 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);
- }
-
- public function testBidiStreaming() {
- $call = self::$client->DivMany();
- $this->assertTrue(is_string($call->getPeer()));
- for ($i = 0; $i < 7; $i++) {
- $div_arg = new math\DivArgs();
- $div_arg->setDividend(2 * $i + 1);
- $div_arg->setDivisor(2);
- $call->write($div_arg);
- $response = $call->read();
- $this->assertSame($i, $response->getQuotient());
- $this->assertSame(1, $response->getRemainder());
- }
- $call->writesDone();
- $status = $call->getStatus();
- $this->assertSame(\Grpc\STATUS_OK, $status->code);
- }
+require_once realpath(dirname(__FILE__).'/../../vendor/autoload.php');
+require_once dirname(__FILE__).'/math.php';
+
+abstract class AbstractGeneratedCodeTest extends PHPUnit_Framework_TestCase
+{
+ /**
+ * These tests require that a server exporting the math service must be
+ * running on $GRPC_TEST_HOST.
+ */
+ protected static $client;
+ protected static $timeout;
+
+ public function testWaitForNotReady()
+ {
+ $this->assertFalse(self::$client->waitForReady(1));
+ }
+
+ public function testWaitForReady()
+ {
+ $this->assertTrue(self::$client->waitForReady(250000));
+ }
+
+ public function testAlreadyReady()
+ {
+ $this->assertTrue(self::$client->waitForReady(250000));
+ $this->assertTrue(self::$client->waitForReady(100));
+ }
+
+ public function testGetTarget()
+ {
+ $this->assertTrue(is_string(self::$client->getTarget()));
+ }
+
+ /**
+ * @expectedException InvalidArgumentException
+ */
+ public function testClose()
+ {
+ self::$client->close();
+ $div_arg = new math\DivArgs();
+ $call = self::$client->Div($div_arg);
+ }
+
+ /**
+ * @expectedException InvalidArgumentException
+ */
+ public function testInvalidMetadata()
+ {
+ $div_arg = new math\DivArgs();
+ $call = self::$client->Div($div_arg, [' ' => 'abc123']);
+ }
+
+ public function testGetCallMetadata()
+ {
+ $div_arg = new math\DivArgs();
+ $call = self::$client->Div($div_arg);
+ $this->assertTrue(is_array($call->getMetadata()));
+ }
+
+ public function testTimeout()
+ {
+ $div_arg = new math\DivArgs();
+ $call = self::$client->Div($div_arg, ['timeout' => 100]);
+ list($response, $status) = $call->wait();
+ $this->assertSame(\Grpc\STATUS_DEADLINE_EXCEEDED, $status->code);
+ }
+
+ public function testCancel()
+ {
+ $div_arg = new math\DivArgs();
+ $call = self::$client->Div($div_arg);
+ $call->cancel();
+ list($response, $status) = $call->wait();
+ $this->assertSame(\Grpc\STATUS_CANCELLED, $status->code);
+ }
+
+ /**
+ * @expectedException InvalidArgumentException
+ */
+ public function testInvalidMethodName()
+ {
+ $invalid_client = new DummyInvalidClient('host', []);
+ $div_arg = new math\DivArgs();
+ $invalid_client->InvalidUnaryCall($div_arg);
+ }
+
+ public function testWriteFlags()
+ {
+ $div_arg = new math\DivArgs();
+ $div_arg->setDividend(7);
+ $div_arg->setDivisor(4);
+ $call = self::$client->Div($div_arg, [],
+ ['flags' => Grpc\WRITE_NO_COMPRESS]);
+ $this->assertTrue(is_string($call->getPeer()));
+ list($response, $status) = $call->wait();
+ $this->assertSame(1, $response->getQuotient());
+ $this->assertSame(3, $response->getRemainder());
+ $this->assertSame(\Grpc\STATUS_OK, $status->code);
+ }
+
+ public function testWriteFlagsServerStreaming()
+ {
+ $fib_arg = new math\FibArgs();
+ $fib_arg->setLimit(7);
+ $call = self::$client->Fib($fib_arg, [],
+ ['flags' => Grpc\WRITE_NO_COMPRESS]);
+ $result_array = iterator_to_array($call->responses());
+ $status = $call->getStatus();
+ $this->assertSame(\Grpc\STATUS_OK, $status->code);
+ }
+
+ public function testWriteFlagsClientStreaming()
+ {
+ $call = self::$client->Sum();
+ $num = new math\Num();
+ $num->setNum(1);
+ $call->write($num, ['flags' => Grpc\WRITE_NO_COMPRESS]);
+ list($response, $status) = $call->wait();
+ $this->assertSame(\Grpc\STATUS_OK, $status->code);
+ }
+
+ public function testWriteFlagsBidiStreaming()
+ {
+ $call = self::$client->DivMany();
+ $div_arg = new math\DivArgs();
+ $div_arg->setDividend(7);
+ $div_arg->setDivisor(4);
+ $call->write($div_arg, ['flags' => Grpc\WRITE_NO_COMPRESS]);
+ $response = $call->read();
+ $call->writesDone();
+ $status = $call->getStatus();
+ $this->assertSame(\Grpc\STATUS_OK, $status->code);
+ }
+
+ public function testSimpleRequest()
+ {
+ $div_arg = new math\DivArgs();
+ $div_arg->setDividend(7);
+ $div_arg->setDivisor(4);
+ $call = self::$client->Div($div_arg);
+ $this->assertTrue(is_string($call->getPeer()));
+ list($response, $status) = $call->wait();
+ $this->assertSame(1, $response->getQuotient());
+ $this->assertSame(3, $response->getRemainder());
+ $this->assertSame(\Grpc\STATUS_OK, $status->code);
+ }
+
+ public function testServerStreaming()
+ {
+ $fib_arg = new math\FibArgs();
+ $fib_arg->setLimit(7);
+ $call = self::$client->Fib($fib_arg);
+ $this->assertTrue(is_string($call->getPeer()));
+ $result_array = iterator_to_array($call->responses());
+ $extract_num = function ($num) {
+ return $num->getNum();
+ };
+ $values = array_map($extract_num, $result_array);
+ $this->assertSame([1, 1, 2, 3, 5, 8, 13], $values);
+ $status = $call->getStatus();
+ $this->assertSame(\Grpc\STATUS_OK, $status->code);
+ }
+
+ 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);
+ }
+
+ public function testBidiStreaming()
+ {
+ $call = self::$client->DivMany();
+ $this->assertTrue(is_string($call->getPeer()));
+ for ($i = 0; $i < 7; ++$i) {
+ $div_arg = new math\DivArgs();
+ $div_arg->setDividend(2 * $i + 1);
+ $div_arg->setDivisor(2);
+ $call->write($div_arg);
+ $response = $call->read();
+ $this->assertSame($i, $response->getQuotient());
+ $this->assertSame(1, $response->getRemainder());
+ }
+ $call->writesDone();
+ $status = $call->getStatus();
+ $this->assertSame(\Grpc\STATUS_OK, $status->code);
+ }
}
-class DummyInvalidClient extends \Grpc\BaseStub {
- public function InvalidUnaryCall(\math\DivArgs $argument,
- $metadata = array(),
- $options = array()) {
- return $this->_simpleRequest('invalidMethodName', $argument,
- function() {}, $metadata, $options);
- }
+class DummyInvalidClient extends \Grpc\BaseStub
+{
+ public function InvalidUnaryCall(\math\DivArgs $argument,
+ $metadata = [],
+ $options = [])
+ {
+ return $this->_simpleRequest('invalidMethodName',
+ $argument,
+ function () {},
+ $metadata,
+ $options);
+ }
}
diff --git a/src/php/tests/generated_code/GeneratedCodeTest.php b/src/php/tests/generated_code/GeneratedCodeTest.php
index 64bcf45b4a..7043e8e1d1 100755
--- a/src/php/tests/generated_code/GeneratedCodeTest.php
+++ b/src/php/tests/generated_code/GeneratedCodeTest.php
@@ -31,15 +31,18 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
-require_once dirname(__FILE__) . '/AbstractGeneratedCodeTest.php';
+require_once dirname(__FILE__).'/AbstractGeneratedCodeTest.php';
-class GeneratedCodeTest extends AbstractGeneratedCodeTest {
- public function setUp() {
- self::$client = new math\MathClient(
+class GeneratedCodeTest extends AbstractGeneratedCodeTest
+{
+ public function setUp()
+ {
+ self::$client = new math\MathClient(
getenv('GRPC_TEST_HOST'), []);
- }
+ }
- public static function tearDownAfterClass() {
- self::$client->close();
- }
+ public static function tearDownAfterClass()
+ {
+ self::$client->close();
+ }
}
diff --git a/src/php/tests/generated_code/GeneratedCodeWithCallbackTest.php b/src/php/tests/generated_code/GeneratedCodeWithCallbackTest.php
index 09c09cf353..5a20e684c7 100644
--- a/src/php/tests/generated_code/GeneratedCodeWithCallbackTest.php
+++ b/src/php/tests/generated_code/GeneratedCodeWithCallbackTest.php
@@ -31,21 +31,25 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
-require_once dirname(__FILE__) . '/AbstractGeneratedCodeTest.php';
+require_once dirname(__FILE__).'/AbstractGeneratedCodeTest.php';
-class GeneratedCodeWithCallbackTest extends AbstractGeneratedCodeTest {
- public function setUp() {
- self::$client = new math\MathClient(
- getenv('GRPC_TEST_HOST'), ['update_metadata' =>
- function($a_hash,
- $client = array()) {
- $a_copy = $a_hash;
- $a_copy['foo'] = ['bar'];
- return $a_copy;
- }]);
- }
+class GeneratedCodeWithCallbackTest extends AbstractGeneratedCodeTest
+{
+ public function setUp()
+ {
+ self::$client = new math\MathClient(
+ getenv('GRPC_TEST_HOST'),
+ ['update_metadata' => function ($a_hash,
+ $client = []) {
+ $a_copy = $a_hash;
+ $a_copy['foo'] = ['bar'];
- public static function tearDownAfterClass() {
- self::$client->close();
- }
+ return $a_copy;
+ }]);
+ }
+
+ public static function tearDownAfterClass()
+ {
+ self::$client->close();
+ }
}
diff --git a/src/php/tests/generated_code/math_client.php b/src/php/tests/generated_code/math_client.php
index 7bc78287be..76ccabc068 100644
--- a/src/php/tests/generated_code/math_client.php
+++ b/src/php/tests/generated_code/math_client.php
@@ -36,31 +36,32 @@
include 'vendor/autoload.php';
include 'tests/generated_code/math.php';
-function p($line) {
- print("$line<br/>\n");
+function p($line)
+{
+ print("$line<br/>\n");
}
-$host = "localhost:50051";
+$host = 'localhost:50051';
p("Connecting to host: $host");
$client = new math\MathClient($host, []);
-p("Client class: ".get_class($client));
+p('Client class: '.get_class($client));
p('');
-p("Running unary call test:");
+p('Running unary call test:');
$dividend = 7;
$divisor = 4;
$div_arg = new math\DivArgs();
$div_arg->setDividend($dividend);
$div_arg->setDivisor($divisor);
$call = $client->Div($div_arg);
-p("Call peer: ".$call->getPeer());
+p('Call peer: '.$call->getPeer());
p("Dividing $dividend by $divisor");
list($response, $status) = $call->wait();
-p("quotient = ".$response->getQuotient());
-p("remainder = ".$response->getRemainder());
+p('quotient = '.$response->getQuotient());
+p('remainder = '.$response->getRemainder());
p('');
-p("Running server streaming test:");
+p('Running server streaming test:');
$limit = 7;
$fib_arg = new math\FibArgs();
$fib_arg->setLimit($limit);
@@ -68,35 +69,35 @@ $call = $client->Fib($fib_arg);
$result_array = iterator_to_array($call->responses());
$result = '';
foreach ($result_array as $num) {
- $result .= ' '.$num->getNum();
+ $result .= ' '.$num->getNum();
}
p("The first $limit Fibonacci numbers are:".$result);
p('');
-p("Running client streaming test:");
+p('Running client streaming test:');
$call = $client->Sum();
-for ($i = 0; $i <= $limit; $i++) {
- $num = new math\Num();
- $num->setNum($i);
- $call->write($num);
+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",
+p(sprintf('The first %d positive integers sum to: %d',
$limit, $response->getNum()));
p('');
-p("Running bidi-streaming test:");
+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);
- p("client writing: $dividend / $divisor");
- $response = $call->read();
- p(sprintf("server writing: quotient = %d, remainder = %d",
+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);
+ p("client writing: $dividend / $divisor");
+ $response = $call->read();
+ p(sprintf('server writing: quotient = %d, remainder = %d',
$response->getQuotient(), $response->getRemainder()));
}
$call->writesDone();