1212
1313class FunctionalSecureServerTest extends TestCase
1414{
15+ const TIMEOUT = 0.5 ;
16+
1517 public function setUp ()
1618 {
1719 if (!function_exists ('stream_socket_enable_crypto ' )) {
@@ -27,7 +29,6 @@ public function testEmitsConnectionForNewConnection()
2729 $ server = new SecureServer ($ server , $ loop , array (
2830 'local_cert ' => __DIR__ . '/../examples/localhost.pem '
2931 ));
30- $ server ->on ('error ' , 'var_dump ' );
3132 $ server ->on ('connection ' , $ this ->expectCallableOnce ());
3233 $ server ->listen (0 );
3334 $ port = $ server ->getPort ();
@@ -37,9 +38,7 @@ public function testEmitsConnectionForNewConnection()
3738 ));
3839 $ promise = $ connector ->create ('127.0.0.1 ' , $ port );
3940
40- $ promise ->then ($ this ->expectCallableOnce ());
41-
42- Block \sleep (0.1 , $ loop );
41+ Block \await ($ promise , $ loop , self ::TIMEOUT );
4342 }
4443
4544 public function testEmitsConnectionForNewConnectionWithEncryptedCertificate ()
@@ -60,9 +59,7 @@ public function testEmitsConnectionForNewConnectionWithEncryptedCertificate()
6059 ));
6160 $ promise = $ connector ->create ('127.0.0.1 ' , $ port );
6261
63- $ promise ->then ($ this ->expectCallableOnce ());
64-
65- Block \sleep (0.1 , $ loop );
62+ Block \await ($ promise , $ loop , self ::TIMEOUT );
6663 }
6764
6865 public function testEmitsErrorForServerWithInvalidCertificate ()
@@ -83,9 +80,8 @@ public function testEmitsErrorForServerWithInvalidCertificate()
8380 ));
8481 $ promise = $ connector ->create ('127.0.0.1 ' , $ port );
8582
86- $ promise ->then (null , $ this ->expectCallableOnce ());
87-
88- Block \sleep (0.1 , $ loop );
83+ $ this ->setExpectedException ('RuntimeException ' , 'handshake ' );
84+ Block \await ($ promise , $ loop , self ::TIMEOUT );
8985 }
9086
9187 public function testEmitsErrorForServerWithEncryptedCertificateMissingPassphrase ()
@@ -106,9 +102,8 @@ public function testEmitsErrorForServerWithEncryptedCertificateMissingPassphrase
106102 ));
107103 $ promise = $ connector ->create ('127.0.0.1 ' , $ port );
108104
109- $ promise ->then (null , $ this ->expectCallableOnce ());
110-
111- Block \sleep (0.1 , $ loop );
105+ $ this ->setExpectedException ('RuntimeException ' , 'handshake ' );
106+ Block \await ($ promise , $ loop , self ::TIMEOUT );
112107 }
113108
114109 public function testEmitsErrorForServerWithEncryptedCertificateWithInvalidPassphrase ()
@@ -130,9 +125,8 @@ public function testEmitsErrorForServerWithEncryptedCertificateWithInvalidPassph
130125 ));
131126 $ promise = $ connector ->create ('127.0.0.1 ' , $ port );
132127
133- $ promise ->then (null , $ this ->expectCallableOnce ());
134-
135- Block \sleep (0.1 , $ loop );
128+ $ this ->setExpectedException ('RuntimeException ' , 'handshake ' );
129+ Block \await ($ promise , $ loop , self ::TIMEOUT );
136130 }
137131
138132 public function testEmitsErrorForConnectionWithPeerVerification ()
@@ -154,8 +148,7 @@ public function testEmitsErrorForConnectionWithPeerVerification()
154148 $ promise = $ connector ->create ('127.0.0.1 ' , $ port );
155149
156150 $ promise ->then (null , $ this ->expectCallableOnce ());
157-
158- Block \sleep (0.1 , $ loop );
151+ Block \sleep (self ::TIMEOUT , $ loop );
159152 }
160153
161154 public function testEmitsErrorIfConnectionIsCancelled ()
@@ -178,8 +171,7 @@ public function testEmitsErrorIfConnectionIsCancelled()
178171 $ promise ->cancel ();
179172
180173 $ promise ->then (null , $ this ->expectCallableOnce ());
181-
182- Block \sleep (0.1 , $ loop );
174+ Block \sleep (self ::TIMEOUT , $ loop );
183175 }
184176
185177 public function testEmitsNothingIfConnectionIsIdle ()
@@ -199,8 +191,7 @@ public function testEmitsNothingIfConnectionIsIdle()
199191 $ promise = $ connector ->create ('127.0.0.1 ' , $ port );
200192
201193 $ promise ->then ($ this ->expectCallableOnce ());
202-
203- Block \sleep (0.1 , $ loop );
194+ Block \sleep (self ::TIMEOUT , $ loop );
204195 }
205196
206197 public function testEmitsErrorIfConnectionIsNotSecureHandshake ()
@@ -223,6 +214,6 @@ public function testEmitsErrorIfConnectionIsNotSecureHandshake()
223214 $ stream ->write ("GET / HTTP/1.0 \r\n\r\n" );
224215 });
225216
226- Block \sleep (0.1 , $ loop );
217+ Block \sleep (self :: TIMEOUT , $ loop );
227218 }
228219}
0 commit comments