File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -302,6 +302,26 @@ public function routes() : array
302302 return $ this ->routesDef ;
303303 }
304304
305+ /**
306+ * Returns the primary route.
307+ *
308+ * The primary route is the one marked primary in `routes.yaml`, or else
309+ * the first non-redirect route in that file if none are marked.
310+ *
311+ * @return array
312+ * The route definition. The generated URL of the route is added as a "url" key.
313+ */
314+ public function getPrimaryRoute () : array
315+ {
316+ foreach ($ this ->routes () as $ url => $ route ) {
317+ if ($ route ['primary ' ] == true ) {
318+ return $ route ;
319+ }
320+ }
321+
322+ throw new \InvalidArgumentException (sprintf ('No primary route found. This isn \'t supposed to happen ' ));
323+ }
324+
305325 /**
306326 * Returns a single route definition.
307327 *
Original file line number Diff line number Diff line change @@ -133,6 +133,17 @@ public function test_get_non_existent_route_throws_exception() : void
133133 $ route = $ config ->getRoute ('missing ' );
134134 }
135135
136+ public function test_primary_route_returns_correct_route () : void
137+ {
138+ $ config = new Config ($ this ->mockEnvironmentDeploy );
139+
140+ $ route = $ config ->getPrimaryRoute ();
141+
142+ $ this ->assertEquals ('https://www.{default}/ ' , $ route ['original_url ' ]);
143+ $ this ->assertEquals ('main ' , $ route ['id ' ]);
144+ $ this ->assertTrue ($ route ['primary ' ]);
145+ }
146+
136147 public function test_onenterprise_returns_true_on_enterprise () : void
137148 {
138149 $ env = $ this ->mockEnvironmentDeploy ;
You can’t perform that action at this time.
0 commit comments