Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Add getter to retrieve configured routes #421 #426

Merged
merged 1 commit into from
Jan 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,16 @@ public function route($path, $middleware = null, array $methods = null, $name =
return $route;
}

/**
* Retrieve all directly registered routes with the application.
*
* @return Router\Route[]
*/
public function getRoutes()
{
return $this->routes;
}

/**
* Run the application
*
Expand Down
12 changes: 12 additions & 0 deletions test/ApplicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -730,4 +730,16 @@ public function testRunInvokesFinalHandlerWhenServerRequestFactoryRaisesExceptio
$this->fail($e->getMessage());
}
}

public function testRetrieveRegisteredRoutes()
{
$route = new Route('/foo', $this->noopMiddleware);
$this->router->addRoute($route)->shouldBeCalled();
$app = $this->getApp();
$test = $app->route($route);
$this->assertSame($route, $test);
$routes = $app->getRoutes();
$this->assertCount(1, $routes);
$this->assertInstanceOf(Route::class, $routes[0]);
}
}