Skip to content

Commit d3c8486

Browse files
committed
make sure that we only return route objects from route provider. fix #152
1 parent 702c1b4 commit d3c8486

File tree

2 files changed

+56
-2
lines changed

2 files changed

+56
-2
lines changed

Doctrine/Phpcr/RouteProvider.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,12 @@ public function getRouteByName($name, $parameters = array())
110110
{
111111
// $name is the route document path
112112
$route = $this->getObjectManager()->find($this->className, $name);
113+
113114
if (!$route) {
114-
throw new RouteNotFoundException("No route found for path '$name'");
115+
throw new RouteNotFoundException(sprintf('No route found for path "%s"', $name));
116+
}
117+
if (!$route instanceof SymfonyRoute) {
118+
throw new RouteNotFoundException(sprintf('Document at path "%s" is no route', $name));
115119
}
116120

117121
return $route;

Tests/Unit/Doctrine/Phpcr/RouteProviderTest.php

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,12 @@ public function testGetRouteCollectionForRequest()
3333

3434
public function testGetRouteByName()
3535
{
36+
3637
$this->route
3738
->expects($this->any())
3839
->method('getPath')
39-
->will($this->returnValue('/cms/routes/test-route'));
40+
->will($this->returnValue('/cms/routes/test-route'))
41+
;
4042

4143
$this->objectManager
4244
->expects($this->any())
@@ -60,6 +62,54 @@ public function testGetRouteByName()
6062
$this->assertEquals('/cms/routes/test-route', $foundRoute->getPath());
6163
}
6264

65+
/**
66+
* @expectedException \Symfony\Component\Routing\Exception\RouteNotFoundException
67+
*/
68+
public function testGetRouteByNameNotFound()
69+
{
70+
$this->objectManager
71+
->expects($this->any())
72+
->method('find')
73+
->with(null, '/cms/routes/test-route')
74+
->will($this->returnValue(null))
75+
;
76+
77+
$this->managerRegistry
78+
->expects($this->any())
79+
->method('getManager')
80+
->will($this->returnValue($this->objectManager))
81+
;
82+
83+
$routeProvider = new RouteProvider($this->managerRegistry);
84+
$routeProvider->setManagerName('default');
85+
86+
$routeProvider->getRouteByName('/cms/routes/test-route');
87+
}
88+
89+
/**
90+
* @expectedException \Symfony\Component\Routing\Exception\RouteNotFoundException
91+
*/
92+
public function testGetRouteByNameNoRoute()
93+
{
94+
$this->objectManager
95+
->expects($this->any())
96+
->method('find')
97+
->with(null, '/cms/routes/test-route')
98+
->will($this->returnValue($this))
99+
;
100+
101+
$this->managerRegistry
102+
->expects($this->any())
103+
->method('getManager')
104+
->will($this->returnValue($this->objectManager))
105+
;
106+
107+
$routeProvider = new RouteProvider($this->managerRegistry);
108+
$routeProvider->setManagerName('default');
109+
110+
$routeProvider->getRouteByName('/cms/routes/test-route');
111+
}
112+
63113
public function testGetRoutesByNames()
64114
{
65115
$this->markTestIncomplete();

0 commit comments

Comments
 (0)