1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Doctrine\Tests\DBAL\Platforms; |
4
|
|
|
|
5
|
|
|
use Doctrine\Common\EventManager; |
6
|
|
|
use Doctrine\DBAL\Events; |
7
|
|
|
use Doctrine\DBAL\Platforms\AbstractPlatform; |
8
|
|
|
use Doctrine\DBAL\Schema\Column; |
9
|
|
|
use Doctrine\DBAL\Schema\ColumnDiff; |
10
|
|
|
use Doctrine\DBAL\Schema\Comparator; |
11
|
|
|
use Doctrine\DBAL\Schema\ForeignKeyConstraint; |
12
|
|
|
use Doctrine\DBAL\Schema\Index; |
13
|
|
|
use Doctrine\DBAL\Schema\Table; |
14
|
|
|
use Doctrine\DBAL\Schema\TableDiff; |
15
|
|
|
use Doctrine\DBAL\Types\Type; |
16
|
|
|
use Doctrine\Tests\Types\CommentedType; |
17
|
|
|
|
18
|
|
|
abstract class AbstractPlatformTestCase extends \Doctrine\Tests\DbalTestCase |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @var \Doctrine\DBAL\Platforms\AbstractPlatform |
22
|
|
|
*/ |
23
|
|
|
protected $_platform; |
24
|
|
|
|
25
|
|
|
abstract public function createPlatform(); |
26
|
|
|
|
27
|
|
|
protected function setUp() |
28
|
|
|
{ |
29
|
|
|
$this->_platform = $this->createPlatform(); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @group DDC-1360 |
34
|
|
|
*/ |
35
|
|
|
public function testQuoteIdentifier() |
36
|
|
|
{ |
37
|
|
|
if ($this->_platform->getName() == "mssql") { |
38
|
|
|
$this->markTestSkipped('Not working this way on mssql.'); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
$c = $this->_platform->getIdentifierQuoteCharacter(); |
42
|
|
|
self::assertEquals($c."test".$c, $this->_platform->quoteIdentifier("test")); |
43
|
|
|
self::assertEquals($c."test".$c.".".$c."test".$c, $this->_platform->quoteIdentifier("test.test")); |
44
|
|
|
self::assertEquals(str_repeat($c, 4), $this->_platform->quoteIdentifier($c)); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @group DDC-1360 |
49
|
|
|
*/ |
50
|
|
|
public function testQuoteSingleIdentifier() |
51
|
|
|
{ |
52
|
|
|
if ($this->_platform->getName() == "mssql") { |
53
|
|
|
$this->markTestSkipped('Not working this way on mssql.'); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
$c = $this->_platform->getIdentifierQuoteCharacter(); |
57
|
|
|
self::assertEquals($c."test".$c, $this->_platform->quoteSingleIdentifier("test")); |
58
|
|
|
self::assertEquals($c."test.test".$c, $this->_platform->quoteSingleIdentifier("test.test")); |
59
|
|
|
self::assertEquals(str_repeat($c, 4), $this->_platform->quoteSingleIdentifier($c)); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @group DBAL-1029 |
64
|
|
|
* |
65
|
|
|
* @dataProvider getReturnsForeignKeyReferentialActionSQL |
66
|
|
|
*/ |
67
|
|
|
public function testReturnsForeignKeyReferentialActionSQL($action, $expectedSQL) |
68
|
|
|
{ |
69
|
|
|
self::assertSame($expectedSQL, $this->_platform->getForeignKeyReferentialActionSQL($action)); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @return array |
74
|
|
|
*/ |
75
|
|
View Code Duplication |
public function getReturnsForeignKeyReferentialActionSQL() |
|
|
|
|
76
|
|
|
{ |
77
|
|
|
return array( |
78
|
|
|
array('CASCADE', 'CASCADE'), |
79
|
|
|
array('SET NULL', 'SET NULL'), |
80
|
|
|
array('NO ACTION', 'NO ACTION'), |
81
|
|
|
array('RESTRICT', 'RESTRICT'), |
82
|
|
|
array('SET DEFAULT', 'SET DEFAULT'), |
83
|
|
|
array('CaScAdE', 'CASCADE'), |
84
|
|
|
); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
public function testGetInvalidForeignKeyReferentialActionSQL() |
88
|
|
|
{ |
89
|
|
|
$this->expectException('InvalidArgumentException'); |
90
|
|
|
$this->_platform->getForeignKeyReferentialActionSQL('unknown'); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
public function testGetUnknownDoctrineMappingType() |
94
|
|
|
{ |
95
|
|
|
$this->expectException('Doctrine\DBAL\DBALException'); |
96
|
|
|
$this->_platform->getDoctrineTypeMapping('foobar'); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
public function testRegisterDoctrineMappingType() |
100
|
|
|
{ |
101
|
|
|
$this->_platform->registerDoctrineTypeMapping('foo', 'integer'); |
102
|
|
|
self::assertEquals('integer', $this->_platform->getDoctrineTypeMapping('foo')); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
public function testRegisterUnknownDoctrineMappingType() |
106
|
|
|
{ |
107
|
|
|
$this->expectException('Doctrine\DBAL\DBALException'); |
108
|
|
|
$this->_platform->registerDoctrineTypeMapping('foo', 'bar'); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @group DBAL-2594 |
113
|
|
|
*/ |
114
|
|
|
public function testRegistersCommentedDoctrineMappingTypeImplicitly() |
115
|
|
|
{ |
116
|
|
|
if (!Type::hasType('my_commented')) { |
117
|
|
|
Type::addType('my_commented', CommentedType::class); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
$type = Type::getType('my_commented'); |
121
|
|
|
$this->_platform->registerDoctrineTypeMapping('foo', 'my_commented'); |
122
|
|
|
|
123
|
|
|
self::assertTrue($this->_platform->isCommentedDoctrineType($type)); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* @group DBAL-939 |
128
|
|
|
* |
129
|
|
|
* @dataProvider getIsCommentedDoctrineType |
130
|
|
|
*/ |
131
|
|
|
public function testIsCommentedDoctrineType(Type $type, $commented) |
132
|
|
|
{ |
133
|
|
|
self::assertSame($commented, $this->_platform->isCommentedDoctrineType($type)); |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
public function getIsCommentedDoctrineType() |
137
|
|
|
{ |
138
|
|
|
$this->setUp(); |
139
|
|
|
|
140
|
|
|
$data = array(); |
141
|
|
|
|
142
|
|
|
foreach (Type::getTypesMap() as $typeName => $className) { |
143
|
|
|
$type = Type::getType($typeName); |
144
|
|
|
|
145
|
|
|
$data[$typeName] = array( |
146
|
|
|
$type, |
147
|
|
|
$type->requiresSQLCommentHint($this->_platform), |
148
|
|
|
); |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
return $data; |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
public function testCreateWithNoColumns() |
155
|
|
|
{ |
156
|
|
|
$table = new Table('test'); |
157
|
|
|
|
158
|
|
|
$this->expectException('Doctrine\DBAL\DBALException'); |
159
|
|
|
$sql = $this->_platform->getCreateTableSQL($table); |
|
|
|
|
160
|
|
|
} |
161
|
|
|
|
162
|
|
View Code Duplication |
public function testGeneratesTableCreationSql() |
|
|
|
|
163
|
|
|
{ |
164
|
|
|
$table = new Table('test'); |
165
|
|
|
$table->addColumn('id', 'integer', array('notnull' => true, 'autoincrement' => true)); |
166
|
|
|
$table->addColumn('test', 'string', array('notnull' => false, 'length' => 255)); |
167
|
|
|
$table->setPrimaryKey(array('id')); |
168
|
|
|
|
169
|
|
|
$sql = $this->_platform->getCreateTableSQL($table); |
170
|
|
|
self::assertEquals($this->getGenerateTableSql(), $sql[0]); |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
abstract public function getGenerateTableSql(); |
174
|
|
|
|
175
|
|
View Code Duplication |
public function testGenerateTableWithMultiColumnUniqueIndex() |
|
|
|
|
176
|
|
|
{ |
177
|
|
|
$table = new Table('test'); |
178
|
|
|
$table->addColumn('foo', 'string', array('notnull' => false, 'length' => 255)); |
179
|
|
|
$table->addColumn('bar', 'string', array('notnull' => false, 'length' => 255)); |
180
|
|
|
$table->addUniqueIndex(array("foo", "bar")); |
181
|
|
|
|
182
|
|
|
$sql = $this->_platform->getCreateTableSQL($table); |
183
|
|
|
self::assertEquals($this->getGenerateTableWithMultiColumnUniqueIndexSql(), $sql); |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
abstract public function getGenerateTableWithMultiColumnUniqueIndexSql(); |
187
|
|
|
|
188
|
|
View Code Duplication |
public function testGeneratesIndexCreationSql() |
|
|
|
|
189
|
|
|
{ |
190
|
|
|
$indexDef = new \Doctrine\DBAL\Schema\Index('my_idx', array('user_name', 'last_login')); |
191
|
|
|
|
192
|
|
|
self::assertEquals( |
193
|
|
|
$this->getGenerateIndexSql(), |
194
|
|
|
$this->_platform->getCreateIndexSQL($indexDef, 'mytable') |
195
|
|
|
); |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
abstract public function getGenerateIndexSql(); |
199
|
|
|
|
200
|
|
View Code Duplication |
public function testGeneratesUniqueIndexCreationSql() |
|
|
|
|
201
|
|
|
{ |
202
|
|
|
$indexDef = new \Doctrine\DBAL\Schema\Index('index_name', array('test', 'test2'), true); |
203
|
|
|
|
204
|
|
|
$sql = $this->_platform->getCreateIndexSQL($indexDef, 'test'); |
205
|
|
|
self::assertEquals($this->getGenerateUniqueIndexSql(), $sql); |
206
|
|
|
} |
207
|
|
|
|
208
|
|
|
abstract public function getGenerateUniqueIndexSql(); |
209
|
|
|
|
210
|
|
|
public function testGeneratesPartialIndexesSqlOnlyWhenSupportingPartialIndexes() |
211
|
|
|
{ |
212
|
|
|
$where = 'test IS NULL AND test2 IS NOT NULL'; |
213
|
|
|
$indexDef = new \Doctrine\DBAL\Schema\Index('name', array('test', 'test2'), false, false, array(), array('where' => $where)); |
214
|
|
|
$uniqueIndex = new \Doctrine\DBAL\Schema\Index('name', array('test', 'test2'), true, false, array(), array('where' => $where)); |
215
|
|
|
|
216
|
|
|
$expected = ' WHERE ' . $where; |
217
|
|
|
|
218
|
|
|
$actuals = array(); |
219
|
|
|
|
220
|
|
|
if ($this->supportsInlineIndexDeclaration()) { |
221
|
|
|
$actuals []= $this->_platform->getIndexDeclarationSQL('name', $indexDef); |
222
|
|
|
} |
223
|
|
|
|
224
|
|
|
$actuals []= $this->_platform->getUniqueConstraintDeclarationSQL('name', $uniqueIndex); |
225
|
|
|
$actuals []= $this->_platform->getCreateIndexSQL($indexDef, 'table'); |
226
|
|
|
|
227
|
|
|
foreach ($actuals as $actual) { |
228
|
|
|
if ($this->_platform->supportsPartialIndexes()) { |
229
|
|
|
self::assertStringEndsWith($expected, $actual, 'WHERE clause should be present'); |
230
|
|
|
} else { |
231
|
|
|
self::assertStringEndsNotWith($expected, $actual, 'WHERE clause should NOT be present'); |
232
|
|
|
} |
233
|
|
|
} |
234
|
|
|
} |
235
|
|
|
|
236
|
|
|
public function testGeneratesForeignKeyCreationSql() |
237
|
|
|
{ |
238
|
|
|
$fk = new \Doctrine\DBAL\Schema\ForeignKeyConstraint(array('fk_name_id'), 'other_table', array('id'), ''); |
239
|
|
|
|
240
|
|
|
$sql = $this->_platform->getCreateForeignKeySQL($fk, 'test'); |
241
|
|
|
self::assertEquals($sql, $this->getGenerateForeignKeySql()); |
242
|
|
|
} |
243
|
|
|
|
244
|
|
|
abstract public function getGenerateForeignKeySql(); |
245
|
|
|
|
246
|
|
|
public function testGeneratesConstraintCreationSql() |
247
|
|
|
{ |
248
|
|
|
$idx = new \Doctrine\DBAL\Schema\Index('constraint_name', array('test'), true, false); |
249
|
|
|
$sql = $this->_platform->getCreateConstraintSQL($idx, 'test'); |
250
|
|
|
self::assertEquals($this->getGenerateConstraintUniqueIndexSql(), $sql); |
251
|
|
|
|
252
|
|
|
$pk = new \Doctrine\DBAL\Schema\Index('constraint_name', array('test'), true, true); |
253
|
|
|
$sql = $this->_platform->getCreateConstraintSQL($pk, 'test'); |
254
|
|
|
self::assertEquals($this->getGenerateConstraintPrimaryIndexSql(), $sql); |
255
|
|
|
|
256
|
|
|
$fk = new \Doctrine\DBAL\Schema\ForeignKeyConstraint(array('fk_name'), 'foreign', array('id'), 'constraint_fk'); |
257
|
|
|
$sql = $this->_platform->getCreateConstraintSQL($fk, 'test'); |
258
|
|
|
self::assertEquals($this->getGenerateConstraintForeignKeySql($fk), $sql); |
259
|
|
|
} |
260
|
|
|
|
261
|
|
|
public function testGeneratesForeignKeySqlOnlyWhenSupportingForeignKeys() |
262
|
|
|
{ |
263
|
|
|
$fk = new \Doctrine\DBAL\Schema\ForeignKeyConstraint(array('fk_name'), 'foreign', array('id'), 'constraint_fk'); |
264
|
|
|
|
265
|
|
|
if ($this->_platform->supportsForeignKeyConstraints()) { |
266
|
|
|
self::assertInternalType( |
267
|
|
|
'string', |
268
|
|
|
$this->_platform->getCreateForeignKeySQL($fk, 'test') |
269
|
|
|
); |
270
|
|
|
} else { |
271
|
|
|
$this->expectException('Doctrine\DBAL\DBALException'); |
272
|
|
|
$this->_platform->getCreateForeignKeySQL($fk, 'test'); |
273
|
|
|
} |
274
|
|
|
} |
275
|
|
|
|
276
|
|
|
protected function getBitAndComparisonExpressionSql($value1, $value2) |
277
|
|
|
{ |
278
|
|
|
return '(' . $value1 . ' & ' . $value2 . ')'; |
279
|
|
|
} |
280
|
|
|
|
281
|
|
|
/** |
282
|
|
|
* @group DDC-1213 |
283
|
|
|
*/ |
284
|
|
|
public function testGeneratesBitAndComparisonExpressionSql() |
285
|
|
|
{ |
286
|
|
|
$sql = $this->_platform->getBitAndComparisonExpression(2, 4); |
287
|
|
|
self::assertEquals($this->getBitAndComparisonExpressionSql(2, 4), $sql); |
288
|
|
|
} |
289
|
|
|
|
290
|
|
|
protected function getBitOrComparisonExpressionSql($value1, $value2) |
291
|
|
|
{ |
292
|
|
|
return '(' . $value1 . ' | ' . $value2 . ')'; |
293
|
|
|
} |
294
|
|
|
|
295
|
|
|
/** |
296
|
|
|
* @group DDC-1213 |
297
|
|
|
*/ |
298
|
|
|
public function testGeneratesBitOrComparisonExpressionSql() |
299
|
|
|
{ |
300
|
|
|
$sql = $this->_platform->getBitOrComparisonExpression(2, 4); |
301
|
|
|
self::assertEquals($this->getBitOrComparisonExpressionSql(2, 4), $sql); |
302
|
|
|
} |
303
|
|
|
|
304
|
|
|
public function getGenerateConstraintUniqueIndexSql() |
305
|
|
|
{ |
306
|
|
|
return 'ALTER TABLE test ADD CONSTRAINT constraint_name UNIQUE (test)'; |
307
|
|
|
} |
308
|
|
|
|
309
|
|
|
public function getGenerateConstraintPrimaryIndexSql() |
310
|
|
|
{ |
311
|
|
|
return 'ALTER TABLE test ADD CONSTRAINT constraint_name PRIMARY KEY (test)'; |
312
|
|
|
} |
313
|
|
|
|
314
|
|
|
public function getGenerateConstraintForeignKeySql(ForeignKeyConstraint $fk) |
315
|
|
|
{ |
316
|
|
|
$quotedForeignTable = $fk->getQuotedForeignTableName($this->_platform); |
317
|
|
|
|
318
|
|
|
return "ALTER TABLE test ADD CONSTRAINT constraint_fk FOREIGN KEY (fk_name) REFERENCES $quotedForeignTable (id)"; |
319
|
|
|
} |
320
|
|
|
|
321
|
|
|
abstract public function getGenerateAlterTableSql(); |
322
|
|
|
|
323
|
|
|
public function testGeneratesTableAlterationSql() |
324
|
|
|
{ |
325
|
|
|
$expectedSql = $this->getGenerateAlterTableSql(); |
326
|
|
|
|
327
|
|
|
$table = new Table('mytable'); |
328
|
|
|
$table->addColumn('id', 'integer', array('autoincrement' => true)); |
329
|
|
|
$table->addColumn('foo', 'integer'); |
330
|
|
|
$table->addColumn('bar', 'string'); |
331
|
|
|
$table->addColumn('bloo', 'boolean'); |
332
|
|
|
$table->setPrimaryKey(array('id')); |
333
|
|
|
|
334
|
|
|
$tableDiff = new TableDiff('mytable'); |
335
|
|
|
$tableDiff->fromTable = $table; |
336
|
|
|
$tableDiff->newName = 'userlist'; |
337
|
|
|
$tableDiff->addedColumns['quota'] = new \Doctrine\DBAL\Schema\Column('quota', \Doctrine\DBAL\Types\Type::getType('integer'), array('notnull' => false)); |
338
|
|
|
$tableDiff->removedColumns['foo'] = new \Doctrine\DBAL\Schema\Column('foo', \Doctrine\DBAL\Types\Type::getType('integer')); |
339
|
|
|
$tableDiff->changedColumns['bar'] = new \Doctrine\DBAL\Schema\ColumnDiff( |
340
|
|
|
'bar', new \Doctrine\DBAL\Schema\Column( |
341
|
|
|
'baz', \Doctrine\DBAL\Types\Type::getType('string'), array('default' => 'def') |
342
|
|
|
), |
343
|
|
|
array('type', 'notnull', 'default') |
344
|
|
|
); |
345
|
|
|
$tableDiff->changedColumns['bloo'] = new \Doctrine\DBAL\Schema\ColumnDiff( |
346
|
|
|
'bloo', new \Doctrine\DBAL\Schema\Column( |
347
|
|
|
'bloo', \Doctrine\DBAL\Types\Type::getType('boolean'), array('default' => false) |
348
|
|
|
), |
349
|
|
|
array('type', 'notnull', 'default') |
350
|
|
|
); |
351
|
|
|
|
352
|
|
|
$sql = $this->_platform->getAlterTableSQL($tableDiff); |
353
|
|
|
|
354
|
|
|
self::assertEquals($expectedSql, $sql); |
355
|
|
|
} |
356
|
|
|
|
357
|
|
|
public function testGetCustomColumnDeclarationSql() |
358
|
|
|
{ |
359
|
|
|
$field = array('columnDefinition' => 'MEDIUMINT(6) UNSIGNED'); |
360
|
|
|
self::assertEquals('foo MEDIUMINT(6) UNSIGNED', $this->_platform->getColumnDeclarationSQL('foo', $field)); |
361
|
|
|
} |
362
|
|
|
|
363
|
|
|
public function testGetCreateTableSqlDispatchEvent() |
364
|
|
|
{ |
365
|
|
|
$listenerMock = $this->getMockBuilder('GetCreateTableSqlDispatchEvenListener') |
366
|
|
|
->setMethods(array('onSchemaCreateTable', 'onSchemaCreateTableColumn')) |
367
|
|
|
->getMock(); |
368
|
|
|
$listenerMock |
369
|
|
|
->expects($this->once()) |
370
|
|
|
->method('onSchemaCreateTable'); |
371
|
|
|
$listenerMock |
372
|
|
|
->expects($this->exactly(2)) |
373
|
|
|
->method('onSchemaCreateTableColumn'); |
374
|
|
|
|
375
|
|
|
$eventManager = new EventManager(); |
376
|
|
|
$eventManager->addEventListener(array(Events::onSchemaCreateTable, Events::onSchemaCreateTableColumn), $listenerMock); |
377
|
|
|
|
378
|
|
|
$this->_platform->setEventManager($eventManager); |
379
|
|
|
|
380
|
|
|
$table = new Table('test'); |
381
|
|
|
$table->addColumn('foo', 'string', array('notnull' => false, 'length' => 255)); |
382
|
|
|
$table->addColumn('bar', 'string', array('notnull' => false, 'length' => 255)); |
383
|
|
|
|
384
|
|
|
$this->_platform->getCreateTableSQL($table); |
385
|
|
|
} |
386
|
|
|
|
387
|
|
|
public function testGetDropTableSqlDispatchEvent() |
388
|
|
|
{ |
389
|
|
|
$listenerMock = $this->getMockBuilder('GetDropTableSqlDispatchEventListener') |
390
|
|
|
->setMethods(array('onSchemaDropTable')) |
391
|
|
|
->getMock(); |
392
|
|
|
$listenerMock |
393
|
|
|
->expects($this->once()) |
394
|
|
|
->method('onSchemaDropTable'); |
395
|
|
|
|
396
|
|
|
$eventManager = new EventManager(); |
397
|
|
|
$eventManager->addEventListener(array(Events::onSchemaDropTable), $listenerMock); |
398
|
|
|
|
399
|
|
|
$this->_platform->setEventManager($eventManager); |
400
|
|
|
|
401
|
|
|
$this->_platform->getDropTableSQL('TABLE'); |
402
|
|
|
} |
403
|
|
|
|
404
|
|
|
public function testGetAlterTableSqlDispatchEvent() |
405
|
|
|
{ |
406
|
|
|
$events = array( |
407
|
|
|
'onSchemaAlterTable', |
408
|
|
|
'onSchemaAlterTableAddColumn', |
409
|
|
|
'onSchemaAlterTableRemoveColumn', |
410
|
|
|
'onSchemaAlterTableChangeColumn', |
411
|
|
|
'onSchemaAlterTableRenameColumn' |
412
|
|
|
); |
413
|
|
|
|
414
|
|
|
$listenerMock = $this->getMockBuilder('GetAlterTableSqlDispatchEvenListener') |
415
|
|
|
->setMethods($events) |
416
|
|
|
->getMock(); |
417
|
|
|
$listenerMock |
418
|
|
|
->expects($this->once()) |
419
|
|
|
->method('onSchemaAlterTable'); |
420
|
|
|
$listenerMock |
421
|
|
|
->expects($this->once()) |
422
|
|
|
->method('onSchemaAlterTableAddColumn'); |
423
|
|
|
$listenerMock |
424
|
|
|
->expects($this->once()) |
425
|
|
|
->method('onSchemaAlterTableRemoveColumn'); |
426
|
|
|
$listenerMock |
427
|
|
|
->expects($this->once()) |
428
|
|
|
->method('onSchemaAlterTableChangeColumn'); |
429
|
|
|
$listenerMock |
430
|
|
|
->expects($this->once()) |
431
|
|
|
->method('onSchemaAlterTableRenameColumn'); |
432
|
|
|
|
433
|
|
|
$eventManager = new EventManager(); |
434
|
|
|
$events = array( |
435
|
|
|
Events::onSchemaAlterTable, |
436
|
|
|
Events::onSchemaAlterTableAddColumn, |
437
|
|
|
Events::onSchemaAlterTableRemoveColumn, |
438
|
|
|
Events::onSchemaAlterTableChangeColumn, |
439
|
|
|
Events::onSchemaAlterTableRenameColumn |
440
|
|
|
); |
441
|
|
|
$eventManager->addEventListener($events, $listenerMock); |
442
|
|
|
|
443
|
|
|
$this->_platform->setEventManager($eventManager); |
444
|
|
|
|
445
|
|
|
$table = new Table('mytable'); |
446
|
|
|
$table->addColumn('removed', 'integer'); |
447
|
|
|
$table->addColumn('changed', 'integer'); |
448
|
|
|
$table->addColumn('renamed', 'integer'); |
449
|
|
|
|
450
|
|
|
$tableDiff = new TableDiff('mytable'); |
451
|
|
|
$tableDiff->fromTable = $table; |
452
|
|
|
$tableDiff->addedColumns['added'] = new \Doctrine\DBAL\Schema\Column('added', \Doctrine\DBAL\Types\Type::getType('integer'), array()); |
453
|
|
|
$tableDiff->removedColumns['removed'] = new \Doctrine\DBAL\Schema\Column('removed', \Doctrine\DBAL\Types\Type::getType('integer'), array()); |
454
|
|
|
$tableDiff->changedColumns['changed'] = new \Doctrine\DBAL\Schema\ColumnDiff( |
455
|
|
|
'changed', new \Doctrine\DBAL\Schema\Column( |
456
|
|
|
'changed2', \Doctrine\DBAL\Types\Type::getType('string'), array() |
457
|
|
|
), |
458
|
|
|
array() |
459
|
|
|
); |
460
|
|
|
$tableDiff->renamedColumns['renamed'] = new \Doctrine\DBAL\Schema\Column('renamed2', \Doctrine\DBAL\Types\Type::getType('integer'), array()); |
461
|
|
|
|
462
|
|
|
$this->_platform->getAlterTableSQL($tableDiff); |
463
|
|
|
} |
464
|
|
|
|
465
|
|
|
/** |
466
|
|
|
* @group DBAL-42 |
467
|
|
|
*/ |
468
|
|
|
public function testCreateTableColumnComments() |
469
|
|
|
{ |
470
|
|
|
$table = new Table('test'); |
471
|
|
|
$table->addColumn('id', 'integer', array('comment' => 'This is a comment')); |
472
|
|
|
$table->setPrimaryKey(array('id')); |
473
|
|
|
|
474
|
|
|
self::assertEquals($this->getCreateTableColumnCommentsSQL(), $this->_platform->getCreateTableSQL($table)); |
475
|
|
|
} |
476
|
|
|
|
477
|
|
|
/** |
478
|
|
|
* @group DBAL-42 |
479
|
|
|
*/ |
480
|
|
|
public function testAlterTableColumnComments() |
481
|
|
|
{ |
482
|
|
|
$tableDiff = new TableDiff('mytable'); |
483
|
|
|
$tableDiff->addedColumns['quota'] = new \Doctrine\DBAL\Schema\Column('quota', \Doctrine\DBAL\Types\Type::getType('integer'), array('comment' => 'A comment')); |
484
|
|
|
$tableDiff->changedColumns['foo'] = new \Doctrine\DBAL\Schema\ColumnDiff( |
485
|
|
|
'foo', new \Doctrine\DBAL\Schema\Column( |
486
|
|
|
'foo', \Doctrine\DBAL\Types\Type::getType('string') |
487
|
|
|
), |
488
|
|
|
array('comment') |
489
|
|
|
); |
490
|
|
|
$tableDiff->changedColumns['bar'] = new \Doctrine\DBAL\Schema\ColumnDiff( |
491
|
|
|
'bar', new \Doctrine\DBAL\Schema\Column( |
492
|
|
|
'baz', \Doctrine\DBAL\Types\Type::getType('string'), array('comment' => 'B comment') |
493
|
|
|
), |
494
|
|
|
array('comment') |
495
|
|
|
); |
496
|
|
|
|
497
|
|
|
self::assertEquals($this->getAlterTableColumnCommentsSQL(), $this->_platform->getAlterTableSQL($tableDiff)); |
498
|
|
|
} |
499
|
|
|
|
500
|
|
View Code Duplication |
public function testCreateTableColumnTypeComments() |
|
|
|
|
501
|
|
|
{ |
502
|
|
|
$table = new Table('test'); |
503
|
|
|
$table->addColumn('id', 'integer'); |
504
|
|
|
$table->addColumn('data', 'array'); |
505
|
|
|
$table->setPrimaryKey(array('id')); |
506
|
|
|
|
507
|
|
|
self::assertEquals($this->getCreateTableColumnTypeCommentsSQL(), $this->_platform->getCreateTableSQL($table)); |
508
|
|
|
} |
509
|
|
|
|
510
|
|
|
public function getCreateTableColumnCommentsSQL() |
511
|
|
|
{ |
512
|
|
|
$this->markTestSkipped('Platform does not support Column comments.'); |
513
|
|
|
} |
514
|
|
|
|
515
|
|
|
public function getAlterTableColumnCommentsSQL() |
516
|
|
|
{ |
517
|
|
|
$this->markTestSkipped('Platform does not support Column comments.'); |
518
|
|
|
} |
519
|
|
|
|
520
|
|
|
public function getCreateTableColumnTypeCommentsSQL() |
521
|
|
|
{ |
522
|
|
|
$this->markTestSkipped('Platform does not support Column comments.'); |
523
|
|
|
} |
524
|
|
|
|
525
|
|
|
public function testGetDefaultValueDeclarationSQL() |
526
|
|
|
{ |
527
|
|
|
// non-timestamp value will get single quotes |
528
|
|
|
$field = array( |
529
|
|
|
'type' => 'string', |
530
|
|
|
'default' => 'non_timestamp' |
531
|
|
|
); |
532
|
|
|
|
533
|
|
|
self::assertEquals(" DEFAULT 'non_timestamp'", $this->_platform->getDefaultValueDeclarationSQL($field)); |
534
|
|
|
} |
535
|
|
|
|
536
|
|
|
public function testGetDefaultValueDeclarationSQLDateTime() |
537
|
|
|
{ |
538
|
|
|
// timestamps on datetime types should not be quoted |
539
|
|
|
foreach (array('datetime', 'datetimetz') as $type) { |
540
|
|
|
|
541
|
|
|
$field = array( |
542
|
|
|
'type' => Type::getType($type), |
543
|
|
|
'default' => $this->_platform->getCurrentTimestampSQL() |
544
|
|
|
); |
545
|
|
|
|
546
|
|
|
self::assertEquals(' DEFAULT ' . $this->_platform->getCurrentTimestampSQL(), $this->_platform->getDefaultValueDeclarationSQL($field)); |
547
|
|
|
|
548
|
|
|
} |
549
|
|
|
} |
550
|
|
|
|
551
|
|
|
public function testGetDefaultValueDeclarationSQLForIntegerTypes() |
552
|
|
|
{ |
553
|
|
|
foreach(array('bigint', 'integer', 'smallint') as $type) { |
554
|
|
|
$field = array( |
555
|
|
|
'type' => Type::getType($type), |
556
|
|
|
'default' => 1 |
557
|
|
|
); |
558
|
|
|
|
559
|
|
|
self::assertEquals( |
560
|
|
|
' DEFAULT 1', |
561
|
|
|
$this->_platform->getDefaultValueDeclarationSQL($field) |
562
|
|
|
); |
563
|
|
|
} |
564
|
|
|
} |
565
|
|
|
|
566
|
|
View Code Duplication |
public function testGetDefaultValueDeclarationSQLForDateType() |
|
|
|
|
567
|
|
|
{ |
568
|
|
|
$currentDateSql = $this->_platform->getCurrentDateSQL(); |
569
|
|
|
$field = array( |
570
|
|
|
'type' => Type::getType('date'), |
571
|
|
|
'default' => $currentDateSql, |
572
|
|
|
); |
573
|
|
|
|
574
|
|
|
$this->assertEquals( |
575
|
|
|
' DEFAULT '.$currentDateSql, |
576
|
|
|
$this->_platform->getDefaultValueDeclarationSQL($field) |
577
|
|
|
); |
578
|
|
|
} |
579
|
|
|
|
580
|
|
|
/** |
581
|
|
|
* @group DBAL-45 |
582
|
|
|
*/ |
583
|
|
|
public function testKeywordList() |
584
|
|
|
{ |
585
|
|
|
$keywordList = $this->_platform->getReservedKeywordsList(); |
586
|
|
|
self::assertInstanceOf('Doctrine\DBAL\Platforms\Keywords\KeywordList', $keywordList); |
587
|
|
|
|
588
|
|
|
self::assertTrue($keywordList->isKeyword('table')); |
589
|
|
|
} |
590
|
|
|
|
591
|
|
|
/** |
592
|
|
|
* @group DBAL-374 |
593
|
|
|
*/ |
594
|
|
View Code Duplication |
public function testQuotedColumnInPrimaryKeyPropagation() |
|
|
|
|
595
|
|
|
{ |
596
|
|
|
$table = new Table('`quoted`'); |
597
|
|
|
$table->addColumn('create', 'string'); |
598
|
|
|
$table->setPrimaryKey(array('create')); |
599
|
|
|
|
600
|
|
|
$sql = $this->_platform->getCreateTableSQL($table); |
601
|
|
|
self::assertEquals($this->getQuotedColumnInPrimaryKeySQL(), $sql); |
602
|
|
|
} |
603
|
|
|
|
604
|
|
|
abstract protected function getQuotedColumnInPrimaryKeySQL(); |
605
|
|
|
abstract protected function getQuotedColumnInIndexSQL(); |
606
|
|
|
abstract protected function getQuotedNameInIndexSQL(); |
607
|
|
|
abstract protected function getQuotedColumnInForeignKeySQL(); |
608
|
|
|
|
609
|
|
|
/** |
610
|
|
|
* @group DBAL-374 |
611
|
|
|
*/ |
612
|
|
View Code Duplication |
public function testQuotedColumnInIndexPropagation() |
|
|
|
|
613
|
|
|
{ |
614
|
|
|
$table = new Table('`quoted`'); |
615
|
|
|
$table->addColumn('create', 'string'); |
616
|
|
|
$table->addIndex(array('create')); |
617
|
|
|
|
618
|
|
|
$sql = $this->_platform->getCreateTableSQL($table); |
619
|
|
|
self::assertEquals($this->getQuotedColumnInIndexSQL(), $sql); |
620
|
|
|
} |
621
|
|
|
|
622
|
|
View Code Duplication |
public function testQuotedNameInIndexSQL() |
|
|
|
|
623
|
|
|
{ |
624
|
|
|
$table = new Table('test'); |
625
|
|
|
$table->addColumn('column1', 'string'); |
626
|
|
|
$table->addIndex(array('column1'), '`key`'); |
627
|
|
|
|
628
|
|
|
$sql = $this->_platform->getCreateTableSQL($table); |
629
|
|
|
self::assertEquals($this->getQuotedNameInIndexSQL(), $sql); |
630
|
|
|
} |
631
|
|
|
|
632
|
|
|
/** |
633
|
|
|
* @group DBAL-374 |
634
|
|
|
*/ |
635
|
|
|
public function testQuotedColumnInForeignKeyPropagation() |
636
|
|
|
{ |
637
|
|
|
$table = new Table('`quoted`'); |
638
|
|
|
$table->addColumn('create', 'string'); |
639
|
|
|
$table->addColumn('foo', 'string'); |
640
|
|
|
$table->addColumn('`bar`', 'string'); |
641
|
|
|
|
642
|
|
|
// Foreign table with reserved keyword as name (needs quotation). |
643
|
|
|
$foreignTable = new Table('foreign'); |
644
|
|
|
$foreignTable->addColumn('create', 'string'); // Foreign column with reserved keyword as name (needs quotation). |
645
|
|
|
$foreignTable->addColumn('bar', 'string'); // Foreign column with non-reserved keyword as name (does not need quotation). |
646
|
|
|
$foreignTable->addColumn('`foo-bar`', 'string'); // Foreign table with special character in name (needs quotation on some platforms, e.g. Sqlite). |
647
|
|
|
|
648
|
|
|
$table->addForeignKeyConstraint($foreignTable, array('create', 'foo', '`bar`'), array('create', 'bar', '`foo-bar`'), array(), 'FK_WITH_RESERVED_KEYWORD'); |
649
|
|
|
|
650
|
|
|
// Foreign table with non-reserved keyword as name (does not need quotation). |
651
|
|
|
$foreignTable = new Table('foo'); |
652
|
|
|
$foreignTable->addColumn('create', 'string'); // Foreign column with reserved keyword as name (needs quotation). |
653
|
|
|
$foreignTable->addColumn('bar', 'string'); // Foreign column with non-reserved keyword as name (does not need quotation). |
654
|
|
|
$foreignTable->addColumn('`foo-bar`', 'string'); // Foreign table with special character in name (needs quotation on some platforms, e.g. Sqlite). |
655
|
|
|
|
656
|
|
|
$table->addForeignKeyConstraint($foreignTable, array('create', 'foo', '`bar`'), array('create', 'bar', '`foo-bar`'), array(), 'FK_WITH_NON_RESERVED_KEYWORD'); |
657
|
|
|
|
658
|
|
|
// Foreign table with special character in name (needs quotation on some platforms, e.g. Sqlite). |
659
|
|
|
$foreignTable = new Table('`foo-bar`'); |
660
|
|
|
$foreignTable->addColumn('create', 'string'); // Foreign column with reserved keyword as name (needs quotation). |
661
|
|
|
$foreignTable->addColumn('bar', 'string'); // Foreign column with non-reserved keyword as name (does not need quotation). |
662
|
|
|
$foreignTable->addColumn('`foo-bar`', 'string'); // Foreign table with special character in name (needs quotation on some platforms, e.g. Sqlite). |
663
|
|
|
|
664
|
|
|
$table->addForeignKeyConstraint($foreignTable, array('create', 'foo', '`bar`'), array('create', 'bar', '`foo-bar`'), array(), 'FK_WITH_INTENDED_QUOTATION'); |
665
|
|
|
|
666
|
|
|
$sql = $this->_platform->getCreateTableSQL($table, AbstractPlatform::CREATE_FOREIGNKEYS); |
667
|
|
|
self::assertEquals($this->getQuotedColumnInForeignKeySQL(), $sql); |
668
|
|
|
} |
669
|
|
|
|
670
|
|
|
/** |
671
|
|
|
* @group DBAL-1051 |
672
|
|
|
*/ |
673
|
|
|
public function testQuotesReservedKeywordInUniqueConstraintDeclarationSQL() |
674
|
|
|
{ |
675
|
|
|
$index = new Index('select', array('foo'), true); |
676
|
|
|
|
677
|
|
|
self::assertSame( |
678
|
|
|
$this->getQuotesReservedKeywordInUniqueConstraintDeclarationSQL(), |
679
|
|
|
$this->_platform->getUniqueConstraintDeclarationSQL('select', $index) |
680
|
|
|
); |
681
|
|
|
} |
682
|
|
|
|
683
|
|
|
/** |
684
|
|
|
* @return string |
685
|
|
|
*/ |
686
|
|
|
abstract protected function getQuotesReservedKeywordInUniqueConstraintDeclarationSQL(); |
687
|
|
|
|
688
|
|
|
/** |
689
|
|
|
* @group DBAL-2270 |
690
|
|
|
*/ |
691
|
|
|
public function testQuotesReservedKeywordInTruncateTableSQL() |
692
|
|
|
{ |
693
|
|
|
self::assertSame( |
694
|
|
|
$this->getQuotesReservedKeywordInTruncateTableSQL(), |
695
|
|
|
$this->_platform->getTruncateTableSQL('select') |
696
|
|
|
); |
697
|
|
|
} |
698
|
|
|
|
699
|
|
|
/** |
700
|
|
|
* @return string |
701
|
|
|
*/ |
702
|
|
|
abstract protected function getQuotesReservedKeywordInTruncateTableSQL(); |
703
|
|
|
|
704
|
|
|
/** |
705
|
|
|
* @group DBAL-1051 |
706
|
|
|
*/ |
707
|
|
|
public function testQuotesReservedKeywordInIndexDeclarationSQL() |
708
|
|
|
{ |
709
|
|
|
$index = new Index('select', array('foo')); |
710
|
|
|
|
711
|
|
|
if (! $this->supportsInlineIndexDeclaration()) { |
712
|
|
|
$this->expectException('Doctrine\DBAL\DBALException'); |
713
|
|
|
} |
714
|
|
|
|
715
|
|
|
self::assertSame( |
716
|
|
|
$this->getQuotesReservedKeywordInIndexDeclarationSQL(), |
717
|
|
|
$this->_platform->getIndexDeclarationSQL('select', $index) |
718
|
|
|
); |
719
|
|
|
} |
720
|
|
|
|
721
|
|
|
/** |
722
|
|
|
* @return string |
723
|
|
|
*/ |
724
|
|
|
abstract protected function getQuotesReservedKeywordInIndexDeclarationSQL(); |
725
|
|
|
|
726
|
|
|
/** |
727
|
|
|
* @return boolean |
728
|
|
|
*/ |
729
|
|
|
protected function supportsInlineIndexDeclaration() |
730
|
|
|
{ |
731
|
|
|
return true; |
732
|
|
|
} |
733
|
|
|
|
734
|
|
|
public function testSupportsCommentOnStatement() |
735
|
|
|
{ |
736
|
|
|
self::assertSame($this->supportsCommentOnStatement(), $this->_platform->supportsCommentOnStatement()); |
737
|
|
|
} |
738
|
|
|
|
739
|
|
|
/** |
740
|
|
|
* @return bool |
741
|
|
|
*/ |
742
|
|
|
protected function supportsCommentOnStatement() |
743
|
|
|
{ |
744
|
|
|
return false; |
745
|
|
|
} |
746
|
|
|
|
747
|
|
|
/** |
748
|
|
|
* @expectedException \Doctrine\DBAL\DBALException |
749
|
|
|
*/ |
750
|
|
|
public function testGetCreateSchemaSQL() |
751
|
|
|
{ |
752
|
|
|
$this->_platform->getCreateSchemaSQL('schema'); |
753
|
|
|
} |
754
|
|
|
|
755
|
|
|
/** |
756
|
|
|
* @group DBAL-585 |
757
|
|
|
*/ |
758
|
|
|
public function testAlterTableChangeQuotedColumn() |
759
|
|
|
{ |
760
|
|
|
$tableDiff = new \Doctrine\DBAL\Schema\TableDiff('mytable'); |
761
|
|
|
$tableDiff->fromTable = new \Doctrine\DBAL\Schema\Table('mytable'); |
762
|
|
|
$tableDiff->changedColumns['foo'] = new \Doctrine\DBAL\Schema\ColumnDiff( |
763
|
|
|
'select', new \Doctrine\DBAL\Schema\Column( |
764
|
|
|
'select', \Doctrine\DBAL\Types\Type::getType('string') |
765
|
|
|
), |
766
|
|
|
array('type') |
767
|
|
|
); |
768
|
|
|
|
769
|
|
|
self::assertContains( |
770
|
|
|
$this->_platform->quoteIdentifier('select'), |
771
|
|
|
implode(';', $this->_platform->getAlterTableSQL($tableDiff)) |
772
|
|
|
); |
773
|
|
|
} |
774
|
|
|
|
775
|
|
|
/** |
776
|
|
|
* @group DBAL-563 |
777
|
|
|
*/ |
778
|
|
|
public function testUsesSequenceEmulatedIdentityColumns() |
779
|
|
|
{ |
780
|
|
|
self::assertFalse($this->_platform->usesSequenceEmulatedIdentityColumns()); |
781
|
|
|
} |
782
|
|
|
|
783
|
|
|
/** |
784
|
|
|
* @group DBAL-563 |
785
|
|
|
* @expectedException \Doctrine\DBAL\DBALException |
786
|
|
|
*/ |
787
|
|
|
public function testReturnsIdentitySequenceName() |
788
|
|
|
{ |
789
|
|
|
$this->_platform->getIdentitySequenceName('mytable', 'mycolumn'); |
790
|
|
|
} |
791
|
|
|
|
792
|
|
|
public function testReturnsBinaryDefaultLength() |
793
|
|
|
{ |
794
|
|
|
self::assertSame($this->getBinaryDefaultLength(), $this->_platform->getBinaryDefaultLength()); |
795
|
|
|
} |
796
|
|
|
|
797
|
|
|
protected function getBinaryDefaultLength() |
798
|
|
|
{ |
799
|
|
|
return 255; |
800
|
|
|
} |
801
|
|
|
|
802
|
|
|
public function testReturnsBinaryMaxLength() |
803
|
|
|
{ |
804
|
|
|
self::assertSame($this->getBinaryMaxLength(), $this->_platform->getBinaryMaxLength()); |
805
|
|
|
} |
806
|
|
|
|
807
|
|
|
protected function getBinaryMaxLength() |
808
|
|
|
{ |
809
|
|
|
return 4000; |
810
|
|
|
} |
811
|
|
|
|
812
|
|
|
/** |
813
|
|
|
* @expectedException \Doctrine\DBAL\DBALException |
814
|
|
|
*/ |
815
|
|
|
public function testReturnsBinaryTypeDeclarationSQL() |
816
|
|
|
{ |
817
|
|
|
$this->_platform->getBinaryTypeDeclarationSQL(array()); |
818
|
|
|
} |
819
|
|
|
|
820
|
|
|
/** |
821
|
|
|
* @group DBAL-553 |
822
|
|
|
*/ |
823
|
|
|
public function hasNativeJsonType() |
824
|
|
|
{ |
825
|
|
|
self::assertFalse($this->_platform->hasNativeJsonType()); |
826
|
|
|
} |
827
|
|
|
|
828
|
|
|
/** |
829
|
|
|
* @group DBAL-553 |
830
|
|
|
*/ |
831
|
|
|
public function testReturnsJsonTypeDeclarationSQL() |
832
|
|
|
{ |
833
|
|
|
$column = array( |
834
|
|
|
'length' => 666, |
835
|
|
|
'notnull' => true, |
836
|
|
|
'type' => Type::getType('json_array'), |
837
|
|
|
); |
838
|
|
|
|
839
|
|
|
self::assertSame( |
840
|
|
|
$this->_platform->getClobTypeDeclarationSQL($column), |
841
|
|
|
$this->_platform->getJsonTypeDeclarationSQL($column) |
842
|
|
|
); |
843
|
|
|
} |
844
|
|
|
|
845
|
|
|
/** |
846
|
|
|
* @group DBAL-234 |
847
|
|
|
*/ |
848
|
|
View Code Duplication |
public function testAlterTableRenameIndex() |
|
|
|
|
849
|
|
|
{ |
850
|
|
|
$tableDiff = new TableDiff('mytable'); |
851
|
|
|
$tableDiff->fromTable = new Table('mytable'); |
852
|
|
|
$tableDiff->fromTable->addColumn('id', 'integer'); |
853
|
|
|
$tableDiff->fromTable->setPrimaryKey(array('id')); |
854
|
|
|
$tableDiff->renamedIndexes = array( |
|
|
|
|
855
|
|
|
'idx_foo' => new Index('idx_bar', array('id')) |
856
|
|
|
); |
857
|
|
|
|
858
|
|
|
self::assertSame( |
859
|
|
|
$this->getAlterTableRenameIndexSQL(), |
860
|
|
|
$this->_platform->getAlterTableSQL($tableDiff) |
861
|
|
|
); |
862
|
|
|
} |
863
|
|
|
|
864
|
|
|
/** |
865
|
|
|
* @group DBAL-234 |
866
|
|
|
*/ |
867
|
|
|
protected function getAlterTableRenameIndexSQL() |
868
|
|
|
{ |
869
|
|
|
return array( |
870
|
|
|
'DROP INDEX idx_foo', |
871
|
|
|
'CREATE INDEX idx_bar ON mytable (id)', |
872
|
|
|
); |
873
|
|
|
} |
874
|
|
|
|
875
|
|
|
/** |
876
|
|
|
* @group DBAL-234 |
877
|
|
|
*/ |
878
|
|
View Code Duplication |
public function testQuotesAlterTableRenameIndex() |
|
|
|
|
879
|
|
|
{ |
880
|
|
|
$tableDiff = new TableDiff('table'); |
881
|
|
|
$tableDiff->fromTable = new Table('table'); |
882
|
|
|
$tableDiff->fromTable->addColumn('id', 'integer'); |
883
|
|
|
$tableDiff->fromTable->setPrimaryKey(array('id')); |
884
|
|
|
$tableDiff->renamedIndexes = array( |
|
|
|
|
885
|
|
|
'create' => new Index('select', array('id')), |
886
|
|
|
'`foo`' => new Index('`bar`', array('id')), |
887
|
|
|
); |
888
|
|
|
|
889
|
|
|
self::assertSame( |
890
|
|
|
$this->getQuotedAlterTableRenameIndexSQL(), |
891
|
|
|
$this->_platform->getAlterTableSQL($tableDiff) |
892
|
|
|
); |
893
|
|
|
} |
894
|
|
|
|
895
|
|
|
/** |
896
|
|
|
* @group DBAL-234 |
897
|
|
|
*/ |
898
|
|
|
protected function getQuotedAlterTableRenameIndexSQL() |
899
|
|
|
{ |
900
|
|
|
return array( |
901
|
|
|
'DROP INDEX "create"', |
902
|
|
|
'CREATE INDEX "select" ON "table" (id)', |
903
|
|
|
'DROP INDEX "foo"', |
904
|
|
|
'CREATE INDEX "bar" ON "table" (id)', |
905
|
|
|
); |
906
|
|
|
} |
907
|
|
|
|
908
|
|
|
/** |
909
|
|
|
* @group DBAL-835 |
910
|
|
|
*/ |
911
|
|
|
public function testQuotesAlterTableRenameColumn() |
912
|
|
|
{ |
913
|
|
|
$fromTable = new Table('mytable'); |
914
|
|
|
|
915
|
|
|
$fromTable->addColumn('unquoted1', 'integer', array('comment' => 'Unquoted 1')); |
916
|
|
|
$fromTable->addColumn('unquoted2', 'integer', array('comment' => 'Unquoted 2')); |
917
|
|
|
$fromTable->addColumn('unquoted3', 'integer', array('comment' => 'Unquoted 3')); |
918
|
|
|
|
919
|
|
|
$fromTable->addColumn('create', 'integer', array('comment' => 'Reserved keyword 1')); |
920
|
|
|
$fromTable->addColumn('table', 'integer', array('comment' => 'Reserved keyword 2')); |
921
|
|
|
$fromTable->addColumn('select', 'integer', array('comment' => 'Reserved keyword 3')); |
922
|
|
|
|
923
|
|
|
$fromTable->addColumn('`quoted1`', 'integer', array('comment' => 'Quoted 1')); |
924
|
|
|
$fromTable->addColumn('`quoted2`', 'integer', array('comment' => 'Quoted 2')); |
925
|
|
|
$fromTable->addColumn('`quoted3`', 'integer', array('comment' => 'Quoted 3')); |
926
|
|
|
|
927
|
|
|
$toTable = new Table('mytable'); |
928
|
|
|
|
929
|
|
|
$toTable->addColumn('unquoted', 'integer', array('comment' => 'Unquoted 1')); // unquoted -> unquoted |
930
|
|
|
$toTable->addColumn('where', 'integer', array('comment' => 'Unquoted 2')); // unquoted -> reserved keyword |
931
|
|
|
$toTable->addColumn('`foo`', 'integer', array('comment' => 'Unquoted 3')); // unquoted -> quoted |
932
|
|
|
|
933
|
|
|
$toTable->addColumn('reserved_keyword', 'integer', array('comment' => 'Reserved keyword 1')); // reserved keyword -> unquoted |
934
|
|
|
$toTable->addColumn('from', 'integer', array('comment' => 'Reserved keyword 2')); // reserved keyword -> reserved keyword |
935
|
|
|
$toTable->addColumn('`bar`', 'integer', array('comment' => 'Reserved keyword 3')); // reserved keyword -> quoted |
936
|
|
|
|
937
|
|
|
$toTable->addColumn('quoted', 'integer', array('comment' => 'Quoted 1')); // quoted -> unquoted |
938
|
|
|
$toTable->addColumn('and', 'integer', array('comment' => 'Quoted 2')); // quoted -> reserved keyword |
939
|
|
|
$toTable->addColumn('`baz`', 'integer', array('comment' => 'Quoted 3')); // quoted -> quoted |
940
|
|
|
|
941
|
|
|
$comparator = new Comparator(); |
942
|
|
|
|
943
|
|
|
self::assertEquals( |
944
|
|
|
$this->getQuotedAlterTableRenameColumnSQL(), |
945
|
|
|
$this->_platform->getAlterTableSQL($comparator->diffTable($fromTable, $toTable)) |
|
|
|
|
946
|
|
|
); |
947
|
|
|
} |
948
|
|
|
|
949
|
|
|
/** |
950
|
|
|
* Returns SQL statements for {@link testQuotesAlterTableRenameColumn}. |
951
|
|
|
* |
952
|
|
|
* @return array |
953
|
|
|
* |
954
|
|
|
* @group DBAL-835 |
955
|
|
|
*/ |
956
|
|
|
abstract protected function getQuotedAlterTableRenameColumnSQL(); |
957
|
|
|
|
958
|
|
|
/** |
959
|
|
|
* @group DBAL-835 |
960
|
|
|
*/ |
961
|
|
|
public function testQuotesAlterTableChangeColumnLength() |
962
|
|
|
{ |
963
|
|
|
$fromTable = new Table('mytable'); |
964
|
|
|
|
965
|
|
|
$fromTable->addColumn('unquoted1', 'string', array('comment' => 'Unquoted 1', 'length' => 10)); |
966
|
|
|
$fromTable->addColumn('unquoted2', 'string', array('comment' => 'Unquoted 2', 'length' => 10)); |
967
|
|
|
$fromTable->addColumn('unquoted3', 'string', array('comment' => 'Unquoted 3', 'length' => 10)); |
968
|
|
|
|
969
|
|
|
$fromTable->addColumn('create', 'string', array('comment' => 'Reserved keyword 1', 'length' => 10)); |
970
|
|
|
$fromTable->addColumn('table', 'string', array('comment' => 'Reserved keyword 2', 'length' => 10)); |
971
|
|
|
$fromTable->addColumn('select', 'string', array('comment' => 'Reserved keyword 3', 'length' => 10)); |
972
|
|
|
|
973
|
|
|
$toTable = new Table('mytable'); |
974
|
|
|
|
975
|
|
|
$toTable->addColumn('unquoted1', 'string', array('comment' => 'Unquoted 1', 'length' => 255)); |
976
|
|
|
$toTable->addColumn('unquoted2', 'string', array('comment' => 'Unquoted 2', 'length' => 255)); |
977
|
|
|
$toTable->addColumn('unquoted3', 'string', array('comment' => 'Unquoted 3', 'length' => 255)); |
978
|
|
|
|
979
|
|
|
$toTable->addColumn('create', 'string', array('comment' => 'Reserved keyword 1', 'length' => 255)); |
980
|
|
|
$toTable->addColumn('table', 'string', array('comment' => 'Reserved keyword 2', 'length' => 255)); |
981
|
|
|
$toTable->addColumn('select', 'string', array('comment' => 'Reserved keyword 3', 'length' => 255)); |
982
|
|
|
|
983
|
|
|
$comparator = new Comparator(); |
984
|
|
|
|
985
|
|
|
self::assertEquals( |
986
|
|
|
$this->getQuotedAlterTableChangeColumnLengthSQL(), |
987
|
|
|
$this->_platform->getAlterTableSQL($comparator->diffTable($fromTable, $toTable)) |
|
|
|
|
988
|
|
|
); |
989
|
|
|
} |
990
|
|
|
|
991
|
|
|
/** |
992
|
|
|
* Returns SQL statements for {@link testQuotesAlterTableChangeColumnLength}. |
993
|
|
|
* |
994
|
|
|
* @return array |
995
|
|
|
* |
996
|
|
|
* @group DBAL-835 |
997
|
|
|
*/ |
998
|
|
|
abstract protected function getQuotedAlterTableChangeColumnLengthSQL(); |
999
|
|
|
|
1000
|
|
|
/** |
1001
|
|
|
* @group DBAL-807 |
1002
|
|
|
*/ |
1003
|
|
View Code Duplication |
public function testAlterTableRenameIndexInSchema() |
|
|
|
|
1004
|
|
|
{ |
1005
|
|
|
$tableDiff = new TableDiff('myschema.mytable'); |
1006
|
|
|
$tableDiff->fromTable = new Table('myschema.mytable'); |
1007
|
|
|
$tableDiff->fromTable->addColumn('id', 'integer'); |
1008
|
|
|
$tableDiff->fromTable->setPrimaryKey(array('id')); |
1009
|
|
|
$tableDiff->renamedIndexes = array( |
|
|
|
|
1010
|
|
|
'idx_foo' => new Index('idx_bar', array('id')) |
1011
|
|
|
); |
1012
|
|
|
|
1013
|
|
|
self::assertSame( |
1014
|
|
|
$this->getAlterTableRenameIndexInSchemaSQL(), |
1015
|
|
|
$this->_platform->getAlterTableSQL($tableDiff) |
1016
|
|
|
); |
1017
|
|
|
} |
1018
|
|
|
|
1019
|
|
|
/** |
1020
|
|
|
* @group DBAL-807 |
1021
|
|
|
*/ |
1022
|
|
|
protected function getAlterTableRenameIndexInSchemaSQL() |
1023
|
|
|
{ |
1024
|
|
|
return array( |
1025
|
|
|
'DROP INDEX idx_foo', |
1026
|
|
|
'CREATE INDEX idx_bar ON myschema.mytable (id)', |
1027
|
|
|
); |
1028
|
|
|
} |
1029
|
|
|
|
1030
|
|
|
/** |
1031
|
|
|
* @group DBAL-807 |
1032
|
|
|
*/ |
1033
|
|
View Code Duplication |
public function testQuotesAlterTableRenameIndexInSchema() |
|
|
|
|
1034
|
|
|
{ |
1035
|
|
|
$tableDiff = new TableDiff('`schema`.table'); |
1036
|
|
|
$tableDiff->fromTable = new Table('`schema`.table'); |
1037
|
|
|
$tableDiff->fromTable->addColumn('id', 'integer'); |
1038
|
|
|
$tableDiff->fromTable->setPrimaryKey(array('id')); |
1039
|
|
|
$tableDiff->renamedIndexes = array( |
|
|
|
|
1040
|
|
|
'create' => new Index('select', array('id')), |
1041
|
|
|
'`foo`' => new Index('`bar`', array('id')), |
1042
|
|
|
); |
1043
|
|
|
|
1044
|
|
|
self::assertSame( |
1045
|
|
|
$this->getQuotedAlterTableRenameIndexInSchemaSQL(), |
1046
|
|
|
$this->_platform->getAlterTableSQL($tableDiff) |
1047
|
|
|
); |
1048
|
|
|
} |
1049
|
|
|
|
1050
|
|
|
/** |
1051
|
|
|
* @group DBAL-234 |
1052
|
|
|
*/ |
1053
|
|
|
protected function getQuotedAlterTableRenameIndexInSchemaSQL() |
1054
|
|
|
{ |
1055
|
|
|
return array( |
1056
|
|
|
'DROP INDEX "schema"."create"', |
1057
|
|
|
'CREATE INDEX "select" ON "schema"."table" (id)', |
1058
|
|
|
'DROP INDEX "schema"."foo"', |
1059
|
|
|
'CREATE INDEX "bar" ON "schema"."table" (id)', |
1060
|
|
|
); |
1061
|
|
|
} |
1062
|
|
|
|
1063
|
|
|
/** |
1064
|
|
|
* @group DBAL-1237 |
1065
|
|
|
*/ |
1066
|
|
|
public function testQuotesDropForeignKeySQL() |
1067
|
|
|
{ |
1068
|
|
|
if (! $this->_platform->supportsForeignKeyConstraints()) { |
1069
|
|
|
$this->markTestSkipped( |
1070
|
|
|
sprintf('%s does not support foreign key constraints.', get_class($this->_platform)) |
1071
|
|
|
); |
1072
|
|
|
} |
1073
|
|
|
|
1074
|
|
|
$tableName = 'table'; |
1075
|
|
|
$table = new Table($tableName); |
1076
|
|
|
$foreignKeyName = 'select'; |
1077
|
|
|
$foreignKey = new ForeignKeyConstraint(array(), 'foo', array(), 'select'); |
1078
|
|
|
$expectedSql = $this->getQuotesDropForeignKeySQL(); |
1079
|
|
|
|
1080
|
|
|
self::assertSame($expectedSql, $this->_platform->getDropForeignKeySQL($foreignKeyName, $tableName)); |
1081
|
|
|
self::assertSame($expectedSql, $this->_platform->getDropForeignKeySQL($foreignKey, $table)); |
1082
|
|
|
} |
1083
|
|
|
|
1084
|
|
|
protected function getQuotesDropForeignKeySQL() |
1085
|
|
|
{ |
1086
|
|
|
return 'ALTER TABLE "table" DROP FOREIGN KEY "select"'; |
1087
|
|
|
} |
1088
|
|
|
|
1089
|
|
|
/** |
1090
|
|
|
* @group DBAL-1237 |
1091
|
|
|
*/ |
1092
|
|
|
public function testQuotesDropConstraintSQL() |
1093
|
|
|
{ |
1094
|
|
|
$tableName = 'table'; |
1095
|
|
|
$table = new Table($tableName); |
1096
|
|
|
$constraintName = 'select'; |
1097
|
|
|
$constraint = new ForeignKeyConstraint(array(), 'foo', array(), 'select'); |
1098
|
|
|
$expectedSql = $this->getQuotesDropConstraintSQL(); |
1099
|
|
|
|
1100
|
|
|
self::assertSame($expectedSql, $this->_platform->getDropConstraintSQL($constraintName, $tableName)); |
1101
|
|
|
self::assertSame($expectedSql, $this->_platform->getDropConstraintSQL($constraint, $table)); |
1102
|
|
|
} |
1103
|
|
|
|
1104
|
|
|
protected function getQuotesDropConstraintSQL() |
1105
|
|
|
{ |
1106
|
|
|
return 'ALTER TABLE "table" DROP CONSTRAINT "select"'; |
1107
|
|
|
} |
1108
|
|
|
|
1109
|
|
|
protected function getStringLiteralQuoteCharacter() |
1110
|
|
|
{ |
1111
|
|
|
return "'"; |
1112
|
|
|
} |
1113
|
|
|
|
1114
|
|
|
public function testGetStringLiteralQuoteCharacter() |
1115
|
|
|
{ |
1116
|
|
|
self::assertSame($this->getStringLiteralQuoteCharacter(), $this->_platform->getStringLiteralQuoteCharacter()); |
1117
|
|
|
} |
1118
|
|
|
|
1119
|
|
|
protected function getQuotedCommentOnColumnSQLWithoutQuoteCharacter() |
1120
|
|
|
{ |
1121
|
|
|
return "COMMENT ON COLUMN mytable.id IS 'This is a comment'"; |
1122
|
|
|
} |
1123
|
|
|
|
1124
|
|
|
public function testGetCommentOnColumnSQLWithoutQuoteCharacter() |
1125
|
|
|
{ |
1126
|
|
|
self::assertEquals( |
1127
|
|
|
$this->getQuotedCommentOnColumnSQLWithoutQuoteCharacter(), |
1128
|
|
|
$this->_platform->getCommentOnColumnSQL('mytable', 'id', 'This is a comment') |
1129
|
|
|
); |
1130
|
|
|
} |
1131
|
|
|
|
1132
|
|
|
protected function getQuotedCommentOnColumnSQLWithQuoteCharacter() |
1133
|
|
|
{ |
1134
|
|
|
return "COMMENT ON COLUMN mytable.id IS 'It''s a quote !'"; |
1135
|
|
|
} |
1136
|
|
|
|
1137
|
|
|
public function testGetCommentOnColumnSQLWithQuoteCharacter() |
1138
|
|
|
{ |
1139
|
|
|
$c = $this->getStringLiteralQuoteCharacter(); |
1140
|
|
|
|
1141
|
|
|
self::assertEquals( |
1142
|
|
|
$this->getQuotedCommentOnColumnSQLWithQuoteCharacter(), |
1143
|
|
|
$this->_platform->getCommentOnColumnSQL('mytable', 'id', "It" . $c . "s a quote !") |
1144
|
|
|
); |
1145
|
|
|
} |
1146
|
|
|
|
1147
|
|
|
/** |
1148
|
|
|
* @return array |
1149
|
|
|
* |
1150
|
|
|
* @see testGetCommentOnColumnSQL |
1151
|
|
|
*/ |
1152
|
|
|
abstract protected function getCommentOnColumnSQL(); |
1153
|
|
|
|
1154
|
|
|
/** |
1155
|
|
|
* @group DBAL-1004 |
1156
|
|
|
*/ |
1157
|
|
|
public function testGetCommentOnColumnSQL() |
1158
|
|
|
{ |
1159
|
|
|
self::assertSame( |
1160
|
|
|
$this->getCommentOnColumnSQL(), |
1161
|
|
|
array( |
1162
|
|
|
$this->_platform->getCommentOnColumnSQL('foo', 'bar', 'comment'), // regular identifiers |
1163
|
|
|
$this->_platform->getCommentOnColumnSQL('`Foo`', '`BAR`', 'comment'), // explicitly quoted identifiers |
1164
|
|
|
$this->_platform->getCommentOnColumnSQL('select', 'from', 'comment'), // reserved keyword identifiers |
1165
|
|
|
) |
1166
|
|
|
); |
1167
|
|
|
} |
1168
|
|
|
|
1169
|
|
|
/** |
1170
|
|
|
* @group DBAL-1176 |
1171
|
|
|
* |
1172
|
|
|
* @dataProvider getGeneratesInlineColumnCommentSQL |
1173
|
|
|
*/ |
1174
|
|
|
public function testGeneratesInlineColumnCommentSQL($comment, $expectedSql) |
1175
|
|
|
{ |
1176
|
|
|
if (! $this->_platform->supportsInlineColumnComments()) { |
1177
|
|
|
$this->markTestSkipped(sprintf('%s does not support inline column comments.', get_class($this->_platform))); |
1178
|
|
|
} |
1179
|
|
|
|
1180
|
|
|
self::assertSame($expectedSql, $this->_platform->getInlineColumnCommentSQL($comment)); |
1181
|
|
|
} |
1182
|
|
|
|
1183
|
|
|
public function getGeneratesInlineColumnCommentSQL() |
1184
|
|
|
{ |
1185
|
|
|
return array( |
1186
|
|
|
'regular comment' => array('Regular comment', $this->getInlineColumnRegularCommentSQL()), |
1187
|
|
|
'comment requiring escaping' => array( |
1188
|
|
|
sprintf( |
1189
|
|
|
'Using inline comment delimiter %s works', |
1190
|
|
|
$this->getInlineColumnCommentDelimiter() |
1191
|
|
|
), |
1192
|
|
|
$this->getInlineColumnCommentRequiringEscapingSQL() |
1193
|
|
|
), |
1194
|
|
|
'empty comment' => array('', $this->getInlineColumnEmptyCommentSQL()), |
1195
|
|
|
); |
1196
|
|
|
} |
1197
|
|
|
|
1198
|
|
|
protected function getInlineColumnCommentDelimiter() |
1199
|
|
|
{ |
1200
|
|
|
return "'"; |
1201
|
|
|
} |
1202
|
|
|
|
1203
|
|
|
protected function getInlineColumnRegularCommentSQL() |
1204
|
|
|
{ |
1205
|
|
|
return "COMMENT 'Regular comment'"; |
1206
|
|
|
} |
1207
|
|
|
|
1208
|
|
|
protected function getInlineColumnCommentRequiringEscapingSQL() |
1209
|
|
|
{ |
1210
|
|
|
return "COMMENT 'Using inline comment delimiter '' works'"; |
1211
|
|
|
} |
1212
|
|
|
|
1213
|
|
|
protected function getInlineColumnEmptyCommentSQL() |
1214
|
|
|
{ |
1215
|
|
|
return "COMMENT ''"; |
1216
|
|
|
} |
1217
|
|
|
|
1218
|
|
|
protected function getQuotedStringLiteralWithoutQuoteCharacter() |
1219
|
|
|
{ |
1220
|
|
|
return "'No quote'"; |
1221
|
|
|
} |
1222
|
|
|
|
1223
|
|
|
protected function getQuotedStringLiteralWithQuoteCharacter() |
1224
|
|
|
{ |
1225
|
|
|
return "'It''s a quote'"; |
1226
|
|
|
} |
1227
|
|
|
|
1228
|
|
|
protected function getQuotedStringLiteralQuoteCharacter() |
1229
|
|
|
{ |
1230
|
|
|
return "''''"; |
1231
|
|
|
} |
1232
|
|
|
|
1233
|
|
|
/** |
1234
|
|
|
* @group DBAL-1176 |
1235
|
|
|
*/ |
1236
|
|
|
public function testThrowsExceptionOnGeneratingInlineColumnCommentSQLIfUnsupported() |
1237
|
|
|
{ |
1238
|
|
|
if ($this->_platform->supportsInlineColumnComments()) { |
1239
|
|
|
$this->markTestSkipped(sprintf('%s supports inline column comments.', get_class($this->_platform))); |
1240
|
|
|
} |
1241
|
|
|
|
1242
|
|
|
$this->expectException( |
1243
|
|
|
'Doctrine\DBAL\DBALException', |
1244
|
|
|
"Operation 'Doctrine\\DBAL\\Platforms\\AbstractPlatform::getInlineColumnCommentSQL' is not supported by platform.", |
|
|
|
|
1245
|
|
|
0 |
1246
|
|
|
); |
1247
|
|
|
|
1248
|
|
|
$this->_platform->getInlineColumnCommentSQL('unsupported'); |
1249
|
|
|
} |
1250
|
|
|
|
1251
|
|
|
public function testQuoteStringLiteral() |
1252
|
|
|
{ |
1253
|
|
|
$c = $this->getStringLiteralQuoteCharacter(); |
1254
|
|
|
|
1255
|
|
|
self::assertEquals( |
1256
|
|
|
$this->getQuotedStringLiteralWithoutQuoteCharacter(), |
1257
|
|
|
$this->_platform->quoteStringLiteral('No quote') |
1258
|
|
|
); |
1259
|
|
|
self::assertEquals( |
1260
|
|
|
$this->getQuotedStringLiteralWithQuoteCharacter(), |
1261
|
|
|
$this->_platform->quoteStringLiteral('It' . $c . 's a quote') |
1262
|
|
|
); |
1263
|
|
|
self::assertEquals( |
1264
|
|
|
$this->getQuotedStringLiteralQuoteCharacter(), |
1265
|
|
|
$this->_platform->quoteStringLiteral($c) |
1266
|
|
|
); |
1267
|
|
|
} |
1268
|
|
|
|
1269
|
|
|
/** |
1270
|
|
|
* @group DBAL-423 |
1271
|
|
|
* |
1272
|
|
|
* @expectedException \Doctrine\DBAL\DBALException |
1273
|
|
|
*/ |
1274
|
|
|
public function testReturnsGuidTypeDeclarationSQL() |
1275
|
|
|
{ |
1276
|
|
|
$this->_platform->getGuidTypeDeclarationSQL(array()); |
1277
|
|
|
} |
1278
|
|
|
|
1279
|
|
|
/** |
1280
|
|
|
* @group DBAL-1010 |
1281
|
|
|
*/ |
1282
|
|
|
public function testGeneratesAlterTableRenameColumnSQL() |
1283
|
|
|
{ |
1284
|
|
|
$table = new Table('foo'); |
1285
|
|
|
$table->addColumn( |
1286
|
|
|
'bar', |
1287
|
|
|
'integer', |
1288
|
|
|
array('notnull' => true, 'default' => 666, 'comment' => 'rename test') |
1289
|
|
|
); |
1290
|
|
|
|
1291
|
|
|
$tableDiff = new TableDiff('foo'); |
1292
|
|
|
$tableDiff->fromTable = $table; |
1293
|
|
|
$tableDiff->renamedColumns['bar'] = new Column( |
1294
|
|
|
'baz', |
1295
|
|
|
Type::getType('integer'), |
1296
|
|
|
array('notnull' => true, 'default' => 666, 'comment' => 'rename test') |
1297
|
|
|
); |
1298
|
|
|
|
1299
|
|
|
self::assertSame($this->getAlterTableRenameColumnSQL(), $this->_platform->getAlterTableSQL($tableDiff)); |
1300
|
|
|
} |
1301
|
|
|
|
1302
|
|
|
/** |
1303
|
|
|
* @return array |
1304
|
|
|
*/ |
1305
|
|
|
abstract public function getAlterTableRenameColumnSQL(); |
1306
|
|
|
|
1307
|
|
|
/** |
1308
|
|
|
* @group DBAL-1016 |
1309
|
|
|
*/ |
1310
|
|
|
public function testQuotesTableIdentifiersInAlterTableSQL() |
1311
|
|
|
{ |
1312
|
|
|
$table = new Table('"foo"'); |
1313
|
|
|
$table->addColumn('id', 'integer'); |
1314
|
|
|
$table->addColumn('fk', 'integer'); |
1315
|
|
|
$table->addColumn('fk2', 'integer'); |
1316
|
|
|
$table->addColumn('fk3', 'integer'); |
1317
|
|
|
$table->addColumn('bar', 'integer'); |
1318
|
|
|
$table->addColumn('baz', 'integer'); |
1319
|
|
|
$table->addForeignKeyConstraint('fk_table', array('fk'), array('id'), array(), 'fk1'); |
1320
|
|
|
$table->addForeignKeyConstraint('fk_table', array('fk2'), array('id'), array(), 'fk2'); |
1321
|
|
|
|
1322
|
|
|
$tableDiff = new TableDiff('"foo"'); |
1323
|
|
|
$tableDiff->fromTable = $table; |
1324
|
|
|
$tableDiff->newName = 'table'; |
1325
|
|
|
$tableDiff->addedColumns['bloo'] = new Column('bloo', Type::getType('integer')); |
1326
|
|
|
$tableDiff->changedColumns['bar'] = new ColumnDiff( |
1327
|
|
|
'bar', |
1328
|
|
|
new Column('bar', Type::getType('integer'), array('notnull' => false)), |
1329
|
|
|
array('notnull'), |
1330
|
|
|
$table->getColumn('bar') |
1331
|
|
|
); |
1332
|
|
|
$tableDiff->renamedColumns['id'] = new Column('war', Type::getType('integer')); |
1333
|
|
|
$tableDiff->removedColumns['baz'] = new Column('baz', Type::getType('integer')); |
1334
|
|
|
$tableDiff->addedForeignKeys[] = new ForeignKeyConstraint(array('fk3'), 'fk_table', array('id'), 'fk_add'); |
1335
|
|
|
$tableDiff->changedForeignKeys[] = new ForeignKeyConstraint(array('fk2'), 'fk_table2', array('id'), 'fk2'); |
1336
|
|
|
$tableDiff->removedForeignKeys[] = new ForeignKeyConstraint(array('fk'), 'fk_table', array('id'), 'fk1'); |
1337
|
|
|
|
1338
|
|
|
self::assertSame( |
1339
|
|
|
$this->getQuotesTableIdentifiersInAlterTableSQL(), |
1340
|
|
|
$this->_platform->getAlterTableSQL($tableDiff) |
1341
|
|
|
); |
1342
|
|
|
} |
1343
|
|
|
|
1344
|
|
|
/** |
1345
|
|
|
* @return array |
1346
|
|
|
*/ |
1347
|
|
|
abstract protected function getQuotesTableIdentifiersInAlterTableSQL(); |
1348
|
|
|
|
1349
|
|
|
/** |
1350
|
|
|
* @group DBAL-1090 |
1351
|
|
|
*/ |
1352
|
|
|
public function testAlterStringToFixedString() |
1353
|
|
|
{ |
1354
|
|
|
|
1355
|
|
|
$table = new Table('mytable'); |
1356
|
|
|
$table->addColumn('name', 'string', array('length' => 2)); |
1357
|
|
|
|
1358
|
|
|
$tableDiff = new TableDiff('mytable'); |
1359
|
|
|
$tableDiff->fromTable = $table; |
1360
|
|
|
|
1361
|
|
|
$tableDiff->changedColumns['name'] = new \Doctrine\DBAL\Schema\ColumnDiff( |
1362
|
|
|
'name', new \Doctrine\DBAL\Schema\Column( |
1363
|
|
|
'name', \Doctrine\DBAL\Types\Type::getType('string'), array('fixed' => true, 'length' => 2) |
1364
|
|
|
), |
1365
|
|
|
array('fixed') |
1366
|
|
|
); |
1367
|
|
|
|
1368
|
|
|
$sql = $this->_platform->getAlterTableSQL($tableDiff); |
1369
|
|
|
|
1370
|
|
|
$expectedSql = $this->getAlterStringToFixedStringSQL(); |
1371
|
|
|
|
1372
|
|
|
self::assertEquals($expectedSql, $sql); |
1373
|
|
|
} |
1374
|
|
|
|
1375
|
|
|
/** |
1376
|
|
|
* @return array |
1377
|
|
|
*/ |
1378
|
|
|
abstract protected function getAlterStringToFixedStringSQL(); |
1379
|
|
|
|
1380
|
|
|
/** |
1381
|
|
|
* @group DBAL-1062 |
1382
|
|
|
*/ |
1383
|
|
|
public function testGeneratesAlterTableRenameIndexUsedByForeignKeySQL() |
1384
|
|
|
{ |
1385
|
|
|
$foreignTable = new Table('foreign_table'); |
1386
|
|
|
$foreignTable->addColumn('id', 'integer'); |
1387
|
|
|
$foreignTable->setPrimaryKey(array('id')); |
1388
|
|
|
|
1389
|
|
|
$primaryTable = new Table('mytable'); |
1390
|
|
|
$primaryTable->addColumn('foo', 'integer'); |
1391
|
|
|
$primaryTable->addColumn('bar', 'integer'); |
1392
|
|
|
$primaryTable->addColumn('baz', 'integer'); |
1393
|
|
|
$primaryTable->addIndex(array('foo'), 'idx_foo'); |
1394
|
|
|
$primaryTable->addIndex(array('bar'), 'idx_bar'); |
1395
|
|
|
$primaryTable->addForeignKeyConstraint($foreignTable, array('foo'), array('id'), array(), 'fk_foo'); |
1396
|
|
|
$primaryTable->addForeignKeyConstraint($foreignTable, array('bar'), array('id'), array(), 'fk_bar'); |
1397
|
|
|
|
1398
|
|
|
$tableDiff = new TableDiff('mytable'); |
1399
|
|
|
$tableDiff->fromTable = $primaryTable; |
1400
|
|
|
$tableDiff->renamedIndexes['idx_foo'] = new Index('idx_foo_renamed', array('foo')); |
1401
|
|
|
|
1402
|
|
|
self::assertSame( |
1403
|
|
|
$this->getGeneratesAlterTableRenameIndexUsedByForeignKeySQL(), |
1404
|
|
|
$this->_platform->getAlterTableSQL($tableDiff) |
1405
|
|
|
); |
1406
|
|
|
} |
1407
|
|
|
|
1408
|
|
|
/** |
1409
|
|
|
* @return array |
1410
|
|
|
*/ |
1411
|
|
|
abstract protected function getGeneratesAlterTableRenameIndexUsedByForeignKeySQL(); |
1412
|
|
|
|
1413
|
|
|
/** |
1414
|
|
|
* @group DBAL-1082 |
1415
|
|
|
* |
1416
|
|
|
* @dataProvider getGeneratesDecimalTypeDeclarationSQL |
1417
|
|
|
*/ |
1418
|
|
|
public function testGeneratesDecimalTypeDeclarationSQL(array $column, $expectedSql) |
1419
|
|
|
{ |
1420
|
|
|
self::assertSame($expectedSql, $this->_platform->getDecimalTypeDeclarationSQL($column)); |
1421
|
|
|
} |
1422
|
|
|
|
1423
|
|
|
/** |
1424
|
|
|
* @return array |
1425
|
|
|
*/ |
1426
|
|
View Code Duplication |
public function getGeneratesDecimalTypeDeclarationSQL() |
|
|
|
|
1427
|
|
|
{ |
1428
|
|
|
return array( |
1429
|
|
|
array(array(), 'NUMERIC(10, 0)'), |
1430
|
|
|
array(array('unsigned' => true), 'NUMERIC(10, 0)'), |
1431
|
|
|
array(array('unsigned' => false), 'NUMERIC(10, 0)'), |
1432
|
|
|
array(array('precision' => 5), 'NUMERIC(5, 0)'), |
1433
|
|
|
array(array('scale' => 5), 'NUMERIC(10, 5)'), |
1434
|
|
|
array(array('precision' => 8, 'scale' => 2), 'NUMERIC(8, 2)'), |
1435
|
|
|
); |
1436
|
|
|
} |
1437
|
|
|
|
1438
|
|
|
/** |
1439
|
|
|
* @group DBAL-1082 |
1440
|
|
|
* |
1441
|
|
|
* @dataProvider getGeneratesFloatDeclarationSQL |
1442
|
|
|
*/ |
1443
|
|
|
public function testGeneratesFloatDeclarationSQL(array $column, $expectedSql) |
1444
|
|
|
{ |
1445
|
|
|
self::assertSame($expectedSql, $this->_platform->getFloatDeclarationSQL($column)); |
1446
|
|
|
} |
1447
|
|
|
|
1448
|
|
|
/** |
1449
|
|
|
* @return array |
1450
|
|
|
*/ |
1451
|
|
View Code Duplication |
public function getGeneratesFloatDeclarationSQL() |
|
|
|
|
1452
|
|
|
{ |
1453
|
|
|
return array( |
1454
|
|
|
array(array(), 'DOUBLE PRECISION'), |
1455
|
|
|
array(array('unsigned' => true), 'DOUBLE PRECISION'), |
1456
|
|
|
array(array('unsigned' => false), 'DOUBLE PRECISION'), |
1457
|
|
|
array(array('precision' => 5), 'DOUBLE PRECISION'), |
1458
|
|
|
array(array('scale' => 5), 'DOUBLE PRECISION'), |
1459
|
|
|
array(array('precision' => 8, 'scale' => 2), 'DOUBLE PRECISION'), |
1460
|
|
|
); |
1461
|
|
|
} |
1462
|
|
|
} |
1463
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.