Rajout de doctrine/orm
[zf2.biz/galerie.git] / vendor / doctrine / orm / tests / Doctrine / Tests / ORM / Functional / Ticket / DDC1461Test.php
1 <?php
2
3 namespace Doctrine\Tests\ORM\Functional\Ticket;
4
5 use Doctrine\Common\Collections\ArrayCollection;
6 use Doctrine\Tests\Models\CMS\CmsArticle;
7 use Doctrine\Tests\Models\CMS\CmsUser;
8 require_once __DIR__ . '/../../../TestInit.php';
9
10 /**
11  * @group DDC-1461
12  */
13 class DDC1461Test extends \Doctrine\Tests\OrmFunctionalTestCase
14 {
15     public function setUp()
16     {
17         parent::setUp();
18
19         try {
20             $this->_schemaTool->createSchema(array(
21                 $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1461TwitterAccount'),
22                 $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1461User')
23             ));
24         } catch(\Exception $e) {
25
26         }
27     }
28
29     public function testChangeDetectionDeferredExplicit()
30     {
31         $user = new DDC1461User;
32         $this->_em->persist($user);
33         $this->_em->flush();
34
35         $this->assertEquals(\Doctrine\ORM\UnitOfWork::STATE_MANAGED, $this->_em->getUnitOfWork()->getEntityState($user, \Doctrine\ORM\UnitOfWork::STATE_NEW), "Entity should be managed.");
36         $this->assertEquals(\Doctrine\ORM\UnitOfWork::STATE_MANAGED, $this->_em->getUnitOfWork()->getEntityState($user), "Entity should be managed.");
37
38         $acc = new DDC1461TwitterAccount;
39         $user->twitterAccount = $acc;
40
41         $this->_em->persist($user);
42         $this->_em->flush();
43
44         $user = $this->_em->find(get_class($user), $user->id);
45         $this->assertNotNull($user->twitterAccount);
46     }
47 }
48
49 /**
50  * @Entity
51  * @ChangeTrackingPolicy("DEFERRED_EXPLICIT")
52  */
53 class DDC1461User
54 {
55     /**
56      * @Id
57      * @GeneratedValue(strategy="AUTO")
58      * @Column(type="integer")
59      */
60     public $id;
61
62     /**
63      * @OneToOne(targetEntity="DDC1461TwitterAccount", orphanRemoval=true, fetch="EAGER", cascade = {"persist"}, inversedBy="user")
64      * @var TwitterAccount
65      */
66     public $twitterAccount;
67 }
68
69 /**
70  * @Entity
71  * @ChangeTrackingPolicy("DEFERRED_EXPLICIT")
72  */
73 class DDC1461TwitterAccount
74 {
75     /**
76      * @Id
77      * @GeneratedValue(strategy="AUTO")
78      * @Column(type="integer")
79      */
80     public $id;
81
82     /**
83      * @OneToOne(targetEntity="DDC1461User", fetch="EAGER")
84      */
85     public $user;
86 }