Rajout de doctrine/orm
[zf2.biz/galerie.git] / vendor / doctrine / orm / tests / Doctrine / Tests / ORM / Functional / Ticket / DDC1526Test.php
1 <?php
2
3 namespace Doctrine\Tests\ORM\Functional\Ticket;
4
5 /**
6  * @group DDC-1526
7  */
8 class DDC1526Test extends \Doctrine\Tests\OrmFunctionalTestCase
9 {
10     public function setUp()
11     {
12         parent::setUp();
13         $this->_schemaTool->createSchema(array(
14             $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1526Menu'),
15         ));
16     }
17
18     public function testIssue()
19     {
20         $parents = array();
21         for ($i = 0; $i < 9; $i++) {
22             $entity = new DDC1526Menu;
23
24             if (isset ($parents[($i % 3)])) {
25                 $entity->parent = $parents[($i%3)];
26             }
27
28             $this->_em->persist($entity);
29             $parents[$i] = $entity;
30         }
31         $this->_em->flush();
32         $this->_em->clear();
33
34
35         $dql = "SELECT m, c
36             FROM " . __NAMESPACE__ . "\DDC1526Menu m
37             LEFT JOIN m.children c";
38         $menus = $this->_em->createQuery($dql)->getResult();
39
40         // All Children collection now have to be initiailzed
41         foreach ($menus as $menu) {
42             $this->assertTrue($menu->children->isInitialized());
43         }
44     }
45 }
46
47 /**
48  * @Entity
49  */
50 class DDC1526Menu
51 {
52     /**
53      * @Column(type="integer")
54      * @Id
55      * @GeneratedValue
56      */
57     public $id;
58     /**
59      * @ManyToOne(targetEntity="DDC1526Menu", inversedBy="children")
60      */
61     public $parent;
62
63     /**
64      * @OneToMany(targetEntity="DDC1526Menu", mappedBy="parent")
65      */
66     public $children;
67 }