Rajout de doctrine/orm
[zf2.biz/galerie.git] / vendor / doctrine / orm / tests / Doctrine / Tests / ORM / Functional / Ticket / DDC742Test.php
1 <?php
2
3 namespace Doctrine\Tests\ORM\Functional\Ticket;
4
5 use Doctrine\Common\Collections\ArrayCollection;
6
7 require_once __DIR__ . '/../../../TestInit.php';
8
9 class DDC742Test extends \Doctrine\Tests\OrmFunctionalTestCase
10 {
11     private $userCm;
12     private $commentCm;
13
14     protected function setUp()
15     {
16         parent::setUp();
17
18         if (\extension_loaded('memcache')) {
19             $memcache = new \Memcache();
20             $memcache->addServer('localhost');
21             $memcache->flush();
22
23             $cacheDriver = new \Doctrine\Common\Cache\MemcacheCache();
24             $cacheDriver->setMemcache($memcache);
25
26             $this->_em->getMetadataFactory()->setCacheDriver($cacheDriver);
27         } else if (\extension_loaded('apc')) {
28             $this->_em->getMetadataFactory()->setCacheDriver(new \Doctrine\Common\Cache\ApcCache());
29         }
30
31         try {
32             $this->_schemaTool->createSchema(array(
33                 $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC742User'),
34                 $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC742Comment')
35             ));
36         } catch(\Exception $e) {
37
38         }
39
40         // make sure classes will be deserialized from caches
41         $this->_em->getMetadataFactory()->setMetadataFor(__NAMESPACE__ . '\DDC742User', null);
42         $this->_em->getMetadataFactory()->setMetadataFor(__NAMESPACE__ . '\DDC742Comment', null);
43     }
44
45     public function testIssue()
46     {
47         $user = new DDC742User();
48         $user->title = "Foo";
49         $user->favoriteComments = new ArrayCollection();
50
51         $comment1 = new DDC742Comment();
52         $comment1->content = "foo";
53
54         $comment2 = new DDC742Comment();
55         $comment2->content = "bar";
56
57         $comment3 = new DDC742Comment();
58         $comment3->content = "baz";
59
60         $user->favoriteComments->add($comment1);
61         $user->favoriteComments->add($comment2);
62
63         $this->_em->persist($user);
64         $this->_em->persist($comment1);
65         $this->_em->persist($comment2);
66         $this->_em->persist($comment3);
67         $this->_em->flush();
68         $this->_em->clear();
69
70         $user = $this->_em->find(get_class($user), $user->id);
71         $comment3 = $this->_em->find(get_class($comment3), $comment3->id);
72         $user->favoriteComments->add($comment3);
73         $this->_em->flush();
74     }
75 }
76
77 /**
78  * @Entity
79  * @Table(name="users")
80  */
81 class DDC742User
82 {
83     /**
84      * User Id
85      *
86      * @Id
87      * @GeneratedValue(strategy="AUTO")
88      * @Column(type="integer")
89      * @var integer
90      */
91     public $id;
92     /**
93      * @Column(length=100, type="string")
94      * @var string
95      */
96     public $title;
97     /**
98      * @ManyToMany(targetEntity="DDC742Comment", cascade={"persist"}, fetch="EAGER")
99      * @JoinTable(
100      *  name="user_comments",
101      *  joinColumns={@JoinColumn(name="user_id",referencedColumnName="id")},
102      *  inverseJoinColumns={@JoinColumn(name="comment_id", referencedColumnName="id")}
103      * )
104      *
105      * @var Doctrine\ORM\PersistentCollection
106      */
107     public $favoriteComments;
108 }
109
110 /**
111  * @Entity
112  * @Table(name="comments")
113  */
114 class DDC742Comment
115 {
116     /**
117      * User Id
118      *
119      * @Id
120      * @GeneratedValue(strategy="AUTO")
121      * @Column(type="integer")
122      * @var integer
123      */
124     public $id;
125     /**
126      * @Column(length=100, type="string")
127      * @var string
128      */
129     public $content;
130 }