diff --git a/Adapter/PhpcrOdmAdapter.php b/Adapter/PhpcrOdmAdapter.php index 03ebdfd..bd06de5 100644 --- a/Adapter/PhpcrOdmAdapter.php +++ b/Adapter/PhpcrOdmAdapter.php @@ -118,6 +118,12 @@ public function createAutoRoute($uri, $contentDocument, $autoRouteTag) { $path = $this->baseRoutePath; $document = $parentDocument = $this->dm->find(null, $path); + if (null === $parentDocument) { + throw new \RuntimeException(sprintf('The "route_basepath" configuration points to a non-existant path "%s".', + $path + )); + } + $segments = preg_split('#/#', $uri, null, PREG_SPLIT_NO_EMPTY); $headName = array_pop($segments); foreach ($segments as $segment) { diff --git a/Tests/Unit/Adapter/PhpcrOdmAdapterTest.php b/Tests/Unit/Adapter/PhpcrOdmAdapterTest.php index e2cdcc3..a3e0a8f 100644 --- a/Tests/Unit/Adapter/PhpcrOdmAdapterTest.php +++ b/Tests/Unit/Adapter/PhpcrOdmAdapterTest.php @@ -126,6 +126,18 @@ public function testCreateAutoRoute($path, $expectedParentPath, $expectedName, $ $this->assertSame($this->contentDocument, $res->getContent()); } + /** + * @expectedException \RuntimeException + * @expectedExceptionMessage configuration points to a non-existant path + */ + public function testCreateAutoRouteNonExistingBasePath() + { + $this->dm->getPhpcrSession()->willReturn($this->phpcrSession); + $this->dm->find(null, $this->baseRoutePath)->willReturn(null); + $this->adapter->createAutoRoute('/foo', $this->contentDocument, 'fr'); + } + + public function testGetRealClassName() { $res = $this->adapter->getRealClassName('Class/Foo');