Completed
Push — master ( bd48a4...4fe654 )
by Daniel
9s
created

PhpcrOdmAgentTest::testSetParentNoParentMapping()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 0
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')
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
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