Skip to content
This repository was archived by the owner on Sep 16, 2021. It is now read-only.

Commit 8f8d3aa

Browse files
committed
findRouteForUri returns false if found node is not an AutoRoute
1 parent 8fe022c commit 8f8d3aa

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

Adapter/PhpcrOdmAdapter.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,11 @@ public function getReferringAutoRoutes($contentDocument)
190190
public function findRouteForUri($uri, UriContext $uriContext)
191191
{
192192
$path = $this->getPathFromUri($uri);
193-
194-
return $this->dm->find(null, $path);
193+
$node = $this->dm->find(null, $path);
194+
if ($node instanceof AutoRouteInterface) {
195+
return $node;
196+
}
197+
return false;
195198
}
196199

197200
private function getPathFromUri($uri)

Tests/Unit/Adapter/PhpcrOdmAdapterTest.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,11 +174,19 @@ public function testGetReferringRoutes()
174174
public function testFindRouteForUri()
175175
{
176176
$uri = '/this/is/uri';
177-
$expectedRoutes = array($this->route->reveal());
177+
$expectedRoute = $this->route->reveal();
178178

179-
$this->dm->find(null, $this->baseRoutePath . $uri)->willReturn($expectedRoutes);
179+
$this->dm->find(null, $this->baseRoutePath . $uri)->willReturn($expectedRoute);
180180

181181
$res = $this->adapter->findRouteForUri($uri, $this->uriContext->reveal());
182-
$this->assertSame($expectedRoutes, $res);
182+
$this->assertSame($expectedRoute, $res);
183+
}
184+
185+
public function testFindRouteForUriShouldReturnFalseWhenNodeAtGivenPathIsNotAnAutoRoute()
186+
{
187+
$uri = '/this/is/uri';
188+
$genericNode = $this->prophesize('Doctrine\ODM\PHPCR\Document\Generic');
189+
$this->dm->find(null, $this->baseRoutePath . $uri)->willReturn($genericNode);
190+
$this->assertFalse($this->adapter->findRouteForUri($uri, $this->uriContext->reveal()));
183191
}
184192
}

0 commit comments

Comments
 (0)