44
55namespace Temporal \Tests \Unit \Client \GRPC ;
66
7- use DateTimeImmutable ;
87use PHPUnit \Framework \TestCase ;
98use Temporal \Api \Workflowservice \V1 \GetSystemInfoRequest ;
109use Temporal \Api \Workflowservice \V1 \GetSystemInfoResponse ;
@@ -48,18 +47,14 @@ public function testGetCapabilitiesClearsCache(): void
4847 public function testClose (): void
4948 {
5049 $ client = $ this ->createClientMock (static fn () => new class extends WorkflowServiceClient {
51- public function __construct ()
52- {
53- }
50+ public function __construct () {}
5451
5552 public function getConnectivityState ($ try_to_connect = false ): int
5653 {
5754 return ConnectionState::TransientFailure->value ;
5855 }
5956
60- public function close (): void
61- {
62- }
57+ public function close (): void {}
6358 });
6459 $ client ->close ();
6560
@@ -105,7 +100,7 @@ public function testContextGetDeadlineWithoutDeadline(): void
105100 public function testContextGetDeadlineWithStaticDeadline (): void
106101 {
107102 $ client = $ this ->createClientMock ();
108- $ context = $ client ->getContext ()->withDeadline (new DateTimeImmutable ('+1 second ' ));
103+ $ context = $ client ->getContext ()->withDeadline (new \ DateTimeImmutable ('+1 second ' ));
109104
110105 $ this ->assertSame ($ context ->getDeadline (), $ context ->getDeadline ());
111106 }
@@ -160,22 +155,21 @@ public function __toString(): string
160155
161156 public function testServiceClientCallDeadlineReached (): void
162157 {
163- $ client = $ this ->createClientMock (fn () => new class () extends WorkflowServiceClient {
158+ $ client = $ this ->createClientMock (static fn () => new class extends WorkflowServiceClient {
164159 public function __construct () {}
165- public function testCall ()
166- {
167- throw new class ((object )['code ' => StatusCode::UNKNOWN , 'metadata ' => []])
168- extends ServiceClientException {
169- };
170- }
171- public function close (): void
160+
161+ public function testCall (): void
172162 {
163+ throw new class ((object ) ['code ' => StatusCode::UNKNOWN , 'metadata ' => []]) extends ServiceClientException {};
173164 }
165+
166+ public function close (): void {}
174167 })->withInterceptorPipeline (null );
175168
176- $ client = $ client ->withContext ($ client ->getContext ()
177- ->withDeadline (new DateTimeImmutable ('-1 second ' ))
178- ->withRetryOptions (RpcRetryOptions::new ()->withMaximumAttempts (2 )) // stop if deadline doesn't work
169+ $ client = $ client ->withContext (
170+ $ client ->getContext ()
171+ ->withDeadline (new \DateTimeImmutable ('-1 second ' ))
172+ ->withRetryOptions (RpcRetryOptions::new ()->withMaximumAttempts (2 )), // stop if deadline doesn't work
179173 );
180174
181175 self ::expectException (TimeoutException::class);
@@ -185,20 +179,21 @@ public function close(): void
185179
186180 public function testServiceClientCallCustomException (): void
187181 {
188- $ client = $ this ->createClientMock (fn () => new class () extends WorkflowServiceClient {
182+ $ client = $ this ->createClientMock (static fn () => new class extends WorkflowServiceClient {
189183 public function __construct () {}
190- public function testCall ()
184+
185+ public function testCall (): void
191186 {
192187 throw new \RuntimeException ('foo ' );
193188 }
194- public function close (): void
195- {
196- }
189+
190+ public function close (): void {}
197191 })->withInterceptorPipeline (null );
198192
199- $ client = $ client ->withContext ($ client ->getContext ()
200- ->withDeadline (new DateTimeImmutable ('-1 second ' ))
201- ->withRetryOptions (RpcRetryOptions::new ()->withMaximumAttempts (2 )) // stop if deadline doesn't work
193+ $ client = $ client ->withContext (
194+ $ client ->getContext ()
195+ ->withDeadline (new \DateTimeImmutable ('-1 second ' ))
196+ ->withRetryOptions (RpcRetryOptions::new ()->withMaximumAttempts (2 )), // stop if deadline doesn't work
202197 );
203198
204199 self ::expectException (\RuntimeException::class);
@@ -212,31 +207,32 @@ public function close(): void
212207 */
213208 public function testServiceClientCallMaximumAttemptsReached (): void
214209 {
215- $ client = $ this ->createClientMock (fn () => new class () extends WorkflowServiceClient {
210+ $ client = $ this ->createClientMock (fn () => new class extends WorkflowServiceClient {
216211 public function __construct () {}
217- public function testCall ()
212+
213+ public function testCall (): void
218214 {
219215 static $ counter = 0 ;
220- throw new class (++$ counter )
221- extends ServiceClientException {
216+ throw new class (++$ counter ) extends ServiceClientException {
222217 public function __construct (public int $ attempt )
223218 {
224- parent ::__construct ((object )['code ' => StatusCode::UNKNOWN , 'metadata ' => []]);
219+ parent ::__construct ((object ) ['code ' => StatusCode::UNKNOWN , 'metadata ' => []]);
225220 }
221+
226222 public function isTestError (): bool
227223 {
228224 return true ;
229225 }
230226 };
231227 }
232- public function close (): void
233- {
234- }
228+
229+ public function close (): void {}
235230 })->withInterceptorPipeline (null );
236231
237- $ client = $ client ->withContext ($ client ->getContext ()
238- ->withDeadline (new DateTimeImmutable ('+2 seconds ' )) // stop if attempts don't work
239- ->withRetryOptions (RpcRetryOptions::new ()->withMaximumAttempts (3 )->withBackoffCoefficient (1 ))
232+ $ client = $ client ->withContext (
233+ $ client ->getContext ()
234+ ->withDeadline (new \DateTimeImmutable ('+2 seconds ' )) // stop if attempts don't work
235+ ->withRetryOptions (RpcRetryOptions::new ()->withMaximumAttempts (3 )->withBackoffCoefficient (1 )),
240236 );
241237
242238 try {
@@ -251,41 +247,38 @@ public function close(): void
251247 private function createClientMock (?callable $ serviceClientFactory = null ): BaseClient
252248 {
253249 return (new class ($ serviceClientFactory ?? static fn () => new class extends WorkflowServiceClient {
254- public function __construct ()
255- {
256- }
250+ public function __construct () {}
257251
258252 public function getConnectivityState ($ try_to_connect = false ): int
259253 {
260254 return ConnectionState::Ready->value ;
261255 }
262256
263- public function close (): void
264- {
265- }
257+ public function close (): void {}
266258 }) extends ServiceClient {
259+
267260 public function getSystemInfo (
268261 GetSystemInfoRequest $ arg ,
269- ContextInterface $ ctx = null ,
262+ ? ContextInterface $ ctx = null ,
270263 ): GetSystemInfoResponse {
271264 return (new GetSystemInfoResponse ())
272- ->setCapabilities ((new Capabilities )->setSupportsSchedules (true ))
265+ ->setCapabilities ((new Capabilities () )->setSupportsSchedules (true ))
273266 ->setServerVersion ('1.2.3 ' );
274267 }
275268
276269 public function testCall (): mixed
277270 {
278- return $ this ->invoke ("testCall " , (object )[], null );
271+ return $ this ->invoke ("testCall " , (object ) [], null );
279272 }
280273 })->withInterceptorPipeline (
281274 Pipeline::prepare ([new class implements \Temporal \Interceptor \GrpcClientInterceptor {
282275 public function interceptCall (
283276 string $ method ,
284277 object $ arg ,
285278 ContextInterface $ ctx ,
286- callable $ next
279+ callable $ next,
287280 ): object {
288- return (object )['method ' => $ method , 'arg ' => $ arg , 'ctx ' => $ ctx , 'next ' => $ next ];
281+ return (object ) ['method ' => $ method , 'arg ' => $ arg , 'ctx ' => $ ctx , 'next ' => $ next ];
289282 }
290283 }]),
291284 );
0 commit comments