Failed Conditions
Push — develop ( 776429...7c38e8 )
by Sergei
64:07 queued 10s
created

testModifiesLimitQueryWithoutLimit()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Doctrine\Tests\DBAL\Platforms;
4
5
use Doctrine\DBAL\DBALException;
6
use Doctrine\DBAL\LockMode;
7
use Doctrine\DBAL\Platforms\AbstractPlatform;
8
use Doctrine\DBAL\Platforms\SQLAnywherePlatform;
9
use Doctrine\DBAL\Platforms\TrimMode;
10
use Doctrine\DBAL\Schema\Column;
11
use Doctrine\DBAL\Schema\ColumnDiff;
12
use Doctrine\DBAL\Schema\Comparator;
13
use Doctrine\DBAL\Schema\Constraint;
14
use Doctrine\DBAL\Schema\ForeignKeyConstraint;
15
use Doctrine\DBAL\Schema\Index;
16
use Doctrine\DBAL\Schema\Sequence;
17
use Doctrine\DBAL\Schema\Table;
18
use Doctrine\DBAL\Schema\TableDiff;
19
use Doctrine\DBAL\Schema\UniqueConstraint;
20
use Doctrine\DBAL\TransactionIsolationLevel;
21
use Doctrine\DBAL\Types\Type;
22
use InvalidArgumentException;
23
use function mt_rand;
24
use function strlen;
25
use function substr;
26
27
class SQLAnywherePlatformTest extends AbstractPlatformTestCase
28
{
29
    /** @var SQLAnywherePlatform */
30
    protected $platform;
31
32
    public function createPlatform()
33
    {
34
        return new SQLAnywherePlatform();
35
    }
36
37
    public function getGenerateAlterTableSql()
38
    {
39
        return [
40
            "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",
41
            'ALTER TABLE mytable RENAME userlist',
42
        ];
43
    }
44
45
    public function getGenerateForeignKeySql()
46
    {
47
        return 'ALTER TABLE test ADD FOREIGN KEY (fk_name_id) REFERENCES other_table (id)';
48
    }
49
50
    public function getGenerateIndexSql()
51
    {
52
        return 'CREATE INDEX my_idx ON mytable (user_name, last_login)';
53
    }
54
55
    public function getGenerateTableSql()
56
    {
57
        return 'CREATE TABLE test (id INT IDENTITY NOT NULL, test VARCHAR(255) DEFAULT NULL, PRIMARY KEY (id))';
58
    }
59
60
    public function getGenerateTableWithMultiColumnUniqueIndexSql()
61
    {
62
        return [
63
            'CREATE TABLE test (foo VARCHAR(255) DEFAULT NULL, bar VARCHAR(255) DEFAULT NULL)',
64
            'CREATE UNIQUE INDEX UNIQ_D87F7E0C8C73652176FF8CAA ON test (foo, bar)',
65
        ];
66
    }
67
68
    public function getGenerateUniqueIndexSql()
69
    {
70
        return 'CREATE UNIQUE INDEX index_name ON test (test, test2)';
71
    }
72
73
    protected function getQuotedColumnInForeignKeySQL()
74
    {
75
        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"))'];
76
    }
77
78
    protected function getQuotedColumnInIndexSQL()
79
    {
80
        return [
81
            'CREATE TABLE "quoted" ("create" VARCHAR(255) NOT NULL)',
82
            'CREATE INDEX IDX_22660D028FD6E0FB ON "quoted" ("create")',
83
        ];
84
    }
85
86
    protected function getQuotedNameInIndexSQL()
87
    {
88
        return [
89
            'CREATE TABLE test (column1 VARCHAR(255) NOT NULL)',
90
            'CREATE INDEX "key" ON test (column1)',
91
        ];
92
    }
93
94
    protected function getQuotedColumnInPrimaryKeySQL()
95
    {
96
        return ['CREATE TABLE "quoted" ("create" VARCHAR(255) NOT NULL, PRIMARY KEY ("create"))'];
97
    }
98
99
    public function getCreateTableColumnCommentsSQL()
100
    {
101
        return [
102
            'CREATE TABLE test (id INT NOT NULL, PRIMARY KEY (id))',
103
            "COMMENT ON COLUMN test.id IS 'This is a comment'",
104
        ];
105
    }
106
107
    public function getAlterTableColumnCommentsSQL()
108
    {
109
        return [
110
            'ALTER TABLE mytable ADD quota INT NOT NULL',
111
            "COMMENT ON COLUMN mytable.quota IS 'A comment'",
112
            'COMMENT ON COLUMN mytable.foo IS NULL',
113
            "COMMENT ON COLUMN mytable.baz IS 'B comment'",
114
        ];
115
    }
116
117
    public function getCreateTableColumnTypeCommentsSQL()
118
    {
119
        return [
120
            'CREATE TABLE test (id INT NOT NULL, data TEXT NOT NULL, PRIMARY KEY (id))',
121
            "COMMENT ON COLUMN test.data IS '(DC2Type:array)'",
122
        ];
123
    }
124
125
    public function testHasCorrectPlatformName()
126
    {
127
        self::assertEquals('sqlanywhere', $this->platform->getName());
128
    }
129
130
    public function testGeneratesCreateTableSQLWithCommonIndexes()
131
    {
132
        $table = new Table('test');
133
        $table->addColumn('id', 'integer');
134
        $table->addColumn('name', 'string', ['length' => 50]);
135
        $table->setPrimaryKey(['id']);
136
        $table->addIndex(['name']);
137
        $table->addIndex(['id', 'name'], 'composite_idx');
138
139
        self::assertEquals(
140
            [
141
                'CREATE TABLE test (id INT NOT NULL, name VARCHAR(50) NOT NULL, PRIMARY KEY (id))',
142
                'CREATE INDEX IDX_D87F7E0C5E237E06 ON test (name)',
143
                'CREATE INDEX composite_idx ON test (id, name)',
144
            ],
145
            $this->platform->getCreateTableSQL($table)
146
        );
147
    }
148
149
    public function testGeneratesCreateTableSQLWithForeignKeyConstraints()
150
    {
151
        $table = new Table('test');
152
        $table->addColumn('id', 'integer');
153
        $table->addColumn('fk_1', 'integer');
154
        $table->addColumn('fk_2', 'integer');
155
        $table->setPrimaryKey(['id']);
156
        $table->addForeignKeyConstraint('foreign_table', ['fk_1', 'fk_2'], ['pk_1', 'pk_2']);
157
        $table->addForeignKeyConstraint(
158
            'foreign_table2',
159
            ['fk_1', 'fk_2'],
160
            ['pk_1', 'pk_2'],
161
            [],
162
            'named_fk'
163
        );
164
165
        self::assertEquals(
166
            ['CREATE TABLE test (id INT NOT NULL, fk_1 INT NOT NULL, fk_2 INT NOT NULL, ' .
167
                'CONSTRAINT FK_D87F7E0C177612A38E7F4319 FOREIGN KEY (fk_1, fk_2) REFERENCES foreign_table (pk_1, pk_2), ' .
168
                'CONSTRAINT named_fk FOREIGN KEY (fk_1, fk_2) REFERENCES foreign_table2 (pk_1, pk_2))',
169
            ],
170
            $this->platform->getCreateTableSQL($table, AbstractPlatform::CREATE_FOREIGNKEYS)
171
        );
172
    }
173
174
    public function testGeneratesCreateTableSQLWithCheckConstraints()
175
    {
176
        $table = new Table('test');
177
        $table->addColumn('id', 'integer');
178
        $table->addColumn('check_max', 'integer', ['platformOptions' => ['max' => 10]]);
179
        $table->addColumn('check_min', 'integer', ['platformOptions' => ['min' => 10]]);
180
        $table->setPrimaryKey(['id']);
181
182
        self::assertEquals(
183
            ['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))'],
184
            $this->platform->getCreateTableSQL($table)
185
        );
186
    }
187
188
    public function testGeneratesTableAlterationWithRemovedColumnCommentSql()
189
    {
190
        $table = new Table('mytable');
191
        $table->addColumn('foo', 'string', ['comment' => 'foo comment']);
192
193
        $tableDiff                        = new TableDiff('mytable');
194
        $tableDiff->fromTable             = $table;
195
        $tableDiff->changedColumns['foo'] = new ColumnDiff(
196
            'foo',
197
            new Column('foo', Type::getType('string')),
198
            ['comment']
199
        );
200
201
        self::assertEquals(
202
            ['COMMENT ON COLUMN mytable.foo IS NULL'],
203
            $this->platform->getAlterTableSQL($tableDiff)
204
        );
205
    }
206
207
    /**
208
     * @dataProvider getLockHints
209
     */
210
    public function testAppendsLockHint($lockMode, $lockHint)
211
    {
212
        $fromClause     = 'FROM users';
213
        $expectedResult = $fromClause . $lockHint;
214
215
        self::assertSame($expectedResult, $this->platform->appendLockHint($fromClause, $lockMode));
216
    }
217
218
    public function getLockHints()
219
    {
220
        return [
221
            [null, ''],
222
            [false, ''],
223
            [true, ''],
224
            [LockMode::NONE, ' WITH (NOLOCK)'],
225
            [LockMode::OPTIMISTIC, ''],
226
            [LockMode::PESSIMISTIC_READ, ' WITH (UPDLOCK)'],
227
            [LockMode::PESSIMISTIC_WRITE, ' WITH (XLOCK)'],
228
        ];
229
    }
230
231
    public function testHasCorrectMaxIdentifierLength()
232
    {
233
        self::assertEquals(128, $this->platform->getMaxIdentifierLength());
234
    }
235
236
    public function testFixesSchemaElementNames()
237
    {
238
        $maxIdentifierLength = $this->platform->getMaxIdentifierLength();
239
        $characters          = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
240
        $schemaElementName   = '';
241
242
        for ($i = 0; $i < $maxIdentifierLength + 100; $i++) {
243
            $schemaElementName .= $characters[mt_rand(0, strlen($characters) - 1)];
244
        }
245
246
        $fixedSchemaElementName = substr($schemaElementName, 0, $maxIdentifierLength);
247
248
        self::assertEquals(
249
            $fixedSchemaElementName,
250
            $this->platform->fixSchemaElementName($schemaElementName)
251
        );
252
        self::assertEquals(
253
            $fixedSchemaElementName,
254
            $this->platform->fixSchemaElementName($fixedSchemaElementName)
255
        );
256
    }
257
258
    public function testGeneratesColumnTypesDeclarationSQL()
259
    {
260
        $fullColumnDef = [
261
            'length' => 10,
262
            'fixed' => true,
263
            'unsigned' => true,
264
            'autoincrement' => true,
265
        ];
266
267
        self::assertEquals('SMALLINT', $this->platform->getSmallIntTypeDeclarationSQL([]));
268
        self::assertEquals('UNSIGNED SMALLINT', $this->platform->getSmallIntTypeDeclarationSQL(['unsigned' => true]));
269
        self::assertEquals('UNSIGNED SMALLINT IDENTITY', $this->platform->getSmallIntTypeDeclarationSQL($fullColumnDef));
270
        self::assertEquals('INT', $this->platform->getIntegerTypeDeclarationSQL([]));
271
        self::assertEquals('UNSIGNED INT', $this->platform->getIntegerTypeDeclarationSQL(['unsigned' => true]));
272
        self::assertEquals('UNSIGNED INT IDENTITY', $this->platform->getIntegerTypeDeclarationSQL($fullColumnDef));
273
        self::assertEquals('BIGINT', $this->platform->getBigIntTypeDeclarationSQL([]));
274
        self::assertEquals('UNSIGNED BIGINT', $this->platform->getBigIntTypeDeclarationSQL(['unsigned' => true]));
275
        self::assertEquals('UNSIGNED BIGINT IDENTITY', $this->platform->getBigIntTypeDeclarationSQL($fullColumnDef));
276
        self::assertEquals('LONG BINARY', $this->platform->getBlobTypeDeclarationSQL($fullColumnDef));
277
        self::assertEquals('BIT', $this->platform->getBooleanTypeDeclarationSQL($fullColumnDef));
278
        self::assertEquals('TEXT', $this->platform->getClobTypeDeclarationSQL($fullColumnDef));
279
        self::assertEquals('DATE', $this->platform->getDateTypeDeclarationSQL($fullColumnDef));
280
        self::assertEquals('DATETIME', $this->platform->getDateTimeTypeDeclarationSQL($fullColumnDef));
281
        self::assertEquals('TIME', $this->platform->getTimeTypeDeclarationSQL($fullColumnDef));
282
        self::assertEquals('UNIQUEIDENTIFIER', $this->platform->getGuidTypeDeclarationSQL($fullColumnDef));
283
284
        self::assertEquals(1, $this->platform->getVarcharDefaultLength());
285
        self::assertEquals(32767, $this->platform->getVarcharMaxLength());
286
    }
287
288
    public function testHasNativeGuidType()
289
    {
290
        self::assertTrue($this->platform->hasNativeGuidType());
291
    }
292
293
    public function testGeneratesDDLSnippets()
294
    {
295
        self::assertEquals("CREATE DATABASE 'foobar'", $this->platform->getCreateDatabaseSQL('foobar'));
296
        self::assertEquals("CREATE DATABASE 'foobar'", $this->platform->getCreateDatabaseSQL('"foobar"'));
297
        self::assertEquals("CREATE DATABASE 'create'", $this->platform->getCreateDatabaseSQL('create'));
298
        self::assertEquals("DROP DATABASE 'foobar'", $this->platform->getDropDatabaseSQL('foobar'));
299
        self::assertEquals("DROP DATABASE 'foobar'", $this->platform->getDropDatabaseSQL('"foobar"'));
300
        self::assertEquals("DROP DATABASE 'create'", $this->platform->getDropDatabaseSQL('create'));
301
        self::assertEquals('CREATE GLOBAL TEMPORARY TABLE', $this->platform->getCreateTemporaryTableSnippetSQL());
302
        self::assertEquals("START DATABASE 'foobar' AUTOSTOP OFF", $this->platform->getStartDatabaseSQL('foobar'));
303
        self::assertEquals("START DATABASE 'foobar' AUTOSTOP OFF", $this->platform->getStartDatabaseSQL('"foobar"'));
304
        self::assertEquals("START DATABASE 'create' AUTOSTOP OFF", $this->platform->getStartDatabaseSQL('create'));
305
        self::assertEquals('STOP DATABASE "foobar" UNCONDITIONALLY', $this->platform->getStopDatabaseSQL('foobar'));
306
        self::assertEquals('STOP DATABASE "foobar" UNCONDITIONALLY', $this->platform->getStopDatabaseSQL('"foobar"'));
307
        self::assertEquals('STOP DATABASE "create" UNCONDITIONALLY', $this->platform->getStopDatabaseSQL('create'));
308
        self::assertEquals('TRUNCATE TABLE foobar', $this->platform->getTruncateTableSQL('foobar'));
309
        self::assertEquals('TRUNCATE TABLE foobar', $this->platform->getTruncateTableSQL('foobar'), true);
0 ignored issues
show
Bug introduced by
true of type true is incompatible with the type string expected by parameter $message of PHPUnit\Framework\Assert::assertEquals(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

309
        self::assertEquals('TRUNCATE TABLE foobar', $this->platform->getTruncateTableSQL('foobar'), /** @scrutinizer ignore-type */ true);
Loading history...
310
311
        $viewSql = 'SELECT * FROM footable';
312
        self::assertEquals('CREATE VIEW fooview AS ' . $viewSql, $this->platform->getCreateViewSQL('fooview', $viewSql));
313
        self::assertEquals('DROP VIEW fooview', $this->platform->getDropViewSQL('fooview'));
314
    }
315
316
    public function testGeneratesPrimaryKeyDeclarationSQL()
317
    {
318
        self::assertEquals(
319
            'CONSTRAINT pk PRIMARY KEY CLUSTERED (a, b)',
320
            $this->platform->getPrimaryKeyDeclarationSQL(
321
                new Index(null, ['a', 'b'], true, true, ['clustered']),
322
                'pk'
323
            )
324
        );
325
        self::assertEquals(
326
            'PRIMARY KEY (a, b)',
327
            $this->platform->getPrimaryKeyDeclarationSQL(
328
                new Index(null, ['a', 'b'], true, true)
329
            )
330
        );
331
    }
332
333
    public function testCannotGeneratePrimaryKeyDeclarationSQLWithEmptyColumns()
334
    {
335
        $this->expectException(InvalidArgumentException::class);
336
337
        $this->platform->getPrimaryKeyDeclarationSQL(new Index('pk', [], true, true));
338
    }
339
340
    public function testGeneratesCreateUnnamedPrimaryKeySQL()
341
    {
342
        self::assertEquals(
343
            'ALTER TABLE foo ADD PRIMARY KEY CLUSTERED (a, b)',
344
            $this->platform->getCreatePrimaryKeySQL(
345
                new Index('pk', ['a', 'b'], true, true, ['clustered']),
346
                'foo'
347
            )
348
        );
349
        self::assertEquals(
350
            'ALTER TABLE foo ADD PRIMARY KEY (a, b)',
351
            $this->platform->getCreatePrimaryKeySQL(
352
                new Index('any_pk_name', ['a', 'b'], true, true),
353
                new Table('foo')
354
            )
355
        );
356
    }
357
358
    public function testGeneratesUniqueConstraintDeclarationSQL()
359
    {
360
        self::assertEquals(
361
            'CONSTRAINT unique_constraint UNIQUE CLUSTERED (a, b)',
362
            $this->platform->getUniqueConstraintDeclarationSQL(
363
                'unique_constraint',
364
                new UniqueConstraint(null, ['a', 'b'], ['clustered'])
365
            )
366
        );
367
        self::assertEquals(
368
            'CONSTRAINT UNIQUE (a, b)',
369
            $this->platform->getUniqueConstraintDeclarationSQL(null, new UniqueConstraint(null, ['a', 'b']))
370
        );
371
    }
372
373
    public function testCannotGenerateUniqueConstraintDeclarationSQLWithEmptyColumns()
374
    {
375
        $this->expectException(InvalidArgumentException::class);
376
377
        $this->platform->getUniqueConstraintDeclarationSQL('constr', new UniqueConstraint('constr', []));
378
    }
379
380
    public function testGeneratesForeignKeyConstraintsWithAdvancedPlatformOptionsSQL()
381
    {
382
        self::assertEquals(
383
            'CONSTRAINT fk ' .
384
                'NOT NULL FOREIGN KEY (a, b) ' .
385
                'REFERENCES foreign_table (c, d) ' .
386
                'MATCH UNIQUE SIMPLE ON UPDATE CASCADE ON DELETE SET NULL CHECK ON COMMIT CLUSTERED FOR OLAP WORKLOAD',
387
            $this->platform->getForeignKeyDeclarationSQL(
388
                new ForeignKeyConstraint(['a', 'b'], 'foreign_table', ['c', 'd'], 'fk', [
389
                    'notnull' => true,
390
                    'match' => SQLAnywherePlatform::FOREIGN_KEY_MATCH_SIMPLE_UNIQUE,
391
                    'onUpdate' => 'CASCADE',
392
                    'onDelete' => 'SET NULL',
393
                    'check_on_commit' => true,
394
                    'clustered' => true,
395
                    'for_olap_workload' => true,
396
                ])
397
            )
398
        );
399
        self::assertEquals(
400
            'FOREIGN KEY (a, b) REFERENCES foreign_table (c, d)',
401
            $this->platform->getForeignKeyDeclarationSQL(
402
                new ForeignKeyConstraint(['a', 'b'], 'foreign_table', ['c', 'd'])
403
            )
404
        );
405
    }
406
407
    public function testGeneratesForeignKeyMatchClausesSQL()
408
    {
409
        self::assertEquals('SIMPLE', $this->platform->getForeignKeyMatchClauseSQL(1));
410
        self::assertEquals('FULL', $this->platform->getForeignKeyMatchClauseSQL(2));
411
        self::assertEquals('UNIQUE SIMPLE', $this->platform->getForeignKeyMatchClauseSQL(129));
412
        self::assertEquals('UNIQUE FULL', $this->platform->getForeignKeyMatchClauseSQL(130));
413
    }
414
415
    public function testCannotGenerateInvalidForeignKeyMatchClauseSQL()
416
    {
417
        $this->expectException(InvalidArgumentException::class);
418
419
        $this->platform->getForeignKeyMatchCLauseSQL(3);
420
    }
421
422
    public function testCannotGenerateForeignKeyConstraintSQLWithEmptyLocalColumns()
423
    {
424
        $this->expectException(InvalidArgumentException::class);
425
        $this->platform->getForeignKeyDeclarationSQL(new ForeignKeyConstraint([], 'foreign_tbl', ['c', 'd']));
426
    }
427
428
    public function testCannotGenerateForeignKeyConstraintSQLWithEmptyForeignColumns()
429
    {
430
        $this->expectException(InvalidArgumentException::class);
431
        $this->platform->getForeignKeyDeclarationSQL(new ForeignKeyConstraint(['a', 'b'], 'foreign_tbl', []));
432
    }
433
434
    public function testCannotGenerateForeignKeyConstraintSQLWithEmptyForeignTableName()
435
    {
436
        $this->expectException(InvalidArgumentException::class);
437
        $this->platform->getForeignKeyDeclarationSQL(new ForeignKeyConstraint(['a', 'b'], '', ['c', 'd']));
438
    }
439
440
    public function testCannotGenerateCommonIndexWithCreateConstraintSQL()
441
    {
442
        $this->expectException(InvalidArgumentException::class);
443
444
        $this->platform->getCreateConstraintSQL(new Index('fooindex', []), new Table('footable'));
445
    }
446
447
    public function testCannotGenerateCustomConstraintWithCreateConstraintSQL()
448
    {
449
        $this->expectException(InvalidArgumentException::class);
450
451
        $this->platform->getCreateConstraintSQL($this->createMock(Constraint::class), 'footable');
452
    }
453
454
    public function testGeneratesCreateIndexWithAdvancedPlatformOptionsSQL()
455
    {
456
        self::assertEquals(
457
            'CREATE UNIQUE INDEX fooindex ON footable (a, b) WITH NULLS DISTINCT',
458
            $this->platform->getCreateIndexSQL(
459
                new Index(
460
                    'fooindex',
461
                    ['a', 'b'],
462
                    true,
463
                    false,
464
                    ['with_nulls_distinct']
465
                ),
466
                'footable'
467
            )
468
        );
469
470
        // WITH NULLS DISTINCT clause not available on primary indexes.
471
        self::assertEquals(
472
            'ALTER TABLE footable ADD PRIMARY KEY (a, b)',
473
            $this->platform->getCreateIndexSQL(
474
                new Index(
475
                    'fooindex',
476
                    ['a', 'b'],
477
                    false,
478
                    true,
479
                    ['with_nulls_distinct']
480
                ),
481
                'footable'
482
            )
483
        );
484
485
        // WITH NULLS DISTINCT clause not available on non-unique indexes.
486
        self::assertEquals(
487
            'CREATE INDEX fooindex ON footable (a, b)',
488
            $this->platform->getCreateIndexSQL(
489
                new Index(
490
                    'fooindex',
491
                    ['a', 'b'],
492
                    false,
493
                    false,
494
                    ['with_nulls_distinct']
495
                ),
496
                'footable'
497
            )
498
        );
499
500
        self::assertEquals(
501
            'CREATE VIRTUAL UNIQUE CLUSTERED INDEX fooindex ON footable (a, b) WITH NULLS NOT DISTINCT FOR OLAP WORKLOAD',
502
            $this->platform->getCreateIndexSQL(
503
                new Index(
504
                    'fooindex',
505
                    ['a', 'b'],
506
                    true,
507
                    false,
508
                    ['virtual', 'clustered', 'with_nulls_not_distinct', 'for_olap_workload']
509
                ),
510
                'footable'
511
            )
512
        );
513
        self::assertEquals(
514
            'CREATE VIRTUAL CLUSTERED INDEX fooindex ON footable (a, b) FOR OLAP WORKLOAD',
515
            $this->platform->getCreateIndexSQL(
516
                new Index(
517
                    'fooindex',
518
                    ['a', 'b'],
519
                    false,
520
                    false,
521
                    ['virtual', 'clustered', 'with_nulls_not_distinct', 'for_olap_workload']
522
                ),
523
                'footable'
524
            )
525
        );
526
527
        // WITH NULLS NOT DISTINCT clause not available on primary indexes.
528
        self::assertEquals(
529
            'ALTER TABLE footable ADD PRIMARY KEY (a, b)',
530
            $this->platform->getCreateIndexSQL(
531
                new Index(
532
                    'fooindex',
533
                    ['a', 'b'],
534
                    false,
535
                    true,
536
                    ['with_nulls_not_distinct']
537
                ),
538
                'footable'
539
            )
540
        );
541
542
        // WITH NULLS NOT DISTINCT clause not available on non-unique indexes.
543
        self::assertEquals(
544
            'CREATE INDEX fooindex ON footable (a, b)',
545
            $this->platform->getCreateIndexSQL(
546
                new Index(
547
                    'fooindex',
548
                    ['a', 'b'],
549
                    false,
550
                    false,
551
                    ['with_nulls_not_distinct']
552
                ),
553
                'footable'
554
            )
555
        );
556
    }
557
558
    public function testThrowsExceptionOnInvalidWithNullsNotDistinctIndexOptions()
559
    {
560
        $this->expectException('UnexpectedValueException');
561
562
        $this->platform->getCreateIndexSQL(
563
            new Index(
564
                'fooindex',
565
                ['a', 'b'],
566
                false,
567
                false,
568
                ['with_nulls_distinct', 'with_nulls_not_distinct']
569
            ),
570
            'footable'
571
        );
572
    }
573
574
    public function testDoesNotSupportIndexDeclarationInCreateAlterTableStatements()
575
    {
576
        $this->expectException(DBALException::class);
577
578
        $this->platform->getIndexDeclarationSQL('index', new Index('index', []));
579
    }
580
581
    public function testGeneratesDropIndexSQL()
582
    {
583
        $index = new Index('fooindex', []);
584
585
        self::assertEquals('DROP INDEX fooindex', $this->platform->getDropIndexSQL($index));
586
        self::assertEquals('DROP INDEX footable.fooindex', $this->platform->getDropIndexSQL($index, 'footable'));
587
        self::assertEquals('DROP INDEX footable.fooindex', $this->platform->getDropIndexSQL(
588
            $index,
589
            new Table('footable')
590
        ));
591
    }
592
593
    public function testCannotGenerateDropIndexSQLWithInvalidIndexParameter()
594
    {
595
        $this->expectException(InvalidArgumentException::class);
596
597
        $this->platform->getDropIndexSQL(['index'], 'table');
598
    }
599
600
    public function testCannotGenerateDropIndexSQLWithInvalidTableParameter()
601
    {
602
        $this->expectException(InvalidArgumentException::class);
603
604
        $this->platform->getDropIndexSQL('index', ['table']);
605
    }
606
607
    public function testGeneratesSQLSnippets()
608
    {
609
        self::assertEquals('STRING(column1, "string1", column2, "string2")', $this->platform->getConcatExpression(
610
            'column1',
611
            '"string1"',
612
            'column2',
613
            '"string2"'
614
        ));
615
        self::assertEquals('CURRENT DATE', $this->platform->getCurrentDateSQL());
616
        self::assertEquals('CURRENT TIME', $this->platform->getCurrentTimeSQL());
617
        self::assertEquals('CURRENT TIMESTAMP', $this->platform->getCurrentTimestampSQL());
618
        self::assertEquals("DATEADD(DAY, 4, '1987/05/02')", $this->platform->getDateAddDaysExpression("'1987/05/02'", 4));
619
        self::assertEquals("DATEADD(HOUR, 12, '1987/05/02')", $this->platform->getDateAddHourExpression("'1987/05/02'", 12));
620
        self::assertEquals("DATEADD(MINUTE, 2, '1987/05/02')", $this->platform->getDateAddMinutesExpression("'1987/05/02'", 2));
621
        self::assertEquals("DATEADD(MONTH, 102, '1987/05/02')", $this->platform->getDateAddMonthExpression("'1987/05/02'", 102));
622
        self::assertEquals("DATEADD(QUARTER, 5, '1987/05/02')", $this->platform->getDateAddQuartersExpression("'1987/05/02'", 5));
623
        self::assertEquals("DATEADD(SECOND, 1, '1987/05/02')", $this->platform->getDateAddSecondsExpression("'1987/05/02'", 1));
624
        self::assertEquals("DATEADD(WEEK, 3, '1987/05/02')", $this->platform->getDateAddWeeksExpression("'1987/05/02'", 3));
625
        self::assertEquals("DATEADD(YEAR, 10, '1987/05/02')", $this->platform->getDateAddYearsExpression("'1987/05/02'", 10));
626
        self::assertEquals("DATEDIFF(day, '1987/04/01', '1987/05/02')", $this->platform->getDateDiffExpression("'1987/05/02'", "'1987/04/01'"));
627
        self::assertEquals("DATEADD(DAY, -1 * 4, '1987/05/02')", $this->platform->getDateSubDaysExpression("'1987/05/02'", 4));
628
        self::assertEquals("DATEADD(HOUR, -1 * 12, '1987/05/02')", $this->platform->getDateSubHourExpression("'1987/05/02'", 12));
629
        self::assertEquals("DATEADD(MINUTE, -1 * 2, '1987/05/02')", $this->platform->getDateSubMinutesExpression("'1987/05/02'", 2));
630
        self::assertEquals("DATEADD(MONTH, -1 * 102, '1987/05/02')", $this->platform->getDateSubMonthExpression("'1987/05/02'", 102));
631
        self::assertEquals("DATEADD(QUARTER, -1 * 5, '1987/05/02')", $this->platform->getDateSubQuartersExpression("'1987/05/02'", 5));
632
        self::assertEquals("DATEADD(SECOND, -1 * 1, '1987/05/02')", $this->platform->getDateSubSecondsExpression("'1987/05/02'", 1));
633
        self::assertEquals("DATEADD(WEEK, -1 * 3, '1987/05/02')", $this->platform->getDateSubWeeksExpression("'1987/05/02'", 3));
634
        self::assertEquals("DATEADD(YEAR, -1 * 10, '1987/05/02')", $this->platform->getDateSubYearsExpression("'1987/05/02'", 10));
635
        self::assertEquals('Y-m-d H:i:s.u', $this->platform->getDateTimeFormatString());
636
        self::assertEquals('H:i:s.u', $this->platform->getTimeFormatString());
637
        self::assertEquals('', $this->platform->getForUpdateSQL());
638
        self::assertEquals('LOCATE(string_column, substring_column)', $this->platform->getLocateExpression('string_column', 'substring_column'));
639
        self::assertEquals('LOCATE(string_column, substring_column, 1)', $this->platform->getLocateExpression('string_column', 'substring_column', 1));
640
        self::assertEquals("HASH(column, 'MD5')", $this->platform->getMd5Expression('column'));
641
        self::assertEquals('SUBSTRING(column, 5)', $this->platform->getSubstringExpression('column', 5));
642
        self::assertEquals('SUBSTRING(column, 5, 2)', $this->platform->getSubstringExpression('column', 5, 2));
643
        self::assertEquals('GLOBAL TEMPORARY', $this->platform->getTemporaryTableSQL());
644
        self::assertEquals(
645
            'LTRIM(column)',
646
            $this->platform->getTrimExpression('column', TrimMode::LEADING)
647
        );
648
        self::assertEquals(
649
            'RTRIM(column)',
650
            $this->platform->getTrimExpression('column', TrimMode::TRAILING)
651
        );
652
        self::assertEquals(
653
            'TRIM(column)',
654
            $this->platform->getTrimExpression('column')
655
        );
656
        self::assertEquals(
657
            'TRIM(column)',
658
            $this->platform->getTrimExpression('column', TrimMode::UNSPECIFIED)
659
        );
660
        self::assertEquals(
661
            "SUBSTR(column, PATINDEX('%[^' + c + ']%', column))",
662
            $this->platform->getTrimExpression('column', TrimMode::LEADING, 'c')
663
        );
664
        self::assertEquals(
665
            "REVERSE(SUBSTR(REVERSE(column), PATINDEX('%[^' + c + ']%', REVERSE(column))))",
666
            $this->platform->getTrimExpression('column', TrimMode::TRAILING, 'c')
667
        );
668
        self::assertEquals(
669
            "REVERSE(SUBSTR(REVERSE(SUBSTR(column, PATINDEX('%[^' + c + ']%', column))), PATINDEX('%[^' + c + ']%', " .
670
            "REVERSE(SUBSTR(column, PATINDEX('%[^' + c + ']%', column))))))",
671
            $this->platform->getTrimExpression('column', null, 'c')
672
        );
673
        self::assertEquals(
674
            "REVERSE(SUBSTR(REVERSE(SUBSTR(column, PATINDEX('%[^' + c + ']%', column))), PATINDEX('%[^' + c + ']%', " .
675
            "REVERSE(SUBSTR(column, PATINDEX('%[^' + c + ']%', column))))))",
676
            $this->platform->getTrimExpression('column', TrimMode::UNSPECIFIED, 'c')
677
        );
678
    }
679
680
    public function testHasCorrectDateTimeTzFormatString()
681
    {
682
        self::assertEquals('Y-m-d H:i:s.uP', $this->platform->getDateTimeTzFormatString());
683
    }
684
685
    public function testGeneratesDateTimeTzColumnTypeDeclarationSQL()
686
    {
687
        self::assertEquals(
688
            'TIMESTAMP WITH TIME ZONE',
689
            $this->platform->getDateTimeTzTypeDeclarationSQL([
690
                'length' => 10,
691
                'fixed' => true,
692
                'unsigned' => true,
693
                'autoincrement' => true,
694
            ])
695
        );
696
    }
697
698
    public function testInitializesDateTimeTzTypeMapping()
699
    {
700
        self::assertTrue($this->platform->hasDoctrineTypeMappingFor('timestamp with time zone'));
701
        self::assertEquals('datetime', $this->platform->getDoctrineTypeMapping('timestamp with time zone'));
702
    }
703
704
    public function testHasCorrectDefaultTransactionIsolationLevel()
705
    {
706
        self::assertEquals(
707
            TransactionIsolationLevel::READ_UNCOMMITTED,
708
            $this->platform->getDefaultTransactionIsolationLevel()
709
        );
710
    }
711
712
    public function testGeneratesTransactionsCommands()
713
    {
714
        self::assertEquals(
715
            'SET TEMPORARY OPTION isolation_level = 0',
716
            $this->platform->getSetTransactionIsolationSQL(TransactionIsolationLevel::READ_UNCOMMITTED)
717
        );
718
        self::assertEquals(
719
            'SET TEMPORARY OPTION isolation_level = 1',
720
            $this->platform->getSetTransactionIsolationSQL(TransactionIsolationLevel::READ_COMMITTED)
721
        );
722
        self::assertEquals(
723
            'SET TEMPORARY OPTION isolation_level = 2',
724
            $this->platform->getSetTransactionIsolationSQL(TransactionIsolationLevel::REPEATABLE_READ)
725
        );
726
        self::assertEquals(
727
            'SET TEMPORARY OPTION isolation_level = 3',
728
            $this->platform->getSetTransactionIsolationSQL(TransactionIsolationLevel::SERIALIZABLE)
729
        );
730
    }
731
732
    public function testCannotGenerateTransactionCommandWithInvalidIsolationLevel()
733
    {
734
        $this->expectException(InvalidArgumentException::class);
735
736
        $this->platform->getSetTransactionIsolationSQL('invalid_transaction_isolation_level');
737
    }
738
739
    public function testModifiesLimitQuery()
740
    {
741
        self::assertEquals(
742
            'SELECT TOP 10 * FROM user',
743
            $this->platform->modifyLimitQuery('SELECT * FROM user', 10, 0)
744
        );
745
    }
746
747
    public function testModifiesLimitQueryWithEmptyOffset()
748
    {
749
        self::assertEquals(
750
            'SELECT TOP 10 * FROM user',
751
            $this->platform->modifyLimitQuery('SELECT * FROM user', 10)
752
        );
753
    }
754
755
    public function testModifiesLimitQueryWithOffset()
756
    {
757
        self::assertEquals(
758
            'SELECT TOP 10 START AT 6 * FROM user',
759
            $this->platform->modifyLimitQuery('SELECT * FROM user', 10, 5)
760
        );
761
        self::assertEquals(
762
            'SELECT TOP 0 START AT 6 * FROM user',
763
            $this->platform->modifyLimitQuery('SELECT * FROM user', 0, 5)
764
        );
765
    }
766
767
    public function testModifiesLimitQueryWithSubSelect()
768
    {
769
        self::assertEquals(
770
            'SELECT TOP 10 * FROM (SELECT u.id as uid, u.name as uname FROM user) AS doctrine_tbl',
771
            $this->platform->modifyLimitQuery('SELECT * FROM (SELECT u.id as uid, u.name as uname FROM user) AS doctrine_tbl', 10)
772
        );
773
    }
774
775
    public function testModifiesLimitQueryWithoutLimit()
776
    {
777
        self::assertEquals(
778
            'SELECT TOP ALL START AT 11 n FROM Foo',
779
            $this->platform->modifyLimitQuery('SELECT n FROM Foo', null, 10)
780
        );
781
    }
782
783
    public function testPrefersIdentityColumns()
784
    {
785
        self::assertTrue($this->platform->prefersIdentityColumns());
786
    }
787
788
    public function testDoesNotPreferSequences()
789
    {
790
        self::assertFalse($this->platform->prefersSequences());
791
    }
792
793
    public function testSupportsIdentityColumns()
794
    {
795
        self::assertTrue($this->platform->supportsIdentityColumns());
796
    }
797
798
    public function testSupportsPrimaryConstraints()
799
    {
800
        self::assertTrue($this->platform->supportsPrimaryConstraints());
801
    }
802
803
    public function testSupportsForeignKeyConstraints()
804
    {
805
        self::assertTrue($this->platform->supportsForeignKeyConstraints());
806
    }
807
808
    public function testSupportsForeignKeyOnUpdate()
809
    {
810
        self::assertTrue($this->platform->supportsForeignKeyOnUpdate());
811
    }
812
813
    public function testSupportsAlterTable()
814
    {
815
        self::assertTrue($this->platform->supportsAlterTable());
816
    }
817
818
    public function testSupportsTransactions()
819
    {
820
        self::assertTrue($this->platform->supportsTransactions());
821
    }
822
823
    public function testSupportsSchemas()
824
    {
825
        self::assertFalse($this->platform->supportsSchemas());
826
    }
827
828
    public function testSupportsIndexes()
829
    {
830
        self::assertTrue($this->platform->supportsIndexes());
831
    }
832
833
    public function testSupportsCommentOnStatement()
834
    {
835
        self::assertTrue($this->platform->supportsCommentOnStatement());
836
    }
837
838
    public function testSupportsSavePoints()
839
    {
840
        self::assertTrue($this->platform->supportsSavepoints());
841
    }
842
843
    public function testSupportsReleasePoints()
844
    {
845
        self::assertTrue($this->platform->supportsReleaseSavepoints());
846
    }
847
848
    public function testSupportsCreateDropDatabase()
849
    {
850
        self::assertTrue($this->platform->supportsCreateDropDatabase());
851
    }
852
853
    public function testSupportsGettingAffectedRows()
854
    {
855
        self::assertTrue($this->platform->supportsGettingAffectedRows());
856
    }
857
858
    public function testDoesNotSupportSequences()
859
    {
860
        self::markTestSkipped('This version of the platform now supports sequences.');
861
    }
862
863
    public function testSupportsSequences()
864
    {
865
        self::assertTrue($this->platform->supportsSequences());
866
    }
867
868
    public function testGeneratesSequenceSqlCommands()
869
    {
870
        $sequence = new Sequence('myseq', 20, 1);
871
        self::assertEquals(
872
            'CREATE SEQUENCE myseq INCREMENT BY 20 START WITH 1 MINVALUE 1',
873
            $this->platform->getCreateSequenceSQL($sequence)
874
        );
875
        self::assertEquals(
876
            'ALTER SEQUENCE myseq INCREMENT BY 20',
877
            $this->platform->getAlterSequenceSQL($sequence)
878
        );
879
        self::assertEquals(
880
            'DROP SEQUENCE myseq',
881
            $this->platform->getDropSequenceSQL('myseq')
882
        );
883
        self::assertEquals(
884
            'DROP SEQUENCE myseq',
885
            $this->platform->getDropSequenceSQL($sequence)
886
        );
887
        self::assertEquals(
888
            'SELECT myseq.NEXTVAL',
889
            $this->platform->getSequenceNextValSQL('myseq')
890
        );
891
        self::assertEquals(
892
            'SELECT sequence_name, increment_by, start_with, min_value FROM SYS.SYSSEQUENCE',
893
            $this->platform->getListSequencesSQL(null)
894
        );
895
    }
896
897
    public function testDoesNotSupportInlineColumnComments()
898
    {
899
        self::assertFalse($this->platform->supportsInlineColumnComments());
900
    }
901
902
    public function testCannotEmulateSchemas()
903
    {
904
        self::assertFalse($this->platform->canEmulateSchemas());
905
    }
906
907
    public function testInitializesDoctrineTypeMappings()
908
    {
909
        self::assertTrue($this->platform->hasDoctrineTypeMappingFor('integer'));
910
        self::assertSame('integer', $this->platform->getDoctrineTypeMapping('integer'));
911
912
        self::assertTrue($this->platform->hasDoctrineTypeMappingFor('binary'));
913
        self::assertSame('binary', $this->platform->getDoctrineTypeMapping('binary'));
914
915
        self::assertTrue($this->platform->hasDoctrineTypeMappingFor('varbinary'));
916
        self::assertSame('binary', $this->platform->getDoctrineTypeMapping('varbinary'));
917
    }
918
919
    protected function getBinaryDefaultLength()
920
    {
921
        return 1;
922
    }
923
924
    protected function getBinaryMaxLength()
925
    {
926
        return 32767;
927
    }
928
929
    public function testReturnsBinaryTypeDeclarationSQL()
930
    {
931
        self::assertSame('VARBINARY(1)', $this->platform->getBinaryTypeDeclarationSQL([]));
932
        self::assertSame('VARBINARY(1)', $this->platform->getBinaryTypeDeclarationSQL(['length' => 0]));
933
        self::assertSame('VARBINARY(32767)', $this->platform->getBinaryTypeDeclarationSQL(['length' => 32767]));
934
935
        self::assertSame('BINARY(1)', $this->platform->getBinaryTypeDeclarationSQL(['fixed' => true]));
936
        self::assertSame('BINARY(1)', $this->platform->getBinaryTypeDeclarationSQL([
937
            'fixed' => true,
938
            'length' => 0,
939
        ]));
940
        self::assertSame('BINARY(32767)', $this->platform->getBinaryTypeDeclarationSQL([
941
            'fixed' => true,
942
            'length' => 32767,
943
        ]));
944
    }
945
946
    /**
947
     * @group DBAL-234
948
     */
949
    protected function getAlterTableRenameIndexSQL()
950
    {
951
        return ['ALTER INDEX idx_foo ON mytable RENAME TO idx_bar'];
952
    }
953
954
    /**
955
     * @group DBAL-234
956
     */
957
    protected function getQuotedAlterTableRenameIndexSQL()
958
    {
959
        return [
960
            'ALTER INDEX "create" ON "table" RENAME TO "select"',
961
            'ALTER INDEX "foo" ON "table" RENAME TO "bar"',
962
        ];
963
    }
964
965
    /**
966
     * {@inheritdoc}
967
     */
968
    protected function getQuotedAlterTableRenameColumnSQL()
969
    {
970
        return [
971
            'ALTER TABLE mytable RENAME unquoted1 TO unquoted',
972
            'ALTER TABLE mytable RENAME unquoted2 TO "where"',
973
            'ALTER TABLE mytable RENAME unquoted3 TO "foo"',
974
            'ALTER TABLE mytable RENAME "create" TO reserved_keyword',
975
            'ALTER TABLE mytable RENAME "table" TO "from"',
976
            'ALTER TABLE mytable RENAME "select" TO "bar"',
977
            'ALTER TABLE mytable RENAME quoted1 TO quoted',
978
            'ALTER TABLE mytable RENAME quoted2 TO "and"',
979
            'ALTER TABLE mytable RENAME quoted3 TO "baz"',
980
        ];
981
    }
982
983
    /**
984
     * {@inheritdoc}
985
     */
986
    protected function getQuotedAlterTableChangeColumnLengthSQL()
987
    {
988
        $this->markTestIncomplete('Not implemented yet');
989
    }
990
991
    /**
992
     * @group DBAL-807
993
     */
994
    protected function getAlterTableRenameIndexInSchemaSQL()
995
    {
996
        return ['ALTER INDEX idx_foo ON myschema.mytable RENAME TO idx_bar'];
997
    }
998
999
    /**
1000
     * @group DBAL-807
1001
     */
1002
    protected function getQuotedAlterTableRenameIndexInSchemaSQL()
1003
    {
1004
        return [
1005
            'ALTER INDEX "create" ON "schema"."table" RENAME TO "select"',
1006
            'ALTER INDEX "foo" ON "schema"."table" RENAME TO "bar"',
1007
        ];
1008
    }
1009
1010
    /**
1011
     * @group DBAL-423
1012
     */
1013
    public function testReturnsGuidTypeDeclarationSQL()
1014
    {
1015
        self::assertSame('UNIQUEIDENTIFIER', $this->platform->getGuidTypeDeclarationSQL([]));
1016
    }
1017
1018
    /**
1019
     * {@inheritdoc}
1020
     */
1021
    public function getAlterTableRenameColumnSQL()
1022
    {
1023
        return ['ALTER TABLE foo RENAME bar TO baz'];
1024
    }
1025
1026
    /**
1027
     * {@inheritdoc}
1028
     */
1029
    protected function getQuotesTableIdentifiersInAlterTableSQL()
1030
    {
1031
        return [
1032
            'ALTER TABLE "foo" DROP FOREIGN KEY fk1',
1033
            'ALTER TABLE "foo" DROP FOREIGN KEY fk2',
1034
            'ALTER TABLE "foo" RENAME id TO war',
1035
            'ALTER TABLE "foo" ADD bloo INT NOT NULL, DROP baz, ALTER bar INT DEFAULT NULL',
1036
            'ALTER TABLE "foo" RENAME "table"',
1037
            'ALTER TABLE "table" ADD CONSTRAINT fk_add FOREIGN KEY (fk3) REFERENCES fk_table (id)',
1038
            'ALTER TABLE "table" ADD CONSTRAINT fk2 FOREIGN KEY (fk2) REFERENCES fk_table2 (id)',
1039
        ];
1040
    }
1041
1042
    /**
1043
     * {@inheritdoc}
1044
     */
1045
    protected function getCommentOnColumnSQL()
1046
    {
1047
        return [
1048
            'COMMENT ON COLUMN foo.bar IS \'comment\'',
1049
            'COMMENT ON COLUMN "Foo"."BAR" IS \'comment\'',
1050
            'COMMENT ON COLUMN "select"."from" IS \'comment\'',
1051
        ];
1052
    }
1053
1054
    /**
1055
     * @group DBAL-1004
1056
     */
1057
    public function testAltersTableColumnCommentWithExplicitlyQuotedIdentifiers()
1058
    {
1059
        $table1 = new Table('"foo"', [new Column('"bar"', Type::getType('integer'))]);
1060
        $table2 = new Table('"foo"', [new Column('"bar"', Type::getType('integer'), ['comment' => 'baz'])]);
1061
1062
        $comparator = new Comparator();
1063
1064
        $tableDiff = $comparator->diffTable($table1, $table2);
1065
1066
        self::assertInstanceOf(TableDiff::class, $tableDiff);
1067
        self::assertSame(
1068
            ['COMMENT ON COLUMN "foo"."bar" IS \'baz\''],
1069
            $this->platform->getAlterTableSQL($tableDiff)
0 ignored issues
show
Bug introduced by
It seems like $tableDiff can also be of type false; however, parameter $diff of Doctrine\DBAL\Platforms\...orm::getAlterTableSQL() does only seem to accept Doctrine\DBAL\Schema\TableDiff, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1069
            $this->platform->getAlterTableSQL(/** @scrutinizer ignore-type */ $tableDiff)
Loading history...
1070
        );
1071
    }
1072
1073
    /**
1074
     * {@inheritdoc}
1075
     */
1076
    public function getReturnsForeignKeyReferentialActionSQL()
1077
    {
1078
        return [
1079
            ['CASCADE', 'CASCADE'],
1080
            ['SET NULL', 'SET NULL'],
1081
            ['NO ACTION', 'RESTRICT'],
1082
            ['RESTRICT', 'RESTRICT'],
1083
            ['SET DEFAULT', 'SET DEFAULT'],
1084
            ['CaScAdE', 'CASCADE'],
1085
        ];
1086
    }
1087
1088
    /**
1089
     * {@inheritdoc}
1090
     */
1091
    protected function getQuotesReservedKeywordInUniqueConstraintDeclarationSQL()
1092
    {
1093
        return 'CONSTRAINT "select" UNIQUE (foo)';
1094
    }
1095
1096
    /**
1097
     * {@inheritdoc}
1098
     */
1099
    protected function getQuotesReservedKeywordInIndexDeclarationSQL()
1100
    {
1101
        return ''; // not supported by this platform
1102
    }
1103
1104
    /**
1105
     * {@inheritdoc}
1106
     */
1107
    protected function getQuotesReservedKeywordInTruncateTableSQL()
1108
    {
1109
        return 'TRUNCATE TABLE "select"';
1110
    }
1111
1112
    /**
1113
     * {@inheritdoc}
1114
     */
1115
    protected function supportsInlineIndexDeclaration()
1116
    {
1117
        return false;
1118
    }
1119
1120
    /**
1121
     * {@inheritdoc}
1122
     */
1123
    protected function getAlterStringToFixedStringSQL()
1124
    {
1125
        return ['ALTER TABLE mytable ALTER name CHAR(2) NOT NULL'];
1126
    }
1127
1128
    /**
1129
     * {@inheritdoc}
1130
     */
1131
    protected function getGeneratesAlterTableRenameIndexUsedByForeignKeySQL()
1132
    {
1133
        return ['ALTER INDEX idx_foo ON mytable RENAME TO idx_foo_renamed'];
1134
    }
1135
1136
    /**
1137
     * @group DBAL-2436
1138
     */
1139
    public function testQuotesSchemaNameInListTableColumnsSQL()
1140
    {
1141
        self::assertContains(
1142
            "'Foo''Bar\\'",
1143
            $this->platform->getListTableColumnsSQL("Foo'Bar\\.baz_table"),
1144
            '',
1145
            true
1146
        );
1147
    }
1148
1149
    /**
1150
     * @group DBAL-2436
1151
     */
1152
    public function testQuotesTableNameInListTableConstraintsSQL()
1153
    {
1154
        self::assertContains("'Foo''Bar\\'", $this->platform->getListTableConstraintsSQL("Foo'Bar\\"), '', true);
1155
    }
1156
1157
    /**
1158
     * @group DBAL-2436
1159
     */
1160
    public function testQuotesSchemaNameInListTableConstraintsSQL()
1161
    {
1162
        self::assertContains(
1163
            "'Foo''Bar\\'",
1164
            $this->platform->getListTableConstraintsSQL("Foo'Bar\\.baz_table"),
1165
            '',
1166
            true
1167
        );
1168
    }
1169
1170
    /**
1171
     * @group DBAL-2436
1172
     */
1173
    public function testQuotesTableNameInListTableForeignKeysSQL()
1174
    {
1175
        self::assertContains("'Foo''Bar\\'", $this->platform->getListTableForeignKeysSQL("Foo'Bar\\"), '', true);
1176
    }
1177
1178
    /**
1179
     * @group DBAL-2436
1180
     */
1181
    public function testQuotesSchemaNameInListTableForeignKeysSQL()
1182
    {
1183
        self::assertContains(
1184
            "'Foo''Bar\\'",
1185
            $this->platform->getListTableForeignKeysSQL("Foo'Bar\\.baz_table"),
1186
            '',
1187
            true
1188
        );
1189
    }
1190
1191
    /**
1192
     * @group DBAL-2436
1193
     */
1194
    public function testQuotesTableNameInListTableIndexesSQL()
1195
    {
1196
        self::assertContains("'Foo''Bar\\'", $this->platform->getListTableIndexesSQL("Foo'Bar\\"), '', true);
1197
    }
1198
1199
    /**
1200
     * @group DBAL-2436
1201
     */
1202
    public function testQuotesSchemaNameInListTableIndexesSQL()
1203
    {
1204
        self::assertContains(
1205
            "'Foo''Bar\\'",
1206
            $this->platform->getListTableIndexesSQL("Foo'Bar\\.baz_table"),
1207
            '',
1208
            true
1209
        );
1210
    }
1211
}
1212