@@ -49,6 +49,49 @@ public function testEmitsConnectionWithRemoteIp()
4949 $ this ->assertContains ('127.0.0.1: ' , $ peer );
5050 }
5151
52+ public function testEmitsConnectionWithLocalIp ()
53+ {
54+ $ loop = Factory::create ();
55+
56+ $ server = new Server (0 , $ loop );
57+ $ local = null ;
58+ $ server ->on ('connection ' , function (ConnectionInterface $ conn ) use (&$ local ) {
59+ $ local = $ conn ->getLocalAddress ();
60+ });
61+ $ port = $ this ->getPort ($ server );
62+
63+ $ connector = new TcpConnector ($ loop );
64+ $ promise = $ connector ->create ('127.0.0.1 ' , $ port );
65+
66+ $ promise ->then ($ this ->expectCallableOnce ());
67+
68+ Block \sleep (0.1 , $ loop );
69+
70+ $ this ->assertEquals ('127.0.0.1: ' . $ port , $ local );
71+ $ this ->assertEquals ($ server ->getAddress (), $ local );
72+ }
73+
74+ public function testEmitsConnectionWithLocalIpDespiteListeningOnAll ()
75+ {
76+ $ loop = Factory::create ();
77+
78+ $ server = new Server ('0.0.0.0:0 ' , $ loop );
79+ $ local = null ;
80+ $ server ->on ('connection ' , function (ConnectionInterface $ conn ) use (&$ local ) {
81+ $ local = $ conn ->getLocalAddress ();
82+ });
83+ $ port = $ this ->getPort ($ server );
84+
85+ $ connector = new TcpConnector ($ loop );
86+ $ promise = $ connector ->create ('127.0.0.1 ' , $ port );
87+
88+ $ promise ->then ($ this ->expectCallableOnce ());
89+
90+ Block \sleep (0.1 , $ loop );
91+
92+ $ this ->assertEquals ('127.0.0.1: ' . $ port , $ local );
93+ }
94+
5295 public function testEmitsConnectionWithRemoteIpAfterConnectionIsClosedByPeer ()
5396 {
5497 $ loop = Factory::create ();
@@ -159,6 +202,33 @@ public function testEmitsConnectionWithRemoteIpv6()
159202 $ this ->assertContains ('[::1]: ' , $ peer );
160203 }
161204
205+ public function testEmitsConnectionWithLocalIpv6 ()
206+ {
207+ $ loop = Factory::create ();
208+
209+ try {
210+ $ server = new Server ('[::1]:0 ' , $ loop );
211+ } catch (ConnectionException $ e ) {
212+ $ this ->markTestSkipped ('Unable to start IPv6 server socket (not available on your platform?) ' );
213+ }
214+
215+ $ local = null ;
216+ $ server ->on ('connection ' , function (ConnectionInterface $ conn ) use (&$ local ) {
217+ $ local = $ conn ->getLocalAddress ();
218+ });
219+ $ port = $ this ->getPort ($ server );
220+
221+ $ connector = new TcpConnector ($ loop );
222+ $ promise = $ connector ->create ('::1 ' , $ port );
223+
224+ $ promise ->then ($ this ->expectCallableOnce ());
225+
226+ Block \sleep (0.1 , $ loop );
227+
228+ $ this ->assertEquals ('[::1]: ' . $ port , $ local );
229+ $ this ->assertEquals ($ server ->getAddress (), $ local );
230+ }
231+
162232 public function testAppliesContextOptionsToSocketStreamResource ()
163233 {
164234 if (defined ('HHVM_VERSION ' ) && version_compare (HHVM_VERSION , '3.13 ' , '< ' )) {
0 commit comments