@@ -217,4 +217,56 @@ public function test_angle_bracket_param_with_wildcard_in_domain()
217217 $ this ->assertTrue ($ route ->match ('/foo ' , 'app.api.example.com ' ));
218218 $ this ->assertEquals ('app ' , $ route ->getParameter ('sub ' ));
219219 }
220+
221+ public function test_router_route_method_with_domain_definition ()
222+ {
223+ $ router = \Bow \Router \Router::getInstance ();
224+
225+ $ router ->route ([
226+ 'path ' => '/api/domain-test ' ,
227+ 'method ' => 'GET ' ,
228+ 'handler ' => fn () => 'domain route ' ,
229+ 'domain ' => 'api.example.com '
230+ ]);
231+
232+ $ routes = $ router ->getRoutes ();
233+ $ route = end ($ routes ['GET ' ]);
234+
235+ $ this ->assertTrue ($ route ->match ('/api/domain-test ' , 'api.example.com ' ));
236+ $ this ->assertFalse ($ route ->match ('/api/domain-test ' , 'other.example.com ' ));
237+ }
238+
239+ public function test_router_route_method_with_wildcard_domain ()
240+ {
241+ $ router = \Bow \Router \Router::getInstance ();
242+
243+ $ router ->route ([
244+ 'path ' => '/api/wildcard-domain ' ,
245+ 'method ' => 'GET ' ,
246+ 'handler ' => fn () => 'wildcard domain ' ,
247+ 'domain ' => '*.example.com '
248+ ]);
249+
250+ $ routes = $ router ->getRoutes ();
251+ $ route = end ($ routes ['GET ' ]);
252+
253+ $ this ->assertTrue ($ route ->match ('/api/wildcard-domain ' , 'api.example.com ' ));
254+ $ this ->assertTrue ($ route ->match ('/api/wildcard-domain ' , 'www.example.com ' ));
255+ $ this ->assertFalse ($ route ->match ('/api/wildcard-domain ' , 'example.com ' ));
256+ }
257+
258+ public function test_router_domain_group_method ()
259+ {
260+ $ router = \Bow \Router \Router::getInstance ();
261+
262+ $ router ->domain ('admin.example.com ' , function ($ router ) {
263+ $ router ->get ('/admin/dashboard ' , fn () => 'admin dashboard ' );
264+ });
265+
266+ $ routes = $ router ->getRoutes ();
267+ $ route = end ($ routes ['GET ' ]);
268+
269+ $ this ->assertTrue ($ route ->match ('/admin/dashboard ' , 'admin.example.com ' ));
270+ $ this ->assertFalse ($ route ->match ('/admin/dashboard ' , 'other.example.com ' ));
271+ }
220272}
0 commit comments