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