1
+ <?php
2
+ /**
3
+ * Created by claudio on 2018-12-31
4
+ */
5
+
6
+ use PHPUnit \Framework \TestCase ;
7
+ use React \EventLoop \Factory ;
8
+ use Ratchet \Client \Connector ;
9
+ use Psr \Http \Message \RequestInterface ;
10
+
11
+ class RequestUriTest extends TestCase {
12
+ protected static function getPrivateClassMethod ($ className , $ methodName ) {
13
+ $ class = new ReflectionClass ($ className );
14
+ $ method = $ class ->getMethod ($ methodName );
15
+ $ method ->setAccessible (true );
16
+ return $ method ;
17
+ }
18
+
19
+ function uriDataProvider () {
20
+ return [
21
+ ['ws://127.0.0.1/bla ' , 'http://127.0.0.1/bla ' ],
22
+ ['wss://127.0.0.1/bla ' , 'https://127.0.0.1/bla ' ],
23
+ ['ws://127.0.0.1:1234/bla ' , 'http://127.0.0.1:1234/bla ' ],
24
+ ['wss://127.0.0.1:4321/bla ' , 'https://127.0.0.1:4321/bla ' ]
25
+ ];
26
+ }
27
+
28
+ /**
29
+ * @dataProvider uriDataProvider
30
+ */
31
+ function testGeneratedRequestUri ($ uri , $ expectedRequestUri ) {
32
+ $ loop = Factory::create ();
33
+
34
+ $ connector = new Connector ($ loop );
35
+
36
+ $ generateRequest = self ::getPrivateClassMethod ('\Ratchet\Client\Connector ' , 'generateRequest ' );
37
+ $ request = $ generateRequest ->invokeArgs ($ connector , [$ uri , [], []]);
38
+
39
+ $ this ->assertEquals ((string )$ request ->getUri (), $ expectedRequestUri );
40
+ }
41
+ }
0 commit comments