33
33
*/
34
34
require_once realpath (dirname (__FILE__ ) . '/../../vendor/autoload.php ' );
35
35
require_once dirname (__FILE__ ) . '/math.php ' ;
36
+
36
37
abstract class AbstractGeneratedCodeTest extends PHPUnit_Framework_TestCase {
37
38
/* These tests require that a server exporting the math service must be
38
39
* running on $GRPC_TEST_HOST */
@@ -47,10 +48,24 @@ public function testWaitForReady() {
47
48
$ this ->assertTrue (self ::$ client ->waitForReady (250000 ));
48
49
}
49
50
51
+ public function testAlreadyReady () {
52
+ $ this ->assertTrue (self ::$ client ->waitForReady (250000 ));
53
+ $ this ->assertTrue (self ::$ client ->waitForReady (100 ));
54
+ }
55
+
50
56
public function testGetTarget () {
51
57
$ this ->assertTrue (is_string (self ::$ client ->getTarget ()));
52
58
}
53
59
60
+ /**
61
+ * @expectedException InvalidArgumentException
62
+ */
63
+ public function testClose () {
64
+ self ::$ client ->close ();
65
+ $ div_arg = new math \DivArgs ();
66
+ $ call = self ::$ client ->Div ($ div_arg );
67
+ }
68
+
54
69
/**
55
70
* @expectedException InvalidArgumentException
56
71
*/
@@ -59,6 +74,36 @@ public function testInvalidMetadata() {
59
74
$ call = self ::$ client ->Div ($ div_arg , array (' ' => 'abc123 ' ));
60
75
}
61
76
77
+ public function testGetCallMetadata () {
78
+ $ div_arg = new math \DivArgs ();
79
+ $ call = self ::$ client ->Div ($ div_arg );
80
+ $ this ->assertTrue (is_array ($ call ->getMetadata ()));
81
+ }
82
+
83
+ public function testTimeout () {
84
+ $ div_arg = new math \DivArgs ();
85
+ $ call = self ::$ client ->Div ($ div_arg , array ('timeout ' => 100 ));
86
+ list ($ response , $ status ) = $ call ->wait ();
87
+ $ this ->assertSame (\Grpc \STATUS_DEADLINE_EXCEEDED , $ status ->code );
88
+ }
89
+
90
+ public function testCancel () {
91
+ $ div_arg = new math \DivArgs ();
92
+ $ call = self ::$ client ->Div ($ div_arg );
93
+ $ call ->cancel ();
94
+ list ($ response , $ status ) = $ call ->wait ();
95
+ $ this ->assertSame (\Grpc \STATUS_CANCELLED , $ status ->code );
96
+ }
97
+
98
+ /**
99
+ * @expectedException InvalidArgumentException
100
+ */
101
+ public function testInvalidMethodName () {
102
+ $ invalid_client = new DummyInvalidClient ('host ' , array ());
103
+ $ div_arg = new math \DivArgs ();
104
+ $ invalid_client ->InvalidUnaryCall ($ div_arg );
105
+ }
106
+
62
107
public function testWriteFlags () {
63
108
$ div_arg = new math \DivArgs ();
64
109
$ div_arg ->setDividend (7 );
@@ -71,6 +116,36 @@ public function testWriteFlags() {
71
116
$ this ->assertSame (\Grpc \STATUS_OK , $ status ->code );
72
117
}
73
118
119
+ public function testWriteFlagsServerStreaming () {
120
+ $ fib_arg = new math \FibArgs ();
121
+ $ fib_arg ->setLimit (7 );
122
+ $ call = self ::$ client ->Fib ($ fib_arg , array (), array ('flags ' => Grpc \WRITE_NO_COMPRESS ));
123
+ $ result_array = iterator_to_array ($ call ->responses ());
124
+ $ status = $ call ->getStatus ();
125
+ $ this ->assertSame (\Grpc \STATUS_OK , $ status ->code );
126
+ }
127
+
128
+ public function testWriteFlagsClientStreaming () {
129
+ $ call = self ::$ client ->Sum ();
130
+ $ num = new math \Num ();
131
+ $ num ->setNum (1 );
132
+ $ call ->write ($ num , array ('flags ' => Grpc \WRITE_NO_COMPRESS ));
133
+ list ($ response , $ status ) = $ call ->wait ();
134
+ $ this ->assertSame (\Grpc \STATUS_OK , $ status ->code );
135
+ }
136
+
137
+ public function testWriteFlagsBidiStreaming () {
138
+ $ call = self ::$ client ->DivMany ();
139
+ $ div_arg = new math \DivArgs ();
140
+ $ div_arg ->setDividend (7 );
141
+ $ div_arg ->setDivisor (4 );
142
+ $ call ->write ($ div_arg , array ('flags ' => Grpc \WRITE_NO_COMPRESS ));
143
+ $ response = $ call ->read ();
144
+ $ call ->writesDone ();
145
+ $ status = $ call ->getStatus ();
146
+ $ this ->assertSame (\Grpc \STATUS_OK , $ status ->code );
147
+ }
148
+
74
149
public function testSimpleRequest () {
75
150
$ div_arg = new math \DivArgs ();
76
151
$ div_arg ->setDividend (7 );
@@ -128,3 +203,12 @@ public function testBidiStreaming() {
128
203
$ this ->assertSame (\Grpc \STATUS_OK , $ status ->code );
129
204
}
130
205
}
206
+
207
+ class DummyInvalidClient extends \Grpc \BaseStub {
208
+ public function InvalidUnaryCall (\math \DivArgs $ argument ,
209
+ $ metadata = array (),
210
+ $ options = array ()) {
211
+ return $ this ->_simpleRequest ('invalidMethodName ' , $ argument ,
212
+ function () {}, $ metadata , $ options );
213
+ }
214
+ }
0 commit comments