Rajout de doctrine/orm
[zf2.biz/galerie.git] / vendor / doctrine / orm / tests / Doctrine / Tests / ORM / Functional / Ticket / DDC748Test.php
1 <?php
2
3 namespace Doctrine\Tests\ORM\Functional\Ticket;
4
5 use Doctrine\Common\Collections\ArrayCollection;
6 use Doctrine\Tests\Models\CMS\CmsUser;
7 use Doctrine\Tests\Models\CMS\CmsArticle;
8 use Doctrine\Tests\Models\CMS\CmsAddress;
9
10 require_once __DIR__ . '/../../../TestInit.php';
11
12 class DDC748Test extends \Doctrine\Tests\OrmFunctionalTestCase
13 {
14     protected function setUp()
15     {
16         $this->useModelSet('cms');
17         parent::setUp();
18     }
19
20     public function testRefreshWithManyToOne()
21     {
22         $user = new CmsUser();
23         $user->name = "beberlei";
24         $user->status = "active";
25         $user->username = "beberlei";
26
27         $article = new CmsArticle();
28         $article->setAuthor($user);
29         $article->text = "foo";
30         $article->topic = "bar";
31
32         $this->_em->persist($user);
33         $this->_em->persist($article);
34         $this->_em->flush();
35
36         $this->assertInstanceOf('Doctrine\Common\Collections\Collection', $user->articles);
37         $this->_em->refresh($article);
38         $this->assertTrue($article !== $user->articles, "The article should not be replaced on the inverse side of the relation.");
39         $this->assertInstanceOf('Doctrine\Common\Collections\Collection', $user->articles);
40     }
41
42     public function testRefreshOneToOne()
43     {
44         $user = new CmsUser();
45         $user->name = "beberlei";
46         $user->status = "active";
47         $user->username = "beberlei";
48
49         $address = new CmsAddress();
50         $address->city = "Bonn";
51         $address->country = "Germany";
52         $address->street = "A street";
53         $address->zip = 12345;
54         $address->setUser($user);
55
56         $this->_em->persist($user);
57         $this->_em->persist($address);
58         $this->_em->flush();
59
60         $this->_em->refresh($address);
61         $this->assertSame($user, $address->user);
62         $this->assertSame($user->address, $address);
63     }
64 }