Failed Conditions
Push — 3.0.x ( f82f5c...40cc9b )
by Grégoire
24s queued 15s
created

AbstractPostgreSQLPlatformTestCase   F

Complexity

Total Complexity 81

Size/Duplication

Total Lines 1049
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 81
eloc 409
dl 0
loc 1049
rs 2
c 0
b 0
f 0

81 Methods

Rating   Name   Duplication   Size   Complexity  
A getQuotesReservedKeywordInUniqueConstraintDeclarationSQL() 0 3 1
A testQuotesSchemaNameInListTableColumnsSQL() 0 5 1
A testConvertFromBoolean() 0 5 1
A getGenerateIndexSql() 0 3 1
A testGeneratesTransactionCommands() 0 17 1
A getQuotedColumnInIndexSQL() 0 5 1
A testCreateSequenceWithCache() 0 4 1
A testGenerateTableWithAutoincrement() 0 7 1
A testGenerateTableWithAutoincrementDoesNotSetDefault() 0 10 1
A testGetDefaultValueDeclarationSQLIgnoresTheDefaultKeyWhenTheFieldIsSerial() 0 11 1
A getQuotedAlterTableRenameIndexSQL() 0 5 1
A testModifyLimitQuery() 0 4 1
A getCommentOnColumnSQL() 0 6 1
A testReturnsCloseActiveDatabaseConnectionsSQL() 0 5 1
A getCreateTableColumnCommentsSQL() 0 5 1
A getGenerateTableWithMultiColumnUniqueIndexSql() 0 5 1
A testUsesSequenceEmulatedIdentityColumns() 0 3 1
A supportsCommentOnStatement() 0 3 1
A testGeneratesSqlSnippets() 0 7 1
A testPrefersSequences() 0 3 1
A getCreateTableColumnTypeCommentsSQL() 0 5 1
A getAlterTableRenameIndexInSchemaSQL() 0 3 1
A testDoesNotPreferIdentityColumns() 0 3 1
A getAlterTableColumnCommentsSQL() 0 7 1
A testConvertBooleanAsLiteralStrings() 0 9 1
A pgBooleanProvider() 0 21 1
A testInitializesTsvectorTypeMapping() 0 4 1
A testQuotesSchemaNameInListTableForeignKeysSQL() 0 5 1
A testReturnsGuidTypeDeclarationSQL() 0 3 1
A testReturnsIdentitySequenceName() 0 3 1
A testAltersTableColumnCommentIfRequiredByType() 0 17 1
A testDoesNotPropagateUnnecessaryTableAlterationOnBinaryType() 0 38 1
A getAlterStringToFixedStringSQL() 0 3 1
A testAlterDecimalPrecisionScale() 0 57 1
A testConvertBooleanAsDatabaseValueIntegers() 0 7 1
A getQuotesDropForeignKeySQL() 0 3 1
A getQuotedAlterTableChangeColumnLengthSQL() 0 9 1
A getQuotesTableIdentifiersInAlterTableSQL() 0 14 1
A getBinaryDefaultLength() 0 3 1
A getQuotesReservedKeywordInIndexDeclarationSQL() 0 3 1
A testQuotesTableNameInListTableForeignKeysSQL() 0 5 1
A getGenerateUniqueIndexSql() 0 3 1
A getGeneratesAlterTableRenameIndexUsedByForeignKeySQL() 0 3 1
A getGenerateAlterTableSql() 0 12 1
A testConvertBooleanAsDatabaseValueStrings() 0 9 1
A testModifyLimitQueryWithEmptyOffset() 0 4 1
A getQuotesReservedKeywordInTruncateTableSQL() 0 3 1
A testQuotesSchemaNameInListTableIndexesSQL() 0 5 1
A testSupportsSavePoints() 0 3 1
A testGetCreateSchemaSQL() 0 5 1
A testConvertBooleanAsLiteralIntegers() 0 10 1
A testQuotesTableNameInListTableConstraintsSQL() 0 5 1
A testAltersTableColumnCommentWithExplicitlyQuotedIdentifiers() 0 13 1
A testGeneratesTypeDeclarationForIntegers() 0 14 1
A getQuotedAlterTableRenameColumnSQL() 0 12 1
A serialTypes() 0 5 1
A testQuotesDatabaseNameInCloseActiveDatabaseConnectionsSQL() 0 5 1
A getGenerateForeignKeySql() 0 3 1
A testGeneratesForeignKeySqlForNonStandardOptions() 0 72 1
A getQuotedColumnInPrimaryKeySQL() 0 3 1
A testGeneratesDDLSnippets() 0 5 1
A getQuotedNameInIndexSQL() 0 5 1
A getQuotedAlterTableRenameIndexInSchemaSQL() 0 5 1
A testCreateTableWithAutoincrementAndNotNullAddsConstraint() 0 10 1
A getBinaryMaxLength() 0 3 1
A testReturnsBinaryTypeDeclarationSQL() 0 9 1
A testDroppingConstraintsBeforeColumns() 0 22 1
A testThrowsExceptionWithInvalidBooleanLiteral() 0 8 1
A getGenerateTableSql() 0 3 1
A testGeneratesSequenceSqlCommands() 0 14 1
A dataCreateSequenceWithCache() 0 4 1
A testQuotesTableNameInListTableIndexesSQL() 0 5 1
A testSupportsSequences() 0 3 1
A testGetNullCommentOnColumnSQL() 0 5 1
A testReturnsDisallowDatabaseConnectionsSQL() 0 5 1
A getQuotedColumnInForeignKeySQL() 0 7 1
A testQuotesTableNameInListTableColumnsSQL() 0 5 1
A getAlterTableRenameColumnSQL() 0 3 1
A testSupportsIdentityColumns() 0 3 1
A testGeneratesTypeDeclarationForStrings() 0 17 1
A getAlterTableRenameIndexSQL() 0 3 1

How to fix   Complexity   

Complex Class

Complex classes like AbstractPostgreSQLPlatformTestCase 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 AbstractPostgreSQLPlatformTestCase, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
namespace Doctrine\Tests\DBAL\Platforms;
4
5
use Doctrine\DBAL\Schema\Column;
6
use Doctrine\DBAL\Schema\ColumnDiff;
7
use Doctrine\DBAL\Schema\Comparator;
8
use Doctrine\DBAL\Schema\ForeignKeyConstraint;
9
use Doctrine\DBAL\Schema\Sequence;
10
use Doctrine\DBAL\Schema\Table;
11
use Doctrine\DBAL\Schema\TableDiff;
12
use Doctrine\DBAL\TransactionIsolationLevel;
13
use Doctrine\DBAL\Types\Type;
14
use UnexpectedValueException;
15
use function sprintf;
16
17
abstract class AbstractPostgreSQLPlatformTestCase extends AbstractPlatformTestCase
18
{
19
    public function getGenerateTableSql() : string
20
    {
21
        return 'CREATE TABLE test (id SERIAL NOT NULL, test VARCHAR(255) DEFAULT NULL, PRIMARY KEY(id))';
22
    }
23
24
    /**
25
     * {@inheritDoc}
26
     */
27
    public function getGenerateTableWithMultiColumnUniqueIndexSql() : array
28
    {
29
        return [
30
            'CREATE TABLE test (foo VARCHAR(255) DEFAULT NULL, bar VARCHAR(255) DEFAULT NULL)',
31
            'CREATE UNIQUE INDEX UNIQ_D87F7E0C8C73652176FF8CAA ON test (foo, bar)',
32
        ];
33
    }
34
35
    /**
36
     * {@inheritDoc}
37
     */
38
    public function getGenerateAlterTableSql() : array
39
    {
40
        return [
41
            'ALTER TABLE mytable ADD quota INT DEFAULT NULL',
42
            'ALTER TABLE mytable DROP foo',
43
            'ALTER TABLE mytable ALTER bar TYPE VARCHAR(255)',
44
            "ALTER TABLE mytable ALTER bar SET DEFAULT 'def'",
45
            'ALTER TABLE mytable ALTER bar SET NOT NULL',
46
            'ALTER TABLE mytable ALTER bloo TYPE BOOLEAN',
47
            "ALTER TABLE mytable ALTER bloo SET DEFAULT 'false'",
48
            'ALTER TABLE mytable ALTER bloo SET NOT NULL',
49
            'ALTER TABLE mytable RENAME TO userlist',
50
        ];
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 getGenerateForeignKeySql() : string
59
    {
60
        return 'ALTER TABLE test ADD FOREIGN KEY (fk_name_id) REFERENCES other_table (id) NOT DEFERRABLE INITIALLY IMMEDIATE';
61
    }
62
63
    public function testGeneratesForeignKeySqlForNonStandardOptions() : void
64
    {
65
        $foreignKey = new ForeignKeyConstraint(
66
            ['foreign_id'],
67
            'my_table',
68
            ['id'],
69
            'my_fk',
70
            ['onDelete' => 'CASCADE']
71
        );
72
        self::assertEquals(
73
            'CONSTRAINT my_fk FOREIGN KEY (foreign_id) REFERENCES my_table (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE',
74
            $this->platform->getForeignKeyDeclarationSQL($foreignKey)
75
        );
76
77
        $foreignKey = new ForeignKeyConstraint(
78
            ['foreign_id'],
79
            'my_table',
80
            ['id'],
81
            'my_fk',
82
            ['match' => 'full']
83
        );
84
        self::assertEquals(
85
            'CONSTRAINT my_fk FOREIGN KEY (foreign_id) REFERENCES my_table (id) MATCH full NOT DEFERRABLE INITIALLY IMMEDIATE',
86
            $this->platform->getForeignKeyDeclarationSQL($foreignKey)
87
        );
88
89
        $foreignKey = new ForeignKeyConstraint(
90
            ['foreign_id'],
91
            'my_table',
92
            ['id'],
93
            'my_fk',
94
            ['deferrable' => true]
95
        );
96
        self::assertEquals(
97
            'CONSTRAINT my_fk FOREIGN KEY (foreign_id) REFERENCES my_table (id) DEFERRABLE INITIALLY IMMEDIATE',
98
            $this->platform->getForeignKeyDeclarationSQL($foreignKey)
99
        );
100
101
        $foreignKey = new ForeignKeyConstraint(
102
            ['foreign_id'],
103
            'my_table',
104
            ['id'],
105
            'my_fk',
106
            ['deferred' => true]
107
        );
108
        self::assertEquals(
109
            'CONSTRAINT my_fk FOREIGN KEY (foreign_id) REFERENCES my_table (id) NOT DEFERRABLE INITIALLY DEFERRED',
110
            $this->platform->getForeignKeyDeclarationSQL($foreignKey)
111
        );
112
113
        $foreignKey = new ForeignKeyConstraint(
114
            ['foreign_id'],
115
            'my_table',
116
            ['id'],
117
            'my_fk',
118
            ['feferred' => true]
119
        );
120
        self::assertEquals(
121
            'CONSTRAINT my_fk FOREIGN KEY (foreign_id) REFERENCES my_table (id) NOT DEFERRABLE INITIALLY DEFERRED',
122
            $this->platform->getForeignKeyDeclarationSQL($foreignKey)
123
        );
124
125
        $foreignKey = new ForeignKeyConstraint(
126
            ['foreign_id'],
127
            'my_table',
128
            ['id'],
129
            'my_fk',
130
            ['deferrable' => true, 'deferred' => true, 'match' => 'full']
131
        );
132
        self::assertEquals(
133
            'CONSTRAINT my_fk FOREIGN KEY (foreign_id) REFERENCES my_table (id) MATCH full DEFERRABLE INITIALLY DEFERRED',
134
            $this->platform->getForeignKeyDeclarationSQL($foreignKey)
135
        );
136
    }
137
138
    public function testGeneratesSqlSnippets() : void
139
    {
140
        self::assertEquals('SIMILAR TO', $this->platform->getRegexpExpression(), 'Regular expression operator is not correct');
141
        self::assertEquals('"', $this->platform->getIdentifierQuoteCharacter(), 'Identifier quote character is not correct');
142
        self::assertEquals('column1 || column2 || column3', $this->platform->getConcatExpression('column1', 'column2', 'column3'), 'Concatenation expression is not correct');
143
        self::assertEquals('SUBSTRING(column FROM 5)', $this->platform->getSubstringExpression('column', 5), 'Substring expression without length is not correct');
144
        self::assertEquals('SUBSTRING(column FROM 1 FOR 5)', $this->platform->getSubstringExpression('column', 1, 5), 'Substring expression with length is not correct');
145
    }
146
147
    public function testGeneratesTransactionCommands() : void
148
    {
149
        self::assertEquals(
150
            'SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL READ UNCOMMITTED',
151
            $this->platform->getSetTransactionIsolationSQL(TransactionIsolationLevel::READ_UNCOMMITTED)
152
        );
153
        self::assertEquals(
154
            'SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL READ COMMITTED',
155
            $this->platform->getSetTransactionIsolationSQL(TransactionIsolationLevel::READ_COMMITTED)
156
        );
157
        self::assertEquals(
158
            'SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL REPEATABLE READ',
159
            $this->platform->getSetTransactionIsolationSQL(TransactionIsolationLevel::REPEATABLE_READ)
160
        );
161
        self::assertEquals(
162
            'SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL SERIALIZABLE',
163
            $this->platform->getSetTransactionIsolationSQL(TransactionIsolationLevel::SERIALIZABLE)
164
        );
165
    }
166
167
    public function testGeneratesDDLSnippets() : void
168
    {
169
        self::assertEquals('CREATE DATABASE foobar', $this->platform->getCreateDatabaseSQL('foobar'));
170
        self::assertEquals('DROP DATABASE foobar', $this->platform->getDropDatabaseSQL('foobar'));
171
        self::assertEquals('DROP TABLE foobar', $this->platform->getDropTableSQL('foobar'));
172
    }
173
174
    public function testGenerateTableWithAutoincrement() : void
175
    {
176
        $table  = new Table('autoinc_table');
177
        $column = $table->addColumn('id', 'integer');
178
        $column->setAutoincrement(true);
179
180
        self::assertEquals(['CREATE TABLE autoinc_table (id SERIAL NOT NULL)'], $this->platform->getCreateTableSQL($table));
181
    }
182
183
    /**
184
     * @return mixed[][]
185
     */
186
    public static function serialTypes() : iterable
187
    {
188
        return [
189
            ['integer', 'SERIAL'],
190
            ['bigint', 'BIGSERIAL'],
191
        ];
192
    }
193
194
    /**
195
     * @dataProvider serialTypes
196
     * @group 2906
197
     */
198
    public function testGenerateTableWithAutoincrementDoesNotSetDefault(string $type, string $definition) : void
199
    {
200
        $table  = new Table('autoinc_table_notnull');
201
        $column = $table->addColumn('id', $type);
202
        $column->setAutoIncrement(true);
203
        $column->setNotNull(false);
204
205
        $sql = $this->platform->getCreateTableSQL($table);
206
207
        self::assertEquals([sprintf('CREATE TABLE autoinc_table_notnull (id %s)', $definition)], $sql);
208
    }
209
210
    /**
211
     * @dataProvider serialTypes
212
     * @group 2906
213
     */
214
    public function testCreateTableWithAutoincrementAndNotNullAddsConstraint(string $type, string $definition) : void
215
    {
216
        $table  = new Table('autoinc_table_notnull_enabled');
217
        $column = $table->addColumn('id', $type);
218
        $column->setAutoIncrement(true);
219
        $column->setNotNull(true);
220
221
        $sql = $this->platform->getCreateTableSQL($table);
222
223
        self::assertEquals([sprintf('CREATE TABLE autoinc_table_notnull_enabled (id %s NOT NULL)', $definition)], $sql);
224
    }
225
226
    /**
227
     * @dataProvider serialTypes
228
     * @group 2906
229
     */
230
    public function testGetDefaultValueDeclarationSQLIgnoresTheDefaultKeyWhenTheFieldIsSerial(string $type) : void
231
    {
232
        $sql = $this->platform->getDefaultValueDeclarationSQL(
233
            [
234
                'autoincrement' => true,
235
                'type'          => Type::getType($type),
236
                'default'       => 1,
237
            ]
238
        );
239
240
        self::assertSame('', $sql);
241
    }
242
243
    public function testGeneratesTypeDeclarationForIntegers() : void
244
    {
245
        self::assertEquals(
246
            'INT',
247
            $this->platform->getIntegerTypeDeclarationSQL([])
248
        );
249
        self::assertEquals(
250
            'SERIAL',
251
            $this->platform->getIntegerTypeDeclarationSQL(['autoincrement' => true])
252
        );
253
        self::assertEquals(
254
            'SERIAL',
255
            $this->platform->getIntegerTypeDeclarationSQL(
256
                ['autoincrement' => true, 'primary' => true]
257
            )
258
        );
259
    }
260
261
    public function testGeneratesTypeDeclarationForStrings() : void
262
    {
263
        self::assertEquals(
264
            'CHAR(10)',
265
            $this->platform->getVarcharTypeDeclarationSQL(
266
                ['length' => 10, 'fixed' => true]
267
            )
268
        );
269
        self::assertEquals(
270
            'VARCHAR(50)',
271
            $this->platform->getVarcharTypeDeclarationSQL(['length' => 50]),
272
            'Variable string declaration is not correct'
273
        );
274
        self::assertEquals(
275
            'VARCHAR(255)',
276
            $this->platform->getVarcharTypeDeclarationSQL([]),
277
            'Long string declaration is not correct'
278
        );
279
    }
280
281
    public function getGenerateUniqueIndexSql() : string
282
    {
283
        return 'CREATE UNIQUE INDEX index_name ON test (test, test2)';
284
    }
285
286
    public function testGeneratesSequenceSqlCommands() : void
287
    {
288
        $sequence = new Sequence('myseq', 20, 1);
289
        self::assertEquals(
290
            'CREATE SEQUENCE myseq INCREMENT BY 20 MINVALUE 1 START 1',
291
            $this->platform->getCreateSequenceSQL($sequence)
292
        );
293
        self::assertEquals(
294
            'DROP SEQUENCE myseq CASCADE',
295
            $this->platform->getDropSequenceSQL('myseq')
296
        );
297
        self::assertEquals(
298
            "SELECT NEXTVAL('myseq')",
299
            $this->platform->getSequenceNextValSQL('myseq')
300
        );
301
    }
302
303
    public function testDoesNotPreferIdentityColumns() : void
304
    {
305
        self::assertFalse($this->platform->prefersIdentityColumns());
306
    }
307
308
    public function testPrefersSequences() : void
309
    {
310
        self::assertTrue($this->platform->prefersSequences());
311
    }
312
313
    public function testSupportsIdentityColumns() : void
314
    {
315
        self::assertTrue($this->platform->supportsIdentityColumns());
316
    }
317
318
    public function testSupportsSavePoints() : void
319
    {
320
        self::assertTrue($this->platform->supportsSavepoints());
321
    }
322
323
    public function testSupportsSequences() : void
324
    {
325
        self::assertTrue($this->platform->supportsSequences());
326
    }
327
328
    /**
329
     * {@inheritdoc}
330
     */
331
    protected function supportsCommentOnStatement() : bool
332
    {
333
        return true;
334
    }
335
336
    public function testModifyLimitQuery() : void
337
    {
338
        $sql = $this->platform->modifyLimitQuery('SELECT * FROM user', 10, 0);
339
        self::assertEquals('SELECT * FROM user LIMIT 10', $sql);
340
    }
341
342
    public function testModifyLimitQueryWithEmptyOffset() : void
343
    {
344
        $sql = $this->platform->modifyLimitQuery('SELECT * FROM user', 10);
345
        self::assertEquals('SELECT * FROM user LIMIT 10', $sql);
346
    }
347
348
    /**
349
     * {@inheritDoc}
350
     */
351
    public function getCreateTableColumnCommentsSQL() : array
352
    {
353
        return [
354
            'CREATE TABLE test (id INT NOT NULL, PRIMARY KEY(id))',
355
            "COMMENT ON COLUMN test.id IS 'This is a comment'",
356
        ];
357
    }
358
359
    /**
360
     * {@inheritDoc}
361
     */
362
    public function getAlterTableColumnCommentsSQL() : array
363
    {
364
        return [
365
            'ALTER TABLE mytable ADD quota INT NOT NULL',
366
            "COMMENT ON COLUMN mytable.quota IS 'A comment'",
367
            'COMMENT ON COLUMN mytable.foo IS NULL',
368
            "COMMENT ON COLUMN mytable.baz IS 'B comment'",
369
        ];
370
    }
371
372
    /**
373
     * {@inheritDoc}
374
     */
375
    public function getCreateTableColumnTypeCommentsSQL() : array
376
    {
377
        return [
378
            'CREATE TABLE test (id INT NOT NULL, data TEXT NOT NULL, PRIMARY KEY(id))',
379
            "COMMENT ON COLUMN test.data IS '(DC2Type:array)'",
380
        ];
381
    }
382
383
    /**
384
     * {@inheritDoc}
385
     */
386
    protected function getQuotedColumnInPrimaryKeySQL() : array
387
    {
388
        return ['CREATE TABLE "quoted" ("create" VARCHAR(255) NOT NULL, PRIMARY KEY("create"))'];
389
    }
390
391
    /**
392
     * {@inheritDoc}
393
     */
394
    protected function getQuotedColumnInIndexSQL() : array
395
    {
396
        return [
397
            'CREATE TABLE "quoted" ("create" VARCHAR(255) NOT NULL)',
398
            'CREATE INDEX IDX_22660D028FD6E0FB ON "quoted" ("create")',
399
        ];
400
    }
401
402
    /**
403
     * {@inheritDoc}
404
     */
405
    protected function getQuotedNameInIndexSQL() : array
406
    {
407
        return [
408
            'CREATE TABLE test (column1 VARCHAR(255) NOT NULL)',
409
            'CREATE INDEX "key" ON test (column1)',
410
        ];
411
    }
412
413
    /**
414
     * {@inheritDoc}
415
     */
416
    protected function getQuotedColumnInForeignKeySQL() : array
417
    {
418
        return [
419
            'CREATE TABLE "quoted" ("create" VARCHAR(255) NOT NULL, foo VARCHAR(255) NOT NULL, "bar" VARCHAR(255) NOT NULL)',
420
            'ALTER TABLE "quoted" ADD CONSTRAINT FK_WITH_RESERVED_KEYWORD FOREIGN KEY ("create", foo, "bar") REFERENCES "foreign" ("create", bar, "foo-bar") NOT DEFERRABLE INITIALLY IMMEDIATE',
421
            'ALTER TABLE "quoted" ADD CONSTRAINT FK_WITH_NON_RESERVED_KEYWORD FOREIGN KEY ("create", foo, "bar") REFERENCES foo ("create", bar, "foo-bar") NOT DEFERRABLE INITIALLY IMMEDIATE',
422
            'ALTER TABLE "quoted" ADD CONSTRAINT FK_WITH_INTENDED_QUOTATION FOREIGN KEY ("create", foo, "bar") REFERENCES "foo-bar" ("create", bar, "foo-bar") NOT DEFERRABLE INITIALLY IMMEDIATE',
423
        ];
424
    }
425
426
    /**
427
     * @param string|bool $databaseValue
428
     *
429
     * @group DBAL-457
430
     * @dataProvider pgBooleanProvider
431
     */
432
    public function testConvertBooleanAsLiteralStrings(
433
        $databaseValue,
434
        string $preparedStatementValue,
435
        ?int $integerValue,
0 ignored issues
show
Unused Code introduced by
The parameter $integerValue is not used and could be removed. ( Ignorable by Annotation )

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

435
        /** @scrutinizer ignore-unused */ ?int $integerValue,

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
436
        ?bool $booleanValue
0 ignored issues
show
Unused Code introduced by
The parameter $booleanValue is not used and could be removed. ( Ignorable by Annotation )

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

436
        /** @scrutinizer ignore-unused */ ?bool $booleanValue

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
437
    ) : void {
438
        $platform = $this->createPlatform();
439
440
        self::assertEquals($preparedStatementValue, $platform->convertBooleans($databaseValue));
441
    }
442
443
    /**
444
     * @group DBAL-457
445
     */
446
    public function testConvertBooleanAsLiteralIntegers() : void
447
    {
448
        $platform = $this->createPlatform();
449
        $platform->setUseBooleanTrueFalseStrings(false);
0 ignored issues
show
Bug introduced by
The method setUseBooleanTrueFalseStrings() does not exist on Doctrine\DBAL\Platforms\AbstractPlatform. It seems like you code against a sub-type of Doctrine\DBAL\Platforms\AbstractPlatform such as Doctrine\DBAL\Platforms\PostgreSQL94Platform. ( Ignorable by Annotation )

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

449
        $platform->/** @scrutinizer ignore-call */ 
450
                   setUseBooleanTrueFalseStrings(false);
Loading history...
450
451
        self::assertEquals(1, $platform->convertBooleans(true));
452
        self::assertEquals(1, $platform->convertBooleans('1'));
453
454
        self::assertEquals(0, $platform->convertBooleans(false));
455
        self::assertEquals(0, $platform->convertBooleans('0'));
456
    }
457
458
    /**
459
     * @param string|bool $databaseValue
460
     *
461
     * @group DBAL-630
462
     * @dataProvider pgBooleanProvider
463
     */
464
    public function testConvertBooleanAsDatabaseValueStrings(
465
        $databaseValue,
0 ignored issues
show
Unused Code introduced by
The parameter $databaseValue is not used and could be removed. ( Ignorable by Annotation )

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

465
        /** @scrutinizer ignore-unused */ $databaseValue,

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
466
        string $preparedStatementValue,
0 ignored issues
show
Unused Code introduced by
The parameter $preparedStatementValue is not used and could be removed. ( Ignorable by Annotation )

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

466
        /** @scrutinizer ignore-unused */ string $preparedStatementValue,

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
467
        ?int $integerValue,
468
        ?bool $booleanValue
469
    ) : void {
470
        $platform = $this->createPlatform();
471
472
        self::assertSame($integerValue, $platform->convertBooleansToDatabaseValue($booleanValue));
473
    }
474
475
    /**
476
     * @group DBAL-630
477
     */
478
    public function testConvertBooleanAsDatabaseValueIntegers() : void
479
    {
480
        $platform = $this->createPlatform();
481
        $platform->setUseBooleanTrueFalseStrings(false);
482
483
        self::assertSame(1, $platform->convertBooleansToDatabaseValue(true));
484
        self::assertSame(0, $platform->convertBooleansToDatabaseValue(false));
485
    }
486
487
    /**
488
     * @param string|bool $databaseValue
489
     *
490
     * @dataProvider pgBooleanProvider
491
     */
492
    public function testConvertFromBoolean($databaseValue, string $prepareStatementValue, ?int $integerValue, ?bool $booleanValue) : void
0 ignored issues
show
Unused Code introduced by
The parameter $prepareStatementValue is not used and could be removed. ( Ignorable by Annotation )

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

492
    public function testConvertFromBoolean($databaseValue, /** @scrutinizer ignore-unused */ string $prepareStatementValue, ?int $integerValue, ?bool $booleanValue) : void

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $integerValue is not used and could be removed. ( Ignorable by Annotation )

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

492
    public function testConvertFromBoolean($databaseValue, string $prepareStatementValue, /** @scrutinizer ignore-unused */ ?int $integerValue, ?bool $booleanValue) : void

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
493
    {
494
        $platform = $this->createPlatform();
495
496
        self::assertSame($booleanValue, $platform->convertFromBoolean($databaseValue));
497
    }
498
499
    public function testThrowsExceptionWithInvalidBooleanLiteral() : void
500
    {
501
        $platform = $this->createPlatform();
502
503
        $this->expectException(UnexpectedValueException::class);
504
        $this->expectExceptionMessage("Unrecognized boolean literal 'my-bool'");
505
506
        $platform->convertBooleansToDatabaseValue('my-bool');
507
    }
508
509
    public function testGetCreateSchemaSQL() : void
510
    {
511
        $schemaName = 'schema';
512
        $sql        = $this->platform->getCreateSchemaSQL($schemaName);
513
        self::assertEquals('CREATE SCHEMA ' . $schemaName, $sql);
514
    }
515
516
    public function testAlterDecimalPrecisionScale() : void
517
    {
518
        $table = new Table('mytable');
519
        $table->addColumn('dfoo1', 'decimal');
520
        $table->addColumn('dfoo2', 'decimal', ['precision' => 10, 'scale' => 6]);
521
        $table->addColumn('dfoo3', 'decimal', ['precision' => 10, 'scale' => 6]);
522
        $table->addColumn('dfoo4', 'decimal', ['precision' => 10, 'scale' => 6]);
523
524
        $tableDiff            = new TableDiff('mytable');
525
        $tableDiff->fromTable = $table;
526
527
        $tableDiff->changedColumns['dloo1'] = new ColumnDiff(
528
            'dloo1',
529
            new Column(
530
                'dloo1',
531
                Type::getType('decimal'),
532
                ['precision' => 16, 'scale' => 6]
533
            ),
534
            ['precision']
535
        );
536
        $tableDiff->changedColumns['dloo2'] = new ColumnDiff(
537
            'dloo2',
538
            new Column(
539
                'dloo2',
540
                Type::getType('decimal'),
541
                ['precision' => 10, 'scale' => 4]
542
            ),
543
            ['scale']
544
        );
545
        $tableDiff->changedColumns['dloo3'] = new ColumnDiff(
546
            'dloo3',
547
            new Column(
548
                'dloo3',
549
                Type::getType('decimal'),
550
                ['precision' => 10, 'scale' => 6]
551
            ),
552
            []
553
        );
554
        $tableDiff->changedColumns['dloo4'] = new ColumnDiff(
555
            'dloo4',
556
            new Column(
557
                'dloo4',
558
                Type::getType('decimal'),
559
                ['precision' => 16, 'scale' => 8]
560
            ),
561
            ['precision', 'scale']
562
        );
563
564
        $sql = $this->platform->getAlterTableSQL($tableDiff);
565
566
        $expectedSql = [
567
            'ALTER TABLE mytable ALTER dloo1 TYPE NUMERIC(16, 6)',
568
            'ALTER TABLE mytable ALTER dloo2 TYPE NUMERIC(10, 4)',
569
            'ALTER TABLE mytable ALTER dloo4 TYPE NUMERIC(16, 8)',
570
        ];
571
572
        self::assertEquals($expectedSql, $sql);
573
    }
574
575
    /**
576
     * @group DBAL-365
577
     */
578
    public function testDroppingConstraintsBeforeColumns() : void
579
    {
580
        $newTable = new Table('mytable');
581
        $newTable->addColumn('id', 'integer');
582
        $newTable->setPrimaryKey(['id']);
583
584
        $oldTable = clone $newTable;
585
        $oldTable->addColumn('parent_id', 'integer');
586
        $oldTable->addUnnamedForeignKeyConstraint('mytable', ['parent_id'], ['id']);
587
588
        $comparator = new Comparator();
589
        $tableDiff  = $comparator->diffTable($oldTable, $newTable);
590
591
        $sql = $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

591
        $sql = $this->platform->getAlterTableSQL(/** @scrutinizer ignore-type */ $tableDiff);
Loading history...
592
593
        $expectedSql = [
594
            'ALTER TABLE mytable DROP CONSTRAINT FK_6B2BD609727ACA70',
595
            'DROP INDEX IDX_6B2BD609727ACA70',
596
            'ALTER TABLE mytable DROP parent_id',
597
        ];
598
599
        self::assertEquals($expectedSql, $sql);
600
    }
601
602
    /**
603
     * @group DBAL-563
604
     */
605
    public function testUsesSequenceEmulatedIdentityColumns() : void
606
    {
607
        self::assertTrue($this->platform->usesSequenceEmulatedIdentityColumns());
608
    }
609
610
    /**
611
     * @group DBAL-563
612
     */
613
    public function testReturnsIdentitySequenceName() : void
614
    {
615
        self::assertSame('mytable_mycolumn_seq', $this->platform->getIdentitySequenceName('mytable', 'mycolumn'));
616
    }
617
618
    /**
619
     * @dataProvider dataCreateSequenceWithCache
620
     * @group DBAL-139
621
     */
622
    public function testCreateSequenceWithCache(int $cacheSize, string $expectedSql) : void
623
    {
624
        $sequence = new Sequence('foo', 1, 1, $cacheSize);
625
        self::assertStringContainsString($expectedSql, $this->platform->getCreateSequenceSQL($sequence));
626
    }
627
628
    /**
629
     * @return mixed[][]
630
     */
631
    public static function dataCreateSequenceWithCache() : iterable
632
    {
633
        return [
634
            [3, 'CACHE 3'],
635
        ];
636
    }
637
638
    protected function getBinaryDefaultLength() : int
639
    {
640
        return 0;
641
    }
642
643
    protected function getBinaryMaxLength() : int
644
    {
645
        return 0;
646
    }
647
648
    public function testReturnsBinaryTypeDeclarationSQL() : void
649
    {
650
        self::assertSame('BYTEA', $this->platform->getBinaryTypeDeclarationSQL([]));
651
        self::assertSame('BYTEA', $this->platform->getBinaryTypeDeclarationSQL(['length' => 0]));
652
        self::assertSame('BYTEA', $this->platform->getBinaryTypeDeclarationSQL(['length' => 9999999]));
653
654
        self::assertSame('BYTEA', $this->platform->getBinaryTypeDeclarationSQL(['fixed' => true]));
655
        self::assertSame('BYTEA', $this->platform->getBinaryTypeDeclarationSQL(['fixed' => true, 'length' => 0]));
656
        self::assertSame('BYTEA', $this->platform->getBinaryTypeDeclarationSQL(['fixed' => true, 'length' => 9999999]));
657
    }
658
659
    public function testDoesNotPropagateUnnecessaryTableAlterationOnBinaryType() : void
660
    {
661
        $table1 = new Table('mytable');
662
        $table1->addColumn('column_varbinary', 'binary');
663
        $table1->addColumn('column_binary', 'binary', ['fixed' => true]);
664
        $table1->addColumn('column_blob', 'blob');
665
666
        $table2 = new Table('mytable');
667
        $table2->addColumn('column_varbinary', 'binary', ['fixed' => true]);
668
        $table2->addColumn('column_binary', 'binary');
669
        $table2->addColumn('column_blob', 'binary');
670
671
        $comparator = new Comparator();
672
673
        // VARBINARY -> BINARY
674
        // BINARY    -> VARBINARY
675
        // BLOB      -> VARBINARY
676
        self::assertEmpty($this->platform->getAlterTableSQL($comparator->diffTable($table1, $table2)));
0 ignored issues
show
Bug introduced by
It seems like $comparator->diffTable($table1, $table2) 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

676
        self::assertEmpty($this->platform->getAlterTableSQL(/** @scrutinizer ignore-type */ $comparator->diffTable($table1, $table2)));
Loading history...
677
678
        $table2 = new Table('mytable');
679
        $table2->addColumn('column_varbinary', 'binary', ['length' => 42]);
680
        $table2->addColumn('column_binary', 'blob');
681
        $table2->addColumn('column_blob', 'binary', ['length' => 11, 'fixed' => true]);
682
683
        // VARBINARY -> VARBINARY with changed length
684
        // BINARY    -> BLOB
685
        // BLOB      -> BINARY
686
        self::assertEmpty($this->platform->getAlterTableSQL($comparator->diffTable($table1, $table2)));
687
688
        $table2 = new Table('mytable');
689
        $table2->addColumn('column_varbinary', 'blob');
690
        $table2->addColumn('column_binary', 'binary', ['length' => 42, 'fixed' => true]);
691
        $table2->addColumn('column_blob', 'blob');
692
693
        // VARBINARY -> BLOB
694
        // BINARY    -> BINARY with changed length
695
        // BLOB      -> BLOB
696
        self::assertEmpty($this->platform->getAlterTableSQL($comparator->diffTable($table1, $table2)));
697
    }
698
699
    /**
700
     * {@inheritDoc}
701
     *
702
     * @group DBAL-234
703
     */
704
    protected function getAlterTableRenameIndexSQL() : array
705
    {
706
        return ['ALTER INDEX idx_foo RENAME TO idx_bar'];
707
    }
708
709
    /**
710
     * {@inheritDoc}
711
     *
712
     * @group DBAL-234
713
     */
714
    protected function getQuotedAlterTableRenameIndexSQL() : array
715
    {
716
        return [
717
            'ALTER INDEX "create" RENAME TO "select"',
718
            'ALTER INDEX "foo" RENAME TO "bar"',
719
        ];
720
    }
721
722
    /**
723
     * PostgreSQL boolean strings provider
724
     *
725
     * @return mixed[][]
726
     */
727
    public static function pgBooleanProvider() : iterable
728
    {
729
        return [
730
            // Database value, prepared statement value, boolean integer value, boolean value.
731
            [true, 'true', 1, true],
732
            ['t', 'true', 1, true],
733
            ['true', 'true', 1, true],
734
            ['y', 'true', 1, true],
735
            ['yes', 'true', 1, true],
736
            ['on', 'true', 1, true],
737
            ['1', 'true', 1, true],
738
739
            [false, 'false', 0, false],
740
            ['f', 'false', 0, false],
741
            ['false', 'false', 0, false],
742
            [ 'n', 'false', 0, false],
743
            ['no', 'false', 0, false],
744
            ['off', 'false', 0, false],
745
            ['0', 'false', 0, false],
746
747
            [null, 'NULL', null, null],
748
        ];
749
    }
750
751
    /**
752
     * {@inheritdoc}
753
     */
754
    protected function getQuotedAlterTableRenameColumnSQL() : array
755
    {
756
        return [
757
            'ALTER TABLE mytable RENAME COLUMN unquoted1 TO unquoted',
758
            'ALTER TABLE mytable RENAME COLUMN unquoted2 TO "where"',
759
            'ALTER TABLE mytable RENAME COLUMN unquoted3 TO "foo"',
760
            'ALTER TABLE mytable RENAME COLUMN "create" TO reserved_keyword',
761
            'ALTER TABLE mytable RENAME COLUMN "table" TO "from"',
762
            'ALTER TABLE mytable RENAME COLUMN "select" TO "bar"',
763
            'ALTER TABLE mytable RENAME COLUMN quoted1 TO quoted',
764
            'ALTER TABLE mytable RENAME COLUMN quoted2 TO "and"',
765
            'ALTER TABLE mytable RENAME COLUMN quoted3 TO "baz"',
766
        ];
767
    }
768
769
    /**
770
     * {@inheritdoc}
771
     */
772
    protected function getQuotedAlterTableChangeColumnLengthSQL() : array
773
    {
774
        return [
775
            'ALTER TABLE mytable ALTER unquoted1 TYPE VARCHAR(255)',
776
            'ALTER TABLE mytable ALTER unquoted2 TYPE VARCHAR(255)',
777
            'ALTER TABLE mytable ALTER unquoted3 TYPE VARCHAR(255)',
778
            'ALTER TABLE mytable ALTER "create" TYPE VARCHAR(255)',
779
            'ALTER TABLE mytable ALTER "table" TYPE VARCHAR(255)',
780
            'ALTER TABLE mytable ALTER "select" TYPE VARCHAR(255)',
781
        ];
782
    }
783
784
    /**
785
     * {@inheritDoc}
786
     *
787
     * @group DBAL-807
788
     */
789
    protected function getAlterTableRenameIndexInSchemaSQL() : array
790
    {
791
        return ['ALTER INDEX myschema.idx_foo RENAME TO idx_bar'];
792
    }
793
794
    /**
795
     * {@inheritDoc}
796
     *
797
     * @group DBAL-807
798
     */
799
    protected function getQuotedAlterTableRenameIndexInSchemaSQL() : array
800
    {
801
        return [
802
            'ALTER INDEX "schema"."create" RENAME TO "select"',
803
            'ALTER INDEX "schema"."foo" RENAME TO "bar"',
804
        ];
805
    }
806
807
    protected function getQuotesDropForeignKeySQL() : string
808
    {
809
        return 'ALTER TABLE "table" DROP CONSTRAINT "select"';
810
    }
811
812
    public function testGetNullCommentOnColumnSQL() : void
813
    {
814
        self::assertEquals(
815
            'COMMENT ON COLUMN mytable.id IS NULL',
816
            $this->platform->getCommentOnColumnSQL('mytable', 'id', null)
817
        );
818
    }
819
820
    /**
821
     * @group DBAL-423
822
     */
823
    public function testReturnsGuidTypeDeclarationSQL() : void
824
    {
825
        self::assertSame('UUID', $this->platform->getGuidTypeDeclarationSQL([]));
826
    }
827
828
    /**
829
     * {@inheritdoc}
830
     */
831
    public function getAlterTableRenameColumnSQL() : array
832
    {
833
        return ['ALTER TABLE foo RENAME COLUMN bar TO baz'];
834
    }
835
836
    /**
837
     * {@inheritdoc}
838
     */
839
    protected function getQuotesTableIdentifiersInAlterTableSQL() : array
840
    {
841
        return [
842
            'ALTER TABLE "foo" DROP CONSTRAINT fk1',
843
            'ALTER TABLE "foo" DROP CONSTRAINT fk2',
844
            'ALTER TABLE "foo" ADD bloo INT NOT NULL',
845
            'ALTER TABLE "foo" DROP baz',
846
            'ALTER TABLE "foo" ALTER bar DROP NOT NULL',
847
            'ALTER TABLE "foo" RENAME COLUMN id TO war',
848
            'ALTER TABLE "foo" RENAME TO "table"',
849
            'ALTER TABLE "table" ADD CONSTRAINT fk_add FOREIGN KEY (fk3) REFERENCES fk_table (id) NOT DEFERRABLE ' .
850
            'INITIALLY IMMEDIATE',
851
            'ALTER TABLE "table" ADD CONSTRAINT fk2 FOREIGN KEY (fk2) REFERENCES fk_table2 (id) NOT DEFERRABLE ' .
852
            'INITIALLY IMMEDIATE',
853
        ];
854
    }
855
856
    /**
857
     * {@inheritdoc}
858
     */
859
    protected function getCommentOnColumnSQL() : array
860
    {
861
        return [
862
            'COMMENT ON COLUMN foo.bar IS \'comment\'',
863
            'COMMENT ON COLUMN "Foo"."BAR" IS \'comment\'',
864
            'COMMENT ON COLUMN "select"."from" IS \'comment\'',
865
        ];
866
    }
867
868
    /**
869
     * @group DBAL-1004
870
     */
871
    public function testAltersTableColumnCommentWithExplicitlyQuotedIdentifiers() : void
872
    {
873
        $table1 = new Table('"foo"', [new Column('"bar"', Type::getType('integer'))]);
874
        $table2 = new Table('"foo"', [new Column('"bar"', Type::getType('integer'), ['comment' => 'baz'])]);
875
876
        $comparator = new Comparator();
877
878
        $tableDiff = $comparator->diffTable($table1, $table2);
879
880
        self::assertInstanceOf(TableDiff::class, $tableDiff);
881
        self::assertSame(
882
            ['COMMENT ON COLUMN "foo"."bar" IS \'baz\''],
883
            $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

883
            $this->platform->getAlterTableSQL(/** @scrutinizer ignore-type */ $tableDiff)
Loading history...
884
        );
885
    }
886
887
    /**
888
     * @group 3158
889
     */
890
    public function testAltersTableColumnCommentIfRequiredByType() : void
891
    {
892
        $table1 = new Table('"foo"', [new Column('"bar"', Type::getType('datetime'))]);
893
        $table2 = new Table('"foo"', [new Column('"bar"', Type::getType('datetime_immutable'))]);
894
895
        $comparator = new Comparator();
896
897
        $tableDiff = $comparator->diffTable($table1, $table2);
898
899
        $this->assertInstanceOf('Doctrine\DBAL\Schema\TableDiff', $tableDiff);
900
        $this->assertSame(
901
            [
902
                'ALTER TABLE "foo" ALTER "bar" TYPE TIMESTAMP(0) WITHOUT TIME ZONE',
903
                'ALTER TABLE "foo" ALTER "bar" DROP DEFAULT',
904
                'COMMENT ON COLUMN "foo"."bar" IS \'(DC2Type:datetime_immutable)\'',
905
            ],
906
            $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

906
            $this->platform->getAlterTableSQL(/** @scrutinizer ignore-type */ $tableDiff)
Loading history...
907
        );
908
    }
909
910
    /**
911
     * {@inheritdoc}
912
     */
913
    protected function getQuotesReservedKeywordInUniqueConstraintDeclarationSQL() : string
914
    {
915
        return 'CONSTRAINT "select" UNIQUE (foo)';
916
    }
917
918
    /**
919
     * {@inheritdoc}
920
     */
921
    protected function getQuotesReservedKeywordInIndexDeclarationSQL() : string
922
    {
923
        return 'INDEX "select" (foo)';
924
    }
925
926
    /**
927
     * {@inheritdoc}
928
     */
929
    protected function getQuotesReservedKeywordInTruncateTableSQL() : string
930
    {
931
        return 'TRUNCATE "select"';
932
    }
933
934
    /**
935
     * {@inheritdoc}
936
     */
937
    protected function getAlterStringToFixedStringSQL() : array
938
    {
939
        return ['ALTER TABLE mytable ALTER name TYPE CHAR(2)'];
940
    }
941
942
    /**
943
     * {@inheritdoc}
944
     */
945
    protected function getGeneratesAlterTableRenameIndexUsedByForeignKeySQL() : array
946
    {
947
        return ['ALTER INDEX idx_foo RENAME TO idx_foo_renamed'];
948
    }
949
950
    /**
951
     * @group DBAL-1142
952
     */
953
    public function testInitializesTsvectorTypeMapping() : void
954
    {
955
        self::assertTrue($this->platform->hasDoctrineTypeMappingFor('tsvector'));
956
        self::assertEquals('text', $this->platform->getDoctrineTypeMapping('tsvector'));
957
    }
958
959
    /**
960
     * @group DBAL-1220
961
     */
962
    public function testReturnsDisallowDatabaseConnectionsSQL() : void
963
    {
964
        self::assertSame(
965
            "UPDATE pg_database SET datallowconn = 'false' WHERE datname = 'foo'",
966
            $this->platform->getDisallowDatabaseConnectionsSQL('foo')
0 ignored issues
show
Bug introduced by
The method getDisallowDatabaseConnectionsSQL() does not exist on Doctrine\DBAL\Platforms\AbstractPlatform. It seems like you code against a sub-type of Doctrine\DBAL\Platforms\AbstractPlatform such as Doctrine\DBAL\Platforms\PostgreSQL94Platform. ( Ignorable by Annotation )

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

966
            $this->platform->/** @scrutinizer ignore-call */ 
967
                             getDisallowDatabaseConnectionsSQL('foo')
Loading history...
967
        );
968
    }
969
970
    /**
971
     * @group DBAL-1220
972
     */
973
    public function testReturnsCloseActiveDatabaseConnectionsSQL() : void
974
    {
975
        self::assertSame(
976
            "SELECT pg_terminate_backend(procpid) FROM pg_stat_activity WHERE datname = 'foo'",
977
            $this->platform->getCloseActiveDatabaseConnectionsSQL('foo')
0 ignored issues
show
Bug introduced by
The method getCloseActiveDatabaseConnectionsSQL() does not exist on Doctrine\DBAL\Platforms\AbstractPlatform. It seems like you code against a sub-type of Doctrine\DBAL\Platforms\AbstractPlatform such as Doctrine\DBAL\Platforms\PostgreSQL94Platform. ( Ignorable by Annotation )

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

977
            $this->platform->/** @scrutinizer ignore-call */ 
978
                             getCloseActiveDatabaseConnectionsSQL('foo')
Loading history...
978
        );
979
    }
980
981
    /**
982
     * @group DBAL-2436
983
     */
984
    public function testQuotesTableNameInListTableForeignKeysSQL() : void
985
    {
986
        self::assertStringContainsStringIgnoringCase(
987
            "'Foo''Bar\\'",
988
            $this->platform->getListTableForeignKeysSQL("Foo'Bar\\")
989
        );
990
    }
991
992
    /**
993
     * @group DBAL-2436
994
     */
995
    public function testQuotesSchemaNameInListTableForeignKeysSQL() : void
996
    {
997
        self::assertStringContainsStringIgnoringCase(
998
            "'Foo''Bar\\'",
999
            $this->platform->getListTableForeignKeysSQL("Foo'Bar\\.baz_table")
1000
        );
1001
    }
1002
1003
    /**
1004
     * @group DBAL-2436
1005
     */
1006
    public function testQuotesTableNameInListTableConstraintsSQL() : void
1007
    {
1008
        self::assertStringContainsStringIgnoringCase(
1009
            "'Foo''Bar\\'",
1010
            $this->platform->getListTableConstraintsSQL("Foo'Bar\\")
1011
        );
1012
    }
1013
1014
    /**
1015
     * @group DBAL-2436
1016
     */
1017
    public function testQuotesTableNameInListTableIndexesSQL() : void
1018
    {
1019
        self::assertStringContainsStringIgnoringCase(
1020
            "'Foo''Bar\\'",
1021
            $this->platform->getListTableIndexesSQL("Foo'Bar\\")
1022
        );
1023
    }
1024
1025
    /**
1026
     * @group DBAL-2436
1027
     */
1028
    public function testQuotesSchemaNameInListTableIndexesSQL() : void
1029
    {
1030
        self::assertStringContainsStringIgnoringCase(
1031
            "'Foo''Bar\\'",
1032
            $this->platform->getListTableIndexesSQL("Foo'Bar\\.baz_table")
1033
        );
1034
    }
1035
1036
    /**
1037
     * @group DBAL-2436
1038
     */
1039
    public function testQuotesTableNameInListTableColumnsSQL() : void
1040
    {
1041
        self::assertStringContainsStringIgnoringCase(
1042
            "'Foo''Bar\\'",
1043
            $this->platform->getListTableColumnsSQL("Foo'Bar\\")
1044
        );
1045
    }
1046
1047
    /**
1048
     * @group DBAL-2436
1049
     */
1050
    public function testQuotesSchemaNameInListTableColumnsSQL() : void
1051
    {
1052
        self::assertStringContainsStringIgnoringCase(
1053
            "'Foo''Bar\\'",
1054
            $this->platform->getListTableColumnsSQL("Foo'Bar\\.baz_table")
1055
        );
1056
    }
1057
1058
    /**
1059
     * @group DBAL-2436
1060
     */
1061
    public function testQuotesDatabaseNameInCloseActiveDatabaseConnectionsSQL() : void
1062
    {
1063
        self::assertStringContainsStringIgnoringCase(
1064
            "'Foo''Bar\\'",
1065
            $this->platform->getCloseActiveDatabaseConnectionsSQL("Foo'Bar\\")
1066
        );
1067
    }
1068
}
1069