Skip to content

Commit

Permalink
Make RouteBuilder::connect() return route instances.
Browse files Browse the repository at this point in the history
The utility of the fluent setters on Route are limited if connect() does
not also return the route instances.
  • Loading branch information
markstory committed Jun 7, 2017
1 parent 5c03776 commit fac7a27
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
4 changes: 3 additions & 1 deletion src/Routing/RouteBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ protected function _methodRoute($method, $template, $target, $name)
* element should match. Also contains additional parameters such as which routed parameters should be
* shifted into the passed arguments, supplying patterns for routing parameters and supplying the name of a
* custom routing class.
* @return void
* @return \Cake\Routing\Route\Route
* @throws \InvalidArgumentException
* @throws \BadMethodCallException
*/
Expand All @@ -615,6 +615,8 @@ public function connect($route, array $defaults = [], array $options = [])

$route = $this->_makeRoute($route, $defaults, $options);
$this->_collection->add($route, $options);

return $route;
}

/**
Expand Down
8 changes: 4 additions & 4 deletions tests/TestCase/Routing/RouteBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public function testConnectInstance()
$routes = new RouteBuilder($this->collection, '/l', ['prefix' => 'api']);

$route = new Route('/:controller');
$this->assertNull($routes->connect($route));
$this->assertSame($route, $routes->connect($route));

$result = $this->collection->routes()[0];
$this->assertSame($route, $result);
Expand All @@ -142,10 +142,10 @@ public function testConnectBasic()
{
$routes = new RouteBuilder($this->collection, '/l', ['prefix' => 'api']);

$this->assertNull($routes->connect('/:controller'));
$route = $this->collection->routes()[0];

$route = $routes->connect('/:controller');
$this->assertInstanceOf(Route::class, $route);

$this->assertSame($route, $this->collection->routes()[0]);
$this->assertEquals('/l/:controller', $route->template);
$expected = ['prefix' => 'api', 'action' => 'index', 'plugin' => null];
$this->assertEquals($expected, $route->defaults);
Expand Down

0 comments on commit fac7a27

Please sign in to comment.