From ce6c9ec2aff9a3763ca17dafcb227a304217953c Mon Sep 17 00:00:00 2001 From: Lukas Kahwe Smith Date: Fri, 29 Aug 2014 14:12:33 +0200 Subject: [PATCH 1/2] throw exception if the base path node does not exist --- Adapter/PhpcrOdmAdapter.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Adapter/PhpcrOdmAdapter.php b/Adapter/PhpcrOdmAdapter.php index 03ebdfd..6cf8434 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) { From 863d6df282e10d3b2ffac9214103b6ce472676b7 Mon Sep 17 00:00:00 2001 From: dantleech Date: Fri, 29 Aug 2014 19:24:47 +0200 Subject: [PATCH 2/2] Added test for non-existant base path --- Adapter/PhpcrOdmAdapter.php | 2 +- Tests/Unit/Adapter/PhpcrOdmAdapterTest.php | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/Adapter/PhpcrOdmAdapter.php b/Adapter/PhpcrOdmAdapter.php index 6cf8434..bd06de5 100644 --- a/Adapter/PhpcrOdmAdapter.php +++ b/Adapter/PhpcrOdmAdapter.php @@ -119,7 +119,7 @@ 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".', + throw new \RuntimeException(sprintf('The "route_basepath" configuration points to a non-existant path "%s".', $path )); } 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');