| Total Complexity | 106 | 
| Total Lines | 1204 | 
| Duplicated Lines | 0 % | 
| Changes | 0 | ||
Complex classes like SQLAnywherePlatformTest 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 SQLAnywherePlatformTest, and based on these observations, apply Extract Interface, too.
| 1 | <?php | ||
| 27 | class SQLAnywherePlatformTest extends AbstractPlatformTestCase | ||
| 28 | { | ||
| 29 | /** @var SQLAnywherePlatform */ | ||
| 30 | protected $platform; | ||
| 31 | |||
| 32 | public function createPlatform() : AbstractPlatform | ||
| 35 | } | ||
| 36 | |||
| 37 | /** | ||
| 38 |      * {@inheritDoc} | ||
| 39 | */ | ||
| 40 | public function getGenerateAlterTableSql() : array | ||
| 41 |     { | ||
| 42 | return [ | ||
| 43 | "ALTER TABLE mytable ADD quota INT DEFAULT NULL, DROP foo, ALTER baz VARCHAR(1) DEFAULT 'def' NOT NULL, ALTER bloo BIT DEFAULT '0' NOT NULL", | ||
| 44 | 'ALTER TABLE mytable RENAME userlist', | ||
| 45 | ]; | ||
| 46 | } | ||
| 47 | |||
| 48 | public function getGenerateForeignKeySql() : string | ||
| 49 |     { | ||
| 50 | return 'ALTER TABLE test ADD FOREIGN KEY (fk_name_id) REFERENCES other_table (id)'; | ||
| 51 | } | ||
| 52 | |||
| 53 | public function getGenerateIndexSql() : string | ||
| 54 |     { | ||
| 55 | return 'CREATE INDEX my_idx ON mytable (user_name, last_login)'; | ||
| 56 | } | ||
| 57 | |||
| 58 | public function getGenerateTableSql() : string | ||
| 59 |     { | ||
| 60 | return 'CREATE TABLE test (id INT IDENTITY NOT NULL, test VARCHAR(255) DEFAULT NULL, PRIMARY KEY (id))'; | ||
| 61 | } | ||
| 62 | |||
| 63 | /** | ||
| 64 |      * {@inheritDoc} | ||
| 65 | */ | ||
| 66 | public function getGenerateTableWithMultiColumnUniqueIndexSql() : array | ||
| 67 |     { | ||
| 68 | return [ | ||
| 69 | 'CREATE TABLE test (foo VARCHAR(255) DEFAULT NULL, bar VARCHAR(255) DEFAULT NULL)', | ||
| 70 | 'CREATE UNIQUE INDEX UNIQ_D87F7E0C8C73652176FF8CAA ON test (foo, bar)', | ||
| 71 | ]; | ||
| 72 | } | ||
| 73 | |||
| 74 | public function getGenerateUniqueIndexSql() : string | ||
| 75 |     { | ||
| 76 | return 'CREATE UNIQUE INDEX index_name ON test (test, test2)'; | ||
| 77 | } | ||
| 78 | |||
| 79 | /** | ||
| 80 |      * {@inheritDoc} | ||
| 81 | */ | ||
| 82 | protected function getQuotedColumnInForeignKeySQL() : array | ||
| 83 |     { | ||
| 84 |         return ['CREATE TABLE "quoted" ("create" VARCHAR(255) NOT NULL, foo VARCHAR(255) NOT NULL, "bar" VARCHAR(255) NOT NULL, CONSTRAINT FK_WITH_RESERVED_KEYWORD FOREIGN KEY ("create", foo, "bar") REFERENCES "foreign" ("create", bar, "foo-bar"), CONSTRAINT FK_WITH_NON_RESERVED_KEYWORD FOREIGN KEY ("create", foo, "bar") REFERENCES foo ("create", bar, "foo-bar"), CONSTRAINT FK_WITH_INTENDED_QUOTATION FOREIGN KEY ("create", foo, "bar") REFERENCES "foo-bar" ("create", bar, "foo-bar"))']; | ||
| 85 | } | ||
| 86 | |||
| 87 | /** | ||
| 88 |      * {@inheritDoc} | ||
| 89 | */ | ||
| 90 | protected function getQuotedColumnInIndexSQL() : array | ||
| 91 |     { | ||
| 92 | return [ | ||
| 93 |             'CREATE TABLE "quoted" ("create" VARCHAR(255) NOT NULL)', | ||
| 94 |             'CREATE INDEX IDX_22660D028FD6E0FB ON "quoted" ("create")', | ||
| 95 | ]; | ||
| 96 | } | ||
| 97 | |||
| 98 | /** | ||
| 99 |      * {@inheritDoc} | ||
| 100 | */ | ||
| 101 | protected function getQuotedNameInIndexSQL() : array | ||
| 102 |     { | ||
| 103 | return [ | ||
| 104 | 'CREATE TABLE test (column1 VARCHAR(255) NOT NULL)', | ||
| 105 | 'CREATE INDEX "key" ON test (column1)', | ||
| 106 | ]; | ||
| 107 | } | ||
| 108 | |||
| 109 | /** | ||
| 110 |      * {@inheritDoc} | ||
| 111 | */ | ||
| 112 | protected function getQuotedColumnInPrimaryKeySQL() : array | ||
| 113 |     { | ||
| 114 |         return ['CREATE TABLE "quoted" ("create" VARCHAR(255) NOT NULL, PRIMARY KEY ("create"))']; | ||
| 115 | } | ||
| 116 | |||
| 117 | /** | ||
| 118 |      * {@inheritDoc} | ||
| 119 | */ | ||
| 120 | public function getCreateTableColumnCommentsSQL() : array | ||
| 121 |     { | ||
| 122 | return [ | ||
| 123 | 'CREATE TABLE test (id INT NOT NULL, PRIMARY KEY (id))', | ||
| 124 | "COMMENT ON COLUMN test.id IS 'This is a comment'", | ||
| 125 | ]; | ||
| 126 | } | ||
| 127 | |||
| 128 | /** | ||
| 129 |      * {@inheritDoc} | ||
| 130 | */ | ||
| 131 | public function getAlterTableColumnCommentsSQL() : array | ||
| 132 |     { | ||
| 133 | return [ | ||
| 134 | 'ALTER TABLE mytable ADD quota INT NOT NULL', | ||
| 135 | "COMMENT ON COLUMN mytable.quota IS 'A comment'", | ||
| 136 | 'COMMENT ON COLUMN mytable.foo IS NULL', | ||
| 137 | "COMMENT ON COLUMN mytable.baz IS 'B comment'", | ||
| 138 | ]; | ||
| 139 | } | ||
| 140 | |||
| 141 | /** | ||
| 142 |      * {@inheritDoc} | ||
| 143 | */ | ||
| 144 | public function getCreateTableColumnTypeCommentsSQL() : array | ||
| 145 |     { | ||
| 146 | return [ | ||
| 147 | 'CREATE TABLE test (id INT NOT NULL, data TEXT NOT NULL, PRIMARY KEY (id))', | ||
| 148 | "COMMENT ON COLUMN test.data IS '(DC2Type:array)'", | ||
| 149 | ]; | ||
| 150 | } | ||
| 151 | |||
| 152 | public function testHasCorrectPlatformName() : void | ||
| 153 |     { | ||
| 154 |         self::assertEquals('sqlanywhere', $this->platform->getName()); | ||
| 155 | } | ||
| 156 | |||
| 157 | public function testGeneratesCreateTableSQLWithCommonIndexes() : void | ||
| 158 |     { | ||
| 159 |         $table = new Table('test'); | ||
| 160 |         $table->addColumn('id', 'integer'); | ||
| 161 |         $table->addColumn('name', 'string', ['length' => 50]); | ||
| 162 | $table->setPrimaryKey(['id']); | ||
| 163 | $table->addIndex(['name']); | ||
| 164 | $table->addIndex(['id', 'name'], 'composite_idx'); | ||
| 165 | |||
| 166 | self::assertEquals( | ||
| 167 | [ | ||
| 168 | 'CREATE TABLE test (id INT NOT NULL, name VARCHAR(50) NOT NULL, PRIMARY KEY (id))', | ||
| 169 | 'CREATE INDEX IDX_D87F7E0C5E237E06 ON test (name)', | ||
| 170 | 'CREATE INDEX composite_idx ON test (id, name)', | ||
| 171 | ], | ||
| 172 | $this->platform->getCreateTableSQL($table) | ||
| 173 | ); | ||
| 174 | } | ||
| 175 | |||
| 176 | public function testGeneratesCreateTableSQLWithForeignKeyConstraints() : void | ||
| 177 |     { | ||
| 178 |         $table = new Table('test'); | ||
| 179 |         $table->addColumn('id', 'integer'); | ||
| 180 |         $table->addColumn('fk_1', 'integer'); | ||
| 181 |         $table->addColumn('fk_2', 'integer'); | ||
| 182 | $table->setPrimaryKey(['id']); | ||
| 183 |         $table->addForeignKeyConstraint('foreign_table', ['fk_1', 'fk_2'], ['pk_1', 'pk_2']); | ||
| 184 | $table->addForeignKeyConstraint( | ||
| 185 | 'foreign_table2', | ||
| 186 | ['fk_1', 'fk_2'], | ||
| 187 | ['pk_1', 'pk_2'], | ||
| 188 | [], | ||
| 189 | 'named_fk' | ||
| 190 | ); | ||
| 191 | |||
| 192 | self::assertEquals( | ||
| 193 | ['CREATE TABLE test (id INT NOT NULL, fk_1 INT NOT NULL, fk_2 INT NOT NULL, ' . | ||
| 194 | 'CONSTRAINT FK_D87F7E0C177612A38E7F4319 FOREIGN KEY (fk_1, fk_2) REFERENCES foreign_table (pk_1, pk_2), ' . | ||
| 195 | 'CONSTRAINT named_fk FOREIGN KEY (fk_1, fk_2) REFERENCES foreign_table2 (pk_1, pk_2))', | ||
| 196 | ], | ||
| 197 | $this->platform->getCreateTableSQL($table, AbstractPlatform::CREATE_FOREIGNKEYS) | ||
| 198 | ); | ||
| 199 | } | ||
| 200 | |||
| 201 | public function testGeneratesCreateTableSQLWithCheckConstraints() : void | ||
| 202 |     { | ||
| 203 |         $table = new Table('test'); | ||
| 204 |         $table->addColumn('id', 'integer'); | ||
| 205 |         $table->addColumn('check_max', 'integer', ['platformOptions' => ['max' => 10]]); | ||
| 206 |         $table->addColumn('check_min', 'integer', ['platformOptions' => ['min' => 10]]); | ||
| 207 | $table->setPrimaryKey(['id']); | ||
| 208 | |||
| 209 | self::assertEquals( | ||
| 210 | ['CREATE TABLE test (id INT NOT NULL, check_max INT NOT NULL, check_min INT NOT NULL, PRIMARY KEY (id), CHECK (check_max <= 10), CHECK (check_min >= 10))'], | ||
| 211 | $this->platform->getCreateTableSQL($table) | ||
| 212 | ); | ||
| 213 | } | ||
| 214 | |||
| 215 | public function testGeneratesTableAlterationWithRemovedColumnCommentSql() : void | ||
| 216 |     { | ||
| 217 |         $table = new Table('mytable'); | ||
| 218 |         $table->addColumn('foo', 'string', ['comment' => 'foo comment']); | ||
| 219 | |||
| 220 |         $tableDiff                        = new TableDiff('mytable'); | ||
| 221 | $tableDiff->fromTable = $table; | ||
| 222 | $tableDiff->changedColumns['foo'] = new ColumnDiff( | ||
| 223 | 'foo', | ||
| 224 |             new Column('foo', Type::getType('string')), | ||
| 225 | ['comment'] | ||
| 226 | ); | ||
| 227 | |||
| 228 | self::assertEquals( | ||
| 229 | ['COMMENT ON COLUMN mytable.foo IS NULL'], | ||
| 230 | $this->platform->getAlterTableSQL($tableDiff) | ||
| 231 | ); | ||
| 232 | } | ||
| 233 | |||
| 234 | /** | ||
| 235 | * @dataProvider getLockHints | ||
| 236 | */ | ||
| 237 | public function testAppendsLockHint(?int $lockMode, string $lockHint) : void | ||
| 238 |     { | ||
| 239 | $fromClause = 'FROM users'; | ||
| 240 | $expectedResult = $fromClause . $lockHint; | ||
| 241 | |||
| 242 | self::assertSame($expectedResult, $this->platform->appendLockHint($fromClause, $lockMode)); | ||
| 243 | } | ||
| 244 | |||
| 245 | /** | ||
| 246 | * @return mixed[][] | ||
| 247 | */ | ||
| 248 | public static function getLockHints() : iterable | ||
| 249 |     { | ||
| 250 | return [ | ||
| 251 | [null, ''], | ||
| 252 | [LockMode::NONE, ' WITH (NOLOCK)'], | ||
| 253 | [LockMode::OPTIMISTIC, ''], | ||
| 254 | [LockMode::PESSIMISTIC_READ, ' WITH (UPDLOCK)'], | ||
| 255 | [LockMode::PESSIMISTIC_WRITE, ' WITH (XLOCK)'], | ||
| 256 | ]; | ||
| 257 | } | ||
| 258 | |||
| 259 | public function testHasCorrectMaxIdentifierLength() : void | ||
| 260 |     { | ||
| 261 | self::assertEquals(128, $this->platform->getMaxIdentifierLength()); | ||
| 262 | } | ||
| 263 | |||
| 264 | public function testFixesSchemaElementNames() : void | ||
| 265 |     { | ||
| 266 | $maxIdentifierLength = $this->platform->getMaxIdentifierLength(); | ||
| 267 | $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; | ||
| 268 | $schemaElementName = ''; | ||
| 269 | |||
| 270 |         for ($i = 0; $i < $maxIdentifierLength + 100; $i++) { | ||
| 271 | $schemaElementName .= $characters[mt_rand(0, strlen($characters) - 1)]; | ||
| 272 | } | ||
| 273 | |||
| 274 | $fixedSchemaElementName = substr($schemaElementName, 0, $maxIdentifierLength); | ||
| 275 | |||
| 276 | self::assertEquals( | ||
| 277 | $fixedSchemaElementName, | ||
| 278 | $this->platform->fixSchemaElementName($schemaElementName) | ||
| 279 | ); | ||
| 280 | self::assertEquals( | ||
| 281 | $fixedSchemaElementName, | ||
| 282 | $this->platform->fixSchemaElementName($fixedSchemaElementName) | ||
| 283 | ); | ||
| 284 | } | ||
| 285 | |||
| 286 | public function testGeneratesColumnTypesDeclarationSQL() : void | ||
| 287 |     { | ||
| 288 | $fullColumnDef = [ | ||
| 289 | 'length' => 10, | ||
| 290 | 'fixed' => true, | ||
| 291 | 'unsigned' => true, | ||
| 292 | 'autoincrement' => true, | ||
| 293 | ]; | ||
| 294 | |||
| 295 |         self::assertEquals('SMALLINT', $this->platform->getSmallIntTypeDeclarationSQL([])); | ||
| 296 |         self::assertEquals('UNSIGNED SMALLINT', $this->platform->getSmallIntTypeDeclarationSQL(['unsigned' => true])); | ||
| 297 |         self::assertEquals('UNSIGNED SMALLINT IDENTITY', $this->platform->getSmallIntTypeDeclarationSQL($fullColumnDef)); | ||
| 298 |         self::assertEquals('INT', $this->platform->getIntegerTypeDeclarationSQL([])); | ||
| 299 |         self::assertEquals('UNSIGNED INT', $this->platform->getIntegerTypeDeclarationSQL(['unsigned' => true])); | ||
| 300 |         self::assertEquals('UNSIGNED INT IDENTITY', $this->platform->getIntegerTypeDeclarationSQL($fullColumnDef)); | ||
| 301 |         self::assertEquals('BIGINT', $this->platform->getBigIntTypeDeclarationSQL([])); | ||
| 302 |         self::assertEquals('UNSIGNED BIGINT', $this->platform->getBigIntTypeDeclarationSQL(['unsigned' => true])); | ||
| 303 |         self::assertEquals('UNSIGNED BIGINT IDENTITY', $this->platform->getBigIntTypeDeclarationSQL($fullColumnDef)); | ||
| 304 |         self::assertEquals('LONG BINARY', $this->platform->getBlobTypeDeclarationSQL($fullColumnDef)); | ||
| 305 |         self::assertEquals('BIT', $this->platform->getBooleanTypeDeclarationSQL($fullColumnDef)); | ||
| 306 |         self::assertEquals('TEXT', $this->platform->getClobTypeDeclarationSQL($fullColumnDef)); | ||
| 307 |         self::assertEquals('DATE', $this->platform->getDateTypeDeclarationSQL($fullColumnDef)); | ||
| 308 |         self::assertEquals('DATETIME', $this->platform->getDateTimeTypeDeclarationSQL($fullColumnDef)); | ||
| 309 |         self::assertEquals('TIME', $this->platform->getTimeTypeDeclarationSQL($fullColumnDef)); | ||
| 310 |         self::assertEquals('UNIQUEIDENTIFIER', $this->platform->getGuidTypeDeclarationSQL($fullColumnDef)); | ||
| 311 | |||
| 312 | self::assertEquals(1, $this->platform->getVarcharDefaultLength()); | ||
| 313 | self::assertEquals(32767, $this->platform->getVarcharMaxLength()); | ||
| 314 | } | ||
| 315 | |||
| 316 | public function testHasNativeGuidType() : void | ||
| 317 |     { | ||
| 318 | self::assertTrue($this->platform->hasNativeGuidType()); | ||
| 319 | } | ||
| 320 | |||
| 321 | public function testGeneratesDDLSnippets() : void | ||
| 322 |     { | ||
| 323 |         self::assertEquals("CREATE DATABASE 'foobar'", $this->platform->getCreateDatabaseSQL('foobar')); | ||
| 324 |         self::assertEquals("CREATE DATABASE 'foobar'", $this->platform->getCreateDatabaseSQL('"foobar"')); | ||
| 325 |         self::assertEquals("CREATE DATABASE 'create'", $this->platform->getCreateDatabaseSQL('create')); | ||
| 326 |         self::assertEquals("DROP DATABASE 'foobar'", $this->platform->getDropDatabaseSQL('foobar')); | ||
| 327 |         self::assertEquals("DROP DATABASE 'foobar'", $this->platform->getDropDatabaseSQL('"foobar"')); | ||
| 328 |         self::assertEquals("DROP DATABASE 'create'", $this->platform->getDropDatabaseSQL('create')); | ||
| 329 |         self::assertEquals('CREATE GLOBAL TEMPORARY TABLE', $this->platform->getCreateTemporaryTableSnippetSQL()); | ||
| 330 |         self::assertEquals("START DATABASE 'foobar' AUTOSTOP OFF", $this->platform->getStartDatabaseSQL('foobar')); | ||
| 331 |         self::assertEquals("START DATABASE 'foobar' AUTOSTOP OFF", $this->platform->getStartDatabaseSQL('"foobar"')); | ||
| 332 |         self::assertEquals("START DATABASE 'create' AUTOSTOP OFF", $this->platform->getStartDatabaseSQL('create')); | ||
| 333 |         self::assertEquals('STOP DATABASE "foobar" UNCONDITIONALLY', $this->platform->getStopDatabaseSQL('foobar')); | ||
| 334 |         self::assertEquals('STOP DATABASE "foobar" UNCONDITIONALLY', $this->platform->getStopDatabaseSQL('"foobar"')); | ||
| 335 |         self::assertEquals('STOP DATABASE "create" UNCONDITIONALLY', $this->platform->getStopDatabaseSQL('create')); | ||
| 336 |         self::assertEquals('TRUNCATE TABLE foobar', $this->platform->getTruncateTableSQL('foobar')); | ||
| 337 |         self::assertEquals('TRUNCATE TABLE foobar', $this->platform->getTruncateTableSQL('foobar'), true); | ||
|  | |||
| 338 | |||
| 339 | $viewSql = 'SELECT * FROM footable'; | ||
| 340 |         self::assertEquals('CREATE VIEW fooview AS ' . $viewSql, $this->platform->getCreateViewSQL('fooview', $viewSql)); | ||
| 341 |         self::assertEquals('DROP VIEW fooview', $this->platform->getDropViewSQL('fooview')); | ||
| 342 | } | ||
| 343 | |||
| 344 | public function testGeneratesPrimaryKeyDeclarationSQL() : void | ||
| 357 | ) | ||
| 358 | ); | ||
| 359 | } | ||
| 360 | |||
| 361 | public function testCannotGeneratePrimaryKeyDeclarationSQLWithEmptyColumns() : void | ||
| 362 |     { | ||
| 363 | $this->expectException(InvalidArgumentException::class); | ||
| 364 | |||
| 365 |         $this->platform->getPrimaryKeyDeclarationSQL(new Index('pk', [], true, true)); | ||
| 366 | } | ||
| 367 | |||
| 368 | public function testGeneratesCreateUnnamedPrimaryKeySQL() : void | ||
| 369 |     { | ||
| 370 | self::assertEquals( | ||
| 371 | 'ALTER TABLE foo ADD PRIMARY KEY CLUSTERED (a, b)', | ||
| 372 | $this->platform->getCreatePrimaryKeySQL( | ||
| 373 |                 new Index('pk', ['a', 'b'], true, true, ['clustered']), | ||
| 374 | 'foo' | ||
| 375 | ) | ||
| 376 | ); | ||
| 377 | self::assertEquals( | ||
| 378 | 'ALTER TABLE foo ADD PRIMARY KEY (a, b)', | ||
| 379 | $this->platform->getCreatePrimaryKeySQL( | ||
| 380 |                 new Index('any_pk_name', ['a', 'b'], true, true), | ||
| 381 |                 new Table('foo') | ||
| 382 | ) | ||
| 383 | ); | ||
| 384 | } | ||
| 385 | |||
| 386 | public function testGeneratesUniqueConstraintDeclarationSQL() : void | ||
| 387 |     { | ||
| 388 | self::assertEquals( | ||
| 389 | 'CONSTRAINT unique_constraint UNIQUE CLUSTERED (a, b)', | ||
| 390 | $this->platform->getUniqueConstraintDeclarationSQL( | ||
| 391 | 'unique_constraint', | ||
| 392 | new UniqueConstraint(null, ['a', 'b'], ['clustered']) | ||
| 393 | ) | ||
| 394 | ); | ||
| 395 | self::assertEquals( | ||
| 396 | 'CONSTRAINT UNIQUE (a, b)', | ||
| 397 | $this->platform->getUniqueConstraintDeclarationSQL(null, new UniqueConstraint(null, ['a', 'b'])) | ||
| 398 | ); | ||
| 399 | } | ||
| 400 | |||
| 401 | public function testCannotGenerateUniqueConstraintDeclarationSQLWithEmptyColumns() : void | ||
| 402 |     { | ||
| 403 | $this->expectException(InvalidArgumentException::class); | ||
| 404 | |||
| 405 |         $this->platform->getUniqueConstraintDeclarationSQL('constr', new UniqueConstraint('constr', [])); | ||
| 406 | } | ||
| 407 | |||
| 408 | public function testGeneratesForeignKeyConstraintsWithAdvancedPlatformOptionsSQL() : void | ||
| 409 |     { | ||
| 410 | self::assertEquals( | ||
| 411 | 'CONSTRAINT fk ' . | ||
| 412 | 'NOT NULL FOREIGN KEY (a, b) ' . | ||
| 413 | 'REFERENCES foreign_table (c, d) ' . | ||
| 414 | 'MATCH UNIQUE SIMPLE ON UPDATE CASCADE ON DELETE SET NULL CHECK ON COMMIT CLUSTERED FOR OLAP WORKLOAD', | ||
| 415 | $this->platform->getForeignKeyDeclarationSQL( | ||
| 416 | new ForeignKeyConstraint(['a', 'b'], 'foreign_table', ['c', 'd'], 'fk', [ | ||
| 417 | 'notnull' => true, | ||
| 418 | 'match' => SQLAnywherePlatform::FOREIGN_KEY_MATCH_SIMPLE_UNIQUE, | ||
| 419 | 'onUpdate' => 'CASCADE', | ||
| 420 | 'onDelete' => 'SET NULL', | ||
| 421 | 'check_on_commit' => true, | ||
| 422 | 'clustered' => true, | ||
| 423 | 'for_olap_workload' => true, | ||
| 424 | ]) | ||
| 425 | ) | ||
| 426 | ); | ||
| 427 | self::assertEquals( | ||
| 428 | 'FOREIGN KEY (a, b) REFERENCES foreign_table (c, d)', | ||
| 429 | $this->platform->getForeignKeyDeclarationSQL( | ||
| 430 | new ForeignKeyConstraint(['a', 'b'], 'foreign_table', ['c', 'd']) | ||
| 431 | ) | ||
| 432 | ); | ||
| 433 | } | ||
| 434 | |||
| 435 | public function testGeneratesForeignKeyMatchClausesSQL() : void | ||
| 436 |     { | ||
| 437 |         self::assertEquals('SIMPLE', $this->platform->getForeignKeyMatchClauseSQL(1)); | ||
| 438 |         self::assertEquals('FULL', $this->platform->getForeignKeyMatchClauseSQL(2)); | ||
| 439 |         self::assertEquals('UNIQUE SIMPLE', $this->platform->getForeignKeyMatchClauseSQL(129)); | ||
| 440 |         self::assertEquals('UNIQUE FULL', $this->platform->getForeignKeyMatchClauseSQL(130)); | ||
| 441 | } | ||
| 442 | |||
| 443 | public function testCannotGenerateInvalidForeignKeyMatchClauseSQL() : void | ||
| 444 |     { | ||
| 445 | $this->expectException(InvalidArgumentException::class); | ||
| 446 | |||
| 447 | $this->platform->getForeignKeyMatchCLauseSQL(3); | ||
| 448 | } | ||
| 449 | |||
| 450 | public function testCannotGenerateForeignKeyConstraintSQLWithEmptyLocalColumns() : void | ||
| 451 |     { | ||
| 452 | $this->expectException(InvalidArgumentException::class); | ||
| 453 | $this->platform->getForeignKeyDeclarationSQL(new ForeignKeyConstraint([], 'foreign_tbl', ['c', 'd'])); | ||
| 454 | } | ||
| 455 | |||
| 456 | public function testCannotGenerateForeignKeyConstraintSQLWithEmptyForeignColumns() : void | ||
| 457 |     { | ||
| 458 | $this->expectException(InvalidArgumentException::class); | ||
| 459 | $this->platform->getForeignKeyDeclarationSQL(new ForeignKeyConstraint(['a', 'b'], 'foreign_tbl', [])); | ||
| 460 | } | ||
| 461 | |||
| 462 | public function testCannotGenerateForeignKeyConstraintSQLWithEmptyForeignTableName() : void | ||
| 463 |     { | ||
| 464 | $this->expectException(InvalidArgumentException::class); | ||
| 465 | $this->platform->getForeignKeyDeclarationSQL(new ForeignKeyConstraint(['a', 'b'], '', ['c', 'd'])); | ||
| 466 | } | ||
| 467 | |||
| 468 | public function testCannotGenerateCommonIndexWithCreateConstraintSQL() : void | ||
| 469 |     { | ||
| 470 | $this->expectException(InvalidArgumentException::class); | ||
| 471 | |||
| 472 |         $this->platform->getCreateConstraintSQL(new Index('fooindex', []), new Table('footable')); | ||
| 473 | } | ||
| 474 | |||
| 475 | public function testCannotGenerateCustomConstraintWithCreateConstraintSQL() : void | ||
| 476 |     { | ||
| 477 | $this->expectException(InvalidArgumentException::class); | ||
| 478 | |||
| 479 | $this->platform->getCreateConstraintSQL($this->createMock(Constraint::class), 'footable'); | ||
| 480 | } | ||
| 481 | |||
| 482 | public function testGeneratesCreateIndexWithAdvancedPlatformOptionsSQL() : void | ||
| 483 |     { | ||
| 484 | self::assertEquals( | ||
| 485 | 'CREATE UNIQUE INDEX fooindex ON footable (a, b) WITH NULLS DISTINCT', | ||
| 486 | $this->platform->getCreateIndexSQL( | ||
| 487 | new Index( | ||
| 488 | 'fooindex', | ||
| 489 | ['a', 'b'], | ||
| 490 | true, | ||
| 491 | false, | ||
| 492 | ['with_nulls_distinct'] | ||
| 493 | ), | ||
| 494 | 'footable' | ||
| 495 | ) | ||
| 496 | ); | ||
| 497 | |||
| 498 | // WITH NULLS DISTINCT clause not available on primary indexes. | ||
| 499 | self::assertEquals( | ||
| 500 | 'ALTER TABLE footable ADD PRIMARY KEY (a, b)', | ||
| 501 | $this->platform->getCreateIndexSQL( | ||
| 502 | new Index( | ||
| 503 | 'fooindex', | ||
| 504 | ['a', 'b'], | ||
| 505 | false, | ||
| 506 | true, | ||
| 507 | ['with_nulls_distinct'] | ||
| 508 | ), | ||
| 509 | 'footable' | ||
| 510 | ) | ||
| 511 | ); | ||
| 512 | |||
| 513 | // WITH NULLS DISTINCT clause not available on non-unique indexes. | ||
| 514 | self::assertEquals( | ||
| 515 | 'CREATE INDEX fooindex ON footable (a, b)', | ||
| 516 | $this->platform->getCreateIndexSQL( | ||
| 517 | new Index( | ||
| 518 | 'fooindex', | ||
| 519 | ['a', 'b'], | ||
| 520 | false, | ||
| 521 | false, | ||
| 522 | ['with_nulls_distinct'] | ||
| 523 | ), | ||
| 524 | 'footable' | ||
| 525 | ) | ||
| 526 | ); | ||
| 527 | |||
| 528 | self::assertEquals( | ||
| 529 | 'CREATE VIRTUAL UNIQUE CLUSTERED INDEX fooindex ON footable (a, b) WITH NULLS NOT DISTINCT FOR OLAP WORKLOAD', | ||
| 530 | $this->platform->getCreateIndexSQL( | ||
| 531 | new Index( | ||
| 532 | 'fooindex', | ||
| 533 | ['a', 'b'], | ||
| 534 | true, | ||
| 535 | false, | ||
| 536 | ['virtual', 'clustered', 'with_nulls_not_distinct', 'for_olap_workload'] | ||
| 537 | ), | ||
| 538 | 'footable' | ||
| 539 | ) | ||
| 540 | ); | ||
| 541 | self::assertEquals( | ||
| 542 | 'CREATE VIRTUAL CLUSTERED INDEX fooindex ON footable (a, b) FOR OLAP WORKLOAD', | ||
| 543 | $this->platform->getCreateIndexSQL( | ||
| 544 | new Index( | ||
| 545 | 'fooindex', | ||
| 546 | ['a', 'b'], | ||
| 547 | false, | ||
| 548 | false, | ||
| 549 | ['virtual', 'clustered', 'with_nulls_not_distinct', 'for_olap_workload'] | ||
| 550 | ), | ||
| 551 | 'footable' | ||
| 552 | ) | ||
| 553 | ); | ||
| 554 | |||
| 555 | // WITH NULLS NOT DISTINCT clause not available on primary indexes. | ||
| 556 | self::assertEquals( | ||
| 557 | 'ALTER TABLE footable ADD PRIMARY KEY (a, b)', | ||
| 558 | $this->platform->getCreateIndexSQL( | ||
| 559 | new Index( | ||
| 560 | 'fooindex', | ||
| 561 | ['a', 'b'], | ||
| 562 | false, | ||
| 563 | true, | ||
| 564 | ['with_nulls_not_distinct'] | ||
| 565 | ), | ||
| 566 | 'footable' | ||
| 567 | ) | ||
| 568 | ); | ||
| 569 | |||
| 570 | // WITH NULLS NOT DISTINCT clause not available on non-unique indexes. | ||
| 571 | self::assertEquals( | ||
| 572 | 'CREATE INDEX fooindex ON footable (a, b)', | ||
| 573 | $this->platform->getCreateIndexSQL( | ||
| 574 | new Index( | ||
| 575 | 'fooindex', | ||
| 576 | ['a', 'b'], | ||
| 577 | false, | ||
| 578 | false, | ||
| 579 | ['with_nulls_not_distinct'] | ||
| 580 | ), | ||
| 581 | 'footable' | ||
| 582 | ) | ||
| 583 | ); | ||
| 584 | } | ||
| 585 | |||
| 586 | public function testThrowsExceptionOnInvalidWithNullsNotDistinctIndexOptions() : void | ||
| 587 |     { | ||
| 588 |         $this->expectException('UnexpectedValueException'); | ||
| 589 | |||
| 590 | $this->platform->getCreateIndexSQL( | ||
| 591 | new Index( | ||
| 592 | 'fooindex', | ||
| 593 | ['a', 'b'], | ||
| 594 | false, | ||
| 595 | false, | ||
| 596 | ['with_nulls_distinct', 'with_nulls_not_distinct'] | ||
| 597 | ), | ||
| 598 | 'footable' | ||
| 599 | ); | ||
| 600 | } | ||
| 601 | |||
| 602 | public function testDoesNotSupportIndexDeclarationInCreateAlterTableStatements() : void | ||
| 603 |     { | ||
| 604 | $this->expectException(DBALException::class); | ||
| 605 | |||
| 606 |         $this->platform->getIndexDeclarationSQL('index', new Index('index', [])); | ||
| 607 | } | ||
| 608 | |||
| 609 | public function testGeneratesDropIndexSQL() : void | ||
| 618 | )); | ||
| 619 | } | ||
| 620 | |||
| 621 | public function testCannotGenerateDropIndexSQLWithInvalidIndexParameter() : void | ||
| 622 |     { | ||
| 623 | $this->expectException(InvalidArgumentException::class); | ||
| 624 | |||
| 625 | $this->platform->getDropIndexSQL(['index'], 'table'); | ||
| 626 | } | ||
| 627 | |||
| 628 | public function testCannotGenerateDropIndexSQLWithInvalidTableParameter() : void | ||
| 629 |     { | ||
| 630 | $this->expectException(InvalidArgumentException::class); | ||
| 631 | |||
| 632 |         $this->platform->getDropIndexSQL('index', ['table']); | ||
| 633 | } | ||
| 634 | |||
| 635 | public function testGeneratesSQLSnippets() : void | ||
| 636 |     { | ||
| 637 |         self::assertEquals('STRING(column1, "string1", column2, "string2")', $this->platform->getConcatExpression( | ||
| 638 | 'column1', | ||
| 639 | '"string1"', | ||
| 640 | 'column2', | ||
| 641 | '"string2"' | ||
| 642 | )); | ||
| 643 |         self::assertEquals('CURRENT DATE', $this->platform->getCurrentDateSQL()); | ||
| 644 |         self::assertEquals('CURRENT TIME', $this->platform->getCurrentTimeSQL()); | ||
| 645 |         self::assertEquals('CURRENT TIMESTAMP', $this->platform->getCurrentTimestampSQL()); | ||
| 646 |         self::assertEquals("DATEADD(DAY, 4, '1987/05/02')", $this->platform->getDateAddDaysExpression("'1987/05/02'", 4)); | ||
| 647 |         self::assertEquals("DATEADD(HOUR, 12, '1987/05/02')", $this->platform->getDateAddHourExpression("'1987/05/02'", 12)); | ||
| 648 |         self::assertEquals("DATEADD(MINUTE, 2, '1987/05/02')", $this->platform->getDateAddMinutesExpression("'1987/05/02'", 2)); | ||
| 649 |         self::assertEquals("DATEADD(MONTH, 102, '1987/05/02')", $this->platform->getDateAddMonthExpression("'1987/05/02'", 102)); | ||
| 650 |         self::assertEquals("DATEADD(QUARTER, 5, '1987/05/02')", $this->platform->getDateAddQuartersExpression("'1987/05/02'", 5)); | ||
| 651 |         self::assertEquals("DATEADD(SECOND, 1, '1987/05/02')", $this->platform->getDateAddSecondsExpression("'1987/05/02'", 1)); | ||
| 652 |         self::assertEquals("DATEADD(WEEK, 3, '1987/05/02')", $this->platform->getDateAddWeeksExpression("'1987/05/02'", 3)); | ||
| 653 |         self::assertEquals("DATEADD(YEAR, 10, '1987/05/02')", $this->platform->getDateAddYearsExpression("'1987/05/02'", 10)); | ||
| 654 |         self::assertEquals("DATEDIFF(day, '1987/04/01', '1987/05/02')", $this->platform->getDateDiffExpression("'1987/05/02'", "'1987/04/01'")); | ||
| 655 |         self::assertEquals("DATEADD(DAY, -1 * 4, '1987/05/02')", $this->platform->getDateSubDaysExpression("'1987/05/02'", 4)); | ||
| 656 |         self::assertEquals("DATEADD(HOUR, -1 * 12, '1987/05/02')", $this->platform->getDateSubHourExpression("'1987/05/02'", 12)); | ||
| 657 |         self::assertEquals("DATEADD(MINUTE, -1 * 2, '1987/05/02')", $this->platform->getDateSubMinutesExpression("'1987/05/02'", 2)); | ||
| 658 |         self::assertEquals("DATEADD(MONTH, -1 * 102, '1987/05/02')", $this->platform->getDateSubMonthExpression("'1987/05/02'", 102)); | ||
| 659 |         self::assertEquals("DATEADD(QUARTER, -1 * 5, '1987/05/02')", $this->platform->getDateSubQuartersExpression("'1987/05/02'", 5)); | ||
| 660 |         self::assertEquals("DATEADD(SECOND, -1 * 1, '1987/05/02')", $this->platform->getDateSubSecondsExpression("'1987/05/02'", 1)); | ||
| 661 |         self::assertEquals("DATEADD(WEEK, -1 * 3, '1987/05/02')", $this->platform->getDateSubWeeksExpression("'1987/05/02'", 3)); | ||
| 662 |         self::assertEquals("DATEADD(YEAR, -1 * 10, '1987/05/02')", $this->platform->getDateSubYearsExpression("'1987/05/02'", 10)); | ||
| 663 |         self::assertEquals('Y-m-d H:i:s.u', $this->platform->getDateTimeFormatString()); | ||
| 664 |         self::assertEquals('H:i:s.u', $this->platform->getTimeFormatString()); | ||
| 665 |         self::assertEquals('', $this->platform->getForUpdateSQL()); | ||
| 666 |         self::assertEquals('LOCATE(string_column, substring_column)', $this->platform->getLocateExpression('string_column', 'substring_column')); | ||
| 667 |         self::assertEquals('LOCATE(string_column, substring_column, 2)', $this->platform->getLocateExpression('string_column', 'substring_column', 2)); | ||
| 668 |         self::assertEquals("HASH(column, 'MD5')", $this->platform->getMd5Expression('column')); | ||
| 669 |         self::assertEquals('SUBSTRING(column, 5)', $this->platform->getSubstringExpression('column', 5)); | ||
| 670 |         self::assertEquals('SUBSTRING(column, 5, 2)', $this->platform->getSubstringExpression('column', 5, 2)); | ||
| 671 |         self::assertEquals('GLOBAL TEMPORARY', $this->platform->getTemporaryTableSQL()); | ||
| 672 | self::assertEquals( | ||
| 673 | 'LTRIM(column)', | ||
| 674 |             $this->platform->getTrimExpression('column', TrimMode::LEADING) | ||
| 675 | ); | ||
| 676 | self::assertEquals( | ||
| 677 | 'RTRIM(column)', | ||
| 678 |             $this->platform->getTrimExpression('column', TrimMode::TRAILING) | ||
| 679 | ); | ||
| 680 | self::assertEquals( | ||
| 681 | 'TRIM(column)', | ||
| 682 |             $this->platform->getTrimExpression('column') | ||
| 683 | ); | ||
| 684 | self::assertEquals( | ||
| 685 | 'TRIM(column)', | ||
| 686 |             $this->platform->getTrimExpression('column', TrimMode::UNSPECIFIED) | ||
| 687 | ); | ||
| 688 | self::assertEquals( | ||
| 689 |             "SUBSTR(column, PATINDEX('%[^' + c + ']%', column))", | ||
| 690 |             $this->platform->getTrimExpression('column', TrimMode::LEADING, 'c') | ||
| 691 | ); | ||
| 692 | self::assertEquals( | ||
| 693 |             "REVERSE(SUBSTR(REVERSE(column), PATINDEX('%[^' + c + ']%', REVERSE(column))))", | ||
| 694 |             $this->platform->getTrimExpression('column', TrimMode::TRAILING, 'c') | ||
| 695 | ); | ||
| 696 | self::assertEquals( | ||
| 697 |             "REVERSE(SUBSTR(REVERSE(SUBSTR(column, PATINDEX('%[^' + c + ']%', column))), PATINDEX('%[^' + c + ']%', " . | ||
| 698 |             "REVERSE(SUBSTR(column, PATINDEX('%[^' + c + ']%', column))))))", | ||
| 699 |             $this->platform->getTrimExpression('column', TrimMode::UNSPECIFIED, 'c') | ||
| 700 | ); | ||
| 701 | } | ||
| 702 | |||
| 703 | public function testHasCorrectDateTimeTzFormatString() : void | ||
| 704 |     { | ||
| 705 |         self::assertEquals('Y-m-d H:i:s.uP', $this->platform->getDateTimeTzFormatString()); | ||
| 706 | } | ||
| 707 | |||
| 708 | public function testGeneratesDateTimeTzColumnTypeDeclarationSQL() : void | ||
| 709 |     { | ||
| 710 | self::assertEquals( | ||
| 711 | 'TIMESTAMP WITH TIME ZONE', | ||
| 712 | $this->platform->getDateTimeTzTypeDeclarationSQL([ | ||
| 713 | 'length' => 10, | ||
| 714 | 'fixed' => true, | ||
| 715 | 'unsigned' => true, | ||
| 716 | 'autoincrement' => true, | ||
| 717 | ]) | ||
| 718 | ); | ||
| 719 | } | ||
| 720 | |||
| 721 | public function testInitializesDateTimeTzTypeMapping() : void | ||
| 725 | } | ||
| 726 | |||
| 727 | public function testHasCorrectDefaultTransactionIsolationLevel() : void | ||
| 728 |     { | ||
| 729 | self::assertEquals( | ||
| 730 | TransactionIsolationLevel::READ_UNCOMMITTED, | ||
| 731 | $this->platform->getDefaultTransactionIsolationLevel() | ||
| 732 | ); | ||
| 733 | } | ||
| 734 | |||
| 735 | public function testGeneratesTransactionsCommands() : void | ||
| 736 |     { | ||
| 737 | self::assertEquals( | ||
| 738 | 'SET TEMPORARY OPTION isolation_level = 0', | ||
| 739 | $this->platform->getSetTransactionIsolationSQL(TransactionIsolationLevel::READ_UNCOMMITTED) | ||
| 740 | ); | ||
| 741 | self::assertEquals( | ||
| 742 | 'SET TEMPORARY OPTION isolation_level = 1', | ||
| 743 | $this->platform->getSetTransactionIsolationSQL(TransactionIsolationLevel::READ_COMMITTED) | ||
| 744 | ); | ||
| 745 | self::assertEquals( | ||
| 746 | 'SET TEMPORARY OPTION isolation_level = 2', | ||
| 747 | $this->platform->getSetTransactionIsolationSQL(TransactionIsolationLevel::REPEATABLE_READ) | ||
| 748 | ); | ||
| 749 | self::assertEquals( | ||
| 750 | 'SET TEMPORARY OPTION isolation_level = 3', | ||
| 751 | $this->platform->getSetTransactionIsolationSQL(TransactionIsolationLevel::SERIALIZABLE) | ||
| 752 | ); | ||
| 753 | } | ||
| 754 | |||
| 755 | public function testModifiesLimitQuery() : void | ||
| 760 | ); | ||
| 761 | } | ||
| 762 | |||
| 763 | public function testModifiesLimitQueryWithEmptyOffset() : void | ||
| 764 |     { | ||
| 765 | self::assertEquals( | ||
| 766 | 'SELECT TOP 10 * FROM user', | ||
| 767 |             $this->platform->modifyLimitQuery('SELECT * FROM user', 10) | ||
| 768 | ); | ||
| 769 | } | ||
| 770 | |||
| 771 | public function testModifiesLimitQueryWithOffset() : void | ||
| 772 |     { | ||
| 773 | self::assertEquals( | ||
| 774 | 'SELECT TOP 10 START AT 6 * FROM user', | ||
| 775 |             $this->platform->modifyLimitQuery('SELECT * FROM user', 10, 5) | ||
| 776 | ); | ||
| 777 | self::assertEquals( | ||
| 778 | 'SELECT TOP 0 START AT 6 * FROM user', | ||
| 779 |             $this->platform->modifyLimitQuery('SELECT * FROM user', 0, 5) | ||
| 780 | ); | ||
| 781 | } | ||
| 782 | |||
| 783 | public function testModifiesLimitQueryWithSubSelect() : void | ||
| 788 | ); | ||
| 789 | } | ||
| 790 | |||
| 791 | public function testModifiesLimitQueryWithoutLimit() : void | ||
| 792 |     { | ||
| 793 | self::assertEquals( | ||
| 794 | 'SELECT TOP ALL START AT 11 n FROM Foo', | ||
| 795 |             $this->platform->modifyLimitQuery('SELECT n FROM Foo', null, 10) | ||
| 796 | ); | ||
| 797 | } | ||
| 798 | |||
| 799 | public function testPrefersIdentityColumns() : void | ||
| 800 |     { | ||
| 801 | self::assertTrue($this->platform->prefersIdentityColumns()); | ||
| 802 | } | ||
| 803 | |||
| 804 | public function testDoesNotPreferSequences() : void | ||
| 805 |     { | ||
| 806 | self::assertFalse($this->platform->prefersSequences()); | ||
| 807 | } | ||
| 808 | |||
| 809 | public function testSupportsIdentityColumns() : void | ||
| 810 |     { | ||
| 811 | self::assertTrue($this->platform->supportsIdentityColumns()); | ||
| 812 | } | ||
| 813 | |||
| 814 | public function testSupportsPrimaryConstraints() : void | ||
| 815 |     { | ||
| 816 | self::assertTrue($this->platform->supportsPrimaryConstraints()); | ||
| 817 | } | ||
| 818 | |||
| 819 | public function testSupportsForeignKeyConstraints() : void | ||
| 820 |     { | ||
| 821 | self::assertTrue($this->platform->supportsForeignKeyConstraints()); | ||
| 822 | } | ||
| 823 | |||
| 824 | public function testSupportsForeignKeyOnUpdate() : void | ||
| 827 | } | ||
| 828 | |||
| 829 | public function testSupportsAlterTable() : void | ||
| 830 |     { | ||
| 831 | self::assertTrue($this->platform->supportsAlterTable()); | ||
| 832 | } | ||
| 833 | |||
| 834 | public function testSupportsTransactions() : void | ||
| 835 |     { | ||
| 836 | self::assertTrue($this->platform->supportsTransactions()); | ||
| 837 | } | ||
| 838 | |||
| 839 | public function testSupportsSchemas() : void | ||
| 840 |     { | ||
| 841 | self::assertFalse($this->platform->supportsSchemas()); | ||
| 842 | } | ||
| 843 | |||
| 844 | public function testSupportsIndexes() : void | ||
| 845 |     { | ||
| 846 | self::assertTrue($this->platform->supportsIndexes()); | ||
| 847 | } | ||
| 848 | |||
| 849 | public function testSupportsCommentOnStatement() : void | ||
| 850 |     { | ||
| 851 | self::assertTrue($this->platform->supportsCommentOnStatement()); | ||
| 852 | } | ||
| 853 | |||
| 854 | public function testSupportsSavePoints() : void | ||
| 855 |     { | ||
| 856 | self::assertTrue($this->platform->supportsSavepoints()); | ||
| 857 | } | ||
| 858 | |||
| 859 | public function testSupportsReleasePoints() : void | ||
| 860 |     { | ||
| 861 | self::assertTrue($this->platform->supportsReleaseSavepoints()); | ||
| 862 | } | ||
| 863 | |||
| 864 | public function testSupportsCreateDropDatabase() : void | ||
| 865 |     { | ||
| 866 | self::assertTrue($this->platform->supportsCreateDropDatabase()); | ||
| 867 | } | ||
| 868 | |||
| 869 | public function testSupportsGettingAffectedRows() : void | ||
| 870 |     { | ||
| 871 | self::assertTrue($this->platform->supportsGettingAffectedRows()); | ||
| 872 | } | ||
| 873 | |||
| 874 | public function testDoesNotSupportSequences() : void | ||
| 875 |     { | ||
| 876 |         self::markTestSkipped('This version of the platform now supports sequences.'); | ||
| 877 | } | ||
| 878 | |||
| 879 | public function testSupportsSequences() : void | ||
| 880 |     { | ||
| 881 | self::assertTrue($this->platform->supportsSequences()); | ||
| 882 | } | ||
| 883 | |||
| 884 | public function testGeneratesSequenceSqlCommands() : void | ||
| 910 | ); | ||
| 911 | } | ||
| 912 | |||
| 913 | public function testDoesNotSupportInlineColumnComments() : void | ||
| 914 |     { | ||
| 915 | self::assertFalse($this->platform->supportsInlineColumnComments()); | ||
| 916 | } | ||
| 917 | |||
| 918 | public function testCannotEmulateSchemas() : void | ||
| 919 |     { | ||
| 920 | self::assertFalse($this->platform->canEmulateSchemas()); | ||
| 921 | } | ||
| 922 | |||
| 923 | public function testInitializesDoctrineTypeMappings() : void | ||
| 924 |     { | ||
| 925 |         self::assertTrue($this->platform->hasDoctrineTypeMappingFor('integer')); | ||
| 926 |         self::assertSame('integer', $this->platform->getDoctrineTypeMapping('integer')); | ||
| 927 | |||
| 928 |         self::assertTrue($this->platform->hasDoctrineTypeMappingFor('binary')); | ||
| 929 |         self::assertSame('binary', $this->platform->getDoctrineTypeMapping('binary')); | ||
| 930 | |||
| 931 |         self::assertTrue($this->platform->hasDoctrineTypeMappingFor('varbinary')); | ||
| 932 |         self::assertSame('binary', $this->platform->getDoctrineTypeMapping('varbinary')); | ||
| 933 | } | ||
| 934 | |||
| 935 | protected function getBinaryDefaultLength() : int | ||
| 936 |     { | ||
| 937 | return 1; | ||
| 938 | } | ||
| 939 | |||
| 940 | protected function getBinaryMaxLength() : int | ||
| 941 |     { | ||
| 942 | return 32767; | ||
| 943 | } | ||
| 944 | |||
| 945 | public function testReturnsBinaryTypeDeclarationSQL() : void | ||
| 946 |     { | ||
| 947 |         self::assertSame('VARBINARY(1)', $this->platform->getBinaryTypeDeclarationSQL([])); | ||
| 948 |         self::assertSame('VARBINARY(1)', $this->platform->getBinaryTypeDeclarationSQL(['length' => 0])); | ||
| 949 |         self::assertSame('VARBINARY(32767)', $this->platform->getBinaryTypeDeclarationSQL(['length' => 32767])); | ||
| 950 | |||
| 951 |         self::assertSame('BINARY(1)', $this->platform->getBinaryTypeDeclarationSQL(['fixed' => true])); | ||
| 952 |         self::assertSame('BINARY(1)', $this->platform->getBinaryTypeDeclarationSQL([ | ||
| 953 | 'fixed' => true, | ||
| 954 | 'length' => 0, | ||
| 955 | ])); | ||
| 956 |         self::assertSame('BINARY(32767)', $this->platform->getBinaryTypeDeclarationSQL([ | ||
| 957 | 'fixed' => true, | ||
| 958 | 'length' => 32767, | ||
| 959 | ])); | ||
| 960 | } | ||
| 961 | |||
| 962 | /** | ||
| 963 |      * {@inheritDoc} | ||
| 964 | * | ||
| 965 | * @group DBAL-234 | ||
| 966 | */ | ||
| 967 | protected function getAlterTableRenameIndexSQL() : array | ||
| 968 |     { | ||
| 969 | return ['ALTER INDEX idx_foo ON mytable RENAME TO idx_bar']; | ||
| 970 | } | ||
| 971 | |||
| 972 | /** | ||
| 973 |      * {@inheritDoc} | ||
| 974 | * | ||
| 975 | * @group DBAL-234 | ||
| 976 | */ | ||
| 977 | protected function getQuotedAlterTableRenameIndexSQL() : array | ||
| 978 |     { | ||
| 979 | return [ | ||
| 980 | 'ALTER INDEX "create" ON "table" RENAME TO "select"', | ||
| 981 | 'ALTER INDEX "foo" ON "table" RENAME TO "bar"', | ||
| 982 | ]; | ||
| 983 | } | ||
| 984 | |||
| 985 | /** | ||
| 986 |      * {@inheritdoc} | ||
| 987 | */ | ||
| 988 | protected function getQuotedAlterTableRenameColumnSQL() : array | ||
| 989 |     { | ||
| 990 | return [ | ||
| 991 | 'ALTER TABLE mytable RENAME unquoted1 TO unquoted', | ||
| 992 | 'ALTER TABLE mytable RENAME unquoted2 TO "where"', | ||
| 993 | 'ALTER TABLE mytable RENAME unquoted3 TO "foo"', | ||
| 994 | 'ALTER TABLE mytable RENAME "create" TO reserved_keyword', | ||
| 995 | 'ALTER TABLE mytable RENAME "table" TO "from"', | ||
| 996 | 'ALTER TABLE mytable RENAME "select" TO "bar"', | ||
| 997 | 'ALTER TABLE mytable RENAME quoted1 TO quoted', | ||
| 998 | 'ALTER TABLE mytable RENAME quoted2 TO "and"', | ||
| 999 | 'ALTER TABLE mytable RENAME quoted3 TO "baz"', | ||
| 1000 | ]; | ||
| 1001 | } | ||
| 1002 | |||
| 1003 | /** | ||
| 1004 |      * {@inheritdoc} | ||
| 1005 | */ | ||
| 1006 | protected function getQuotedAlterTableChangeColumnLengthSQL() : array | ||
| 1007 |     { | ||
| 1008 |         $this->markTestIncomplete('Not implemented yet'); | ||
| 1009 | } | ||
| 1010 | |||
| 1011 | /** | ||
| 1012 |      * {@inheritDoc} | ||
| 1013 | * | ||
| 1014 | * @group DBAL-807 | ||
| 1015 | */ | ||
| 1016 | protected function getAlterTableRenameIndexInSchemaSQL() : array | ||
| 1017 |     { | ||
| 1018 | return ['ALTER INDEX idx_foo ON myschema.mytable RENAME TO idx_bar']; | ||
| 1019 | } | ||
| 1020 | |||
| 1021 | /** | ||
| 1022 |      * {@inheritDoc} | ||
| 1023 | * | ||
| 1024 | * @group DBAL-807 | ||
| 1025 | */ | ||
| 1026 | protected function getQuotedAlterTableRenameIndexInSchemaSQL() : array | ||
| 1027 |     { | ||
| 1028 | return [ | ||
| 1029 | 'ALTER INDEX "create" ON "schema"."table" RENAME TO "select"', | ||
| 1030 | 'ALTER INDEX "foo" ON "schema"."table" RENAME TO "bar"', | ||
| 1031 | ]; | ||
| 1032 | } | ||
| 1033 | |||
| 1034 | /** | ||
| 1035 | * @group DBAL-423 | ||
| 1036 | */ | ||
| 1037 | public function testReturnsGuidTypeDeclarationSQL() : void | ||
| 1038 |     { | ||
| 1039 |         self::assertSame('UNIQUEIDENTIFIER', $this->platform->getGuidTypeDeclarationSQL([])); | ||
| 1040 | } | ||
| 1041 | |||
| 1042 | /** | ||
| 1043 |      * {@inheritdoc} | ||
| 1044 | */ | ||
| 1045 | public function getAlterTableRenameColumnSQL() : array | ||
| 1046 |     { | ||
| 1047 | return ['ALTER TABLE foo RENAME bar TO baz']; | ||
| 1048 | } | ||
| 1049 | |||
| 1050 | /** | ||
| 1051 |      * {@inheritdoc} | ||
| 1052 | */ | ||
| 1053 | protected function getQuotesTableIdentifiersInAlterTableSQL() : array | ||
| 1054 |     { | ||
| 1055 | return [ | ||
| 1056 | 'ALTER TABLE "foo" DROP FOREIGN KEY fk1', | ||
| 1057 | 'ALTER TABLE "foo" DROP FOREIGN KEY fk2', | ||
| 1058 | 'ALTER TABLE "foo" RENAME id TO war', | ||
| 1059 | 'ALTER TABLE "foo" ADD bloo INT NOT NULL, DROP baz, ALTER bar INT DEFAULT NULL', | ||
| 1060 | 'ALTER TABLE "foo" RENAME "table"', | ||
| 1061 | 'ALTER TABLE "table" ADD CONSTRAINT fk_add FOREIGN KEY (fk3) REFERENCES fk_table (id)', | ||
| 1062 | 'ALTER TABLE "table" ADD CONSTRAINT fk2 FOREIGN KEY (fk2) REFERENCES fk_table2 (id)', | ||
| 1063 | ]; | ||
| 1064 | } | ||
| 1065 | |||
| 1066 | /** | ||
| 1067 |      * {@inheritdoc} | ||
| 1068 | */ | ||
| 1069 | protected function getCommentOnColumnSQL() : array | ||
| 1070 |     { | ||
| 1071 | return [ | ||
| 1072 | 'COMMENT ON COLUMN foo.bar IS \'comment\'', | ||
| 1073 | 'COMMENT ON COLUMN "Foo"."BAR" IS \'comment\'', | ||
| 1074 | 'COMMENT ON COLUMN "select"."from" IS \'comment\'', | ||
| 1075 | ]; | ||
| 1076 | } | ||
| 1077 | |||
| 1078 | /** | ||
| 1079 | * @group DBAL-1004 | ||
| 1080 | */ | ||
| 1081 | public function testAltersTableColumnCommentWithExplicitlyQuotedIdentifiers() : void | ||
| 1082 |     { | ||
| 1083 |         $table1 = new Table('"foo"', [new Column('"bar"', Type::getType('integer'))]); | ||
| 1084 |         $table2 = new Table('"foo"', [new Column('"bar"', Type::getType('integer'), ['comment' => 'baz'])]); | ||
| 1085 | |||
| 1086 | $comparator = new Comparator(); | ||
| 1087 | |||
| 1088 | $tableDiff = $comparator->diffTable($table1, $table2); | ||
| 1089 | |||
| 1090 | self::assertInstanceOf(TableDiff::class, $tableDiff); | ||
| 1091 | self::assertSame( | ||
| 1092 | ['COMMENT ON COLUMN "foo"."bar" IS \'baz\''], | ||
| 1093 | $this->platform->getAlterTableSQL($tableDiff) | ||
| 1094 | ); | ||
| 1095 | } | ||
| 1096 | |||
| 1097 | /** | ||
| 1098 |      * {@inheritdoc} | ||
| 1099 | */ | ||
| 1100 | public static function getReturnsForeignKeyReferentialActionSQL() : iterable | ||
| 1101 |     { | ||
| 1102 | return [ | ||
| 1103 | ['CASCADE', 'CASCADE'], | ||
| 1104 | ['SET NULL', 'SET NULL'], | ||
| 1105 | ['NO ACTION', 'RESTRICT'], | ||
| 1106 | ['RESTRICT', 'RESTRICT'], | ||
| 1107 | ['SET DEFAULT', 'SET DEFAULT'], | ||
| 1108 | ['CaScAdE', 'CASCADE'], | ||
| 1109 | ]; | ||
| 1110 | } | ||
| 1111 | |||
| 1112 | /** | ||
| 1113 |      * {@inheritdoc} | ||
| 1114 | */ | ||
| 1115 | protected function getQuotesReservedKeywordInUniqueConstraintDeclarationSQL() : string | ||
| 1116 |     { | ||
| 1117 | return 'CONSTRAINT "select" UNIQUE (foo)'; | ||
| 1118 | } | ||
| 1119 | |||
| 1120 | /** | ||
| 1121 |      * {@inheritdoc} | ||
| 1122 | */ | ||
| 1123 | protected function getQuotesReservedKeywordInIndexDeclarationSQL() : string | ||
| 1124 |     { | ||
| 1125 | return ''; // not supported by this platform | ||
| 1126 | } | ||
| 1127 | |||
| 1128 | /** | ||
| 1129 |      * {@inheritdoc} | ||
| 1130 | */ | ||
| 1131 | protected function getQuotesReservedKeywordInTruncateTableSQL() : string | ||
| 1132 |     { | ||
| 1133 | return 'TRUNCATE TABLE "select"'; | ||
| 1134 | } | ||
| 1135 | |||
| 1136 | /** | ||
| 1137 |      * {@inheritdoc} | ||
| 1138 | */ | ||
| 1139 | protected function supportsInlineIndexDeclaration() : bool | ||
| 1140 |     { | ||
| 1141 | return false; | ||
| 1142 | } | ||
| 1143 | |||
| 1144 | /** | ||
| 1145 |      * {@inheritdoc} | ||
| 1146 | */ | ||
| 1147 | protected function getAlterStringToFixedStringSQL() : array | ||
| 1148 |     { | ||
| 1149 | return ['ALTER TABLE mytable ALTER name CHAR(2) NOT NULL']; | ||
| 1150 | } | ||
| 1151 | |||
| 1152 | /** | ||
| 1153 |      * {@inheritdoc} | ||
| 1154 | */ | ||
| 1155 | protected function getGeneratesAlterTableRenameIndexUsedByForeignKeySQL() : array | ||
| 1156 |     { | ||
| 1157 | return ['ALTER INDEX idx_foo ON mytable RENAME TO idx_foo_renamed']; | ||
| 1158 | } | ||
| 1159 | |||
| 1160 | /** | ||
| 1161 | * @group DBAL-2436 | ||
| 1162 | */ | ||
| 1163 | public function testQuotesSchemaNameInListTableColumnsSQL() : void | ||
| 1164 |     { | ||
| 1165 | self::assertStringContainsStringIgnoringCase( | ||
| 1166 | "'Foo''Bar\\'", | ||
| 1167 |             $this->platform->getListTableColumnsSQL("Foo'Bar\\.baz_table") | ||
| 1168 | ); | ||
| 1169 | } | ||
| 1170 | |||
| 1171 | /** | ||
| 1172 | * @group DBAL-2436 | ||
| 1173 | */ | ||
| 1174 | public function testQuotesTableNameInListTableConstraintsSQL() : void | ||
| 1175 |     { | ||
| 1176 |         self::assertStringContainsStringIgnoringCase("'Foo''Bar\\'", $this->platform->getListTableConstraintsSQL("Foo'Bar\\"), '', true); | ||
| 1177 | } | ||
| 1178 | |||
| 1179 | /** | ||
| 1180 | * @group DBAL-2436 | ||
| 1181 | */ | ||
| 1182 | public function testQuotesSchemaNameInListTableConstraintsSQL() : void | ||
| 1183 |     { | ||
| 1184 | self::assertStringContainsStringIgnoringCase( | ||
| 1185 | "'Foo''Bar\\'", | ||
| 1186 |             $this->platform->getListTableConstraintsSQL("Foo'Bar\\.baz_table") | ||
| 1187 | ); | ||
| 1188 | } | ||
| 1189 | |||
| 1190 | /** | ||
| 1191 | * @group DBAL-2436 | ||
| 1192 | */ | ||
| 1193 | public function testQuotesTableNameInListTableForeignKeysSQL() : void | ||
| 1194 |     { | ||
| 1195 | self::assertStringContainsStringIgnoringCase( | ||
| 1196 | "'Foo''Bar\\'", | ||
| 1197 |             $this->platform->getListTableForeignKeysSQL("Foo'Bar\\") | ||
| 1198 | ); | ||
| 1199 | } | ||
| 1200 | |||
| 1201 | /** | ||
| 1202 | * @group DBAL-2436 | ||
| 1203 | */ | ||
| 1204 | public function testQuotesSchemaNameInListTableForeignKeysSQL() : void | ||
| 1205 |     { | ||
| 1206 | self::assertStringContainsStringIgnoringCase( | ||
| 1207 | "'Foo''Bar\\'", | ||
| 1208 |             $this->platform->getListTableForeignKeysSQL("Foo'Bar\\.baz_table") | ||
| 1209 | ); | ||
| 1210 | } | ||
| 1211 | |||
| 1212 | /** | ||
| 1213 | * @group DBAL-2436 | ||
| 1214 | */ | ||
| 1215 | public function testQuotesTableNameInListTableIndexesSQL() : void | ||
| 1220 | ); | ||
| 1221 | } | ||
| 1222 | |||
| 1223 | /** | ||
| 1224 | * @group DBAL-2436 | ||
| 1225 | */ | ||
| 1226 | public function testQuotesSchemaNameInListTableIndexesSQL() : void | ||
| 1227 |     { | ||
| 1228 | self::assertStringContainsStringIgnoringCase( | ||
| 1229 | "'Foo''Bar\\'", | ||
| 1230 |             $this->platform->getListTableIndexesSQL("Foo'Bar\\.baz_table") | ||
| 1231 | ); | ||
| 1232 | } | ||
| 1233 | } | ||
| 1234 |