1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Doctrine\ODM\CouchDB\Functional; |
4
|
|
|
|
5
|
|
|
class OneToManyAssocationTest extends \Doctrine\Tests\ODM\CouchDB\CouchDBFunctionalTestCase |
6
|
|
|
{ |
7
|
|
|
private $articleIds = array(); |
8
|
|
|
private $userIds = array(); |
9
|
|
|
private $dm; |
10
|
|
|
|
11
|
|
|
public function setUp() |
12
|
|
|
{ |
13
|
|
|
$user1 = new \Doctrine\Tests\Models\CMS\CmsUser(); |
14
|
|
|
$user1->username = "beberlei"; |
15
|
|
|
$user1->status = "active"; |
16
|
|
|
$user1->name = "Benjamin"; |
17
|
|
|
|
18
|
|
|
$user2 = new \Doctrine\Tests\Models\CMS\CmsUser(); |
19
|
|
|
$user2->username = "lsmith"; |
20
|
|
|
$user2->status = "active"; |
21
|
|
|
$user2->name = "Lukas"; |
22
|
|
|
|
23
|
|
|
$article1 = new \Doctrine\Tests\Models\CMS\CmsArticle(); |
24
|
|
|
$article1->text = "Foo"; |
25
|
|
|
$article1->topic = "Foo"; |
26
|
|
|
$article1->setAuthor($user1); |
27
|
|
|
|
28
|
|
|
$article2 = new \Doctrine\Tests\Models\CMS\CmsArticle(); |
29
|
|
|
$article2->text = "Foo"; |
30
|
|
|
$article2->topic = "Foo"; |
31
|
|
|
$article2->setAuthor($user1); |
32
|
|
|
|
33
|
|
|
$this->dm = $this->createDocumentManager(); |
34
|
|
|
$this->dm->persist($user1); |
35
|
|
|
$this->dm->persist($user2); |
36
|
|
|
$this->dm->persist($article1); |
37
|
|
|
$this->dm->persist($article2); |
38
|
|
|
$this->dm->flush(); |
39
|
|
|
|
40
|
|
|
$this->dm->clear(); |
41
|
|
|
|
42
|
|
|
$this->articleIds = array($article1->id, $article2->id); |
43
|
|
|
$this->userIds = array($user1->id, $user2->id); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function testTraverseInverseSide() |
47
|
|
|
{ |
48
|
|
|
$user = $this->dm->find('Doctrine\Tests\Models\CMS\CmsUser', $this->userIds[0]); |
49
|
|
|
|
50
|
|
|
$this->assertInstanceOf('Doctrine\ODM\CouchDB\PersistentCollection', $user->articles); |
51
|
|
|
$this->assertFalse($user->articles->isInitialized); |
52
|
|
|
$this->assertCount(2, $user->articles); |
53
|
|
|
|
54
|
|
|
$this->assertContains($user->articles[0]->id, $this->articleIds); |
55
|
|
|
$this->assertContains($user->articles[1]->id, $this->articleIds); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function testInverseSideChangesAreIgnored() |
59
|
|
|
{ |
60
|
|
|
$user1 = $this->dm->find('Doctrine\Tests\Models\CMS\CmsUser', $this->userIds[0]); |
61
|
|
|
$article3 = new \Doctrine\Tests\Models\CMS\CmsArticle(); |
62
|
|
|
$article3->text = "Foo"; |
63
|
|
|
$article3->topic = "Foo"; |
64
|
|
|
$user1->articles[] = $article3; |
65
|
|
|
|
66
|
|
|
$this->dm->persist($article3); |
67
|
|
|
$this->dm->flush(); |
68
|
|
|
$this->dm->clear(); |
69
|
|
|
|
70
|
|
|
$user = $this->dm->find('Doctrine\Tests\Models\CMS\CmsUser', $this->userIds[0]); |
71
|
|
|
$this->assertCount(2, $user->articles); |
72
|
|
|
} |
73
|
|
|
} |