2424use Hyperf \HttpServer \ResponseEmitter ;
2525use Hyperf \HttpServer \Router \DispatcherFactory ;
2626use Hyperf \HttpServer \Router \Router ;
27+ use Hyperf \Server \Event ;
28+ use Hyperf \Server \Server ;
2729use Hyperf \Testing \Client ;
2830use Hyperf \Utils \ApplicationContext ;
2931use Hyperf \Utils \Coroutine ;
@@ -78,6 +80,27 @@ public function testClientException()
7880 $ this ->assertSame ('Server Error ' , $ data ['message ' ]);
7981 }
8082
83+ public function testClientGetUri ()
84+ {
85+ $ container = $ this ->getContainer ();
86+
87+ $ client = new Client ($ container );
88+
89+ $ data = $ client ->get ('/request ' , [
90+ 'id ' => $ id = uniqid (),
91+ ]);
92+
93+ $ this ->assertSame ($ data ['uri ' ], [
94+ 'scheme ' => 'http ' ,
95+ 'host ' => '127.0.0.1 ' ,
96+ 'port ' => 9501 ,
97+ 'path ' => '/request ' ,
98+ 'query ' => 'id= ' . $ id ,
99+ ]);
100+
101+ $ this ->assertSame ($ id , $ data ['params ' ]['id ' ]);
102+ }
103+
81104 public function getContainer ()
82105 {
83106 $ container = Mockery::mock (Container::class);
@@ -97,6 +120,20 @@ public function getContainer()
97120 ],
98121 ],
99122 ],
123+ 'server ' => [
124+ 'servers ' => [
125+ [
126+ 'name ' => 'http ' ,
127+ 'type ' => Server::SERVER_HTTP ,
128+ 'host ' => '0.0.0.0 ' ,
129+ 'port ' => 9501 ,
130+ 'sock_type ' => SWOOLE_SOCK_TCP ,
131+ 'callbacks ' => [
132+ Event::ON_REQUEST => [Server::class, 'onRequest ' ],
133+ ],
134+ ],
135+ ],
136+ ],
100137 ]));
101138 $ container ->shouldReceive ('get ' )->with (Filesystem::class)->andReturn (new Filesystem ());
102139 $ container ->shouldReceive ('get ' )->with (FooController::class)->andReturn (new FooController ());
@@ -112,6 +149,7 @@ public function getContainer()
112149 Router::get ('/ ' , [FooController::class, 'index ' ]);
113150 Router::get ('/exception ' , [FooController::class, 'exception ' ]);
114151 Router::get ('/id ' , [FooController::class, 'id ' ]);
152+ Router::addRoute (['GET ' , 'POST ' ], '/request ' , [FooController::class, 'request ' ]);
115153
116154 return $ container ;
117155 }
0 commit comments