Skip to content

Commit 702c1b4

Browse files
committed
test getContentId method
1 parent d4cf4db commit 702c1b4

File tree

1 file changed

+43
-1
lines changed

1 file changed

+43
-1
lines changed

Tests/Unit/Doctrine/Phpcr/ContentRepositoryTest.php

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,49 @@ public function testFindById()
4444

4545
public function testGetContentId()
4646
{
47-
$this->markTestIncomplete();
47+
$uow = $this->getMockBuilder('Doctrine\ODM\PHPCR\UnitOfWork')->disableOriginalConstructor()->getMock();
48+
$uow->expects($this->once())
49+
->method('getDocumentId')
50+
->with($this->document)
51+
->will($this->returnValue('id-123'))
52+
;
53+
54+
$dm = $this->getMockBuilder('Doctrine\ODM\PHPCR\DocumentManager')->disableOriginalConstructor()->getMock();
55+
$dm
56+
->expects($this->once())
57+
->method('getUnitOfWork')
58+
->will($this->returnValue($uow))
59+
;
60+
$this->managerRegistry
61+
->expects($this->once())
62+
->method('getManager')
63+
->will($this->returnValue($dm))
64+
;
65+
66+
$contentRepository = new ContentRepository($this->managerRegistry);
67+
$contentRepository->setManagerName('default');
68+
69+
$this->assertEquals('id-123', $contentRepository->getContentId($this->document));
70+
}
71+
72+
public function testGetContentIdNoObject()
73+
{
74+
$contentRepository = new ContentRepository($this->managerRegistry);
75+
$this->assertNull($contentRepository->getContentId('hello'));
76+
}
77+
78+
public function testGetContentIdException()
79+
{
80+
$this->managerRegistry
81+
->expects($this->once())
82+
->method('getManager')
83+
->will($this->throwException(new \Exception()))
84+
;
85+
86+
$contentRepository = new ContentRepository($this->managerRegistry);
87+
$contentRepository->setManagerName('default');
88+
89+
$this->assertNull($contentRepository->getContentId($this->document));
4890
}
4991

5092
/**

0 commit comments

Comments
 (0)