Rajout de doctrine/orm
[zf2.biz/galerie.git] / vendor / doctrine / orm / tests / Doctrine / Tests / ORM / Functional / Ticket / DDC719Test.php
1 <?php
2
3 namespace Doctrine\Tests\ORM\Functional\Ticket;
4
5 require_once __DIR__ . '/../../../TestInit.php';
6
7 class DDC719Test extends \Doctrine\Tests\OrmFunctionalTestCase
8 {
9     protected function setUp()
10     {
11         parent::setUp();
12         //$this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger);
13         $this->_schemaTool->createSchema(array(
14             $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC719Group'),
15         ));
16     }
17
18     public function testIsEmptySqlGeneration()
19     {
20         $q = $this->_em->createQuery('SELECT g, c FROM Doctrine\Tests\ORM\Functional\Ticket\DDC719Group g LEFT JOIN g.children c  WHERE g.parents IS EMPTY');
21
22         $this->assertEquals(
23             strtolower('SELECT g0_.name AS name0, g0_.description AS description1, g0_.id AS id2, g1_.name AS name3, g1_.description AS description4, g1_.id AS id5 FROM groups g0_ LEFT JOIN groups_groups g2_ ON g0_.id = g2_.parent_id LEFT JOIN groups g1_ ON g1_.id = g2_.child_id WHERE (SELECT COUNT(*) FROM groups_groups g3_ WHERE g3_.child_id = g0_.id) = 0'),
24             strtolower($q->getSQL())
25         );
26     }
27 }
28
29 /**
30  * @MappedSuperclass
31  */
32 class Entity
33 {
34     /**
35      * @Id @GeneratedValue
36      * @Column(type="integer")
37      */
38     protected $id;
39
40     public function getId() { return $this->id; }
41 }
42
43 /**
44  * @Entity
45  * @Table(name="groups")
46  */
47 class DDC719Group extends Entity {
48     /** @Column(type="string", nullable=false) */
49     protected $name;
50
51         /** @Column(type="string", nullable=true) */
52         protected $description;
53
54         /**
55          * @ManyToMany(targetEntity="DDC719Group", inversedBy="parents")
56          * @JoinTable(name="groups_groups",
57          *              joinColumns={@JoinColumn(name="parent_id", referencedColumnName="id")},
58          *              inverseJoinColumns={@JoinColumn(name="child_id", referencedColumnName="id")}
59          * )
60          */
61         protected $children = NULL;
62
63         /**
64          * @ManyToMany(targetEntity="DDC719Group", mappedBy="children")
65          */
66         protected $parents = NULL;
67
68         /**
69          * construct
70          */
71         public function __construct() {
72                 parent::__construct();
73
74                 $this->channels = new ArrayCollection();
75                 $this->children = new ArrayCollection();
76                 $this->parents = new ArrayCollection();
77         }
78
79         /**
80          * adds group as new child
81          *
82          * @param Group $child
83          */
84         public function addGroup(Group $child) {
85         if ( ! $this->children->contains($child)) {
86             $this->children->add($child);
87             $child->addGroup($this);
88         }
89         }
90
91         /**
92          * adds channel as new child
93          *
94          * @param Channel $child
95          */
96         public function addChannel(Channel $child) {
97         if ( ! $this->channels->contains($child)) {
98             $this->channels->add($child);
99         }
100         }
101
102         /**
103          * getter & setter
104          */
105         public function getName() { return $this->name; }
106         public function setName($name) { $this->name = $name; }
107         public function getDescription() { return $this->description; }
108         public function setDescription($description) { $this->description = $description; }
109         public function getChildren() { return $this->children; }
110         public function getParents() { return $this->parents; }
111         public function getChannels() { return $this->channels; }
112 }