1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Psi\Bridge\ObjectAgent\Doctrine\PhpcrOdm\Tests\Functional; |
4
|
|
|
|
5
|
|
|
use Psi\Bridge\ObjectAgent\Doctrine\PhpcrOdm\Tests\Functional\Model\Article; |
6
|
|
|
use Psi\Component\ObjectAgent\Tests\Functional\AgentTestTrait; |
7
|
|
|
use Psi\Component\ObjectAgent\Tests\Functional\Model\Page; |
8
|
|
|
|
9
|
|
|
class PhpcrOdmAgentTest extends PhpcrOdmTestCase |
10
|
|
|
{ |
11
|
|
|
private $agent; |
12
|
|
|
private $documentManager; |
13
|
|
|
|
14
|
|
|
use AgentTestTrait; |
15
|
|
|
|
16
|
|
|
public function setUp() |
17
|
|
|
{ |
18
|
|
|
$container = $this->getContainer(); |
19
|
|
|
$this->agent = $container->get('psi_object_agent.phpcr_odm'); |
20
|
|
|
$this->documentManager = $container->get('phpcr_odm'); |
21
|
|
|
$this->initPhpcr($this->documentManager); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* It should set the parent document on a given document. |
26
|
|
|
*/ |
27
|
|
|
public function testSetParent() |
28
|
|
|
{ |
29
|
|
|
$parent = $this->createPage(); |
30
|
|
|
$article = new Article(); |
31
|
|
|
$article->name = 'article'; |
32
|
|
|
$this->agent->setParent($article, $parent); |
33
|
|
|
|
34
|
|
|
$this->documentManager->persist($article); |
35
|
|
|
$this->documentManager->flush(); |
36
|
|
|
|
37
|
|
|
$document = $this->documentManager->find(null, '/test/page-1/article'); |
38
|
|
|
$this->assertNotNull($document); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* It should throw an exception if attempting to set parent on a document with no parent mapping. |
43
|
|
|
* |
44
|
|
|
* @expectedException \RuntimeException |
45
|
|
|
* @expectedExceptionMessage does not have a ParentDocument mapping |
46
|
|
|
*/ |
47
|
|
|
public function testSetParentNoParentMapping() |
48
|
|
|
{ |
49
|
|
|
$parent = $this->createPage(); |
50
|
|
|
$page = new Page(); |
51
|
|
|
$this->agent->setParent($page, $parent); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
View Code Duplication |
private function createPage($title = 'Hello World') |
|
|
|
|
55
|
|
|
{ |
56
|
|
|
static $id = 1; |
57
|
|
|
|
58
|
|
|
$page = new Page(); |
59
|
|
|
$page->title = $title; |
60
|
|
|
$page->path = '/test/page-' . $id++; |
61
|
|
|
$this->documentManager->persist($page); |
62
|
|
|
$this->documentManager->flush(); |
63
|
|
|
|
64
|
|
|
return $page; |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.