ManyToOneAssociationTest::testReuseIdentityMap()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Doctrine\Tests\ODM\CouchDB\Functional;
4
5
use Doctrine\Tests\Models\CMS\CmsNode;
6
7
class ManyToOneAssociationTest extends \Doctrine\Tests\ODM\CouchDB\CouchDBFunctionalTestCase
8
{
9
    private $articleId;
10
    private $userIds = array();
11
    private $dm;
12
13
    public function setUp()
14
    {
15
        $user1 = new \Doctrine\Tests\Models\CMS\CmsUser();
16
        $user1->username = "beberlei";
17
        $user1->status = "active";
18
        $user1->name = "Benjamin";
19
20
        $user2 = new \Doctrine\Tests\Models\CMS\CmsUser();
21
        $user2->username = "lsmith";
22
        $user2->status = "active";
23
        $user2->name = "Lukas";
24
25
        $article = new \Doctrine\Tests\Models\CMS\CmsArticle();
26
        $article->text = "Foo";
27
        $article->topic = "Foo";
28
        $article->setAuthor($user1);
29
30
        $this->dm = $this->createDocumentManager();
31
        $this->dm->persist($user1);
32
        $this->dm->persist($user2);
33
        $this->dm->persist($article);
34
        $this->dm->flush();
35
36
        $this->dm->clear();
37
38
        $this->articleId = $article->id;
39
        $this->userIds = array($user1->id, $user2->id);
40
    }
41
42 View Code Duplication
    public function testSaveWithAssociation()
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...
43
    {
44
        $article = $this->dm->find('Doctrine\Tests\Models\CMS\CmsArticle', $this->articleId);
45
46
        $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $article->user);
47
        $this->assertNull($article->user->username, 'CmsUser is a proxy, username is NULL through public access');
48
        $this->assertEquals('beberlei', $article->user->getUsername());
49
    }
50
51
    public function testSwitchAssociation()
52
    {
53
        $article = $this->dm->find('Doctrine\Tests\Models\CMS\CmsArticle', $this->articleId);
54
        $otherUser = $this->dm->find('Doctrine\Tests\Models\CMS\CmsUser', $this->userIds[1]);
55
56
        $article->setAuthor($otherUser);
57
58
        $this->dm->flush();
59
        $this->dm->clear();
60
61
        $article = $this->dm->find('Doctrine\Tests\Models\CMS\CmsArticle', $this->articleId);
62
        $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $article->user);
63
        $this->assertEquals('lsmith', $article->user->getUsername());
64
    }
65
66
    public function testReuseIdentityMap()
67
    {
68
        $author = $this->dm->find('Doctrine\Tests\Models\CMS\CmsUser', $this->userIds[0]);
69
        $article = $this->dm->find('Doctrine\Tests\Models\CMS\CmsArticle', $this->articleId);
70
71
        $this->assertNotInstanceOf('Doctrine\ODM\CouchDB\Proxy\Proxy', $article->user);
72
        $this->assertSame($author, $article->user);
73
    }
74
75
    public function testNullReference()
76
    {
77
        $this->markTestIncomplete('Test that persisting and hydrating null works smoothly.');
78
    }
79
80
    public function testNoTargetDocument()
81
    {
82
        $node = new CmsNode();
83
        $node->content = $this->dm->find('Doctrine\Tests\Models\CMS\CmsArticle', $this->articleId);
84
85
        $this->dm->persist($node);
86
        $this->dm->flush();
87
        $this->dm->clear();
88
89
        $node = $this->dm->find('Doctrine\Tests\Models\CMS\CmsNode', $node->id);
90
        $this->assertInstanceof('Doctrine\Tests\Models\CMS\CmsArticle', $node->content);
91
    }
92
}
93