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

Commit 670ed28

Browse files
committed
Adds generic node migration exception unit test
1 parent 9c62b47 commit 670ed28

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

Adapter/PhpcrOdmAdapter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,8 @@ private function migrateGenericToAutoRoute(Generic $document, $contentDocument,
250250
if (!$autoRoute instanceof $autoRouteClassName) {
251251
throw new \RuntimeException(
252252
sprintf(
253-
'Failed to migrate migrate existing, non-managed, PHPCR node at "%s" to a managed document ' .
254-
'implementing the AutoRouteInterface. It is an instance of "%s".',
253+
'Failed to migrate existing, non-managed, PHPCR node at "%s" to a managed document implementing ' .
254+
'the AutoRouteInterface. It is an instance of "%s".',
255255
$document->getId(),
256256
get_class($autoRoute)
257257
)

Tests/Unit/Adapter/PhpcrOdmAdapterTest.php

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

129+
/**
130+
* @expectedException \RuntimeException
131+
* @expectedExceptionMessageRegExp /Failed to migrate existing.*? at "\/test\/generic" .*? It is an instance of ".*?stdClass.*?"\./
132+
*/
133+
public function testCreateAutoRouteThrowsExceptionIfItCannotMigrateExistingGenericDocumentToAutoRoute()
134+
{
135+
$uri = '/generic';
136+
$genericDocument = $this->prophesize('Doctrine\ODM\PHPCR\Document\Generic');
137+
$genericDocument->getNode()->willReturn($this->prophesize('PHPCR\NodeInterface')->reveal());
138+
$genericDocument->getId()->willReturn($this->baseRoutePath . $uri);
139+
$documentClassMapper = $this->prophesize('Doctrine\ODM\PHPCR\DocumentClassMapperInterface');
140+
$configuration = $this->prophesize('Doctrine\ODM\PHPCR\Configuration');
141+
$configuration->getDocumentClassMapper()->willReturn($documentClassMapper->reveal());
142+
$this->dm->getConfiguration()->willReturn($configuration->reveal());
143+
$this->dm->getPhpcrSession()->willReturn($this->phpcrSession);
144+
$this->dm->detach($genericDocument)->willReturn(null);
145+
$this->dm->find(null, $this->baseRoutePath)->willReturn($this->baseNode);
146+
$this->dm->find(null, $this->baseRoutePath . $uri)->willReturn(
147+
$genericDocument->reveal(),
148+
$this->prophesize('stdClass')->reveal()
149+
);
150+
$this->uriContext->getUri()->willReturn($uri);
151+
$this->adapter->createAutoRoute($this->uriContext->reveal(), $this->contentDocument, 'it');
152+
}
153+
129154
/**
130155
* @expectedException \RuntimeException
131156
* @expectedExceptionMessage configuration points to a non-existant path

0 commit comments

Comments
 (0)