| Total Complexity | 78 |
| Total Lines | 925 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
Complex classes like AbstractMySQLPlatformTestCase often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use AbstractMySQLPlatformTestCase, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 14 | abstract class AbstractMySQLPlatformTestCase extends AbstractPlatformTestCase |
||
| 15 | { |
||
| 16 | public function testModifyLimitQueryWitoutLimit() |
||
| 17 | { |
||
| 18 | $sql = $this->platform->modifyLimitQuery('SELECT n FROM Foo', null, 10); |
||
| 19 | self::assertEquals('SELECT n FROM Foo LIMIT 18446744073709551615 OFFSET 10', $sql); |
||
| 20 | } |
||
| 21 | |||
| 22 | public function testGenerateMixedCaseTableCreate() |
||
| 23 | { |
||
| 24 | $table = new Table('Foo'); |
||
| 25 | $table->addColumn('Bar', 'integer'); |
||
| 26 | |||
| 27 | $sql = $this->platform->getCreateTableSQL($table); |
||
| 28 | self::assertEquals('CREATE TABLE Foo (Bar INT NOT NULL) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB', array_shift($sql)); |
||
| 29 | } |
||
| 30 | |||
| 31 | public function getGenerateTableSql() |
||
| 32 | { |
||
| 33 | return 'CREATE TABLE test (id INT AUTO_INCREMENT NOT NULL, test VARCHAR(255) DEFAULT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB'; |
||
| 34 | } |
||
| 35 | |||
| 36 | public function getGenerateTableWithMultiColumnUniqueIndexSql() |
||
| 37 | { |
||
| 38 | return ['CREATE TABLE test (foo VARCHAR(255) DEFAULT NULL, bar VARCHAR(255) DEFAULT NULL, UNIQUE INDEX UNIQ_D87F7E0C8C73652176FF8CAA (foo, bar)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB']; |
||
| 39 | } |
||
| 40 | |||
| 41 | public function getGenerateAlterTableSql() |
||
| 42 | { |
||
| 43 | return ["ALTER TABLE mytable RENAME TO userlist, ADD quota INT DEFAULT NULL, DROP foo, CHANGE bar baz VARCHAR(255) DEFAULT 'def' NOT NULL, CHANGE bloo bloo TINYINT(1) DEFAULT '0' NOT NULL"]; |
||
| 44 | } |
||
| 45 | |||
| 46 | public function testGeneratesSqlSnippets() |
||
| 47 | { |
||
| 48 | self::assertEquals('RLIKE', $this->platform->getRegexpExpression(), 'Regular expression operator is not correct'); |
||
| 49 | self::assertEquals('`', $this->platform->getIdentifierQuoteCharacter(), 'Quote character is not correct'); |
||
| 50 | self::assertEquals('CONCAT(column1, column2, column3)', $this->platform->getConcatExpression('column1', 'column2', 'column3'), 'Concatenation function is not correct'); |
||
| 51 | } |
||
| 52 | |||
| 53 | public function testGeneratesTransactionsCommands() |
||
| 54 | { |
||
| 55 | self::assertEquals( |
||
| 56 | 'SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED', |
||
| 57 | $this->platform->getSetTransactionIsolationSQL(TransactionIsolationLevel::READ_UNCOMMITTED), |
||
| 58 | '' |
||
| 59 | ); |
||
| 60 | self::assertEquals( |
||
| 61 | 'SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED', |
||
| 62 | $this->platform->getSetTransactionIsolationSQL(TransactionIsolationLevel::READ_COMMITTED) |
||
| 63 | ); |
||
| 64 | self::assertEquals( |
||
| 65 | 'SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ', |
||
| 66 | $this->platform->getSetTransactionIsolationSQL(TransactionIsolationLevel::REPEATABLE_READ) |
||
| 67 | ); |
||
| 68 | self::assertEquals( |
||
| 69 | 'SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE', |
||
| 70 | $this->platform->getSetTransactionIsolationSQL(TransactionIsolationLevel::SERIALIZABLE) |
||
| 71 | ); |
||
| 72 | } |
||
| 73 | |||
| 74 | |||
| 75 | public function testGeneratesDDLSnippets() |
||
| 76 | { |
||
| 77 | self::assertEquals('SHOW DATABASES', $this->platform->getListDatabasesSQL()); |
||
| 78 | self::assertEquals('CREATE DATABASE foobar', $this->platform->getCreateDatabaseSQL('foobar')); |
||
| 79 | self::assertEquals('DROP DATABASE foobar', $this->platform->getDropDatabaseSQL('foobar')); |
||
| 80 | self::assertEquals('DROP TABLE foobar', $this->platform->getDropTableSQL('foobar')); |
||
| 81 | } |
||
| 82 | |||
| 83 | public function testGeneratesTypeDeclarationForIntegers() |
||
| 84 | { |
||
| 85 | self::assertEquals( |
||
| 86 | 'INT', |
||
| 87 | $this->platform->getIntegerTypeDeclarationSQL([]) |
||
| 88 | ); |
||
| 89 | self::assertEquals( |
||
| 90 | 'INT AUTO_INCREMENT', |
||
| 91 | $this->platform->getIntegerTypeDeclarationSQL(['autoincrement' => true]) |
||
| 92 | ); |
||
| 93 | self::assertEquals( |
||
| 94 | 'INT AUTO_INCREMENT', |
||
| 95 | $this->platform->getIntegerTypeDeclarationSQL( |
||
| 96 | ['autoincrement' => true, 'primary' => true] |
||
| 97 | ) |
||
| 98 | ); |
||
| 99 | } |
||
| 100 | |||
| 101 | public function testGeneratesTypeDeclarationForStrings() |
||
| 102 | { |
||
| 103 | self::assertEquals( |
||
| 104 | 'CHAR(10)', |
||
| 105 | $this->platform->getVarcharTypeDeclarationSQL( |
||
| 106 | ['length' => 10, 'fixed' => true] |
||
| 107 | ) |
||
| 108 | ); |
||
| 109 | self::assertEquals( |
||
| 110 | 'VARCHAR(50)', |
||
| 111 | $this->platform->getVarcharTypeDeclarationSQL(['length' => 50]), |
||
| 112 | 'Variable string declaration is not correct' |
||
| 113 | ); |
||
| 114 | self::assertEquals( |
||
| 115 | 'VARCHAR(255)', |
||
| 116 | $this->platform->getVarcharTypeDeclarationSQL([]), |
||
| 117 | 'Long string declaration is not correct' |
||
| 118 | ); |
||
| 119 | } |
||
| 120 | |||
| 121 | public function testPrefersIdentityColumns() |
||
| 122 | { |
||
| 123 | self::assertTrue($this->platform->prefersIdentityColumns()); |
||
| 124 | } |
||
| 125 | |||
| 126 | public function testSupportsIdentityColumns() |
||
| 127 | { |
||
| 128 | self::assertTrue($this->platform->supportsIdentityColumns()); |
||
| 129 | } |
||
| 130 | |||
| 131 | public function testDoesSupportSavePoints() |
||
| 132 | { |
||
| 133 | self::assertTrue($this->platform->supportsSavepoints()); |
||
| 134 | } |
||
| 135 | |||
| 136 | public function getGenerateIndexSql() |
||
| 137 | { |
||
| 138 | return 'CREATE INDEX my_idx ON mytable (user_name, last_login)'; |
||
| 139 | } |
||
| 140 | |||
| 141 | public function getGenerateUniqueIndexSql() |
||
| 142 | { |
||
| 143 | return 'CREATE UNIQUE INDEX index_name ON test (test, test2)'; |
||
| 144 | } |
||
| 145 | |||
| 146 | public function getGenerateForeignKeySql() |
||
| 147 | { |
||
| 148 | return 'ALTER TABLE test ADD FOREIGN KEY (fk_name_id) REFERENCES other_table (id)'; |
||
| 149 | } |
||
| 150 | |||
| 151 | /** |
||
| 152 | * @group DBAL-126 |
||
| 153 | */ |
||
| 154 | public function testUniquePrimaryKey() |
||
| 155 | { |
||
| 156 | $keyTable = new Table('foo'); |
||
| 157 | $keyTable->addColumn('bar', 'integer'); |
||
| 158 | $keyTable->addColumn('baz', 'string'); |
||
| 159 | $keyTable->setPrimaryKey(['bar']); |
||
| 160 | $keyTable->addUniqueIndex(['baz']); |
||
| 161 | |||
| 162 | $oldTable = new Table('foo'); |
||
| 163 | $oldTable->addColumn('bar', 'integer'); |
||
| 164 | $oldTable->addColumn('baz', 'string'); |
||
| 165 | |||
| 166 | $c = new Comparator(); |
||
| 167 | $diff = $c->diffTable($oldTable, $keyTable); |
||
| 168 | |||
| 169 | $sql = $this->platform->getAlterTableSQL($diff); |
||
|
|
|||
| 170 | |||
| 171 | self::assertEquals([ |
||
| 172 | 'ALTER TABLE foo ADD PRIMARY KEY (bar)', |
||
| 173 | 'CREATE UNIQUE INDEX UNIQ_8C73652178240498 ON foo (baz)', |
||
| 174 | ], $sql); |
||
| 175 | } |
||
| 176 | |||
| 177 | public function testModifyLimitQuery() |
||
| 178 | { |
||
| 179 | $sql = $this->platform->modifyLimitQuery('SELECT * FROM user', 10, 0); |
||
| 180 | self::assertEquals('SELECT * FROM user LIMIT 10', $sql); |
||
| 181 | } |
||
| 182 | |||
| 183 | public function testModifyLimitQueryWithEmptyOffset() |
||
| 184 | { |
||
| 185 | $sql = $this->platform->modifyLimitQuery('SELECT * FROM user', 10); |
||
| 186 | self::assertEquals('SELECT * FROM user LIMIT 10', $sql); |
||
| 187 | } |
||
| 188 | |||
| 189 | /** |
||
| 190 | * @group DDC-118 |
||
| 191 | */ |
||
| 192 | public function testGetDateTimeTypeDeclarationSql() |
||
| 193 | { |
||
| 194 | self::assertEquals('DATETIME', $this->platform->getDateTimeTypeDeclarationSQL(['version' => false])); |
||
| 195 | self::assertEquals('TIMESTAMP', $this->platform->getDateTimeTypeDeclarationSQL(['version' => true])); |
||
| 196 | self::assertEquals('DATETIME', $this->platform->getDateTimeTypeDeclarationSQL([])); |
||
| 197 | } |
||
| 198 | |||
| 199 | public function getCreateTableColumnCommentsSQL() |
||
| 202 | } |
||
| 203 | |||
| 204 | public function getAlterTableColumnCommentsSQL() |
||
| 205 | { |
||
| 206 | return ["ALTER TABLE mytable ADD quota INT NOT NULL COMMENT 'A comment', CHANGE foo foo VARCHAR(255) NOT NULL, CHANGE bar baz VARCHAR(255) NOT NULL COMMENT 'B comment'"]; |
||
| 207 | } |
||
| 208 | |||
| 209 | public function getCreateTableColumnTypeCommentsSQL() |
||
| 212 | } |
||
| 213 | |||
| 214 | /** |
||
| 215 | * @group DBAL-237 |
||
| 216 | */ |
||
| 217 | public function testChangeIndexWithForeignKeys() |
||
| 218 | { |
||
| 219 | $index = new Index('idx', ['col'], false); |
||
| 220 | $unique = new Index('uniq', ['col'], true); |
||
| 221 | |||
| 222 | $diff = new TableDiff('test', [], [], [], [$unique], [], [$index]); |
||
| 223 | $sql = $this->platform->getAlterTableSQL($diff); |
||
| 224 | self::assertEquals(['ALTER TABLE test DROP INDEX idx, ADD UNIQUE INDEX uniq (col)'], $sql); |
||
| 225 | |||
| 226 | $diff = new TableDiff('test', [], [], [], [$index], [], [$unique]); |
||
| 227 | $sql = $this->platform->getAlterTableSQL($diff); |
||
| 228 | self::assertEquals(['ALTER TABLE test DROP INDEX uniq, ADD INDEX idx (col)'], $sql); |
||
| 229 | } |
||
| 230 | |||
| 231 | protected function getQuotedColumnInPrimaryKeySQL() |
||
| 232 | { |
||
| 233 | return ['CREATE TABLE `quoted` (`create` VARCHAR(255) NOT NULL, PRIMARY KEY(`create`)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB']; |
||
| 234 | } |
||
| 235 | |||
| 236 | protected function getQuotedColumnInIndexSQL() |
||
| 237 | { |
||
| 238 | return ['CREATE TABLE `quoted` (`create` VARCHAR(255) NOT NULL, INDEX IDX_22660D028FD6E0FB (`create`)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB']; |
||
| 239 | } |
||
| 240 | |||
| 241 | protected function getQuotedNameInIndexSQL() |
||
| 242 | { |
||
| 243 | return ['CREATE TABLE test (column1 VARCHAR(255) NOT NULL, INDEX `key` (column1)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB']; |
||
| 244 | } |
||
| 245 | |||
| 246 | protected function getQuotedColumnInForeignKeySQL() |
||
| 247 | { |
||
| 248 | return [ |
||
| 249 | 'CREATE TABLE `quoted` (`create` VARCHAR(255) NOT NULL, foo VARCHAR(255) NOT NULL, `bar` VARCHAR(255) NOT NULL) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB', |
||
| 250 | 'ALTER TABLE `quoted` ADD CONSTRAINT FK_WITH_RESERVED_KEYWORD FOREIGN KEY (`create`, foo, `bar`) REFERENCES `foreign` (`create`, bar, `foo-bar`)', |
||
| 251 | 'ALTER TABLE `quoted` ADD CONSTRAINT FK_WITH_NON_RESERVED_KEYWORD FOREIGN KEY (`create`, foo, `bar`) REFERENCES foo (`create`, bar, `foo-bar`)', |
||
| 252 | 'ALTER TABLE `quoted` ADD CONSTRAINT FK_WITH_INTENDED_QUOTATION FOREIGN KEY (`create`, foo, `bar`) REFERENCES `foo-bar` (`create`, bar, `foo-bar`)', |
||
| 253 | ]; |
||
| 254 | } |
||
| 255 | |||
| 256 | public function testCreateTableWithFulltextIndex() |
||
| 257 | { |
||
| 258 | $table = new Table('fulltext_table'); |
||
| 259 | $table->addOption('engine', 'MyISAM'); |
||
| 260 | $table->addColumn('text', 'text'); |
||
| 261 | $table->addIndex(['text'], 'fulltext_text'); |
||
| 262 | |||
| 263 | $index = $table->getIndex('fulltext_text'); |
||
| 264 | $index->addFlag('fulltext'); |
||
| 265 | |||
| 266 | $sql = $this->platform->getCreateTableSQL($table); |
||
| 267 | self::assertEquals(['CREATE TABLE fulltext_table (text LONGTEXT NOT NULL, FULLTEXT INDEX fulltext_text (text)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = MyISAM'], $sql); |
||
| 268 | } |
||
| 269 | |||
| 270 | public function testCreateTableWithSpatialIndex() |
||
| 271 | { |
||
| 272 | $table = new Table('spatial_table'); |
||
| 273 | $table->addOption('engine', 'MyISAM'); |
||
| 274 | $table->addColumn('point', 'text'); // This should be a point type |
||
| 275 | $table->addIndex(['point'], 'spatial_text'); |
||
| 276 | |||
| 277 | $index = $table->getIndex('spatial_text'); |
||
| 278 | $index->addFlag('spatial'); |
||
| 279 | |||
| 280 | $sql = $this->platform->getCreateTableSQL($table); |
||
| 281 | self::assertEquals(['CREATE TABLE spatial_table (point LONGTEXT NOT NULL, SPATIAL INDEX spatial_text (point)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = MyISAM'], $sql); |
||
| 282 | } |
||
| 283 | |||
| 284 | public function testClobTypeDeclarationSQL() |
||
| 285 | { |
||
| 286 | self::assertEquals('TINYTEXT', $this->platform->getClobTypeDeclarationSQL(['length' => 1])); |
||
| 287 | self::assertEquals('TINYTEXT', $this->platform->getClobTypeDeclarationSQL(['length' => 255])); |
||
| 288 | self::assertEquals('TEXT', $this->platform->getClobTypeDeclarationSQL(['length' => 256])); |
||
| 289 | self::assertEquals('TEXT', $this->platform->getClobTypeDeclarationSQL(['length' => 65535])); |
||
| 290 | self::assertEquals('MEDIUMTEXT', $this->platform->getClobTypeDeclarationSQL(['length' => 65536])); |
||
| 291 | self::assertEquals('MEDIUMTEXT', $this->platform->getClobTypeDeclarationSQL(['length' => 16777215])); |
||
| 292 | self::assertEquals('LONGTEXT', $this->platform->getClobTypeDeclarationSQL(['length' => 16777216])); |
||
| 293 | self::assertEquals('LONGTEXT', $this->platform->getClobTypeDeclarationSQL([])); |
||
| 294 | } |
||
| 295 | |||
| 296 | public function testBlobTypeDeclarationSQL() |
||
| 297 | { |
||
| 298 | self::assertEquals('TINYBLOB', $this->platform->getBlobTypeDeclarationSQL(['length' => 1])); |
||
| 299 | self::assertEquals('TINYBLOB', $this->platform->getBlobTypeDeclarationSQL(['length' => 255])); |
||
| 300 | self::assertEquals('BLOB', $this->platform->getBlobTypeDeclarationSQL(['length' => 256])); |
||
| 301 | self::assertEquals('BLOB', $this->platform->getBlobTypeDeclarationSQL(['length' => 65535])); |
||
| 302 | self::assertEquals('MEDIUMBLOB', $this->platform->getBlobTypeDeclarationSQL(['length' => 65536])); |
||
| 303 | self::assertEquals('MEDIUMBLOB', $this->platform->getBlobTypeDeclarationSQL(['length' => 16777215])); |
||
| 304 | self::assertEquals('LONGBLOB', $this->platform->getBlobTypeDeclarationSQL(['length' => 16777216])); |
||
| 305 | self::assertEquals('LONGBLOB', $this->platform->getBlobTypeDeclarationSQL([])); |
||
| 306 | } |
||
| 307 | |||
| 308 | /** |
||
| 309 | * @group DBAL-400 |
||
| 310 | */ |
||
| 311 | public function testAlterTableAddPrimaryKey() |
||
| 312 | { |
||
| 313 | $table = new Table('alter_table_add_pk'); |
||
| 314 | $table->addColumn('id', 'integer'); |
||
| 315 | $table->addColumn('foo', 'integer'); |
||
| 316 | $table->addIndex(['id'], 'idx_id'); |
||
| 317 | |||
| 318 | $comparator = new Comparator(); |
||
| 319 | $diffTable = clone $table; |
||
| 320 | |||
| 321 | $diffTable->dropIndex('idx_id'); |
||
| 322 | $diffTable->setPrimaryKey(['id']); |
||
| 323 | |||
| 324 | self::assertEquals( |
||
| 325 | ['DROP INDEX idx_id ON alter_table_add_pk', 'ALTER TABLE alter_table_add_pk ADD PRIMARY KEY (id)'], |
||
| 326 | $this->platform->getAlterTableSQL($comparator->diffTable($table, $diffTable)) |
||
| 327 | ); |
||
| 328 | } |
||
| 329 | |||
| 330 | /** |
||
| 331 | * @group DBAL-1132 |
||
| 332 | */ |
||
| 333 | public function testAlterPrimaryKeyWithAutoincrementColumn() |
||
| 334 | { |
||
| 335 | $table = new Table('alter_primary_key'); |
||
| 336 | $table->addColumn('id', 'integer', ['autoincrement' => true]); |
||
| 337 | $table->addColumn('foo', 'integer'); |
||
| 338 | $table->setPrimaryKey(['id']); |
||
| 339 | |||
| 340 | $comparator = new Comparator(); |
||
| 341 | $diffTable = clone $table; |
||
| 342 | |||
| 343 | $diffTable->dropPrimaryKey(); |
||
| 344 | $diffTable->setPrimaryKey(['foo']); |
||
| 345 | |||
| 346 | self::assertEquals( |
||
| 347 | [ |
||
| 348 | 'ALTER TABLE alter_primary_key MODIFY id INT NOT NULL', |
||
| 349 | 'ALTER TABLE alter_primary_key DROP PRIMARY KEY', |
||
| 350 | 'ALTER TABLE alter_primary_key ADD PRIMARY KEY (foo)', |
||
| 351 | ], |
||
| 352 | $this->platform->getAlterTableSQL($comparator->diffTable($table, $diffTable)) |
||
| 353 | ); |
||
| 354 | } |
||
| 355 | |||
| 356 | /** |
||
| 357 | * @group DBAL-464 |
||
| 358 | */ |
||
| 359 | public function testDropPrimaryKeyWithAutoincrementColumn() |
||
| 360 | { |
||
| 361 | $table = new Table('drop_primary_key'); |
||
| 362 | $table->addColumn('id', 'integer', ['autoincrement' => true]); |
||
| 363 | $table->addColumn('foo', 'integer'); |
||
| 364 | $table->addColumn('bar', 'integer'); |
||
| 365 | $table->setPrimaryKey(['id', 'foo']); |
||
| 366 | |||
| 367 | $comparator = new Comparator(); |
||
| 368 | $diffTable = clone $table; |
||
| 369 | |||
| 370 | $diffTable->dropPrimaryKey(); |
||
| 371 | |||
| 372 | self::assertEquals( |
||
| 373 | [ |
||
| 374 | 'ALTER TABLE drop_primary_key MODIFY id INT NOT NULL', |
||
| 375 | 'ALTER TABLE drop_primary_key DROP PRIMARY KEY', |
||
| 376 | ], |
||
| 377 | $this->platform->getAlterTableSQL($comparator->diffTable($table, $diffTable)) |
||
| 378 | ); |
||
| 379 | } |
||
| 380 | |||
| 381 | /** |
||
| 382 | * @group DBAL-2302 |
||
| 383 | */ |
||
| 384 | public function testDropNonAutoincrementColumnFromCompositePrimaryKeyWithAutoincrementColumn() |
||
| 385 | { |
||
| 386 | $table = new Table('tbl'); |
||
| 387 | $table->addColumn('id', 'integer', ['autoincrement' => true]); |
||
| 388 | $table->addColumn('foo', 'integer'); |
||
| 389 | $table->addColumn('bar', 'integer'); |
||
| 390 | $table->setPrimaryKey(['id', 'foo']); |
||
| 391 | |||
| 392 | $comparator = new Comparator(); |
||
| 393 | $diffTable = clone $table; |
||
| 394 | |||
| 395 | $diffTable->dropPrimaryKey(); |
||
| 396 | $diffTable->setPrimaryKey(['id']); |
||
| 397 | |||
| 398 | self::assertSame( |
||
| 399 | [ |
||
| 400 | 'ALTER TABLE tbl MODIFY id INT NOT NULL', |
||
| 401 | 'ALTER TABLE tbl DROP PRIMARY KEY', |
||
| 402 | 'ALTER TABLE tbl ADD PRIMARY KEY (id)', |
||
| 403 | ], |
||
| 404 | $this->platform->getAlterTableSQL($comparator->diffTable($table, $diffTable)) |
||
| 405 | ); |
||
| 406 | } |
||
| 407 | |||
| 408 | /** |
||
| 409 | * @group DBAL-2302 |
||
| 410 | */ |
||
| 411 | public function testAddNonAutoincrementColumnToPrimaryKeyWithAutoincrementColumn() |
||
| 412 | { |
||
| 413 | $table = new Table('tbl'); |
||
| 414 | $table->addColumn('id', 'integer', ['autoincrement' => true]); |
||
| 415 | $table->addColumn('foo', 'integer'); |
||
| 416 | $table->addColumn('bar', 'integer'); |
||
| 417 | $table->setPrimaryKey(['id']); |
||
| 418 | |||
| 419 | $comparator = new Comparator(); |
||
| 420 | $diffTable = clone $table; |
||
| 421 | |||
| 422 | $diffTable->dropPrimaryKey(); |
||
| 423 | $diffTable->setPrimaryKey(['id', 'foo']); |
||
| 424 | |||
| 425 | self::assertSame( |
||
| 426 | [ |
||
| 427 | 'ALTER TABLE tbl MODIFY id INT NOT NULL', |
||
| 428 | 'ALTER TABLE tbl DROP PRIMARY KEY', |
||
| 429 | 'ALTER TABLE tbl ADD PRIMARY KEY (id, foo)', |
||
| 430 | ], |
||
| 431 | $this->platform->getAlterTableSQL($comparator->diffTable($table, $diffTable)) |
||
| 432 | ); |
||
| 433 | } |
||
| 434 | |||
| 435 | /** |
||
| 436 | * @group DBAL-586 |
||
| 437 | */ |
||
| 438 | public function testAddAutoIncrementPrimaryKey() |
||
| 439 | { |
||
| 440 | $keyTable = new Table('foo'); |
||
| 441 | $keyTable->addColumn('id', 'integer', ['autoincrement' => true]); |
||
| 442 | $keyTable->addColumn('baz', 'string'); |
||
| 443 | $keyTable->setPrimaryKey(['id']); |
||
| 444 | |||
| 445 | $oldTable = new Table('foo'); |
||
| 446 | $oldTable->addColumn('baz', 'string'); |
||
| 447 | |||
| 448 | $c = new Comparator(); |
||
| 449 | $diff = $c->diffTable($oldTable, $keyTable); |
||
| 450 | |||
| 451 | $sql = $this->platform->getAlterTableSQL($diff); |
||
| 452 | |||
| 453 | self::assertEquals(['ALTER TABLE foo ADD id INT AUTO_INCREMENT NOT NULL, ADD PRIMARY KEY (id)'], $sql); |
||
| 454 | } |
||
| 455 | |||
| 456 | public function testNamedPrimaryKey() |
||
| 457 | { |
||
| 458 | $diff = new TableDiff('mytable'); |
||
| 459 | $diff->changedIndexes['foo_index'] = new Index('foo_index', ['foo'], true, true); |
||
| 460 | |||
| 461 | $sql = $this->platform->getAlterTableSQL($diff); |
||
| 462 | |||
| 463 | self::assertEquals([ |
||
| 464 | 'ALTER TABLE mytable DROP PRIMARY KEY', |
||
| 465 | 'ALTER TABLE mytable ADD PRIMARY KEY (foo)', |
||
| 466 | ], $sql); |
||
| 467 | } |
||
| 468 | |||
| 469 | public function testAlterPrimaryKeyWithNewColumn() |
||
| 470 | { |
||
| 471 | $table = new Table('yolo'); |
||
| 472 | $table->addColumn('pkc1', 'integer'); |
||
| 473 | $table->addColumn('col_a', 'integer'); |
||
| 474 | $table->setPrimaryKey(['pkc1']); |
||
| 475 | |||
| 476 | $comparator = new Comparator(); |
||
| 477 | $diffTable = clone $table; |
||
| 478 | |||
| 479 | $diffTable->addColumn('pkc2', 'integer'); |
||
| 480 | $diffTable->dropPrimaryKey(); |
||
| 481 | $diffTable->setPrimaryKey(['pkc1', 'pkc2']); |
||
| 482 | |||
| 483 | self::assertSame( |
||
| 484 | [ |
||
| 485 | 'ALTER TABLE yolo DROP PRIMARY KEY', |
||
| 486 | 'ALTER TABLE yolo ADD pkc2 INT NOT NULL', |
||
| 487 | 'ALTER TABLE yolo ADD PRIMARY KEY (pkc1, pkc2)', |
||
| 488 | ], |
||
| 489 | $this->platform->getAlterTableSQL($comparator->diffTable($table, $diffTable)) |
||
| 490 | ); |
||
| 491 | } |
||
| 492 | |||
| 493 | public function testInitializesDoctrineTypeMappings() |
||
| 494 | { |
||
| 495 | self::assertTrue($this->platform->hasDoctrineTypeMappingFor('binary')); |
||
| 496 | self::assertSame('binary', $this->platform->getDoctrineTypeMapping('binary')); |
||
| 497 | |||
| 498 | self::assertTrue($this->platform->hasDoctrineTypeMappingFor('varbinary')); |
||
| 499 | self::assertSame('binary', $this->platform->getDoctrineTypeMapping('varbinary')); |
||
| 500 | } |
||
| 501 | |||
| 502 | protected function getBinaryMaxLength() |
||
| 503 | { |
||
| 504 | return 65535; |
||
| 505 | } |
||
| 506 | |||
| 507 | public function testReturnsBinaryTypeDeclarationSQL() |
||
| 508 | { |
||
| 509 | self::assertSame('VARBINARY(255)', $this->platform->getBinaryTypeDeclarationSQL([])); |
||
| 510 | self::assertSame('VARBINARY(255)', $this->platform->getBinaryTypeDeclarationSQL(['length' => 0])); |
||
| 511 | self::assertSame('VARBINARY(65535)', $this->platform->getBinaryTypeDeclarationSQL(['length' => 65535])); |
||
| 512 | |||
| 513 | self::assertSame('BINARY(255)', $this->platform->getBinaryTypeDeclarationSQL(['fixed' => true])); |
||
| 514 | self::assertSame('BINARY(255)', $this->platform->getBinaryTypeDeclarationSQL(['fixed' => true, 'length' => 0])); |
||
| 515 | self::assertSame('BINARY(65535)', $this->platform->getBinaryTypeDeclarationSQL(['fixed' => true, 'length' => 65535])); |
||
| 516 | } |
||
| 517 | |||
| 518 | /** |
||
| 519 | * @group legacy |
||
| 520 | * @expectedDeprecation Binary field length 65536 is greater than supported by the platform (65535). Reduce the field length or use a BLOB field instead. |
||
| 521 | * @expectedDeprecation Binary field length 16777215 is greater than supported by the platform (65535). Reduce the field length or use a BLOB field instead. |
||
| 522 | * @expectedDeprecation Binary field length 16777216 is greater than supported by the platform (65535). Reduce the field length or use a BLOB field instead. |
||
| 523 | */ |
||
| 524 | public function testReturnsBinaryTypeLongerThanMaxDeclarationSQL() |
||
| 525 | { |
||
| 526 | self::assertSame('MEDIUMBLOB', $this->platform->getBinaryTypeDeclarationSQL(['length' => 65536])); |
||
| 527 | self::assertSame('MEDIUMBLOB', $this->platform->getBinaryTypeDeclarationSQL(['length' => 16777215])); |
||
| 528 | self::assertSame('LONGBLOB', $this->platform->getBinaryTypeDeclarationSQL(['length' => 16777216])); |
||
| 529 | |||
| 530 | self::assertSame('MEDIUMBLOB', $this->platform->getBinaryTypeDeclarationSQL(['fixed' => true, 'length' => 65536])); |
||
| 531 | self::assertSame('MEDIUMBLOB', $this->platform->getBinaryTypeDeclarationSQL(['fixed' => true, 'length' => 16777215])); |
||
| 532 | self::assertSame('LONGBLOB', $this->platform->getBinaryTypeDeclarationSQL(['fixed' => true, 'length' => 16777216])); |
||
| 533 | } |
||
| 534 | |||
| 535 | public function testDoesNotPropagateForeignKeyCreationForNonSupportingEngines() |
||
| 536 | { |
||
| 537 | $table = new Table('foreign_table'); |
||
| 538 | $table->addColumn('id', 'integer'); |
||
| 539 | $table->addColumn('fk_id', 'integer'); |
||
| 540 | $table->addForeignKeyConstraint('foreign_table', ['fk_id'], ['id']); |
||
| 541 | $table->setPrimaryKey(['id']); |
||
| 542 | $table->addOption('engine', 'MyISAM'); |
||
| 543 | |||
| 544 | self::assertSame( |
||
| 545 | ['CREATE TABLE foreign_table (id INT NOT NULL, fk_id INT NOT NULL, INDEX IDX_5690FFE2A57719D0 (fk_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = MyISAM'], |
||
| 546 | $this->platform->getCreateTableSQL( |
||
| 547 | $table, |
||
| 548 | AbstractPlatform::CREATE_INDEXES|AbstractPlatform::CREATE_FOREIGNKEYS |
||
| 549 | ) |
||
| 550 | ); |
||
| 551 | |||
| 552 | $table = clone $table; |
||
| 553 | $table->addOption('engine', 'InnoDB'); |
||
| 554 | |||
| 555 | self::assertSame( |
||
| 556 | [ |
||
| 557 | 'CREATE TABLE foreign_table (id INT NOT NULL, fk_id INT NOT NULL, INDEX IDX_5690FFE2A57719D0 (fk_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB', |
||
| 558 | 'ALTER TABLE foreign_table ADD CONSTRAINT FK_5690FFE2A57719D0 FOREIGN KEY (fk_id) REFERENCES foreign_table (id)', |
||
| 559 | ], |
||
| 560 | $this->platform->getCreateTableSQL( |
||
| 561 | $table, |
||
| 562 | AbstractPlatform::CREATE_INDEXES|AbstractPlatform::CREATE_FOREIGNKEYS |
||
| 563 | ) |
||
| 564 | ); |
||
| 565 | } |
||
| 566 | |||
| 567 | public function testDoesNotPropagateForeignKeyAlterationForNonSupportingEngines() |
||
| 568 | { |
||
| 569 | $table = new Table('foreign_table'); |
||
| 570 | $table->addColumn('id', 'integer'); |
||
| 571 | $table->addColumn('fk_id', 'integer'); |
||
| 572 | $table->addForeignKeyConstraint('foreign_table', ['fk_id'], ['id']); |
||
| 573 | $table->setPrimaryKey(['id']); |
||
| 574 | $table->addOption('engine', 'MyISAM'); |
||
| 575 | |||
| 576 | $addedForeignKeys = [new ForeignKeyConstraint(['fk_id'], 'foo', ['id'], 'fk_add')]; |
||
| 577 | $changedForeignKeys = [new ForeignKeyConstraint(['fk_id'], 'bar', ['id'], 'fk_change')]; |
||
| 578 | $removedForeignKeys = [new ForeignKeyConstraint(['fk_id'], 'baz', ['id'], 'fk_remove')]; |
||
| 579 | |||
| 580 | $tableDiff = new TableDiff('foreign_table'); |
||
| 581 | $tableDiff->fromTable = $table; |
||
| 582 | $tableDiff->addedForeignKeys = $addedForeignKeys; |
||
| 583 | $tableDiff->changedForeignKeys = $changedForeignKeys; |
||
| 584 | $tableDiff->removedForeignKeys = $removedForeignKeys; |
||
| 585 | |||
| 586 | self::assertEmpty($this->platform->getAlterTableSQL($tableDiff)); |
||
| 587 | |||
| 588 | $table->addOption('engine', 'InnoDB'); |
||
| 589 | |||
| 590 | $tableDiff = new TableDiff('foreign_table'); |
||
| 591 | $tableDiff->fromTable = $table; |
||
| 592 | $tableDiff->addedForeignKeys = $addedForeignKeys; |
||
| 593 | $tableDiff->changedForeignKeys = $changedForeignKeys; |
||
| 594 | $tableDiff->removedForeignKeys = $removedForeignKeys; |
||
| 595 | |||
| 596 | self::assertSame( |
||
| 597 | [ |
||
| 598 | 'ALTER TABLE foreign_table DROP FOREIGN KEY fk_remove', |
||
| 599 | 'ALTER TABLE foreign_table DROP FOREIGN KEY fk_change', |
||
| 600 | 'ALTER TABLE foreign_table ADD CONSTRAINT fk_add FOREIGN KEY (fk_id) REFERENCES foo (id)', |
||
| 601 | 'ALTER TABLE foreign_table ADD CONSTRAINT fk_change FOREIGN KEY (fk_id) REFERENCES bar (id)', |
||
| 602 | ], |
||
| 603 | $this->platform->getAlterTableSQL($tableDiff) |
||
| 604 | ); |
||
| 605 | } |
||
| 606 | |||
| 607 | /** |
||
| 608 | * @group DBAL-234 |
||
| 609 | */ |
||
| 610 | protected function getAlterTableRenameIndexSQL() |
||
| 611 | { |
||
| 612 | return [ |
||
| 613 | 'DROP INDEX idx_foo ON mytable', |
||
| 614 | 'CREATE INDEX idx_bar ON mytable (id)', |
||
| 615 | ]; |
||
| 616 | } |
||
| 617 | |||
| 618 | /** |
||
| 619 | * @group DBAL-234 |
||
| 620 | */ |
||
| 621 | protected function getQuotedAlterTableRenameIndexSQL() |
||
| 622 | { |
||
| 623 | return [ |
||
| 624 | 'DROP INDEX `create` ON `table`', |
||
| 625 | 'CREATE INDEX `select` ON `table` (id)', |
||
| 626 | 'DROP INDEX `foo` ON `table`', |
||
| 627 | 'CREATE INDEX `bar` ON `table` (id)', |
||
| 628 | ]; |
||
| 629 | } |
||
| 630 | |||
| 631 | /** |
||
| 632 | * @group DBAL-807 |
||
| 633 | */ |
||
| 634 | protected function getAlterTableRenameIndexInSchemaSQL() |
||
| 635 | { |
||
| 636 | return [ |
||
| 637 | 'DROP INDEX idx_foo ON myschema.mytable', |
||
| 638 | 'CREATE INDEX idx_bar ON myschema.mytable (id)', |
||
| 639 | ]; |
||
| 640 | } |
||
| 641 | |||
| 642 | /** |
||
| 643 | * @group DBAL-807 |
||
| 644 | */ |
||
| 645 | protected function getQuotedAlterTableRenameIndexInSchemaSQL() |
||
| 646 | { |
||
| 647 | return [ |
||
| 648 | 'DROP INDEX `create` ON `schema`.`table`', |
||
| 649 | 'CREATE INDEX `select` ON `schema`.`table` (id)', |
||
| 650 | 'DROP INDEX `foo` ON `schema`.`table`', |
||
| 651 | 'CREATE INDEX `bar` ON `schema`.`table` (id)', |
||
| 652 | ]; |
||
| 653 | } |
||
| 654 | |||
| 655 | protected function getQuotesDropForeignKeySQL() |
||
| 656 | { |
||
| 657 | return 'ALTER TABLE `table` DROP FOREIGN KEY `select`'; |
||
| 658 | } |
||
| 659 | |||
| 660 | protected function getQuotesDropConstraintSQL() |
||
| 661 | { |
||
| 662 | return 'ALTER TABLE `table` DROP CONSTRAINT `select`'; |
||
| 663 | } |
||
| 664 | |||
| 665 | public function testDoesNotPropagateDefaultValuesForUnsupportedColumnTypes() |
||
| 666 | { |
||
| 667 | $table = new Table('text_blob_default_value'); |
||
| 668 | $table->addColumn('def_text', 'text', ['default' => 'def']); |
||
| 669 | $table->addColumn('def_text_null', 'text', ['notnull' => false, 'default' => 'def']); |
||
| 670 | $table->addColumn('def_blob', 'blob', ['default' => 'def']); |
||
| 671 | $table->addColumn('def_blob_null', 'blob', ['notnull' => false, 'default' => 'def']); |
||
| 672 | |||
| 673 | self::assertSame( |
||
| 674 | ['CREATE TABLE text_blob_default_value (def_text LONGTEXT NOT NULL, def_text_null LONGTEXT DEFAULT NULL, def_blob LONGBLOB NOT NULL, def_blob_null LONGBLOB DEFAULT NULL) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB'], |
||
| 675 | $this->platform->getCreateTableSQL($table) |
||
| 676 | ); |
||
| 677 | |||
| 678 | $diffTable = clone $table; |
||
| 679 | $diffTable->changeColumn('def_text', ['default' => null]); |
||
| 680 | $diffTable->changeColumn('def_text_null', ['default' => null]); |
||
| 681 | $diffTable->changeColumn('def_blob', ['default' => null]); |
||
| 682 | $diffTable->changeColumn('def_blob_null', ['default' => null]); |
||
| 683 | |||
| 684 | $comparator = new Comparator(); |
||
| 685 | |||
| 686 | self::assertEmpty($this->platform->getAlterTableSQL($comparator->diffTable($table, $diffTable))); |
||
| 687 | } |
||
| 688 | |||
| 689 | /** |
||
| 690 | * {@inheritdoc} |
||
| 691 | */ |
||
| 692 | protected function getQuotedAlterTableRenameColumnSQL() |
||
| 693 | { |
||
| 694 | return ['ALTER TABLE mytable ' . |
||
| 695 | "CHANGE unquoted1 unquoted INT NOT NULL COMMENT 'Unquoted 1', " . |
||
| 696 | "CHANGE unquoted2 `where` INT NOT NULL COMMENT 'Unquoted 2', " . |
||
| 697 | "CHANGE unquoted3 `foo` INT NOT NULL COMMENT 'Unquoted 3', " . |
||
| 698 | "CHANGE `create` reserved_keyword INT NOT NULL COMMENT 'Reserved keyword 1', " . |
||
| 699 | "CHANGE `table` `from` INT NOT NULL COMMENT 'Reserved keyword 2', " . |
||
| 700 | "CHANGE `select` `bar` INT NOT NULL COMMENT 'Reserved keyword 3', " . |
||
| 701 | "CHANGE quoted1 quoted INT NOT NULL COMMENT 'Quoted 1', " . |
||
| 702 | "CHANGE quoted2 `and` INT NOT NULL COMMENT 'Quoted 2', " . |
||
| 703 | "CHANGE quoted3 `baz` INT NOT NULL COMMENT 'Quoted 3'", |
||
| 704 | ]; |
||
| 705 | } |
||
| 706 | |||
| 707 | /** |
||
| 708 | * {@inheritdoc} |
||
| 709 | */ |
||
| 710 | protected function getQuotedAlterTableChangeColumnLengthSQL() |
||
| 711 | { |
||
| 712 | return ['ALTER TABLE mytable ' . |
||
| 713 | "CHANGE unquoted1 unquoted1 VARCHAR(255) NOT NULL COMMENT 'Unquoted 1', " . |
||
| 714 | "CHANGE unquoted2 unquoted2 VARCHAR(255) NOT NULL COMMENT 'Unquoted 2', " . |
||
| 715 | "CHANGE unquoted3 unquoted3 VARCHAR(255) NOT NULL COMMENT 'Unquoted 3', " . |
||
| 716 | "CHANGE `create` `create` VARCHAR(255) NOT NULL COMMENT 'Reserved keyword 1', " . |
||
| 717 | "CHANGE `table` `table` VARCHAR(255) NOT NULL COMMENT 'Reserved keyword 2', " . |
||
| 718 | "CHANGE `select` `select` VARCHAR(255) NOT NULL COMMENT 'Reserved keyword 3'", |
||
| 719 | ]; |
||
| 720 | } |
||
| 721 | |||
| 722 | /** |
||
| 723 | * @group DBAL-423 |
||
| 724 | */ |
||
| 725 | public function testReturnsGuidTypeDeclarationSQL() |
||
| 728 | } |
||
| 729 | |||
| 730 | /** |
||
| 731 | * {@inheritdoc} |
||
| 732 | */ |
||
| 733 | public function getAlterTableRenameColumnSQL() |
||
| 734 | { |
||
| 735 | return ["ALTER TABLE foo CHANGE bar baz INT DEFAULT 666 NOT NULL COMMENT 'rename test'"]; |
||
| 736 | } |
||
| 737 | |||
| 738 | /** |
||
| 739 | * {@inheritdoc} |
||
| 740 | */ |
||
| 741 | protected function getQuotesTableIdentifiersInAlterTableSQL() |
||
| 742 | { |
||
| 743 | return [ |
||
| 744 | 'ALTER TABLE `foo` DROP FOREIGN KEY fk1', |
||
| 745 | 'ALTER TABLE `foo` DROP FOREIGN KEY fk2', |
||
| 746 | 'ALTER TABLE `foo` RENAME TO `table`, ADD bloo INT NOT NULL, DROP baz, CHANGE bar bar INT DEFAULT NULL, ' . |
||
| 747 | 'CHANGE id war INT NOT NULL', |
||
| 748 | 'ALTER TABLE `table` ADD CONSTRAINT fk_add FOREIGN KEY (fk3) REFERENCES fk_table (id)', |
||
| 749 | 'ALTER TABLE `table` ADD CONSTRAINT fk2 FOREIGN KEY (fk2) REFERENCES fk_table2 (id)', |
||
| 750 | ]; |
||
| 751 | } |
||
| 752 | |||
| 753 | /** |
||
| 754 | * {@inheritdoc} |
||
| 755 | */ |
||
| 756 | protected function getCommentOnColumnSQL() |
||
| 762 | ]; |
||
| 763 | } |
||
| 764 | |||
| 765 | /** |
||
| 766 | * {@inheritdoc} |
||
| 767 | */ |
||
| 768 | protected function getQuotesReservedKeywordInUniqueConstraintDeclarationSQL() |
||
| 769 | { |
||
| 770 | return 'CONSTRAINT `select` UNIQUE (foo)'; |
||
| 771 | } |
||
| 772 | |||
| 773 | /** |
||
| 774 | * {@inheritdoc} |
||
| 775 | */ |
||
| 776 | protected function getQuotesReservedKeywordInIndexDeclarationSQL() |
||
| 777 | { |
||
| 778 | return 'INDEX `select` (foo)'; |
||
| 779 | } |
||
| 780 | |||
| 781 | /** |
||
| 782 | * {@inheritdoc} |
||
| 783 | */ |
||
| 784 | protected function getQuotesReservedKeywordInTruncateTableSQL() |
||
| 785 | { |
||
| 786 | return 'TRUNCATE `select`'; |
||
| 787 | } |
||
| 788 | |||
| 789 | /** |
||
| 790 | * {@inheritdoc} |
||
| 791 | */ |
||
| 792 | protected function getAlterStringToFixedStringSQL() |
||
| 793 | { |
||
| 794 | return ['ALTER TABLE mytable CHANGE name name CHAR(2) NOT NULL']; |
||
| 795 | } |
||
| 796 | |||
| 797 | /** |
||
| 798 | * {@inheritdoc} |
||
| 799 | */ |
||
| 800 | protected function getGeneratesAlterTableRenameIndexUsedByForeignKeySQL() |
||
| 801 | { |
||
| 802 | return [ |
||
| 803 | 'ALTER TABLE mytable DROP FOREIGN KEY fk_foo', |
||
| 804 | 'DROP INDEX idx_foo ON mytable', |
||
| 805 | 'CREATE INDEX idx_foo_renamed ON mytable (foo)', |
||
| 806 | 'ALTER TABLE mytable ADD CONSTRAINT fk_foo FOREIGN KEY (foo) REFERENCES foreign_table (id)', |
||
| 807 | ]; |
||
| 808 | } |
||
| 809 | |||
| 810 | /** |
||
| 811 | * {@inheritdoc} |
||
| 812 | */ |
||
| 813 | public function getGeneratesDecimalTypeDeclarationSQL() |
||
| 814 | { |
||
| 815 | return [ |
||
| 816 | [[], 'NUMERIC(10, 0)'], |
||
| 817 | [['unsigned' => true], 'NUMERIC(10, 0) UNSIGNED'], |
||
| 818 | [['unsigned' => false], 'NUMERIC(10, 0)'], |
||
| 819 | [['precision' => 5], 'NUMERIC(5, 0)'], |
||
| 820 | [['scale' => 5], 'NUMERIC(10, 5)'], |
||
| 821 | [['precision' => 8, 'scale' => 2], 'NUMERIC(8, 2)'], |
||
| 822 | ]; |
||
| 823 | } |
||
| 824 | |||
| 825 | /** |
||
| 826 | * {@inheritdoc} |
||
| 827 | */ |
||
| 828 | public function getGeneratesFloatDeclarationSQL() |
||
| 829 | { |
||
| 830 | return [ |
||
| 831 | [[], 'DOUBLE PRECISION'], |
||
| 832 | [['unsigned' => true], 'DOUBLE PRECISION UNSIGNED'], |
||
| 833 | [['unsigned' => false], 'DOUBLE PRECISION'], |
||
| 834 | [['precision' => 5], 'DOUBLE PRECISION'], |
||
| 835 | [['scale' => 5], 'DOUBLE PRECISION'], |
||
| 836 | [['precision' => 8, 'scale' => 2], 'DOUBLE PRECISION'], |
||
| 837 | ]; |
||
| 838 | } |
||
| 839 | |||
| 840 | /** |
||
| 841 | * @group DBAL-2436 |
||
| 842 | */ |
||
| 843 | public function testQuotesTableNameInListTableIndexesSQL() |
||
| 844 | { |
||
| 845 | self::assertContains("'Foo''Bar\\\\'", $this->platform->getListTableIndexesSQL("Foo'Bar\\", 'foo_db'), '', true); |
||
| 846 | } |
||
| 847 | |||
| 848 | /** |
||
| 849 | * @group DBAL-2436 |
||
| 850 | */ |
||
| 851 | public function testQuotesDatabaseNameInListTableIndexesSQL() |
||
| 852 | { |
||
| 853 | self::assertContains("'Foo''Bar\\\\'", $this->platform->getListTableIndexesSQL('foo_table', "Foo'Bar\\"), '', true); |
||
| 854 | } |
||
| 855 | |||
| 856 | /** |
||
| 857 | * @group DBAL-2436 |
||
| 858 | */ |
||
| 859 | public function testQuotesDatabaseNameInListViewsSQL() |
||
| 862 | } |
||
| 863 | |||
| 864 | /** |
||
| 865 | * @group DBAL-2436 |
||
| 866 | */ |
||
| 867 | public function testQuotesTableNameInListTableForeignKeysSQL() |
||
| 870 | } |
||
| 871 | |||
| 872 | /** |
||
| 873 | * @group DBAL-2436 |
||
| 874 | */ |
||
| 875 | public function testQuotesDatabaseNameInListTableForeignKeysSQL() |
||
| 876 | { |
||
| 877 | self::assertContains("'Foo''Bar\\\\'", $this->platform->getListTableForeignKeysSQL('foo_table', "Foo'Bar\\"), '', true); |
||
| 878 | } |
||
| 879 | |||
| 880 | /** |
||
| 881 | * @group DBAL-2436 |
||
| 882 | */ |
||
| 883 | public function testQuotesTableNameInListTableColumnsSQL() |
||
| 884 | { |
||
| 885 | self::assertContains("'Foo''Bar\\\\'", $this->platform->getListTableColumnsSQL("Foo'Bar\\"), '', true); |
||
| 886 | } |
||
| 887 | |||
| 888 | /** |
||
| 889 | * @group DBAL-2436 |
||
| 890 | */ |
||
| 891 | public function testQuotesDatabaseNameInListTableColumnsSQL() |
||
| 892 | { |
||
| 893 | self::assertContains("'Foo''Bar\\\\'", $this->platform->getListTableColumnsSQL('foo_table', "Foo'Bar\\"), '', true); |
||
| 894 | } |
||
| 895 | |||
| 896 | public function testListTableForeignKeysSQLEvaluatesDatabase() |
||
| 897 | { |
||
| 898 | $sql = $this->platform->getListTableForeignKeysSQL('foo'); |
||
| 899 | |||
| 900 | self::assertContains('DATABASE()', $sql); |
||
| 901 | |||
| 902 | $sql = $this->platform->getListTableForeignKeysSQL('foo', 'bar'); |
||
| 903 | |||
| 904 | self::assertContains('bar', $sql); |
||
| 905 | self::assertNotContains('DATABASE()', $sql); |
||
| 906 | } |
||
| 907 | |||
| 908 | public function testColumnCharsetDeclarationSQL() : void |
||
| 909 | { |
||
| 910 | self::assertSame( |
||
| 911 | 'CHARACTER SET ascii', |
||
| 912 | $this->platform->getColumnCharsetDeclarationSQL('ascii') |
||
| 913 | ); |
||
| 914 | } |
||
| 915 | |||
| 916 | public function testSupportsColumnCollation() : void |
||
| 917 | { |
||
| 918 | self::assertTrue($this->platform->supportsColumnCollation()); |
||
| 919 | } |
||
| 920 | |||
| 921 | public function testColumnCollationDeclarationSQL() : void |
||
| 922 | { |
||
| 923 | self::assertSame( |
||
| 924 | 'COLLATE ascii_general_ci', |
||
| 925 | $this->platform->getColumnCollationDeclarationSQL('ascii_general_ci') |
||
| 926 | ); |
||
| 927 | } |
||
| 928 | |||
| 929 | public function testGetCreateTableSQLWithColumnCollation() : void |
||
| 942 |