Rajout de doctrine/orm
[zf2.biz/galerie.git] / vendor / doctrine / orm / tests / Doctrine / Tests / ORM / Functional / Ticket / DDC371Test.php
1 <?php
2 namespace Doctrine\Tests\ORM\Functional\Ticket;
3
4 use Doctrine\ORM\Query;
5
6 require_once __DIR__ . '/../../../TestInit.php';
7
8 /**
9  * @group DDC-371
10  */
11 class DDC371Test extends \Doctrine\Tests\OrmFunctionalTestCase
12 {
13     protected function setUp()
14     {
15         parent::setUp();
16         //$this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger);
17         $this->_schemaTool->createSchema(array(
18             $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC371Parent'),
19             $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC371Child')
20         ));
21     }
22
23     public function testIssue()
24     {
25         $parent = new DDC371Parent;
26         $parent->data = 'parent';
27         $parent->children = new \Doctrine\Common\Collections\ArrayCollection;
28
29         $child = new DDC371Child;
30         $child->data = 'child';
31
32         $child->parent = $parent;
33         $parent->children->add($child);
34
35         $this->_em->persist($parent);
36         $this->_em->persist($child);
37
38         $this->_em->flush();
39         $this->_em->clear();
40
41         $children = $this->_em->createQuery('select c,p from '.__NAMESPACE__.'\DDC371Child c '
42                 . 'left join c.parent p where c.id = 1 and p.id = 1')
43                 ->setHint(Query::HINT_REFRESH, true)
44                 ->getResult();
45
46         $this->assertEquals(1, count($children));
47         $this->assertNotInstanceOf('Doctrine\ORM\Proxy\Proxy', $children[0]->parent);
48         $this->assertFalse($children[0]->parent->children->isInitialized());
49         $this->assertEquals(0, $children[0]->parent->children->unwrap()->count());
50     }
51 }
52
53 /** @Entity */
54 class DDC371Child {
55     /** @Id @Column(type="integer") @GeneratedValue */
56     private $id;
57     /** @Column(type="string") */
58     public $data;
59     /** @ManyToOne(targetEntity="DDC371Parent", inversedBy="children") @JoinColumn(name="parentId") */
60     public $parent;
61 }
62
63 /** @Entity */
64 class DDC371Parent {
65     /** @Id @Column(type="integer") @GeneratedValue */
66     private $id;
67     /** @Column(type="string") */
68     public $data;
69     /** @OneToMany(targetEntity="DDC371Child", mappedBy="parent") */
70     public $children;
71 }
72