@@ -23,20 +23,38 @@ public function testInvalidProxy()
2323 new ProxyConnector ('/// ' , $ this ->connector );
2424 }
2525
26+ /**
27+ * @expectedException InvalidArgumentException
28+ */
29+ public function testInvalidProxyScheme ()
30+ {
31+ new ProxyConnector ('ftp://example.com ' , $ this ->connector );
32+ }
33+
2634 public function testCreatesConnectionToHttpPort ()
2735 {
2836 $ promise = new Promise (function () { });
29- $ this ->connector ->expects ($ this ->once ())->method ('connect ' )->with ('proxy.example.com:80?hostname=google.com ' )->willReturn ($ promise );
37+ $ this ->connector ->expects ($ this ->once ())->method ('connect ' )->with ('tcp:// proxy.example.com:80?hostname=google.com ' )->willReturn ($ promise );
3038
3139 $ proxy = new ProxyConnector ('proxy.example.com ' , $ this ->connector );
3240
3341 $ proxy ->connect ('google.com:80 ' );
3442 }
3543
44+ public function testCreatesConnectionToHttpPortAndPassesThroughUriComponents ()
45+ {
46+ $ promise = new Promise (function () { });
47+ $ this ->connector ->expects ($ this ->once ())->method ('connect ' )->with ('tcp://proxy.example.com:80/path?foo=bar&hostname=google.com#segment ' )->willReturn ($ promise );
48+
49+ $ proxy = new ProxyConnector ('proxy.example.com ' , $ this ->connector );
50+
51+ $ proxy ->connect ('google.com:80/path?foo=bar#segment ' );
52+ }
53+
3654 public function testCreatesConnectionToHttpPortAndObeysExplicitHostname ()
3755 {
3856 $ promise = new Promise (function () { });
39- $ this ->connector ->expects ($ this ->once ())->method ('connect ' )->with ('proxy.example.com:80?hostname=www.google.com ' )->willReturn ($ promise );
57+ $ this ->connector ->expects ($ this ->once ())->method ('connect ' )->with ('tcp:// proxy.example.com:80?hostname=www.google.com ' )->willReturn ($ promise );
4058
4159 $ proxy = new ProxyConnector ('proxy.example.com ' , $ this ->connector );
4260
@@ -46,7 +64,7 @@ public function testCreatesConnectionToHttpPortAndObeysExplicitHostname()
4664 public function testCreatesConnectionToHttpsPort ()
4765 {
4866 $ promise = new Promise (function () { });
49- $ this ->connector ->expects ($ this ->once ())->method ('connect ' )->with ('proxy.example.com:443?hostname=google.com ' )->willReturn ($ promise );
67+ $ this ->connector ->expects ($ this ->once ())->method ('connect ' )->with ('tls:// proxy.example.com:443?hostname=google.com ' )->willReturn ($ promise );
5068
5169 $ proxy = new ProxyConnector ('https://proxy.example.com ' , $ this ->connector );
5270
@@ -80,6 +98,28 @@ public function testWillWriteToOpenConnection()
8098 $ proxy ->connect ('google.com:80 ' );
8199 }
82100
101+ public function testRejectsInvalidUri ()
102+ {
103+ $ this ->connector ->expects ($ this ->never ())->method ('connect ' );
104+
105+ $ proxy = new ProxyConnector ('proxy.example.com ' , $ this ->connector );
106+
107+ $ promise = $ proxy ->connect ('/// ' );
108+
109+ $ promise ->then (null , $ this ->expectCallableOnce ());
110+ }
111+
112+ public function testRejectsUriWithNonTcpScheme ()
113+ {
114+ $ this ->connector ->expects ($ this ->never ())->method ('connect ' );
115+
116+ $ proxy = new ProxyConnector ('proxy.example.com ' , $ this ->connector );
117+
118+ $ promise = $ proxy ->connect ('tls://google.com:80 ' );
119+
120+ $ promise ->then (null , $ this ->expectCallableOnce ());
121+ }
122+
83123 public function testRejectsAndClosesIfStreamWritesNonHttp ()
84124 {
85125 $ stream = $ this ->getMockBuilder ('React\Socket\Connection ' )->disableOriginalConstructor ()->setMethods (array ('close ' , 'write ' ))->getMock ();
0 commit comments