1
1
<?php
2
2
3
+ namespace Clue \Tests \React \SshProxy ;
4
+
3
5
use PHPUnit \Framework \TestCase ;
4
6
use Clue \React \SshProxy \SshSocksConnector ;
5
7
use React \Promise \Deferred ;
@@ -11,7 +13,7 @@ public function testConstructorAcceptsUri()
11
13
$ loop = $ this ->getMockBuilder ('React\EventLoop\LoopInterface ' )->getMock ();
12
14
$ connector = new SshSocksConnector ('host ' , $ loop );
13
15
14
- $ ref = new ReflectionProperty ($ connector , 'cmd ' );
16
+ $ ref = new \ ReflectionProperty ($ connector , 'cmd ' );
15
17
$ ref ->setAccessible (true );
16
18
17
19
$ this ->assertEquals ('exec ssh -v -o ExitOnForwardFailure=yes -N -o BatchMode=yes -D \'127.0.0.1:1080 \' \'host \'' , $ ref ->getValue ($ connector ));
@@ -22,7 +24,7 @@ public function testConstructorAcceptsUriWithDefaultPortWillNotBeAddedToCommand(
22
24
$ loop = $ this ->getMockBuilder ('React\EventLoop\LoopInterface ' )->getMock ();
23
25
$ connector = new SshSocksConnector ('host:22 ' , $ loop );
24
26
25
- $ ref = new ReflectionProperty ($ connector , 'cmd ' );
27
+ $ ref = new \ ReflectionProperty ($ connector , 'cmd ' );
26
28
$ ref ->setAccessible (true );
27
29
28
30
$ this ->assertEquals ('exec ssh -v -o ExitOnForwardFailure=yes -N -o BatchMode=yes -D \'127.0.0.1:1080 \' \'host \'' , $ ref ->getValue ($ connector ));
@@ -33,7 +35,7 @@ public function testConstructorAcceptsUriWithUserAndCustomPort()
33
35
$ loop = $ this ->getMockBuilder ('React\EventLoop\LoopInterface ' )->getMock ();
34
36
$ connector = new SshSocksConnector ('user@host:2222 ' , $ loop );
35
37
36
- $ ref = new ReflectionProperty ($ connector , 'cmd ' );
38
+ $ ref = new \ ReflectionProperty ($ connector , 'cmd ' );
37
39
$ ref ->setAccessible (true );
38
40
39
41
$ this ->assertEquals ('exec ssh -v -o ExitOnForwardFailure=yes -N -o BatchMode=yes -p 2222 -D \'127.0.0.1:1080 \' \'user@host \'' , $ ref ->getValue ($ connector ));
@@ -44,7 +46,7 @@ public function testConstructorAcceptsUriWithPasswordWillPrefixSshCommandWithSsh
44
46
$ loop = $ this ->getMockBuilder ('React\EventLoop\LoopInterface ' )->getMock ();
45
47
$ connector = new SshSocksConnector ('user:pass@host ' , $ loop );
46
48
47
- $ ref = new ReflectionProperty ($ connector , 'cmd ' );
49
+ $ ref = new \ ReflectionProperty ($ connector , 'cmd ' );
48
50
$ ref ->setAccessible (true );
49
51
50
52
$ this ->assertEquals ('exec sshpass -p \'pass \' ssh -v -o ExitOnForwardFailure=yes -N -D \'127.0.0.1:1080 \' \'user@host \'' , $ ref ->getValue ($ connector ));
@@ -55,7 +57,7 @@ public function testConstructorAcceptsUriWithCustomBindUrl()
55
57
$ loop = $ this ->getMockBuilder ('React\EventLoop\LoopInterface ' )->getMock ();
56
58
$ connector = new SshSocksConnector ('host?bind=127.1.0.1:2711 ' , $ loop );
57
59
58
- $ ref = new ReflectionProperty ($ connector , 'cmd ' );
60
+ $ ref = new \ ReflectionProperty ($ connector , 'cmd ' );
59
61
$ ref ->setAccessible (true );
60
62
61
63
$ this ->assertEquals ('exec ssh -v -o ExitOnForwardFailure=yes -N -o BatchMode=yes -D \'127.1.0.1:2711 \' \'host \'' , $ ref ->getValue ($ connector ));
@@ -66,7 +68,7 @@ public function testConstructorAcceptsUriWithCustomBindUrlIpv6()
66
68
$ loop = $ this ->getMockBuilder ('React\EventLoop\LoopInterface ' )->getMock ();
67
69
$ connector = new SshSocksConnector ('host?bind=[::1]:2711 ' , $ loop );
68
70
69
- $ ref = new ReflectionProperty ($ connector , 'cmd ' );
71
+ $ ref = new \ ReflectionProperty ($ connector , 'cmd ' );
70
72
$ ref ->setAccessible (true );
71
73
72
74
$ this ->assertEquals ('exec ssh -v -o ExitOnForwardFailure=yes -N -o BatchMode=yes -D \'[::1]:2711 \' \'host \'' , $ ref ->getValue ($ connector ));
@@ -189,7 +191,7 @@ public function testConnectWillCancelPendingIdleTimerAndWaitForSshListener()
189
191
$ connector = new SshSocksConnector ('host ' , $ loop );
190
192
191
193
$ timer = $ this ->getMockBuilder ('React\EventLoop\TimerInterface ' )->getMock ();
192
- $ ref = new ReflectionProperty ($ connector , 'idleTimer ' );
194
+ $ ref = new \ ReflectionProperty ($ connector , 'idleTimer ' );
193
195
$ ref ->setAccessible (true );
194
196
$ ref ->setValue ($ connector , $ timer );
195
197
@@ -207,13 +209,13 @@ public function testConnectWithFailingSshListenerShouldReturnRejectedPromise()
207
209
$ connector = new SshSocksConnector ('host ' , $ loop );
208
210
209
211
$ deferred = new Deferred ();
210
- $ ref = new ReflectionProperty ($ connector , 'listen ' );
212
+ $ ref = new \ ReflectionProperty ($ connector , 'listen ' );
211
213
$ ref ->setAccessible (true );
212
214
$ ref ->setValue ($ connector , $ deferred ->promise ());
213
215
214
216
$ promise = $ connector ->connect ('google.com:80 ' );
215
217
216
- $ deferred ->reject (new RuntimeException ('foobar ' ));
218
+ $ deferred ->reject (new \ RuntimeException ('foobar ' ));
217
219
218
220
$ exception = null ;
219
221
$ promise ->then (null , function ($ reason ) use (&$ exception ) {
@@ -229,7 +231,7 @@ public function testConnectTwiceWithFailingSshListenerShouldRejectBothPromises()
229
231
$ connector = new SshSocksConnector ('host ' , $ loop );
230
232
231
233
$ deferred = new Deferred ();
232
- $ ref = new ReflectionProperty ($ connector , 'listen ' );
234
+ $ ref = new \ ReflectionProperty ($ connector , 'listen ' );
233
235
$ ref ->setAccessible (true );
234
236
$ ref ->setValue ($ connector , $ deferred ->promise ());
235
237
@@ -239,7 +241,7 @@ public function testConnectTwiceWithFailingSshListenerShouldRejectBothPromises()
239
241
$ second = $ connector ->connect ('google.com:80 ' );
240
242
$ second ->then (null , $ this ->expectCallableOnceWith ($ this ->isInstanceOf ('RuntimeException ' )));
241
243
242
- $ deferred ->reject (new InvalidArgumentException ());
244
+ $ deferred ->reject (new \ InvalidArgumentException ());
243
245
}
244
246
245
247
public function testConnectCancellationWithFailingSshListenerShouldAddTimerOnce ()
@@ -250,14 +252,14 @@ public function testConnectCancellationWithFailingSshListenerShouldAddTimerOnce(
250
252
$ connector = new SshSocksConnector ('host ' , $ loop );
251
253
252
254
$ deferred = new Deferred ();
253
- $ ref = new ReflectionProperty ($ connector , 'listen ' );
255
+ $ ref = new \ ReflectionProperty ($ connector , 'listen ' );
254
256
$ ref ->setAccessible (true );
255
257
$ ref ->setValue ($ connector , $ deferred ->promise ());
256
258
257
259
$ promise = $ connector ->connect ('google.com:80 ' );
258
260
$ promise ->cancel ();
259
261
260
- $ deferred ->reject (new InvalidArgumentException ());
262
+ $ deferred ->reject (new \ InvalidArgumentException ());
261
263
}
262
264
263
265
public function testConnectWithSuccessfulSshListenerWillInvokeSocksConnector ()
@@ -266,15 +268,15 @@ public function testConnectWithSuccessfulSshListenerWillInvokeSocksConnector()
266
268
267
269
$ connector = new SshSocksConnector ('host ' , $ loop );
268
270
269
- $ ref = new ReflectionProperty ($ connector , 'listen ' );
271
+ $ ref = new \ ReflectionProperty ($ connector , 'listen ' );
270
272
$ ref ->setAccessible (true );
271
273
$ ref ->setValue ($ connector , \React \Promise \resolve (null ));
272
274
273
275
$ deferred = new Deferred ();
274
276
$ socks = $ this ->getMockBuilder ('React\Socket\ConnectorInterface ' )->getMock ();
275
277
$ socks ->expects ($ this ->once ())->method ('connect ' )->with ('google.com:80 ' )->willReturn ($ deferred ->promise ());
276
278
277
- $ ref = new ReflectionProperty ($ connector , 'socks ' );
279
+ $ ref = new \ ReflectionProperty ($ connector , 'socks ' );
278
280
$ ref ->setAccessible (true );
279
281
$ ref ->setValue ($ connector , $ socks );
280
282
@@ -292,17 +294,17 @@ public function testConnectCancellationWithSuccessfulSshListenerWillCancelSocksC
292
294
293
295
$ connector = new SshSocksConnector ('host ' , $ loop );
294
296
295
- $ ref = new ReflectionProperty ($ connector , 'listen ' );
297
+ $ ref = new \ ReflectionProperty ($ connector , 'listen ' );
296
298
$ ref ->setAccessible (true );
297
299
$ ref ->setValue ($ connector , \React \Promise \resolve (null ));
298
300
299
301
$ deferred = new Deferred (function () {
300
- throw new RuntimeException ('SOCKS cancelled ' );
302
+ throw new \ RuntimeException ('SOCKS cancelled ' );
301
303
});
302
304
$ socks = $ this ->getMockBuilder ('React\Socket\ConnectorInterface ' )->getMock ();
303
305
$ socks ->expects ($ this ->once ())->method ('connect ' )->willReturn ($ deferred ->promise ());
304
306
305
- $ ref = new ReflectionProperty ($ connector , 'socks ' );
307
+ $ ref = new \ ReflectionProperty ($ connector , 'socks ' );
306
308
$ ref ->setAccessible (true );
307
309
$ ref ->setValue ($ connector , $ socks );
308
310
@@ -327,21 +329,21 @@ public function testConnectWithSuccessfulSshListenerButFailingSocksConnectorShou
327
329
328
330
$ connector = new SshSocksConnector ('host ' , $ loop );
329
331
330
- $ ref = new ReflectionProperty ($ connector , 'listen ' );
332
+ $ ref = new \ ReflectionProperty ($ connector , 'listen ' );
331
333
$ ref ->setAccessible (true );
332
334
$ ref ->setValue ($ connector , \React \Promise \resolve (null ));
333
335
334
336
$ deferred = new Deferred ();
335
337
$ socks = $ this ->getMockBuilder ('React\Socket\ConnectorInterface ' )->getMock ();
336
338
$ socks ->expects ($ this ->once ())->method ('connect ' )->willReturn ($ deferred ->promise ());
337
339
338
- $ ref = new ReflectionProperty ($ connector , 'socks ' );
340
+ $ ref = new \ ReflectionProperty ($ connector , 'socks ' );
339
341
$ ref ->setAccessible (true );
340
342
$ ref ->setValue ($ connector , $ socks );
341
343
342
344
$ promise = $ connector ->connect ('google.com:80 ' );
343
345
344
- $ deferred ->reject (new RuntimeException ('Connection failed ' ));
346
+ $ deferred ->reject (new \ RuntimeException ('Connection failed ' ));
345
347
346
348
$ exception = null ;
347
349
$ promise ->then (null , function ($ reason ) use (&$ exception ) {
@@ -356,7 +358,7 @@ public function testConnectWithSuccessfulSshListenerAndSuccessfulSocksConnectorS
356
358
357
359
$ connector = new SshSocksConnector ('host ' , $ loop );
358
360
359
- $ ref = new ReflectionProperty ($ connector , 'listen ' );
361
+ $ ref = new \ ReflectionProperty ($ connector , 'listen ' );
360
362
$ ref ->setAccessible (true );
361
363
$ ref ->setValue ($ connector , \React \Promise \resolve (null ));
362
364
@@ -367,7 +369,7 @@ public function testConnectWithSuccessfulSshListenerAndSuccessfulSocksConnectorS
367
369
$ socks = $ this ->getMockBuilder ('React\Socket\ConnectorInterface ' )->getMock ();
368
370
$ socks ->expects ($ this ->once ())->method ('connect ' )->willReturn ($ deferred ->promise ());
369
371
370
- $ ref = new ReflectionProperty ($ connector , 'socks ' );
372
+ $ ref = new \ ReflectionProperty ($ connector , 'socks ' );
371
373
$ ref ->setAccessible (true );
372
374
$ ref ->setValue ($ connector , $ socks );
373
375
@@ -383,7 +385,7 @@ public function testConnectWithSuccessfulSshListenerAndSuccessfulSocksConnectorW
383
385
384
386
$ connector = new SshSocksConnector ('host ' , $ loop );
385
387
386
- $ ref = new ReflectionProperty ($ connector , 'listen ' );
388
+ $ ref = new \ ReflectionProperty ($ connector , 'listen ' );
387
389
$ ref ->setAccessible (true );
388
390
$ ref ->setValue ($ connector , \React \Promise \resolve (null ));
389
391
@@ -394,7 +396,7 @@ public function testConnectWithSuccessfulSshListenerAndSuccessfulSocksConnectorW
394
396
$ socks = $ this ->getMockBuilder ('React\Socket\ConnectorInterface ' )->getMock ();
395
397
$ socks ->expects ($ this ->once ())->method ('connect ' )->willReturn ($ deferred ->promise ());
396
398
397
- $ ref = new ReflectionProperty ($ connector , 'socks ' );
399
+ $ ref = new \ ReflectionProperty ($ connector , 'socks ' );
398
400
$ ref ->setAccessible (true );
399
401
$ ref ->setValue ($ connector , $ socks );
400
402
0 commit comments