1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Doctrine\Tests\DBAL\Schema; |
4
|
|
|
|
5
|
|
|
use Doctrine\DBAL\Schema\Column; |
6
|
|
|
use Doctrine\DBAL\Schema\ForeignKeyConstraint; |
7
|
|
|
use Doctrine\DBAL\Schema\Index; |
8
|
|
|
use Doctrine\DBAL\Schema\Table; |
9
|
|
|
use Doctrine\DBAL\Types\Type; |
10
|
|
|
|
11
|
|
|
class TableTest extends \Doctrine\Tests\DbalTestCase |
12
|
|
|
{ |
13
|
|
|
public function testCreateWithInvalidTableName() |
14
|
|
|
{ |
15
|
|
|
$this->setExpectedException('Doctrine\DBAL\DBALException'); |
|
|
|
|
16
|
|
|
$table = new \Doctrine\DBAL\Schema\Table(''); |
|
|
|
|
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
public function testGetName() |
20
|
|
|
{ |
21
|
|
|
$table = new Table("foo", array(), array(), array()); |
22
|
|
|
$this->assertEquals("foo", $table->getName()); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
public function testColumns() |
26
|
|
|
{ |
27
|
|
|
$type = Type::getType('integer'); |
28
|
|
|
$columns = array(); |
29
|
|
|
$columns[] = new Column("foo", $type); |
30
|
|
|
$columns[] = new Column("bar", $type); |
31
|
|
|
$table = new Table("foo", $columns, array(), array()); |
32
|
|
|
|
33
|
|
|
$this->assertTrue($table->hasColumn("foo")); |
34
|
|
|
$this->assertTrue($table->hasColumn("bar")); |
35
|
|
|
$this->assertFalse($table->hasColumn("baz")); |
36
|
|
|
|
37
|
|
|
$this->assertInstanceOf('Doctrine\DBAL\Schema\Column', $table->getColumn("foo")); |
38
|
|
|
$this->assertInstanceOf('Doctrine\DBAL\Schema\Column', $table->getColumn("bar")); |
39
|
|
|
|
40
|
|
|
$this->assertEquals(2, count($table->getColumns())); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function testColumnsCaseInsensitive() |
44
|
|
|
{ |
45
|
|
|
$table = new Table("foo"); |
46
|
|
|
$column = $table->addColumn('Foo', 'integer'); |
47
|
|
|
|
48
|
|
|
$this->assertTrue($table->hasColumn('Foo')); |
49
|
|
|
$this->assertTrue($table->hasColumn('foo')); |
50
|
|
|
$this->assertTrue($table->hasColumn('FOO')); |
51
|
|
|
|
52
|
|
|
$this->assertSame($column, $table->getColumn('Foo')); |
53
|
|
|
$this->assertSame($column, $table->getColumn('foo')); |
54
|
|
|
$this->assertSame($column, $table->getColumn('FOO')); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function testCreateColumn() |
58
|
|
|
{ |
59
|
|
|
$type = Type::getType('integer'); |
60
|
|
|
|
61
|
|
|
$table = new Table("foo"); |
62
|
|
|
|
63
|
|
|
$this->assertFalse($table->hasColumn("bar")); |
64
|
|
|
$table->addColumn("bar", 'integer'); |
65
|
|
|
$this->assertTrue($table->hasColumn("bar")); |
66
|
|
|
$this->assertSame($type, $table->getColumn("bar")->getType()); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function testDropColumn() |
70
|
|
|
{ |
71
|
|
|
$type = Type::getType('integer'); |
72
|
|
|
$columns = array(); |
73
|
|
|
$columns[] = new Column("foo", $type); |
74
|
|
|
$columns[] = new Column("bar", $type); |
75
|
|
|
$table = new Table("foo", $columns, array(), array()); |
76
|
|
|
|
77
|
|
|
$this->assertTrue($table->hasColumn("foo")); |
78
|
|
|
$this->assertTrue($table->hasColumn("bar")); |
79
|
|
|
|
80
|
|
|
$table->dropColumn("foo")->dropColumn("bar"); |
81
|
|
|
|
82
|
|
|
$this->assertFalse($table->hasColumn("foo")); |
83
|
|
|
$this->assertFalse($table->hasColumn("bar")); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
public function testGetUnknownColumnThrowsException() |
87
|
|
|
{ |
88
|
|
|
$this->setExpectedException("Doctrine\DBAL\Schema\SchemaException"); |
|
|
|
|
89
|
|
|
|
90
|
|
|
$table = new Table("foo", array(), array(), array()); |
91
|
|
|
$table->getColumn('unknown'); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
public function testAddColumnTwiceThrowsException() |
95
|
|
|
{ |
96
|
|
|
$this->setExpectedException("Doctrine\DBAL\Schema\SchemaException"); |
|
|
|
|
97
|
|
|
|
98
|
|
|
$type = \Doctrine\DBAL\Types\Type::getType('integer'); |
99
|
|
|
$columns = array(); |
100
|
|
|
$columns[] = new Column("foo", $type); |
101
|
|
|
$columns[] = new Column("foo", $type); |
102
|
|
|
$table = new Table("foo", $columns, array(), array()); |
|
|
|
|
103
|
|
|
} |
104
|
|
|
|
105
|
|
View Code Duplication |
public function testCreateIndex() |
|
|
|
|
106
|
|
|
{ |
107
|
|
|
$type = \Doctrine\DBAL\Types\Type::getType('integer'); |
108
|
|
|
$columns = array(new Column("foo", $type), new Column("bar", $type), new Column("baz", $type)); |
109
|
|
|
$table = new Table("foo", $columns); |
110
|
|
|
|
111
|
|
|
$table->addIndex(array("foo", "bar"), "foo_foo_bar_idx"); |
112
|
|
|
$table->addUniqueIndex(array("bar", "baz"), "foo_bar_baz_uniq"); |
113
|
|
|
|
114
|
|
|
$this->assertTrue($table->hasIndex("foo_foo_bar_idx")); |
115
|
|
|
$this->assertTrue($table->hasIndex("foo_bar_baz_uniq")); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
View Code Duplication |
public function testIndexCaseInsensitive() |
|
|
|
|
119
|
|
|
{ |
120
|
|
|
$type = \Doctrine\DBAL\Types\Type::getType('integer'); |
121
|
|
|
$columns = array( |
122
|
|
|
new Column("foo", $type), |
123
|
|
|
new Column("bar", $type), |
124
|
|
|
new Column("baz", $type) |
125
|
|
|
); |
126
|
|
|
$table = new Table("foo", $columns); |
127
|
|
|
|
128
|
|
|
$table->addIndex(array("foo", "bar", "baz"), "Foo_Idx"); |
129
|
|
|
|
130
|
|
|
$this->assertTrue($table->hasIndex('foo_idx')); |
131
|
|
|
$this->assertTrue($table->hasIndex('Foo_Idx')); |
132
|
|
|
$this->assertTrue($table->hasIndex('FOO_IDX')); |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
public function testAddIndexes() |
136
|
|
|
{ |
137
|
|
|
$type = \Doctrine\DBAL\Types\Type::getType('integer'); |
138
|
|
|
$columns = array( |
139
|
|
|
new Column("foo", $type), |
140
|
|
|
new Column("bar", $type), |
141
|
|
|
); |
142
|
|
|
$indexes = array( |
143
|
|
|
new Index("the_primary", array("foo"), true, true), |
144
|
|
|
new Index("bar_idx", array("bar"), false, false), |
145
|
|
|
); |
146
|
|
|
$table = new Table("foo", $columns, $indexes, array()); |
147
|
|
|
|
148
|
|
|
$this->assertTrue($table->hasIndex("the_primary")); |
149
|
|
|
$this->assertTrue($table->hasIndex("bar_idx")); |
150
|
|
|
$this->assertFalse($table->hasIndex("some_idx")); |
151
|
|
|
|
152
|
|
|
$this->assertInstanceOf('Doctrine\DBAL\Schema\Index', $table->getPrimaryKey()); |
153
|
|
|
$this->assertInstanceOf('Doctrine\DBAL\Schema\Index', $table->getIndex('the_primary')); |
154
|
|
|
$this->assertInstanceOf('Doctrine\DBAL\Schema\Index', $table->getIndex('bar_idx')); |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
public function testGetUnknownIndexThrowsException() |
158
|
|
|
{ |
159
|
|
|
$this->setExpectedException("Doctrine\DBAL\Schema\SchemaException"); |
|
|
|
|
160
|
|
|
|
161
|
|
|
$table = new Table("foo", array(), array(), array()); |
162
|
|
|
$table->getIndex("unknownIndex"); |
163
|
|
|
} |
164
|
|
|
|
165
|
|
View Code Duplication |
public function testAddTwoPrimaryThrowsException() |
|
|
|
|
166
|
|
|
{ |
167
|
|
|
$this->setExpectedException("Doctrine\DBAL\Schema\SchemaException"); |
|
|
|
|
168
|
|
|
|
169
|
|
|
$type = \Doctrine\DBAL\Types\Type::getType('integer'); |
170
|
|
|
$columns = array(new Column("foo", $type), new Column("bar", $type)); |
171
|
|
|
$indexes = array( |
172
|
|
|
new Index("the_primary", array("foo"), true, true), |
173
|
|
|
new Index("other_primary", array("bar"), true, true), |
174
|
|
|
); |
175
|
|
|
$table = new Table("foo", $columns, $indexes, array()); |
|
|
|
|
176
|
|
|
} |
177
|
|
|
|
178
|
|
View Code Duplication |
public function testAddTwoIndexesWithSameNameThrowsException() |
|
|
|
|
179
|
|
|
{ |
180
|
|
|
$this->setExpectedException("Doctrine\DBAL\Schema\SchemaException"); |
|
|
|
|
181
|
|
|
|
182
|
|
|
$type = \Doctrine\DBAL\Types\Type::getType('integer'); |
183
|
|
|
$columns = array(new Column("foo", $type), new Column("bar", $type)); |
184
|
|
|
$indexes = array( |
185
|
|
|
new Index("an_idx", array("foo"), false, false), |
186
|
|
|
new Index("an_idx", array("bar"), false, false), |
187
|
|
|
); |
188
|
|
|
$table = new Table("foo", $columns, $indexes, array()); |
|
|
|
|
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
public function testConstraints() |
192
|
|
|
{ |
193
|
|
|
$constraint = new ForeignKeyConstraint(array(), "foo", array()); |
194
|
|
|
|
195
|
|
|
$tableA = new Table("foo", array(), array(), array($constraint)); |
196
|
|
|
$constraints = $tableA->getForeignKeys(); |
197
|
|
|
|
198
|
|
|
$this->assertEquals(1, count($constraints)); |
199
|
|
|
$this->assertSame($constraint, array_shift($constraints)); |
200
|
|
|
} |
201
|
|
|
|
202
|
|
|
public function testOptions() |
203
|
|
|
{ |
204
|
|
|
$table = new Table("foo", array(), array(), array(), false, array("foo" => "bar")); |
|
|
|
|
205
|
|
|
|
206
|
|
|
$this->assertTrue($table->hasOption("foo")); |
207
|
|
|
$this->assertEquals("bar", $table->getOption("foo")); |
208
|
|
|
} |
209
|
|
|
|
210
|
|
View Code Duplication |
public function testBuilderSetPrimaryKey() |
|
|
|
|
211
|
|
|
{ |
212
|
|
|
$table = new Table("foo"); |
213
|
|
|
|
214
|
|
|
$table->addColumn("bar", 'integer'); |
215
|
|
|
$table->setPrimaryKey(array("bar")); |
216
|
|
|
|
217
|
|
|
$this->assertTrue($table->hasIndex("primary")); |
218
|
|
|
$this->assertInstanceOf('Doctrine\DBAL\Schema\Index', $table->getPrimaryKey()); |
219
|
|
|
$this->assertTrue($table->getIndex("primary")->isUnique()); |
220
|
|
|
$this->assertTrue($table->getIndex("primary")->isPrimary()); |
221
|
|
|
} |
222
|
|
|
|
223
|
|
View Code Duplication |
public function testBuilderAddUniqueIndex() |
|
|
|
|
224
|
|
|
{ |
225
|
|
|
$table = new Table("foo"); |
226
|
|
|
|
227
|
|
|
$table->addColumn("bar", 'integer'); |
228
|
|
|
$table->addUniqueIndex(array("bar"), "my_idx"); |
229
|
|
|
|
230
|
|
|
$this->assertTrue($table->hasIndex("my_idx")); |
231
|
|
|
$this->assertTrue($table->getIndex("my_idx")->isUnique()); |
232
|
|
|
$this->assertFalse($table->getIndex("my_idx")->isPrimary()); |
233
|
|
|
} |
234
|
|
|
|
235
|
|
View Code Duplication |
public function testBuilderAddIndex() |
|
|
|
|
236
|
|
|
{ |
237
|
|
|
$table = new Table("foo"); |
238
|
|
|
|
239
|
|
|
$table->addColumn("bar", 'integer'); |
240
|
|
|
$table->addIndex(array("bar"), "my_idx"); |
241
|
|
|
|
242
|
|
|
$this->assertTrue($table->hasIndex("my_idx")); |
243
|
|
|
$this->assertFalse($table->getIndex("my_idx")->isUnique()); |
244
|
|
|
$this->assertFalse($table->getIndex("my_idx")->isPrimary()); |
245
|
|
|
} |
246
|
|
|
|
247
|
|
|
public function testBuilderAddIndexWithInvalidNameThrowsException() |
248
|
|
|
{ |
249
|
|
|
$this->setExpectedException("Doctrine\DBAL\Schema\SchemaException"); |
|
|
|
|
250
|
|
|
|
251
|
|
|
$table = new Table("foo"); |
252
|
|
|
$table->addColumn("bar",'integer'); |
253
|
|
|
$table->addIndex(array("bar"), "invalid name %&/"); |
254
|
|
|
} |
255
|
|
|
|
256
|
|
|
public function testBuilderAddIndexWithUnknownColumnThrowsException() |
257
|
|
|
{ |
258
|
|
|
$this->setExpectedException("Doctrine\DBAL\Schema\SchemaException"); |
|
|
|
|
259
|
|
|
|
260
|
|
|
$table = new Table("foo"); |
261
|
|
|
$table->addIndex(array("bar"), "invalidName"); |
262
|
|
|
} |
263
|
|
|
|
264
|
|
|
public function testBuilderOptions() |
265
|
|
|
{ |
266
|
|
|
$table = new Table("foo"); |
267
|
|
|
$table->addOption("foo", "bar"); |
268
|
|
|
$this->assertTrue($table->hasOption("foo")); |
269
|
|
|
$this->assertEquals("bar", $table->getOption("foo")); |
270
|
|
|
} |
271
|
|
|
|
272
|
|
View Code Duplication |
public function testAddForeignKeyConstraint_UnknownLocalColumn_ThrowsException() |
|
|
|
|
273
|
|
|
{ |
274
|
|
|
$this->setExpectedException("Doctrine\DBAL\Schema\SchemaException"); |
|
|
|
|
275
|
|
|
|
276
|
|
|
$table = new Table("foo"); |
277
|
|
|
$table->addColumn("id", 'integer'); |
278
|
|
|
|
279
|
|
|
$foreignTable = new Table("bar"); |
280
|
|
|
$foreignTable->addColumn("id", 'integer'); |
281
|
|
|
|
282
|
|
|
$table->addForeignKeyConstraint($foreignTable, array("foo"), array("id")); |
283
|
|
|
} |
284
|
|
|
|
285
|
|
View Code Duplication |
public function testAddForeignKeyConstraint_UnknownForeignColumn_ThrowsException() |
|
|
|
|
286
|
|
|
{ |
287
|
|
|
$this->setExpectedException("Doctrine\DBAL\Schema\SchemaException"); |
|
|
|
|
288
|
|
|
|
289
|
|
|
$table = new Table("foo"); |
290
|
|
|
$table->addColumn("id", 'integer'); |
291
|
|
|
|
292
|
|
|
$foreignTable = new Table("bar"); |
293
|
|
|
$foreignTable->addColumn("id", 'integer'); |
294
|
|
|
|
295
|
|
|
$table->addForeignKeyConstraint($foreignTable, array("id"), array("foo")); |
296
|
|
|
} |
297
|
|
|
|
298
|
|
|
public function testAddForeignKeyConstraint() |
299
|
|
|
{ |
300
|
|
|
$table = new Table("foo"); |
301
|
|
|
$table->addColumn("id", 'integer'); |
302
|
|
|
|
303
|
|
|
$foreignTable = new Table("bar"); |
304
|
|
|
$foreignTable->addColumn("id", 'integer'); |
305
|
|
|
|
306
|
|
|
$table->addForeignKeyConstraint($foreignTable, array("id"), array("id"), array("foo" => "bar")); |
307
|
|
|
|
308
|
|
|
$constraints = $table->getForeignKeys(); |
309
|
|
|
$this->assertEquals(1, count($constraints)); |
310
|
|
|
$constraint = current($constraints); |
311
|
|
|
|
312
|
|
|
$this->assertInstanceOf('Doctrine\DBAL\Schema\ForeignKeyConstraint', $constraint); |
313
|
|
|
|
314
|
|
|
$this->assertTrue($constraint->hasOption("foo")); |
315
|
|
|
$this->assertEquals("bar", $constraint->getOption("foo")); |
316
|
|
|
} |
317
|
|
|
|
318
|
|
|
public function testAddIndexWithCaseSensitiveColumnProblem() |
319
|
|
|
{ |
320
|
|
|
$table = new Table("foo"); |
321
|
|
|
$table->addColumn("id", 'integer'); |
322
|
|
|
|
323
|
|
|
$table->addIndex(array("ID"), "my_idx"); |
324
|
|
|
|
325
|
|
|
$this->assertTrue($table->hasIndex('my_idx')); |
326
|
|
|
$this->assertEquals(array("ID"), $table->getIndex("my_idx")->getColumns()); |
327
|
|
|
$this->assertTrue($table->getIndex('my_idx')->spansColumns(array('id'))); |
328
|
|
|
} |
329
|
|
|
|
330
|
|
View Code Duplication |
public function testAddPrimaryKey_ColumnsAreExplicitlySetToNotNull() |
|
|
|
|
331
|
|
|
{ |
332
|
|
|
$table = new Table("foo"); |
333
|
|
|
$column = $table->addColumn("id", 'integer', array('notnull' => false)); |
334
|
|
|
|
335
|
|
|
$this->assertFalse($column->getNotnull()); |
336
|
|
|
|
337
|
|
|
$table->setPrimaryKey(array('id')); |
338
|
|
|
|
339
|
|
|
$this->assertTrue($column->getNotnull()); |
340
|
|
|
} |
341
|
|
|
|
342
|
|
|
/** |
343
|
|
|
* @group DDC-133 |
344
|
|
|
*/ |
345
|
|
|
public function testAllowImplicitSchemaTableInAutogeneratedIndexNames() |
346
|
|
|
{ |
347
|
|
|
$table = new Table("foo.bar"); |
348
|
|
|
$table->addColumn('baz', 'integer', array()); |
349
|
|
|
$table->addIndex(array('baz')); |
350
|
|
|
|
351
|
|
|
$this->assertEquals(1, count($table->getIndexes())); |
352
|
|
|
} |
353
|
|
|
|
354
|
|
|
/** |
355
|
|
|
* @group DBAL-50 |
356
|
|
|
*/ |
357
|
|
|
public function testAddForeignKeyIndexImplicitly() |
358
|
|
|
{ |
359
|
|
|
$table = new Table("foo"); |
360
|
|
|
$table->addColumn("id", 'integer'); |
361
|
|
|
|
362
|
|
|
$foreignTable = new Table("bar"); |
363
|
|
|
$foreignTable->addColumn("id", 'integer'); |
364
|
|
|
|
365
|
|
|
$table->addForeignKeyConstraint($foreignTable, array("id"), array("id"), array("foo" => "bar")); |
366
|
|
|
|
367
|
|
|
$indexes = $table->getIndexes(); |
368
|
|
|
$this->assertEquals(1, count($indexes)); |
369
|
|
|
$index = current($indexes); |
370
|
|
|
|
371
|
|
|
$this->assertTrue($table->hasIndex($index->getName())); |
372
|
|
|
$this->assertEquals(array('id'), $index->getColumns()); |
373
|
|
|
} |
374
|
|
|
|
375
|
|
|
/** |
376
|
|
|
* @group DBAL-1063 |
377
|
|
|
*/ |
378
|
|
View Code Duplication |
public function testAddForeignKeyDoesNotCreateDuplicateIndex() |
|
|
|
|
379
|
|
|
{ |
380
|
|
|
$table = new Table('foo'); |
381
|
|
|
$table->addColumn('bar', 'integer'); |
382
|
|
|
$table->addIndex(array('bar'), 'bar_idx'); |
383
|
|
|
|
384
|
|
|
$foreignTable = new Table('bar'); |
385
|
|
|
$foreignTable->addColumn('foo', 'integer'); |
386
|
|
|
|
387
|
|
|
$table->addForeignKeyConstraint($foreignTable, array('bar'), array('foo')); |
388
|
|
|
|
389
|
|
|
$this->assertCount(1, $table->getIndexes()); |
390
|
|
|
$this->assertTrue($table->hasIndex('bar_idx')); |
391
|
|
|
$this->assertSame(array('bar'), $table->getIndex('bar_idx')->getColumns()); |
392
|
|
|
} |
393
|
|
|
|
394
|
|
|
/** |
395
|
|
|
* @group DBAL-1063 |
396
|
|
|
*/ |
397
|
|
|
public function testAddForeignKeyAddsImplicitIndexIfIndexColumnsDoNotSpan() |
398
|
|
|
{ |
399
|
|
|
$table = new Table('foo'); |
400
|
|
|
$table->addColumn('bar', 'integer'); |
401
|
|
|
$table->addColumn('baz', 'string'); |
402
|
|
|
$table->addColumn('bloo', 'string'); |
403
|
|
|
$table->addIndex(array('bar'), 'bar_idx'); |
404
|
|
|
$table->addIndex(array('baz', 'bar'), 'composite_idx'); |
405
|
|
|
|
406
|
|
|
$foreignTable = new Table('bar'); |
407
|
|
|
$foreignTable->addColumn('foo', 'integer'); |
408
|
|
|
$foreignTable->addColumn('baz', 'string'); |
409
|
|
|
|
410
|
|
|
$table->addForeignKeyConstraint($foreignTable, array('bar', 'baz'), array('foo', 'baz')); |
411
|
|
|
|
412
|
|
|
self::assertCount(3, $table->getIndexes()); |
413
|
|
|
self::assertTrue($table->hasIndex('composite_idx')); |
414
|
|
|
self::assertTrue($table->hasIndex('bar_idx')); |
415
|
|
|
self::assertTrue($table->hasIndex('idx_8c73652176ff8caa78240498')); |
416
|
|
|
self::assertSame(array('bar'), $table->getIndex('bar_idx')->getColumns()); |
417
|
|
|
self::assertSame(array('baz', 'bar'), $table->getIndex('composite_idx')->getColumns()); |
418
|
|
|
self::assertSame(array('bar', 'baz'), $table->getIndex('idx_8c73652176ff8caa78240498')->getColumns()); |
419
|
|
|
} |
420
|
|
|
|
421
|
|
View Code Duplication |
public function testAddForeignKeyDoesNotAddImplicitIndexIfIndexColumnsSpan() |
|
|
|
|
422
|
|
|
{ |
423
|
|
|
$table = new Table('foo'); |
424
|
|
|
$table->addColumn('bar', 'integer'); |
425
|
|
|
$table->addColumn('baz', 'string'); |
426
|
|
|
$table->addColumn('bloo', 'string'); |
427
|
|
|
$table->addIndex(array('baz', 'bar'), 'composite_idx'); |
428
|
|
|
|
429
|
|
|
$foreignTable = new Table('bar'); |
430
|
|
|
$foreignTable->addColumn('foo', 'integer'); |
431
|
|
|
$foreignTable->addColumn('baz', 'string'); |
432
|
|
|
|
433
|
|
|
$table->addForeignKeyConstraint($foreignTable, array('baz', 'bar'), array('foo', 'baz')); |
434
|
|
|
|
435
|
|
|
self::assertCount(1, $table->getIndexes()); |
436
|
|
|
self::assertTrue($table->hasIndex('composite_idx')); |
437
|
|
|
self::assertSame(array('baz', 'bar'), $table->getIndex('composite_idx')->getColumns()); |
438
|
|
|
} |
439
|
|
|
|
440
|
|
View Code Duplication |
public function testAddForeignKeyDoesNotAddImplicitIndexIfLongerIndexColumnsSpan() |
|
|
|
|
441
|
|
|
{ |
442
|
|
|
$table = new Table('foo'); |
443
|
|
|
$table->addColumn('bar', 'integer'); |
444
|
|
|
$table->addColumn('baz', 'string'); |
445
|
|
|
$table->addColumn('bloo', 'string'); |
446
|
|
|
$table->addIndex(array('baz', 'bar', 'bloo'), 'composite_idx'); |
447
|
|
|
|
448
|
|
|
$foreignTable = new Table('bar'); |
449
|
|
|
$foreignTable->addColumn('foo', 'integer'); |
450
|
|
|
$foreignTable->addColumn('baz', 'string'); |
451
|
|
|
|
452
|
|
|
$table->addForeignKeyConstraint($foreignTable, array('baz', 'bar'), array('foo', 'baz')); |
453
|
|
|
|
454
|
|
|
self::assertCount(1, $table->getIndexes()); |
455
|
|
|
self::assertTrue($table->hasIndex('composite_idx')); |
456
|
|
|
self::assertSame(array('baz', 'bar', 'bloo'), $table->getIndex('composite_idx')->getColumns()); |
457
|
|
|
} |
458
|
|
|
|
459
|
|
|
/** |
460
|
|
|
* @group DBAL-50 |
461
|
|
|
* @group DBAL-1063 |
462
|
|
|
*/ |
463
|
|
|
public function testOverrulingIndexDoesNotDropOverruledIndex() |
464
|
|
|
{ |
465
|
|
|
$table = new Table("bar"); |
466
|
|
|
$table->addColumn('baz', 'integer', array()); |
467
|
|
|
$table->addIndex(array('baz')); |
468
|
|
|
|
469
|
|
|
$indexes = $table->getIndexes(); |
470
|
|
|
$this->assertEquals(1, count($indexes)); |
471
|
|
|
$index = current($indexes); |
472
|
|
|
|
473
|
|
|
$table->addUniqueIndex(array('baz')); |
474
|
|
|
$this->assertEquals(2, count($table->getIndexes())); |
475
|
|
|
$this->assertTrue($table->hasIndex($index->getName())); |
476
|
|
|
} |
477
|
|
|
|
478
|
|
|
/** |
479
|
|
|
* @group DBAL-1063 |
480
|
|
|
*/ |
481
|
|
|
public function testAllowsAddingDuplicateIndexesBasedOnColumns() |
482
|
|
|
{ |
483
|
|
|
$table = new Table('foo'); |
484
|
|
|
$table->addColumn('bar', 'integer'); |
485
|
|
|
$table->addIndex(array('bar'), 'bar_idx'); |
486
|
|
|
$table->addIndex(array('bar'), 'duplicate_idx'); |
487
|
|
|
|
488
|
|
|
$this->assertCount(2, $table->getIndexes()); |
489
|
|
|
$this->assertTrue($table->hasIndex('bar_idx')); |
490
|
|
|
$this->assertTrue($table->hasIndex('duplicate_idx')); |
491
|
|
|
$this->assertSame(array('bar'), $table->getIndex('bar_idx')->getColumns()); |
492
|
|
|
$this->assertSame(array('bar'), $table->getIndex('duplicate_idx')->getColumns()); |
493
|
|
|
} |
494
|
|
|
|
495
|
|
|
/** |
496
|
|
|
* @group DBAL-1063 |
497
|
|
|
*/ |
498
|
|
|
public function testAllowsAddingFulfillingIndexesBasedOnColumns() |
499
|
|
|
{ |
500
|
|
|
$table = new Table('foo'); |
501
|
|
|
$table->addColumn('bar', 'integer'); |
502
|
|
|
$table->addColumn('baz', 'string'); |
503
|
|
|
$table->addIndex(array('bar'), 'bar_idx'); |
504
|
|
|
$table->addIndex(array('bar', 'baz'), 'fulfilling_idx'); |
505
|
|
|
|
506
|
|
|
$this->assertCount(2, $table->getIndexes()); |
507
|
|
|
$this->assertTrue($table->hasIndex('bar_idx')); |
508
|
|
|
$this->assertTrue($table->hasIndex('fulfilling_idx')); |
509
|
|
|
$this->assertSame(array('bar'), $table->getIndex('bar_idx')->getColumns()); |
510
|
|
|
$this->assertSame(array('bar', 'baz'), $table->getIndex('fulfilling_idx')->getColumns()); |
511
|
|
|
} |
512
|
|
|
|
513
|
|
|
/** |
514
|
|
|
* @group DBAL-50 |
515
|
|
|
* @group DBAL-1063 |
516
|
|
|
*/ |
517
|
|
View Code Duplication |
public function testPrimaryKeyOverrulingUniqueIndexDoesNotDropUniqueIndex() |
|
|
|
|
518
|
|
|
{ |
519
|
|
|
$table = new Table("bar"); |
520
|
|
|
$table->addColumn('baz', 'integer', array()); |
521
|
|
|
$table->addUniqueIndex(array('baz'), 'idx_unique'); |
522
|
|
|
|
523
|
|
|
$table->setPrimaryKey(array('baz')); |
524
|
|
|
|
525
|
|
|
$indexes = $table->getIndexes(); |
526
|
|
|
$this->assertEquals(2, count($indexes), "Table should only contain both the primary key table index and the unique one, even though it was overruled."); |
527
|
|
|
|
528
|
|
|
$this->assertTrue($table->hasPrimaryKey()); |
529
|
|
|
$this->assertTrue($table->hasIndex('idx_unique')); |
530
|
|
|
} |
531
|
|
|
|
532
|
|
|
public function testCompoundedPrimaryKeyOverrulingSingleUniqueIndexDoesNotDropUniqueIndex() |
533
|
|
|
{ |
534
|
|
|
$table = new Table("bar"); |
535
|
|
|
$table->addColumn('baz', 'integer', array()); |
536
|
|
|
$table->addColumn('bar', 'integer', array()); |
537
|
|
|
$table->addUniqueIndex(array('baz'), 'idx_unique'); |
538
|
|
|
|
539
|
|
|
$table->setPrimaryKey(array('baz', 'bar')); |
540
|
|
|
|
541
|
|
|
$indexes = $table->getIndexes(); |
542
|
|
|
self::assertCount(2, $indexes); |
543
|
|
|
|
544
|
|
|
self::assertTrue($table->hasPrimaryKey()); |
545
|
|
|
self::assertTrue($table->hasIndex('idx_unique')); |
546
|
|
|
} |
547
|
|
|
|
548
|
|
View Code Duplication |
public function testAddingFulfillingRegularIndexOverridesImplicitForeignKeyConstraintIndex() |
|
|
|
|
549
|
|
|
{ |
550
|
|
|
$foreignTable = new Table('foreign'); |
551
|
|
|
$foreignTable->addColumn('id', 'integer'); |
552
|
|
|
|
553
|
|
|
$localTable = new Table('local'); |
554
|
|
|
$localTable->addColumn('id', 'integer'); |
555
|
|
|
$localTable->addForeignKeyConstraint($foreignTable, array('id'), array('id')); |
556
|
|
|
|
557
|
|
|
$this->assertCount(1, $localTable->getIndexes()); |
558
|
|
|
|
559
|
|
|
$localTable->addIndex(array('id'), 'explicit_idx'); |
560
|
|
|
|
561
|
|
|
$this->assertCount(1, $localTable->getIndexes()); |
562
|
|
|
$this->assertTrue($localTable->hasIndex('explicit_idx')); |
563
|
|
|
} |
564
|
|
|
|
565
|
|
View Code Duplication |
public function testAddingFulfillingUniqueIndexOverridesImplicitForeignKeyConstraintIndex() |
|
|
|
|
566
|
|
|
{ |
567
|
|
|
$foreignTable = new Table('foreign'); |
568
|
|
|
$foreignTable->addColumn('id', 'integer'); |
569
|
|
|
|
570
|
|
|
$localTable = new Table('local'); |
571
|
|
|
$localTable->addColumn('id', 'integer'); |
572
|
|
|
$localTable->addForeignKeyConstraint($foreignTable, array('id'), array('id')); |
573
|
|
|
|
574
|
|
|
$this->assertCount(1, $localTable->getIndexes()); |
575
|
|
|
|
576
|
|
|
$localTable->addUniqueIndex(array('id'), 'explicit_idx'); |
577
|
|
|
|
578
|
|
|
$this->assertCount(1, $localTable->getIndexes()); |
579
|
|
|
$this->assertTrue($localTable->hasIndex('explicit_idx')); |
580
|
|
|
} |
581
|
|
|
|
582
|
|
View Code Duplication |
public function testAddingFulfillingPrimaryKeyOverridesImplicitForeignKeyConstraintIndex() |
|
|
|
|
583
|
|
|
{ |
584
|
|
|
$foreignTable = new Table('foreign'); |
585
|
|
|
$foreignTable->addColumn('id', 'integer'); |
586
|
|
|
|
587
|
|
|
$localTable = new Table('local'); |
588
|
|
|
$localTable->addColumn('id', 'integer'); |
589
|
|
|
$localTable->addForeignKeyConstraint($foreignTable, array('id'), array('id')); |
590
|
|
|
|
591
|
|
|
$this->assertCount(1, $localTable->getIndexes()); |
592
|
|
|
|
593
|
|
|
$localTable->setPrimaryKey(array('id'), 'explicit_idx'); |
594
|
|
|
|
595
|
|
|
$this->assertCount(1, $localTable->getIndexes()); |
596
|
|
|
$this->assertTrue($localTable->hasIndex('explicit_idx')); |
597
|
|
|
} |
598
|
|
|
|
599
|
|
|
public function testAddingFulfillingExplicitIndexOverridingImplicitForeignKeyConstraintIndexWithSameNameDoesNotThrowException() |
600
|
|
|
{ |
601
|
|
|
$foreignTable = new Table('foreign'); |
602
|
|
|
$foreignTable->addColumn('id', 'integer'); |
603
|
|
|
|
604
|
|
|
$localTable = new Table('local'); |
605
|
|
|
$localTable->addColumn('id', 'integer'); |
606
|
|
|
$localTable->addForeignKeyConstraint($foreignTable, array('id'), array('id')); |
607
|
|
|
|
608
|
|
|
$this->assertCount(1, $localTable->getIndexes()); |
609
|
|
|
$this->assertTrue($localTable->hasIndex('IDX_8BD688E8BF396750')); |
610
|
|
|
|
611
|
|
|
$implicitIndex = $localTable->getIndex('IDX_8BD688E8BF396750'); |
612
|
|
|
|
613
|
|
|
$localTable->addIndex(array('id'), 'IDX_8BD688E8BF396750'); |
614
|
|
|
|
615
|
|
|
$this->assertCount(1, $localTable->getIndexes()); |
616
|
|
|
$this->assertTrue($localTable->hasIndex('IDX_8BD688E8BF396750')); |
617
|
|
|
$this->assertNotSame($implicitIndex, $localTable->getIndex('IDX_8BD688E8BF396750')); |
618
|
|
|
} |
619
|
|
|
|
620
|
|
|
/** |
621
|
|
|
* @group DBAL-64 |
622
|
|
|
*/ |
623
|
|
|
public function testQuotedTableName() |
624
|
|
|
{ |
625
|
|
|
$table = new Table("`bar`"); |
626
|
|
|
|
627
|
|
|
$mysqlPlatform = new \Doctrine\DBAL\Platforms\MySqlPlatform(); |
628
|
|
|
$sqlitePlatform = new \Doctrine\DBAL\Platforms\SqlitePlatform(); |
629
|
|
|
|
630
|
|
|
$this->assertEquals('bar', $table->getName()); |
631
|
|
|
$this->assertEquals('`bar`', $table->getQuotedName($mysqlPlatform)); |
632
|
|
|
$this->assertEquals('"bar"', $table->getQuotedName($sqlitePlatform)); |
633
|
|
|
} |
634
|
|
|
|
635
|
|
|
/** |
636
|
|
|
* @group DBAL-79 |
637
|
|
|
*/ |
638
|
|
View Code Duplication |
public function testTableHasPrimaryKey() |
|
|
|
|
639
|
|
|
{ |
640
|
|
|
$table = new Table("test"); |
641
|
|
|
|
642
|
|
|
$this->assertFalse($table->hasPrimaryKey()); |
643
|
|
|
|
644
|
|
|
$table->addColumn("foo", "integer"); |
645
|
|
|
$table->setPrimaryKey(array("foo")); |
646
|
|
|
|
647
|
|
|
$this->assertTrue($table->hasPrimaryKey()); |
648
|
|
|
} |
649
|
|
|
|
650
|
|
|
/** |
651
|
|
|
* @group DBAL-91 |
652
|
|
|
*/ |
653
|
|
View Code Duplication |
public function testAddIndexWithQuotedColumns() |
|
|
|
|
654
|
|
|
{ |
655
|
|
|
$table = new Table("test"); |
656
|
|
|
$table->addColumn('"foo"', 'integer'); |
657
|
|
|
$table->addColumn('bar', 'integer'); |
658
|
|
|
$table->addIndex(array('"foo"', '"bar"')); |
659
|
|
|
} |
660
|
|
|
|
661
|
|
|
/** |
662
|
|
|
* @group DBAL-91 |
663
|
|
|
*/ |
664
|
|
View Code Duplication |
public function testAddForeignKeyWithQuotedColumnsAndTable() |
|
|
|
|
665
|
|
|
{ |
666
|
|
|
$table = new Table("test"); |
667
|
|
|
$table->addColumn('"foo"', 'integer'); |
668
|
|
|
$table->addColumn('bar', 'integer'); |
669
|
|
|
$table->addForeignKeyConstraint('"boing"', array('"foo"', '"bar"'), array("id")); |
670
|
|
|
} |
671
|
|
|
|
672
|
|
|
/** |
673
|
|
|
* @group DBAL-177 |
674
|
|
|
*/ |
675
|
|
|
public function testQuoteSchemaPrefixed() |
676
|
|
|
{ |
677
|
|
|
$table = new Table("`test`.`test`"); |
678
|
|
|
$this->assertEquals("test.test", $table->getName()); |
679
|
|
|
$this->assertEquals("`test`.`test`", $table->getQuotedName(new \Doctrine\DBAL\Platforms\MySqlPlatform)); |
680
|
|
|
} |
681
|
|
|
|
682
|
|
|
/** |
683
|
|
|
* @group DBAL-204 |
684
|
|
|
*/ |
685
|
|
|
public function testFullQualifiedTableName() |
686
|
|
|
{ |
687
|
|
|
$table = new Table("`test`.`test`"); |
688
|
|
|
$this->assertEquals('test.test', $table->getFullQualifiedName("test")); |
689
|
|
|
$this->assertEquals('test.test', $table->getFullQualifiedName("other")); |
690
|
|
|
|
691
|
|
|
$table = new Table("test"); |
692
|
|
|
$this->assertEquals('test.test', $table->getFullQualifiedName("test")); |
693
|
|
|
$this->assertEquals('other.test', $table->getFullQualifiedName("other")); |
694
|
|
|
} |
695
|
|
|
|
696
|
|
|
/** |
697
|
|
|
* @group DBAL-224 |
698
|
|
|
*/ |
699
|
|
|
public function testDropIndex() |
700
|
|
|
{ |
701
|
|
|
$table = new Table("test"); |
702
|
|
|
$table->addColumn('id', 'integer'); |
703
|
|
|
$table->addIndex(array('id'), 'idx'); |
704
|
|
|
|
705
|
|
|
$this->assertTrue($table->hasIndex('idx')); |
706
|
|
|
|
707
|
|
|
$table->dropIndex('idx'); |
708
|
|
|
$this->assertFalse($table->hasIndex('idx')); |
709
|
|
|
} |
710
|
|
|
|
711
|
|
|
/** |
712
|
|
|
* @group DBAL-224 |
713
|
|
|
*/ |
714
|
|
View Code Duplication |
public function testDropPrimaryKey() |
|
|
|
|
715
|
|
|
{ |
716
|
|
|
$table = new Table("test"); |
717
|
|
|
$table->addColumn('id', 'integer'); |
718
|
|
|
$table->setPrimaryKey(array('id')); |
719
|
|
|
|
720
|
|
|
$this->assertTrue($table->hasPrimaryKey()); |
721
|
|
|
|
722
|
|
|
$table->dropPrimaryKey(); |
723
|
|
|
$this->assertFalse($table->hasPrimaryKey()); |
724
|
|
|
} |
725
|
|
|
|
726
|
|
|
/** |
727
|
|
|
* @group DBAL-234 |
728
|
|
|
*/ |
729
|
|
|
public function testRenameIndex() |
730
|
|
|
{ |
731
|
|
|
$table = new Table("test"); |
732
|
|
|
$table->addColumn('id', 'integer'); |
733
|
|
|
$table->addColumn('foo', 'integer'); |
734
|
|
|
$table->addColumn('bar', 'integer'); |
735
|
|
|
$table->addColumn('baz', 'integer'); |
736
|
|
|
$table->setPrimaryKey(array('id'), 'pk'); |
737
|
|
|
$table->addIndex(array('foo'), 'idx', array('flag')); |
738
|
|
|
$table->addUniqueIndex(array('bar', 'baz'), 'uniq'); |
739
|
|
|
|
740
|
|
|
// Rename to custom name. |
741
|
|
|
$this->assertSame($table, $table->renameIndex('pk', 'pk_new')); |
742
|
|
|
$this->assertSame($table, $table->renameIndex('idx', 'idx_new')); |
743
|
|
|
$this->assertSame($table, $table->renameIndex('uniq', 'uniq_new')); |
744
|
|
|
|
745
|
|
|
$this->assertTrue($table->hasPrimaryKey()); |
746
|
|
|
$this->assertTrue($table->hasIndex('pk_new')); |
747
|
|
|
$this->assertTrue($table->hasIndex('idx_new')); |
748
|
|
|
$this->assertTrue($table->hasIndex('uniq_new')); |
749
|
|
|
|
750
|
|
|
$this->assertFalse($table->hasIndex('pk')); |
751
|
|
|
$this->assertFalse($table->hasIndex('idx')); |
752
|
|
|
$this->assertFalse($table->hasIndex('uniq')); |
753
|
|
|
|
754
|
|
|
$this->assertEquals(new Index('pk_new', array('id'), true, true), $table->getPrimaryKey()); |
755
|
|
|
$this->assertEquals(new Index('pk_new', array('id'), true, true), $table->getIndex('pk_new')); |
756
|
|
|
$this->assertEquals( |
757
|
|
|
new Index('idx_new', array('foo'), false, false, array('flag')), |
758
|
|
|
$table->getIndex('idx_new') |
759
|
|
|
); |
760
|
|
|
$this->assertEquals(new Index('uniq_new', array('bar', 'baz'), true), $table->getIndex('uniq_new')); |
761
|
|
|
|
762
|
|
|
// Rename to auto-generated name. |
763
|
|
|
$this->assertSame($table, $table->renameIndex('pk_new', null)); |
764
|
|
|
$this->assertSame($table, $table->renameIndex('idx_new', null)); |
765
|
|
|
$this->assertSame($table, $table->renameIndex('uniq_new', null)); |
766
|
|
|
|
767
|
|
|
$this->assertTrue($table->hasPrimaryKey()); |
768
|
|
|
$this->assertTrue($table->hasIndex('primary')); |
769
|
|
|
$this->assertTrue($table->hasIndex('IDX_D87F7E0C8C736521')); |
770
|
|
|
$this->assertTrue($table->hasIndex('UNIQ_D87F7E0C76FF8CAA78240498')); |
771
|
|
|
|
772
|
|
|
$this->assertFalse($table->hasIndex('pk_new')); |
773
|
|
|
$this->assertFalse($table->hasIndex('idx_new')); |
774
|
|
|
$this->assertFalse($table->hasIndex('uniq_new')); |
775
|
|
|
|
776
|
|
|
$this->assertEquals(new Index('primary', array('id'), true, true), $table->getPrimaryKey()); |
777
|
|
|
$this->assertEquals(new Index('primary', array('id'), true, true), $table->getIndex('primary')); |
778
|
|
|
$this->assertEquals( |
779
|
|
|
new Index('IDX_D87F7E0C8C736521', array('foo'), false, false, array('flag')), |
780
|
|
|
$table->getIndex('IDX_D87F7E0C8C736521') |
781
|
|
|
); |
782
|
|
|
$this->assertEquals( |
783
|
|
|
new Index('UNIQ_D87F7E0C76FF8CAA78240498', array('bar', 'baz'), true), |
784
|
|
|
$table->getIndex('UNIQ_D87F7E0C76FF8CAA78240498') |
785
|
|
|
); |
786
|
|
|
|
787
|
|
|
// Rename to same name (changed case). |
788
|
|
|
$this->assertSame($table, $table->renameIndex('primary', 'PRIMARY')); |
789
|
|
|
$this->assertSame($table, $table->renameIndex('IDX_D87F7E0C8C736521', 'idx_D87F7E0C8C736521')); |
790
|
|
|
$this->assertSame($table, $table->renameIndex('UNIQ_D87F7E0C76FF8CAA78240498', 'uniq_D87F7E0C76FF8CAA78240498')); |
791
|
|
|
|
792
|
|
|
$this->assertTrue($table->hasPrimaryKey()); |
793
|
|
|
$this->assertTrue($table->hasIndex('primary')); |
794
|
|
|
$this->assertTrue($table->hasIndex('IDX_D87F7E0C8C736521')); |
795
|
|
|
$this->assertTrue($table->hasIndex('UNIQ_D87F7E0C76FF8CAA78240498')); |
796
|
|
|
} |
797
|
|
|
|
798
|
|
|
/** |
799
|
|
|
* @group DBAL-2508 |
800
|
|
|
*/ |
801
|
|
View Code Duplication |
public function testKeepsIndexOptionsOnRenamingRegularIndex() |
|
|
|
|
802
|
|
|
{ |
803
|
|
|
$table = new Table('foo'); |
804
|
|
|
$table->addColumn('id', 'integer'); |
805
|
|
|
$table->addIndex(array('id'), 'idx_bar', array(), array('where' => '1 = 1')); |
806
|
|
|
|
807
|
|
|
$table->renameIndex('idx_bar', 'idx_baz'); |
808
|
|
|
|
809
|
|
|
$this->assertSame(array('where' => '1 = 1'), $table->getIndex('idx_baz')->getOptions()); |
810
|
|
|
} |
811
|
|
|
|
812
|
|
|
/** |
813
|
|
|
* @group DBAL-2508 |
814
|
|
|
*/ |
815
|
|
View Code Duplication |
public function testKeepsIndexOptionsOnRenamingUniqueIndex() |
|
|
|
|
816
|
|
|
{ |
817
|
|
|
$table = new Table('foo'); |
818
|
|
|
$table->addColumn('id', 'integer'); |
819
|
|
|
$table->addUniqueIndex(array('id'), 'idx_bar', array('where' => '1 = 1')); |
820
|
|
|
|
821
|
|
|
$table->renameIndex('idx_bar', 'idx_baz'); |
822
|
|
|
|
823
|
|
|
$this->assertSame(array('where' => '1 = 1'), $table->getIndex('idx_baz')->getOptions()); |
824
|
|
|
} |
825
|
|
|
|
826
|
|
|
/** |
827
|
|
|
* @group DBAL-234 |
828
|
|
|
* @expectedException \Doctrine\DBAL\Schema\SchemaException |
829
|
|
|
*/ |
830
|
|
|
public function testThrowsExceptionOnRenamingNonExistingIndex() |
831
|
|
|
{ |
832
|
|
|
$table = new Table("test"); |
833
|
|
|
$table->addColumn('id', 'integer'); |
834
|
|
|
$table->addIndex(array('id'), 'idx'); |
835
|
|
|
|
836
|
|
|
$table->renameIndex('foo', 'bar'); |
837
|
|
|
} |
838
|
|
|
|
839
|
|
|
/** |
840
|
|
|
* @group DBAL-234 |
841
|
|
|
* @expectedException \Doctrine\DBAL\Schema\SchemaException |
842
|
|
|
*/ |
843
|
|
|
public function testThrowsExceptionOnRenamingToAlreadyExistingIndex() |
844
|
|
|
{ |
845
|
|
|
$table = new Table("test"); |
846
|
|
|
$table->addColumn('id', 'integer'); |
847
|
|
|
$table->addColumn('foo', 'integer'); |
848
|
|
|
$table->addIndex(array('id'), 'idx_id'); |
849
|
|
|
$table->addIndex(array('foo'), 'idx_foo'); |
850
|
|
|
|
851
|
|
|
$table->renameIndex('idx_id', 'idx_foo'); |
852
|
|
|
} |
853
|
|
|
|
854
|
|
|
/** |
855
|
|
|
* @dataProvider getNormalizesAssetNames |
856
|
|
|
* @group DBAL-831 |
857
|
|
|
*/ |
858
|
|
|
public function testNormalizesColumnNames($assetName) |
859
|
|
|
{ |
860
|
|
|
$table = new Table('test'); |
861
|
|
|
|
862
|
|
|
$table->addColumn($assetName, 'integer'); |
863
|
|
|
$table->addIndex(array($assetName), $assetName); |
864
|
|
|
$table->addForeignKeyConstraint('test', array($assetName), array($assetName), array(), $assetName); |
865
|
|
|
|
866
|
|
|
$this->assertTrue($table->hasColumn($assetName)); |
867
|
|
|
$this->assertTrue($table->hasColumn('foo')); |
868
|
|
|
$this->assertInstanceOf('Doctrine\DBAL\Schema\Column', $table->getColumn($assetName)); |
869
|
|
|
$this->assertInstanceOf('Doctrine\DBAL\Schema\Column', $table->getColumn('foo')); |
870
|
|
|
|
871
|
|
|
$this->assertTrue($table->hasIndex($assetName)); |
872
|
|
|
$this->assertTrue($table->hasIndex('foo')); |
873
|
|
|
$this->assertInstanceOf('Doctrine\DBAL\Schema\Index', $table->getIndex($assetName)); |
874
|
|
|
$this->assertInstanceOf('Doctrine\DBAL\Schema\Index', $table->getIndex('foo')); |
875
|
|
|
|
876
|
|
|
$this->assertTrue($table->hasForeignKey($assetName)); |
877
|
|
|
$this->assertTrue($table->hasForeignKey('foo')); |
878
|
|
|
$this->assertInstanceOf('Doctrine\DBAL\Schema\ForeignKeyConstraint', $table->getForeignKey($assetName)); |
879
|
|
|
$this->assertInstanceOf('Doctrine\DBAL\Schema\ForeignKeyConstraint', $table->getForeignKey('foo')); |
880
|
|
|
|
881
|
|
|
$table->renameIndex($assetName, $assetName); |
882
|
|
|
$this->assertTrue($table->hasIndex($assetName)); |
883
|
|
|
$this->assertTrue($table->hasIndex('foo')); |
884
|
|
|
|
885
|
|
|
$table->renameIndex($assetName, 'foo'); |
886
|
|
|
$this->assertTrue($table->hasIndex($assetName)); |
887
|
|
|
$this->assertTrue($table->hasIndex('foo')); |
888
|
|
|
|
889
|
|
|
$table->renameIndex('foo', $assetName); |
890
|
|
|
$this->assertTrue($table->hasIndex($assetName)); |
891
|
|
|
$this->assertTrue($table->hasIndex('foo')); |
892
|
|
|
|
893
|
|
|
$table->renameIndex($assetName, 'bar'); |
894
|
|
|
$this->assertFalse($table->hasIndex($assetName)); |
895
|
|
|
$this->assertFalse($table->hasIndex('foo')); |
896
|
|
|
$this->assertTrue($table->hasIndex('bar')); |
897
|
|
|
|
898
|
|
|
$table->renameIndex('bar', $assetName); |
899
|
|
|
|
900
|
|
|
$table->dropColumn($assetName); |
901
|
|
|
$table->dropIndex($assetName); |
902
|
|
|
$table->removeForeignKey($assetName); |
903
|
|
|
|
904
|
|
|
$this->assertFalse($table->hasColumn($assetName)); |
905
|
|
|
$this->assertFalse($table->hasColumn('foo')); |
906
|
|
|
$this->assertFalse($table->hasIndex($assetName)); |
907
|
|
|
$this->assertFalse($table->hasIndex('foo')); |
908
|
|
|
$this->assertFalse($table->hasForeignKey($assetName)); |
909
|
|
|
$this->assertFalse($table->hasForeignKey('foo')); |
910
|
|
|
} |
911
|
|
|
|
912
|
|
|
public function getNormalizesAssetNames() |
913
|
|
|
{ |
914
|
|
|
return array( |
915
|
|
|
array('foo'), |
916
|
|
|
array('FOO'), |
917
|
|
|
array('`foo`'), |
918
|
|
|
array('`FOO`'), |
919
|
|
|
array('"foo"'), |
920
|
|
|
array('"FOO"'), |
921
|
|
|
array('"foo"'), |
922
|
|
|
array('"FOO"'), |
923
|
|
|
); |
924
|
|
|
} |
925
|
|
|
} |
926
|
|
|
|
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.