Rajout de doctrine/orm
[zf2.biz/galerie.git] / vendor / doctrine / orm / tests / Doctrine / Tests / ORM / Tools / SchemaValidatorTest.php
1 <?php
2
3 namespace Doctrine\Tests\ORM\Tools;
4
5 use Doctrine\ORM\Tools\SchemaValidator;
6
7 require_once __DIR__ . '/../../TestInit.php';
8
9 class SchemaValidatorTest extends \Doctrine\Tests\OrmTestCase
10 {
11     /**
12      * @var EntityManager
13      */
14     private $em = null;
15
16     /**
17      * @var SchemaValidator
18      */
19     private $validator = null;
20
21     public function setUp()
22     {
23         $this->em = $this->_getTestEntityManager();
24         $this->validator = new SchemaValidator($this->em);
25     }
26
27     public function testCmsModelSet()
28     {
29         $this->em->getConfiguration()->getMetadataDriverImpl()->addPaths(array(
30             __DIR__ . "/../../Models/CMS"
31         ));
32         $this->validator->validateMapping();
33     }
34
35     public function testCompanyModelSet()
36     {
37         $this->em->getConfiguration()->getMetadataDriverImpl()->addPaths(array(
38             __DIR__ . "/../../Models/Company"
39         ));
40         $this->validator->validateMapping();
41     }
42
43     public function testECommerceModelSet()
44     {
45         $this->em->getConfiguration()->getMetadataDriverImpl()->addPaths(array(
46             __DIR__ . "/../../Models/ECommerce"
47         ));
48         $this->validator->validateMapping();
49     }
50
51     public function testForumModelSet()
52     {
53         $this->em->getConfiguration()->getMetadataDriverImpl()->addPaths(array(
54             __DIR__ . "/../../Models/Forum"
55         ));
56         $this->validator->validateMapping();
57     }
58
59     public function testNavigationModelSet()
60     {
61         $this->em->getConfiguration()->getMetadataDriverImpl()->addPaths(array(
62             __DIR__ . "/../../Models/Navigation"
63         ));
64         $this->validator->validateMapping();
65     }
66
67     public function testRoutingModelSet()
68     {
69         $this->em->getConfiguration()->getMetadataDriverImpl()->addPaths(array(
70             __DIR__ . "/../../Models/Routing"
71         ));
72         $this->validator->validateMapping();
73     }
74
75     /**
76      * @group DDC-1439
77      */
78     public function testInvalidManyToManyJoinColumnSchema()
79     {
80         $class1 = $this->em->getClassMetadata(__NAMESPACE__ . '\InvalidEntity1');
81         $class2 = $this->em->getClassMetadata(__NAMESPACE__ . '\InvalidEntity2');
82
83         $ce = $this->validator->validateClass($class1);
84
85         $this->assertEquals(
86             array(
87                 "The inverse join columns of the many-to-many table 'Entity1Entity2' have to contain to ALL identifier columns of the target entity 'Doctrine\Tests\ORM\Tools\InvalidEntity2', however 'key4' are missing.",
88                 "The join columns of the many-to-many table 'Entity1Entity2' have to contain to ALL identifier columns of the source entity 'Doctrine\Tests\ORM\Tools\InvalidEntity1', however 'key2' are missing."
89             ),
90             $ce
91         );
92     }
93
94     /**
95      * @group DDC-1439
96      */
97     public function testInvalidToOneJoinColumnSchema()
98     {
99         $class1 = $this->em->getClassMetadata(__NAMESPACE__ . '\InvalidEntity1');
100         $class2 = $this->em->getClassMetadata(__NAMESPACE__ . '\InvalidEntity2');
101
102         $ce = $this->validator->validateClass($class2);
103
104         $this->assertEquals(
105             array(
106                 "The referenced column name 'id' has to be a primary key column on the target entity class 'Doctrine\Tests\ORM\Tools\InvalidEntity1'.",
107                 "The join columns of the association 'assoc' have to match to ALL identifier columns of the target entity 'Doctrine\Tests\ORM\Tools\InvalidEntity2', however 'key1, key2' are missing."
108             ),
109             $ce
110         );
111     }
112
113     /**
114      * @group DDC-1587
115      */
116     public function testValidOneToOneAsIdentifierSchema()
117     {
118         $class1 = $this->em->getClassMetadata(__NAMESPACE__ . '\DDC1587ValidEntity2');
119         $class2 = $this->em->getClassMetadata(__NAMESPACE__ . '\DDC1587ValidEntity1');
120
121         $ce = $this->validator->validateClass($class1);
122
123         $this->assertEquals(array(), $ce);
124     }
125
126     /**
127      * @group DDC-1649
128      */
129     public function testInvalidTripleAssociationAsKeyMapping()
130     {
131         $classThree = $this->em->getClassMetadata(__NAMESPACE__ . '\DDC1649Three');
132         $ce = $this->validator->validateClass($classThree);
133
134         $this->assertEquals(Array(
135             "Cannot map association 'Doctrine\Tests\ORM\Tools\DDC1649Three#two as identifier, because the target entity 'Doctrine\Tests\ORM\Tools\DDC1649Two' also maps an association as identifier.",
136             "The referenced column name 'id' has to be a primary key column on the target entity class 'Doctrine\Tests\ORM\Tools\DDC1649Two'."
137         ), $ce);
138     }
139 }
140
141 /**
142  * @Entity
143  */
144 class InvalidEntity1
145 {
146     /**
147      * @Id @Column
148      */
149     protected $key1;
150     /**
151      * @Id @Column
152      */
153     protected $key2;
154     /**
155      * @ManyToMany (targetEntity="InvalidEntity2")
156      * @JoinTable (name="Entity1Entity2",
157      *      joinColumns={@JoinColumn(name="key1", referencedColumnName="key1")},
158      *      inverseJoinColumns={@JoinColumn(name="key3", referencedColumnName="key3")}
159      *      )
160      */
161     protected $entity2;
162 }
163
164 /**
165  * @Entity
166  */
167 class InvalidEntity2
168 {
169     /**
170      * @Id @Column
171      */
172     protected $key3;
173
174     /**
175      * @Id @Column
176      */
177     protected $key4;
178
179     /**
180      * @ManyToOne(targetEntity="InvalidEntity1")
181      */
182     protected $assoc;
183 }
184
185 /**
186  * @Entity(repositoryClass="Entity\Repository\Agent")
187  * @Table(name="agent")
188  */
189 class DDC1587ValidEntity1
190 {
191     /**
192      * @var int
193      *
194      * @Id @GeneratedValue
195      * @Column(name="pk", type="integer")
196      */
197     private $pk;
198
199     /**
200      * @var string
201      *
202      * @Column(name="name", type="string", length=32)
203      */
204     private $name;
205
206     /**
207      * @var Identifier
208      *
209      * @OneToOne(targetEntity="DDC1587ValidEntity2", cascade={"all"}, mappedBy="agent")
210      * @JoinColumn(name="pk", referencedColumnName="pk_agent")
211      */
212     private $identifier;
213 }
214
215 /**
216  * @Entity
217  * @Table
218  */
219 class DDC1587ValidEntity2
220 {
221     /**
222      * @var DDC1587ValidEntity1
223      *
224      * @Id
225      * @OneToOne(targetEntity="DDC1587ValidEntity1", inversedBy="identifier")
226      * @JoinColumn(name="pk_agent", referencedColumnName="pk", nullable=false)
227      */
228     private $agent;
229
230     /**
231      * @var string
232      *
233      * @Column(name="num", type="string", length=16, nullable=true)
234      */
235     private $num;
236 }
237
238 /**
239  * @Entity
240  */
241 class DDC1649One
242 {
243     /**
244      * @Id @Column @GeneratedValue
245      */
246     public $id;
247 }
248
249 /**
250  * @Entity
251  */
252 class DDC1649Two
253 {
254     /** @Id @ManyToOne(targetEntity="DDC1649One")@JoinColumn(name="id", referencedColumnName="id")  */
255     public $one;
256 }
257
258 /**
259  * @Entity
260  */
261 class DDC1649Three
262 {
263     /** @Id @ManyToOne(targetEntity="DDC1649Two") @JoinColumn(name="id",
264      * referencedColumnName="id") */
265     private $two;
266 }
267