MergeTest::testMergeManagedDocument()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 13

Duplication

Lines 13
Ratio 100 %

Importance

Changes 0
Metric Value
dl 13
loc 13
rs 9.8333
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\CmsUser;
6
use Doctrine\Tests\Models\Embedded\Embedder;
7
8
class MergeTest extends \Doctrine\Tests\ODM\CouchDB\CouchDBFunctionalTestCase
9
{
10
    private $dm;
11
12
    public function setUp()
13
    {
14
        $this->dm = $this->createDocumentManager();
15
    }
16
    
17
    public function testMergeNewDocument()
18
    {
19
        $user = new CmsUser();
20
        $user->username = "beberlei";
21
        $user->name = "Benjamin";
22
        
23
        $mergedUser = $this->dm->merge($user);
24
        
25
        $this->assertNotSame($mergedUser, $user);
26
        $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $mergedUser);
27
        $this->assertEquals("beberlei", $mergedUser->username);
28
        $this->assertEquals(32, strlen($mergedUser->id), "Merged new document should have generated UUID");
29
        $this->assertInstanceOf('Doctrine\ODM\CouchDB\PersistentCollection', $mergedUser->groups);
30
        $this->assertInstanceOf('Doctrine\ODM\CouchDB\PersistentCollection', $mergedUser->articles);
31
    }
32
    
33 View Code Duplication
    public function testMergeManagedDocument()
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...
34
    {
35
        $user = new CmsUser();
36
        $user->username = "beberlei";
37
        $user->name = "Benjamin";
38
        
39
        $this->dm->persist($user);
40
        $this->dm->flush();
41
        
42
        $mergedUser = $this->dm->merge($user);
43
     
44
        $this->assertSame($mergedUser, $user);
45
    }
46
    
47
    public function testMergeKnownDocument()
48
    {
49
        $user = new CmsUser();
50
        $user->username = "beberlei";
51
        $user->name = "Benjamin";
52
        
53
        $this->dm->persist($user);
54
        $this->dm->flush();
55
        $this->dm->clear();
56
        
57
        $mergedUser = $this->dm->merge($user);
58
     
59
        $this->assertNotSame($mergedUser, $user);
60
        $this->assertSame($mergedUser->id, $user->id);
61
    }
62
    
63 View Code Duplication
    public function testMergeRemovedDocument()
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...
64
    {
65
        $user = new CmsUser();
66
        $user->username = "beberlei";
67
        $user->name = "Benjamin";
68
        
69
        $this->dm->persist($user);
70
        $this->dm->flush();
71
        
72
        $this->dm->remove($user);
73
        
74
        $this->setExpectedException('InvalidArgumentException', 'Removed document detected during merge. Can not merge with a removed document.');
75
        $this->dm->merge($user);
76
    }
77
    
78
    public function testMergeWithManagedDocument()
79
    {
80
        $user = new CmsUser();
81
        $user->username = "beberlei";
82
        $user->name = "Benjamin";
83
        
84
        $this->dm->persist($user);
85
        $this->dm->flush();
86
        
87
        $mergableUser = new CmsUser();
88
        $mergableUser->id = $user->id;
89
        $mergableUser->username = "jgalt";
90
        $mergableUser->name = "John Galt";
91
        
92
        $mergedUser = $this->dm->merge($mergableUser);
93
        
94
        $this->assertSame($mergedUser, $user);
95
        $this->assertEquals("jgalt", $mergedUser->username);
96
    }
97
    
98 View Code Duplication
    public function testMergeUnknownAssignedId()
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...
99
    {
100
        $doc = new Embedder;
101
        $doc->id = "foo";
102
        $doc->name = "Foo";
103
        
104
        $mergedDoc = $this->dm->merge($doc);
105
        
106
        $this->assertNotSame($mergedDoc, $doc);
107
        $this->assertSame($mergedDoc->id, $doc->id);
108
    }
109
}