22
33namespace Clue \Tests \React \SshProxy ;
44
5- use PHPUnit \Framework \TestCase ;
65use React \EventLoop \Factory ;
76use Clue \React \SshProxy \SshSocksConnector ;
87
@@ -13,7 +12,10 @@ class FunctionalSshSocksConnectorTest extends TestCase
1312 private $ loop ;
1413 private $ connector ;
1514
16- public function setUp ()
15+ /**
16+ * @before
17+ */
18+ public function setUpConnector ()
1719 {
1820 $ url = getenv ('SSH_PROXY ' );
1921 if ($ url === false ) {
@@ -24,45 +26,39 @@ public function setUp()
2426 $ this ->connector = new SshSocksConnector ($ url , $ this ->loop );
2527 }
2628
27- public function tearDown ()
29+ /**
30+ * @after
31+ */
32+ public function tearDownSSHClientProcess ()
2833 {
2934 // run loop in order to shut down SSH client process again
3035 \Clue \React \Block \sleep (0.001 , $ this ->loop );
3136 }
3237
33- /**
34- * @expectedException RuntimeException
35- * @expectedExceptionMessage Connection to example.com:80 failed because SSH client process died
36- */
3738 public function testConnectInvalidProxyUriWillReturnRejectedPromise ()
3839 {
3940 $ this ->connector = new SshSocksConnector (getenv ('SSH_PROXY ' ) . '.invalid ' , $ this ->loop );
4041
4142 $ promise = $ this ->connector ->connect ('example.com:80 ' );
4243
44+ $ this ->setExpectedException ('RuntimeException ' , 'Connection to example.com:80 failed because SSH client process died ' );
4345 \Clue \React \Block \await ($ promise , $ this ->loop , self ::TIMEOUT );
4446 }
4547
46- /**
47- * @expectedException RuntimeException
48- * @expectedExceptionMessage Connection to tcp://example.invalid:80 failed because connection to proxy was lost
49- */
5048 public function testConnectInvalidTargetWillReturnRejectedPromise ()
5149 {
5250 $ promise = $ this ->connector ->connect ('example.invalid:80 ' );
5351
52+ $ this ->setExpectedException ('RuntimeException ' , 'Connection to tcp://example.invalid:80 failed because connection to proxy was lost ' );
5453 \Clue \React \Block \await ($ promise , $ this ->loop , self ::TIMEOUT );
5554 }
5655
57- /**
58- * @expectedException RuntimeException
59- * @expectedExceptionMessage Connection to example.com:80 cancelled while waiting for SSH client
60- */
6156 public function testCancelConnectWillReturnRejectedPromise ()
6257 {
6358 $ promise = $ this ->connector ->connect ('example.com:80 ' );
6459 $ promise ->cancel ();
6560
61+ $ this ->setExpectedException ('RuntimeException ' , 'Connection to example.com:80 cancelled while waiting for SSH client ' );
6662 \Clue \React \Block \await ($ promise , $ this ->loop , 0 );
6763 }
6864
0 commit comments