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

Commit ab78374

Browse files
committed
Merge pull request #131 from symfony-cmf/handle_missing_basepath
throw exception if the base path node does not exist
2 parents 31a7eef + 863d6df commit ab78374

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

Adapter/PhpcrOdmAdapter.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,12 @@ public function createAutoRoute($uri, $contentDocument, $autoRouteTag)
118118
{
119119
$path = $this->baseRoutePath;
120120
$document = $parentDocument = $this->dm->find(null, $path);
121+
if (null === $parentDocument) {
122+
throw new \RuntimeException(sprintf('The "route_basepath" configuration points to a non-existant path "%s".',
123+
$path
124+
));
125+
}
126+
121127
$segments = preg_split('#/#', $uri, null, PREG_SPLIT_NO_EMPTY);
122128
$headName = array_pop($segments);
123129
foreach ($segments as $segment) {

Tests/Unit/Adapter/PhpcrOdmAdapterTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,18 @@ public function testCreateAutoRoute($path, $expectedParentPath, $expectedName, $
126126
$this->assertSame($this->contentDocument, $res->getContent());
127127
}
128128

129+
/**
130+
* @expectedException \RuntimeException
131+
* @expectedExceptionMessage configuration points to a non-existant path
132+
*/
133+
public function testCreateAutoRouteNonExistingBasePath()
134+
{
135+
$this->dm->getPhpcrSession()->willReturn($this->phpcrSession);
136+
$this->dm->find(null, $this->baseRoutePath)->willReturn(null);
137+
$this->adapter->createAutoRoute('/foo', $this->contentDocument, 'fr');
138+
}
139+
140+
129141
public function testGetRealClassName()
130142
{
131143
$res = $this->adapter->getRealClassName('Class/Foo');

0 commit comments

Comments
 (0)