Issue #2795395 by Yogesh Pawar, tresti88, marvin_B8, shashikant_chauhan, tstoeckler, dawehner: PathRootsSubscriber breaks if there are no routes

8.3.x
Alex Pott 2016-10-13 13:00:00 +01:00
parent 3fff17d04a
commit 184a05e06c
2 changed files with 7 additions and 2 deletions

View File

@ -20,7 +20,7 @@ class PathRootsSubscriber implements EventSubscriberInterface {
*
* @var array
*/
protected $pathRoots;
protected $pathRoots = [];
/**
* The state key value store.
@ -58,7 +58,7 @@ class PathRootsSubscriber implements EventSubscriberInterface {
*/
public function onRouteFinished() {
$this->state->set('router.path_roots', array_keys($this->pathRoots));
unset($this->pathRoots);
$this->pathRoots = [];
}
/**

View File

@ -43,6 +43,11 @@ class PathRootsSubscriberTest extends UnitTestCase {
* @covers ::onRouteFinished
*/
public function testSubscribing() {
// Ensure that onRouteFinished can be called without throwing notices
// when no path roots got set.
$this->pathRootsSubscriber->onRouteFinished();
$route_collection = new RouteCollection();
$route_collection->add('test_route1', new Route('/test/bar'));
$route_collection->add('test_route2', new Route('/test/baz'));