aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/php/tests/unit_tests/ServerTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/php/tests/unit_tests/ServerTest.php')
-rw-r--r--src/php/tests/unit_tests/ServerTest.php85
1 files changed, 82 insertions, 3 deletions
diff --git a/src/php/tests/unit_tests/ServerTest.php b/src/php/tests/unit_tests/ServerTest.php
index 76aaa06970..f2346ab113 100644
--- a/src/php/tests/unit_tests/ServerTest.php
+++ b/src/php/tests/unit_tests/ServerTest.php
@@ -36,10 +36,70 @@ class ServerTest extends PHPUnit_Framework_TestCase
{
public function setUp()
{
+ $this->server = null;
}
public function tearDown()
{
+ unset($this->server);
+ }
+
+ public function testConstructorWithNull()
+ {
+ $this->server = new Grpc\Server();
+ $this->assertNotNull($this->server);
+ }
+
+ public function testConstructorWithNullArray()
+ {
+ $this->server = new Grpc\Server([]);
+ $this->assertNotNull($this->server);
+ }
+
+ public function testConstructorWithArray()
+ {
+ // key of array must be string
+ $this->server = new Grpc\Server(['ip' => '127.0.0.1',
+ 'port' => '8080', ]);
+ $this->assertNotNull($this->server);
+ }
+
+ public function testRequestCall()
+ {
+ $this->server = new Grpc\Server();
+ $port = $this->server->addHttp2Port('0.0.0.0:8888');
+ $this->server->start();
+ $channel = new Grpc\Channel('localhost:8888',
+ ['credentials' => Grpc\ChannelCredentials::createInsecure()]);
+
+ $deadline = Grpc\Timeval::infFuture();
+ $call = new Grpc\Call($channel, 'dummy_method', $deadline);
+
+ $event = $call->startBatch([Grpc\OP_SEND_INITIAL_METADATA => [],
+ Grpc\OP_SEND_CLOSE_FROM_CLIENT => true,
+ ]);
+
+ $c = $this->server->requestCall();
+ $this->assertObjectHasAttribute('call', $c);
+ $this->assertObjectHasAttribute('method', $c);
+ $this->assertSame('dummy_method', $c->method);
+ $this->assertObjectHasAttribute('host', $c);
+ $this->assertTrue(is_string($c->host));
+ $this->assertObjectHasAttribute('absolute_deadline', $c);
+ $this->assertObjectHasAttribute('metadata', $c);
+
+ unset($call);
+ unset($channel);
+ }
+
+ private function createSslObj()
+ {
+ $server_credentials = Grpc\ServerCredentials::createSsl(
+ null,
+ file_get_contents(dirname(__FILE__).'/../data/server1.key'),
+ file_get_contents(dirname(__FILE__).'/../data/server1.pem'));
+
+ return $server_credentials;
}
/**
@@ -47,7 +107,8 @@ class ServerTest extends PHPUnit_Framework_TestCase
*/
public function testInvalidConstructor()
{
- $server = new Grpc\Server('invalid_host');
+ $this->server = new Grpc\Server('invalid_host');
+ $this->assertNull($this->server);
}
/**
@@ -56,7 +117,7 @@ class ServerTest extends PHPUnit_Framework_TestCase
public function testInvalidAddHttp2Port()
{
$this->server = new Grpc\Server([]);
- $this->port = $this->server->addHttp2Port(['0.0.0.0:0']);
+ $port = $this->server->addHttp2Port(['0.0.0.0:0']);
}
/**
@@ -65,6 +126,24 @@ class ServerTest extends PHPUnit_Framework_TestCase
public function testInvalidAddSecureHttp2Port()
{
$this->server = new Grpc\Server([]);
- $this->port = $this->server->addSecureHttp2Port(['0.0.0.0:0']);
+ $port = $this->server->addSecureHttp2Port(['0.0.0.0:0']);
+ }
+
+ /**
+ * @expectedException InvalidArgumentException
+ */
+ public function testInvalidAddSecureHttp2Port2()
+ {
+ $this->server = new Grpc\Server();
+ $port = $this->server->addSecureHttp2Port('0.0.0.0:0');
+ }
+
+ /**
+ * @expectedException InvalidArgumentException
+ */
+ public function testInvalidAddSecureHttp2Port3()
+ {
+ $this->server = new Grpc\Server();
+ $port = $this->server->addSecureHttp2Port('0.0.0.0:0', 'invalid');
}
}