diff --git a/UPGRADE.md b/UPGRADE.md index 57b320f7069..b4ee920bd27 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -1,5 +1,11 @@ # Upgrade to 3.0 +## BC BREAK: Changes in the `Doctrine\DBAL\Schema` API + +- Column precision no longer defaults to 10. The default value is NULL. +- Asset names are no longer nullable. An empty asset name should be represented as an empty string. +- `Doctrine\DBAL\Schema\AbstractSchemaManager::_getPortableTriggersList()` and `::_getPortableTriggerDefinition()` have been removed. + ## BC BREAK: Changes in the `Doctrine\DBAL\Event` API - `SchemaAlterTableAddColumnEventArgs::addSql()` and the same method in other `SchemaEventArgs`-based classes no longer accept an array of SQL statements. They accept a variadic string. diff --git a/lib/Doctrine/DBAL/Schema/AbstractAsset.php b/lib/Doctrine/DBAL/Schema/AbstractAsset.php index 6afec63d20d..6453826731b 100644 --- a/lib/Doctrine/DBAL/Schema/AbstractAsset.php +++ b/lib/Doctrine/DBAL/Schema/AbstractAsset.php @@ -25,7 +25,7 @@ abstract class AbstractAsset { /** @var string */ - protected $_name; + protected $_name = ''; /** * Namespace of the asset. If none isset the default namespace is assumed. @@ -138,7 +138,7 @@ public function getName() : string return $this->_namespace . '.' . $this->_name; } - return $this->_name ?? ''; + return $this->_name; } /** @@ -167,7 +167,7 @@ public function getQuotedName(AbstractPlatform $platform) : string */ protected function _generateIdentifierName(array $columnNames, string $prefix = '', int $maxSize = 30) : string { - $hash = implode('', array_map(static function ($column) { + $hash = implode('', array_map(static function ($column) : string { return dechex(crc32($column)); }, $columnNames)); diff --git a/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php b/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php index 0e59e607db3..fc7a79eb9ad 100644 --- a/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php @@ -223,7 +223,7 @@ public function listTableNames() : array * * @return array */ - protected function filterAssetNames(array $assetNames) + protected function filterAssetNames(array $assetNames) : array { $filter = $this->_conn->getConfiguration()->getSchemaAssetsFilter(); if (! $filter) { @@ -605,35 +605,6 @@ protected function getPortableNamespaceDefinition(array $namespace) : string return array_shift($namespace); } - /** - * @param array> $triggers - * - * @return array - */ - protected function _getPortableTriggersList(array $triggers) - { - $list = []; - foreach ($triggers as $value) { - $value = $this->_getPortableTriggerDefinition($value); - - if (! $value) { - continue; - } - - $list[] = $value; - } - - return $list; - } - - /** - * @param array $trigger - */ - protected function _getPortableTriggerDefinition(array $trigger) : string - { - return array_shift($trigger); - } - /** * @param array> $sequences * diff --git a/lib/Doctrine/DBAL/Schema/Column.php b/lib/Doctrine/DBAL/Schema/Column.php index 928f0485ec2..ea90241b419 100644 --- a/lib/Doctrine/DBAL/Schema/Column.php +++ b/lib/Doctrine/DBAL/Schema/Column.php @@ -23,7 +23,7 @@ class Column extends AbstractAsset protected $_length; /** @var int|null */ - protected $_precision = 10; + protected $_precision; /** @var int */ protected $_scale = 0; @@ -106,10 +106,6 @@ public function setLength(?int $length) : self public function setPrecision(?int $precision) : self { - if ($precision === null) { - $precision = 10; // defaults to 10 when no precision is given. - } - $this->_precision = $precision; return $this; @@ -195,7 +191,7 @@ public function getPrecision() : ?int return $this->_precision; } - public function getScale() : ?int + public function getScale() : int { return $this->_scale; } diff --git a/lib/Doctrine/DBAL/Schema/ForeignKeyConstraint.php b/lib/Doctrine/DBAL/Schema/ForeignKeyConstraint.php index 6b7844f4b42..aeaef414020 100644 --- a/lib/Doctrine/DBAL/Schema/ForeignKeyConstraint.php +++ b/lib/Doctrine/DBAL/Schema/ForeignKeyConstraint.php @@ -59,14 +59,12 @@ class ForeignKeyConstraint extends AbstractAsset implements Constraint * @param array $localColumnNames Names of the referencing table columns. * @param Table|string $foreignTableName Referenced table. * @param array $foreignColumnNames Names of the referenced table columns. - * @param string|null $name Name of the foreign key constraint. + * @param string $name Name of the foreign key constraint. * @param array $options Options associated with the foreign key constraint. */ - public function __construct(array $localColumnNames, $foreignTableName, array $foreignColumnNames, $name = null, array $options = []) + public function __construct(array $localColumnNames, $foreignTableName, array $foreignColumnNames, string $name = '', array $options = []) { - if ($name !== null) { - $this->_setName($name); - } + $this->_setName($name); $this->_localColumnNames = $this->createIdentifierMap($localColumnNames); diff --git a/lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php b/lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php index 206c6fd8ed9..2511746fda4 100644 --- a/lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php @@ -92,7 +92,7 @@ public function determineExistingSchemaSearchPaths() : void $names = $this->getSchemaNames(); $paths = $this->getSchemaSearchPaths(); - $this->existingSchemaPaths = array_filter($paths, static function ($v) use ($names) { + $this->existingSchemaPaths = array_filter($paths, static function ($v) use ($names) : bool { return in_array($v, $names); }); } @@ -161,14 +161,6 @@ protected function _getPortableTableForeignKeyDefinition(array $tableForeignKey) ); } - /** - * {@inheritdoc} - */ - protected function _getPortableTriggerDefinition(array $trigger) : string - { - return $trigger['trigger_name']; - } - /** * {@inheritdoc} */ diff --git a/lib/Doctrine/DBAL/Schema/SQLAnywhereSchemaManager.php b/lib/Doctrine/DBAL/Schema/SQLAnywhereSchemaManager.php index bfb34b44a21..58ae1f4d906 100644 --- a/lib/Doctrine/DBAL/Schema/SQLAnywhereSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/SQLAnywhereSchemaManager.php @@ -45,13 +45,13 @@ public function dropDatabase(string $database) : void parent::dropDatabase($database); } - public function startDatabase(string $database) + public function startDatabase(string $database) : void { assert($this->_platform instanceof SQLAnywherePlatform); $this->_execSql($this->_platform->getStartDatabaseSQL($database)); } - public function stopDatabase(string $database) + public function stopDatabase(string $database) : void { assert($this->_platform instanceof SQLAnywherePlatform); $this->_execSql($this->_platform->getStopDatabaseSQL($database)); diff --git a/lib/Doctrine/DBAL/Schema/Schema.php b/lib/Doctrine/DBAL/Schema/Schema.php index 155578efb3c..96e2f111c76 100644 --- a/lib/Doctrine/DBAL/Schema/Schema.php +++ b/lib/Doctrine/DBAL/Schema/Schema.php @@ -408,8 +408,6 @@ public function visit(Visitor $visitor) : void /** * Cloning a Schema triggers a deep clone of all related assets. - * - * @return void */ public function __clone() { diff --git a/lib/Doctrine/DBAL/Schema/SchemaDiff.php b/lib/Doctrine/DBAL/Schema/SchemaDiff.php index 6a572f3ba8e..92281181cb6 100644 --- a/lib/Doctrine/DBAL/Schema/SchemaDiff.php +++ b/lib/Doctrine/DBAL/Schema/SchemaDiff.php @@ -120,7 +120,7 @@ protected function _toSql(AbstractPlatform $platform, bool $saveMode = false) : } } - if ($platform->supportsSequences() === true) { + if ($platform->supportsSequences()) { foreach ($this->changedSequences as $sequence) { $sql[] = $platform->getAlterSequenceSQL($sequence); } diff --git a/lib/Doctrine/DBAL/Schema/Table.php b/lib/Doctrine/DBAL/Schema/Table.php index 99a742a6010..1c271e7fc83 100644 --- a/lib/Doctrine/DBAL/Schema/Table.php +++ b/lib/Doctrine/DBAL/Schema/Table.php @@ -462,7 +462,7 @@ public function getColumns() : array $colNames = array_unique(array_merge($pkCols, $fkCols, array_keys($columns))); - uksort($columns, static function ($a, $b) use ($colNames) { + uksort($columns, static function ($a, $b) use ($colNames) : bool { return array_search($a, $colNames) >= array_search($b, $colNames); }); @@ -580,7 +580,7 @@ public function getUniqueConstraints() : array * * @return array */ - public function getForeignKeys() + public function getForeignKeys() : array { return $this->_fkConstraints; } @@ -625,8 +625,6 @@ public function visit(Visitor $visitor) : void /** * Clone of a Table triggers a deep clone of all affected assets. - * - * @return void */ public function __clone() { diff --git a/lib/Doctrine/DBAL/Schema/Visitor/SchemaDiffVisitor.php b/lib/Doctrine/DBAL/Schema/Visitor/SchemaDiffVisitor.php index 358ddf7d777..77c7670bff7 100644 --- a/lib/Doctrine/DBAL/Schema/Visitor/SchemaDiffVisitor.php +++ b/lib/Doctrine/DBAL/Schema/Visitor/SchemaDiffVisitor.php @@ -17,25 +17,25 @@ interface SchemaDiffVisitor /** * Visit an orphaned foreign key whose table was deleted. */ - public function visitOrphanedForeignKey(ForeignKeyConstraint $foreignKey); + public function visitOrphanedForeignKey(ForeignKeyConstraint $foreignKey) : void; /** * Visit a sequence that has changed. */ - public function visitChangedSequence(Sequence $sequence); + public function visitChangedSequence(Sequence $sequence) : void; /** * Visit a sequence that has been removed. */ - public function visitRemovedSequence(Sequence $sequence); + public function visitRemovedSequence(Sequence $sequence) : void; - public function visitNewSequence(Sequence $sequence); + public function visitNewSequence(Sequence $sequence) : void; - public function visitNewTable(Table $table); + public function visitNewTable(Table $table) : void; - public function visitNewTableForeignKey(Table $table, ForeignKeyConstraint $foreignKey); + public function visitNewTableForeignKey(Table $table, ForeignKeyConstraint $foreignKey) : void; - public function visitRemovedTable(Table $table); + public function visitRemovedTable(Table $table) : void; - public function visitChangedTable(TableDiff $tableDiff); + public function visitChangedTable(TableDiff $tableDiff) : void; } diff --git a/phpcs.xml.dist b/phpcs.xml.dist index c216ff26623..f646f005707 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -20,14 +20,6 @@ - - */lib/* - - - - */lib/* - - */tests/* diff --git a/tests/Doctrine/Tests/DBAL/Driver/AbstractOracleDriver/EasyConnectStringTest.php b/tests/Doctrine/Tests/DBAL/Driver/AbstractOracleDriver/EasyConnectStringTest.php index e53b7ae695f..192ba76144a 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/AbstractOracleDriver/EasyConnectStringTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/AbstractOracleDriver/EasyConnectStringTest.php @@ -22,7 +22,7 @@ public function testFromConnectionParameters(array $params, string $expected) : } /** - * @return mixed[] + * @return iterable> */ public static function connectionParametersProvider() : iterable { diff --git a/tests/Doctrine/Tests/DBAL/Functional/ConnectionTest.php b/tests/Doctrine/Tests/DBAL/Functional/ConnectionTest.php index e37ff1fc6e0..4d01175aae6 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/ConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/ConnectionTest.php @@ -251,17 +251,6 @@ public function testTransactionalReturnValue() : void self::assertEquals(42, $res); } - /** - * Tests that the quote function accepts DBAL and PDO types. - */ - public function testQuote() : void - { - self::assertEquals( - $this->connection->quote('foo'), - $this->connection->quote('foo') - ); - } - public function testPingDoesTriggersConnect() : void { $this->connection->close(); diff --git a/tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php b/tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php index 2c4030e7608..4095ff2076c 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php @@ -512,11 +512,9 @@ public function testNativeArrayListSupport() : void } /** - * @param string|false $char - * * @dataProvider getTrimExpressionData */ - public function testTrimExpression(string $value, int $position, $char, string $expectedResult) : void + public function testTrimExpression(string $value, int $position, ?string $char, string $expectedResult) : void { $sql = 'SELECT ' . $this->connection->getDatabasePlatform()->getTrimExpression($value, $position, $char) . ' AS trimmed ' . diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php index 9424120f329..427a21d2c2b 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php @@ -293,54 +293,54 @@ public function testListTableColumns() : void self::assertArrayHasKey('test', $columns); self::assertEquals(1, array_search('test', $columnsKeys)); - self::assertEquals('test', strtolower($columns['test']->getname())); - self::assertInstanceOf(StringType::class, $columns['test']->gettype()); - self::assertEquals(255, $columns['test']->getlength()); - self::assertEquals(false, $columns['test']->getfixed()); - self::assertEquals(false, $columns['test']->getnotnull()); - self::assertEquals('expected default', $columns['test']->getdefault()); + self::assertEquals('test', strtolower($columns['test']->getName())); + self::assertInstanceOf(StringType::class, $columns['test']->getType()); + self::assertEquals(255, $columns['test']->getLength()); + self::assertEquals(false, $columns['test']->getFixed()); + self::assertEquals(false, $columns['test']->getNotnull()); + self::assertEquals('expected default', $columns['test']->getDefault()); self::assertIsArray($columns['test']->getPlatformOptions()); - self::assertEquals('foo', strtolower($columns['foo']->getname())); + self::assertEquals('foo', strtolower($columns['foo']->getName())); self::assertEquals(2, array_search('foo', $columnsKeys)); - self::assertInstanceOf(TextType::class, $columns['foo']->gettype()); - self::assertEquals(false, $columns['foo']->getunsigned()); - self::assertEquals(false, $columns['foo']->getfixed()); - self::assertEquals(true, $columns['foo']->getnotnull()); - self::assertEquals(null, $columns['foo']->getdefault()); + self::assertInstanceOf(TextType::class, $columns['foo']->getType()); + self::assertEquals(false, $columns['foo']->getUnsigned()); + self::assertEquals(false, $columns['foo']->getFixed()); + self::assertEquals(true, $columns['foo']->getNotnull()); + self::assertEquals(null, $columns['foo']->getDefault()); self::assertIsArray($columns['foo']->getPlatformOptions()); - self::assertEquals('bar', strtolower($columns['bar']->getname())); + self::assertEquals('bar', strtolower($columns['bar']->getName())); self::assertEquals(3, array_search('bar', $columnsKeys)); - self::assertInstanceOf(DecimalType::class, $columns['bar']->gettype()); - self::assertEquals(null, $columns['bar']->getlength()); - self::assertEquals(10, $columns['bar']->getprecision()); - self::assertEquals(4, $columns['bar']->getscale()); - self::assertEquals(false, $columns['bar']->getunsigned()); - self::assertEquals(false, $columns['bar']->getfixed()); - self::assertEquals(false, $columns['bar']->getnotnull()); - self::assertEquals(null, $columns['bar']->getdefault()); + self::assertInstanceOf(DecimalType::class, $columns['bar']->getType()); + self::assertEquals(null, $columns['bar']->getLength()); + self::assertEquals(10, $columns['bar']->getPrecision()); + self::assertEquals(4, $columns['bar']->getScale()); + self::assertEquals(false, $columns['bar']->getUnsigned()); + self::assertEquals(false, $columns['bar']->getFixed()); + self::assertEquals(false, $columns['bar']->getNotnull()); + self::assertEquals(null, $columns['bar']->getDefault()); self::assertIsArray($columns['bar']->getPlatformOptions()); - self::assertEquals('baz1', strtolower($columns['baz1']->getname())); + self::assertEquals('baz1', strtolower($columns['baz1']->getName())); self::assertEquals(4, array_search('baz1', $columnsKeys)); - self::assertInstanceOf(DateTimeType::class, $columns['baz1']->gettype()); - self::assertEquals(true, $columns['baz1']->getnotnull()); - self::assertEquals(null, $columns['baz1']->getdefault()); + self::assertInstanceOf(DateTimeType::class, $columns['baz1']->getType()); + self::assertEquals(true, $columns['baz1']->getNotnull()); + self::assertEquals(null, $columns['baz1']->getDefault()); self::assertIsArray($columns['baz1']->getPlatformOptions()); - self::assertEquals('baz2', strtolower($columns['baz2']->getname())); + self::assertEquals('baz2', strtolower($columns['baz2']->getName())); self::assertEquals(5, array_search('baz2', $columnsKeys)); - self::assertContains($columns['baz2']->gettype()->getName(), ['time', 'date', 'datetime']); - self::assertEquals(true, $columns['baz2']->getnotnull()); - self::assertEquals(null, $columns['baz2']->getdefault()); + self::assertContains($columns['baz2']->getType()->getName(), ['time', 'date', 'datetime']); + self::assertEquals(true, $columns['baz2']->getNotnull()); + self::assertEquals(null, $columns['baz2']->getDefault()); self::assertIsArray($columns['baz2']->getPlatformOptions()); - self::assertEquals('baz3', strtolower($columns['baz3']->getname())); + self::assertEquals('baz3', strtolower($columns['baz3']->getName())); self::assertEquals(6, array_search('baz3', $columnsKeys)); - self::assertContains($columns['baz3']->gettype()->getName(), ['time', 'date', 'datetime']); - self::assertEquals(true, $columns['baz3']->getnotnull()); - self::assertEquals(null, $columns['baz3']->getdefault()); + self::assertContains($columns['baz3']->getType()->getName(), ['time', 'date', 'datetime']); + self::assertEquals(true, $columns['baz3']->getNotnull()); + self::assertEquals(null, $columns['baz3']->getDefault()); self::assertIsArray($columns['baz3']->getPlatformOptions()); } diff --git a/tests/Doctrine/Tests/DBAL/Functional/WriteTest.php b/tests/Doctrine/Tests/DBAL/Functional/WriteTest.php index fc784a4b608..ed8c24a8d13 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/WriteTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/WriteTest.php @@ -154,7 +154,6 @@ public function testLastInsertId() : void self::assertEquals(1, $this->connection->insert('write_table', ['test_int' => 2, 'test_string' => 'bar'])); $num = $this->lastInsertId(); - self::assertNotNull($num, 'LastInsertId() should not be null.'); self::assertGreaterThan(0, $num, 'LastInsertId() should be non-negative number.'); } @@ -343,11 +342,9 @@ public function testDeleteWhereIsNull() : void * Returns the ID of the last inserted row or skips the test if the currently used driver * doesn't support this feature * - * @return string|false - * * @throws DriverException */ - private function lastInsertId(?string $name = null) + private function lastInsertId(?string $name = null) : string { try { return $this->connection->lastInsertId($name); diff --git a/tests/Doctrine/Tests/DBAL/Platforms/AbstractPostgreSqlPlatformTestCase.php b/tests/Doctrine/Tests/DBAL/Platforms/AbstractPostgreSqlPlatformTestCase.php index 2f2f240f581..9d17ad83bf5 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/AbstractPostgreSqlPlatformTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/AbstractPostgreSqlPlatformTestCase.php @@ -426,16 +426,14 @@ protected function getQuotedColumnInForeignKeySQL() : array } /** - * @param string|bool $databaseValue - * * @group DBAL-457 * @dataProvider pgBooleanProvider */ public function testConvertBooleanAsLiteralStrings( - $databaseValue, + string $databaseValue, string $preparedStatementValue, - ?int $integerValue, - ?bool $booleanValue + int $integerValue, + bool $booleanValue ) : void { $platform = $this->createPlatform(); @@ -458,16 +456,14 @@ public function testConvertBooleanAsLiteralIntegers() : void } /** - * @param string|bool $databaseValue - * * @group DBAL-630 * @dataProvider pgBooleanProvider */ public function testConvertBooleanAsDatabaseValueStrings( - $databaseValue, + string $databaseValue, string $preparedStatementValue, - ?int $integerValue, - ?bool $booleanValue + int $integerValue, + bool $booleanValue ) : void { $platform = $this->createPlatform(); @@ -487,11 +483,9 @@ public function testConvertBooleanAsDatabaseValueIntegers() : void } /** - * @param string|bool $databaseValue - * * @dataProvider pgBooleanProvider */ - public function testConvertFromBoolean($databaseValue, string $prepareStatementValue, ?int $integerValue, ?bool $booleanValue) : void + public function testConvertFromBoolean(string $databaseValue, string $prepareStatementValue, int $integerValue, bool $booleanValue) : void { $platform = $this->createPlatform(); @@ -730,7 +724,6 @@ public static function pgBooleanProvider() : iterable { return [ // Database value, prepared statement value, boolean integer value, boolean value. - [true, 'true', 1, true], ['t', 'true', 1, true], ['true', 'true', 1, true], ['y', 'true', 1, true], @@ -738,15 +731,12 @@ public static function pgBooleanProvider() : iterable ['on', 'true', 1, true], ['1', 'true', 1, true], - [false, 'false', 0, false], ['f', 'false', 0, false], ['false', 'false', 0, false], [ 'n', 'false', 0, false], ['no', 'false', 0, false], ['off', 'false', 0, false], ['0', 'false', 0, false], - - [null, 'NULL', null, null], ]; } @@ -811,14 +801,6 @@ protected function getQuotesDropForeignKeySQL() : string return 'ALTER TABLE "table" DROP CONSTRAINT "select"'; } - public function testGetNullCommentOnColumnSQL() : void - { - self::assertEquals( - 'COMMENT ON COLUMN mytable.id IS NULL', - $this->platform->getCommentOnColumnSQL('mytable', 'id', null) - ); - } - /** * @group DBAL-423 */ diff --git a/tests/Doctrine/Tests/DBAL/Platforms/OraclePlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/OraclePlatformTest.php index 85d32449435..af26f39c0f1 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/OraclePlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/OraclePlatformTest.php @@ -246,7 +246,7 @@ public function getGenerateForeignKeySql() : string */ public function testGeneratesAdvancedForeignKeyOptionsSQL(array $options, string $expectedSql) : void { - $foreignKey = new ForeignKeyConstraint(['foo'], 'foreign_table', ['bar'], null, $options); + $foreignKey = new ForeignKeyConstraint(['foo'], 'foreign_table', ['bar'], '', $options); self::assertSame($expectedSql, $this->platform->getAdvancedForeignKeyOptionsSQL($foreignKey)); } diff --git a/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywherePlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywherePlatformTest.php index 506d9358ad0..bd63658f250 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywherePlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywherePlatformTest.php @@ -234,11 +234,9 @@ public function testGeneratesTableAlterationWithRemovedColumnCommentSql() : void } /** - * @param int|bool|null $lockMode - * * @dataProvider getLockHints */ - public function testAppendsLockHint($lockMode, string $lockHint) : void + public function testAppendsLockHint(?int $lockMode, string $lockHint) : void { $fromClause = 'FROM users'; $expectedResult = $fromClause . $lockHint; diff --git a/tests/Doctrine/Tests/DBAL/Platforms/SQLServerPlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/SQLServerPlatformTest.php index f6156d394de..4afef27eac4 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/SQLServerPlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/SQLServerPlatformTest.php @@ -16,12 +16,10 @@ public function createPlatform() : AbstractPlatform } /** - * @param int|bool|null $lockMode - * * @group DDC-2310 * @dataProvider getLockHints */ - public function testAppendsLockHint($lockMode, string $lockHint) : void + public function testAppendsLockHint(?int $lockMode, string $lockHint) : void { $fromClause = 'FROM users'; $expectedResult = $fromClause . $lockHint; @@ -33,7 +31,7 @@ public function testAppendsLockHint($lockMode, string $lockHint) : void * @group DBAL-2408 * @dataProvider getModifyLimitQueries */ - public function testScrubInnerOrderBy(string $query, int $limit, ?int $offset, string $expectedResult) : void + public function testScrubInnerOrderBy(string $query, int $limit, int $offset, string $expectedResult) : void { self::assertSame($expectedResult, $this->platform->modifyLimitQuery($query, $limit, $offset)); } diff --git a/tests/Doctrine/Tests/DBAL/Sharding/PoolingShardConnectionTest.php b/tests/Doctrine/Tests/DBAL/Sharding/PoolingShardConnectionTest.php index 1f56361668d..d78d5977d4b 100644 --- a/tests/Doctrine/Tests/DBAL/Sharding/PoolingShardConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Sharding/PoolingShardConnectionTest.php @@ -11,6 +11,7 @@ use InvalidArgumentException; use PHPUnit\Framework\TestCase; use stdClass; +use function array_merge; /** * @requires extension pdo_sqlite @@ -19,8 +20,7 @@ class PoolingShardConnectionTest extends TestCase { public function testConnect() : void { - $conn = DriverManager::getConnection([ - 'wrapperClass' => PoolingShardConnection::class, + $conn = $this->createConnection([ 'driver' => 'pdo_sqlite', 'global' => ['memory' => true], 'shards' => [ @@ -56,8 +56,7 @@ public function testNoGlobalServerException() : void $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('Connection Parameters require "global" and "shards" configurations.'); - DriverManager::getConnection([ - 'wrapperClass' => PoolingShardConnection::class, + $this->createConnection([ 'driver' => 'pdo_sqlite', 'shards' => [ ['id' => 1, 'memory' => true], @@ -72,8 +71,7 @@ public function testNoShardsServersException() : void $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('Connection Parameters require "global" and "shards" configurations.'); - DriverManager::getConnection([ - 'wrapperClass' => PoolingShardConnection::class, + $this->createConnection([ 'driver' => 'pdo_sqlite', 'global' => ['memory' => true], 'shardChoser' => MultiTenantShardChoser::class, @@ -85,8 +83,7 @@ public function testNoShardsChoserException() : void $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('Missing Shard Choser configuration "shardChoser".'); - DriverManager::getConnection([ - 'wrapperClass' => PoolingShardConnection::class, + $this->createConnection([ 'driver' => 'pdo_sqlite', 'global' => ['memory' => true], 'shards' => [ @@ -101,8 +98,7 @@ public function testShardChoserWrongInstance() : void $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('The "shardChoser" configuration is not a valid instance of Doctrine\DBAL\Sharding\ShardChoser\ShardChoser'); - DriverManager::getConnection([ - 'wrapperClass' => PoolingShardConnection::class, + $this->createConnection([ 'driver' => 'pdo_sqlite', 'global' => ['memory' => true], 'shards' => [ @@ -118,8 +114,7 @@ public function testShardNonNumericId() : void $this->expectException('InvalidArgumentException'); $this->expectExceptionMessage('Shard Id has to be a non-negative number.'); - DriverManager::getConnection([ - 'wrapperClass' => PoolingShardConnection::class, + $this->createConnection([ 'driver' => 'pdo_sqlite', 'global' => ['memory' => true], 'shards' => [ @@ -134,8 +129,7 @@ public function testShardMissingId() : void $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('Missing "id" for one configured shard. Please specify a unique shard-id.'); - DriverManager::getConnection([ - 'wrapperClass' => PoolingShardConnection::class, + $this->createConnection([ 'driver' => 'pdo_sqlite', 'global' => ['memory' => true], 'shards' => [ @@ -150,8 +144,7 @@ public function testDuplicateShardId() : void $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('Shard "1" is duplicated in the configuration.'); - DriverManager::getConnection([ - 'wrapperClass' => PoolingShardConnection::class, + $this->createConnection([ 'driver' => 'pdo_sqlite', 'global' => ['memory' => true], 'shards' => [ @@ -164,8 +157,7 @@ public function testDuplicateShardId() : void public function testSwitchShardWithOpenTransactionException() : void { - $conn = DriverManager::getConnection([ - 'wrapperClass' => PoolingShardConnection::class, + $conn = $this->createConnection([ 'driver' => 'pdo_sqlite', 'global' => ['memory' => true], 'shards' => [ @@ -183,8 +175,7 @@ public function testSwitchShardWithOpenTransactionException() : void public function testGetActiveShardId() : void { - $conn = DriverManager::getConnection([ - 'wrapperClass' => PoolingShardConnection::class, + $conn = $this->createConnection([ 'driver' => 'pdo_sqlite', 'global' => ['memory' => true], 'shards' => [ @@ -207,8 +198,7 @@ public function testGetActiveShardId() : void public function testGetParamsOverride() : void { - $conn = DriverManager::getConnection([ - 'wrapperClass' => PoolingShardConnection::class, + $conn = $this->createConnection([ 'driver' => 'pdo_sqlite', 'global' => ['memory' => true, 'host' => 'localhost'], 'shards' => [ @@ -243,4 +233,15 @@ public function testGetParamsOverride() : void 'host' => 'foo', ], $conn->getParams()); } + + /** + * @param array $parameters + */ + private function createConnection(array $parameters) : PoolingShardConnection + { + return DriverManager::getConnection(array_merge( + ['wrapperClass' => PoolingShardConnection::class], + $parameters + )); + } }