aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/php/tests/generated_code/AbstractGeneratedCodeTest.php
diff options
context:
space:
mode:
authorGravatar Stanley Cheung <stanleycheung@google.com>2015-10-20 16:27:55 -0700
committerGravatar Stanley Cheung <stanleycheung@google.com>2015-10-20 16:27:55 -0700
commit75457ff7e15263fd659049d7b09a382dde706aea (patch)
treea8662c7432aba0790c2684c7bc6d9d7419db0d23 /src/php/tests/generated_code/AbstractGeneratedCodeTest.php
parent63544f78083fa03bbbf7c2c212c9f5ba968425e2 (diff)
php: add more unit test for code coverage analysis
Diffstat (limited to 'src/php/tests/generated_code/AbstractGeneratedCodeTest.php')
-rw-r--r--src/php/tests/generated_code/AbstractGeneratedCodeTest.php84
1 files changed, 84 insertions, 0 deletions
diff --git a/src/php/tests/generated_code/AbstractGeneratedCodeTest.php b/src/php/tests/generated_code/AbstractGeneratedCodeTest.php
index 940635389b..1819e401f6 100644
--- a/src/php/tests/generated_code/AbstractGeneratedCodeTest.php
+++ b/src/php/tests/generated_code/AbstractGeneratedCodeTest.php
@@ -33,6 +33,7 @@
*/
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 */
@@ -47,6 +48,11 @@ abstract class AbstractGeneratedCodeTest extends PHPUnit_Framework_TestCase {
$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()));
}
@@ -54,11 +60,50 @@ abstract class AbstractGeneratedCodeTest extends PHPUnit_Framework_TestCase {
/**
* @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);
@@ -71,6 +116,36 @@ abstract class AbstractGeneratedCodeTest extends PHPUnit_Framework_TestCase {
$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);
@@ -128,3 +203,12 @@ abstract class AbstractGeneratedCodeTest extends PHPUnit_Framework_TestCase {
$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);
+ }
+}