diff --git a/lib/Doctrine/DBAL/Cache/QueryCacheProfile.php b/lib/Doctrine/DBAL/Cache/QueryCacheProfile.php index b1270846512..3a57358faad 100644 --- a/lib/Doctrine/DBAL/Cache/QueryCacheProfile.php +++ b/lib/Doctrine/DBAL/Cache/QueryCacheProfile.php @@ -3,6 +3,7 @@ namespace Doctrine\DBAL\Cache; use Doctrine\Common\Cache\Cache; +use Doctrine\DBAL\Types\Type; use function hash; use function serialize; @@ -68,10 +69,10 @@ public function getCacheKey() /** * Generates the real cache key from query, params, types and connection parameters. * - * @param string $sql - * @param mixed[] $params - * @param int[]|string[] $types - * @param mixed[] $connectionParams + * @param string $sql + * @param array|array $params + * @param array|array $types + * @param array $connectionParams * * @return string[] */ diff --git a/lib/Doctrine/DBAL/Connection.php b/lib/Doctrine/DBAL/Connection.php index 5eb4ae23924..cd5f6e4da7e 100644 --- a/lib/Doctrine/DBAL/Connection.php +++ b/lib/Doctrine/DBAL/Connection.php @@ -543,11 +543,11 @@ public function setFetchMode($fetchMode) * * @deprecated Use fetchAssociative() * - * @param string $sql The query SQL - * @param mixed[] $params The query parameters - * @param int[]|string[] $types The query parameter types + * @param string $sql SQL query + * @param array|array $params Query parameters + * @param array|array $types Parameter types * - * @return mixed[]|false False is returned if no rows are found. + * @return array|false False is returned if no rows are found. * * @throws Exception */ @@ -562,11 +562,11 @@ public function fetchAssoc($sql, array $params = [], array $types = []) * * @deprecated Use fetchNumeric() * - * @param string $sql The query SQL - * @param mixed[] $params The query parameters - * @param int[]|string[] $types The query parameter types + * @param string $sql SQL query + * @param array|array $params Query parameters + * @param array|array $types Parameter types * - * @return mixed[]|false False is returned if no rows are found. + * @return array|false False is returned if no rows are found. */ public function fetchArray($sql, array $params = [], array $types = []) { @@ -579,10 +579,10 @@ public function fetchArray($sql, array $params = [], array $types = []) * * @deprecated Use fetchOne() instead. * - * @param string $sql The query SQL - * @param mixed[] $params The query parameters - * @param int $column The 0-indexed column number to retrieve - * @param int[]|string[] $types The query parameter types + * @param string $sql SQL query + * @param array|array $params Query parameters + * @param int $column 0-indexed column number + * @param array|array $types Parameter types * * @return mixed|false False is returned if no rows are found. * @@ -597,9 +597,9 @@ public function fetchColumn($sql, array $params = [], $column = 0, array $types * Prepares and executes an SQL query and returns the first row of the result * as an associative array. * - * @param string $query The SQL query. - * @param array|array $params The prepared statement params. - * @param array|array $types The query parameter types. + * @param string $query SQL query + * @param array|array $params Query parameters + * @param array|array $types Parameter types * * @return array|false False is returned if no rows are found. * @@ -624,9 +624,9 @@ public function fetchAssociative(string $query, array $params = [], array $types * Prepares and executes an SQL query and returns the first row of the result * as a numerically indexed array. * - * @param string $query The SQL query to be executed. - * @param array|array $params The prepared statement params. - * @param array|array $types The query parameter types. + * @param string $query SQL query + * @param array|array $params Query parameters + * @param array|array $types Parameter types * * @return array|false False is returned if no rows are found. * @@ -651,9 +651,9 @@ public function fetchNumeric(string $query, array $params = [], array $types = [ * Prepares and executes an SQL query and returns the value of a single column * of the first row of the result. * - * @param string $query The SQL query to be executed. - * @param array|array $params The prepared statement params. - * @param array|array $types The query parameter types. + * @param string $query SQL query + * @param array|array $params Query parameters + * @param array|array $types Parameter types * * @return mixed|false False is returned if no rows are found. * @@ -695,24 +695,24 @@ public function isTransactionActive() } /** - * Adds identifier condition to the query components + * Adds condition based on the criteria to the query components * - * @param mixed[] $identifier Map of key columns to their values + * @param mixed[] $criteria Map of key columns to their values * @param string[] $columns Column names * @param mixed[] $values Column values * @param string[] $conditions Key conditions * * @throws Exception */ - private function addIdentifierCondition( - array $identifier, + private function addCriteriaCondition( + array $criteria, array &$columns, array &$values, array &$conditions ): void { $platform = $this->getDatabasePlatform(); - foreach ($identifier as $columnName => $value) { + foreach ($criteria as $columnName => $value) { if ($value === null) { $conditions[] = $platform->getIsNullExpression($columnName); continue; @@ -729,23 +729,23 @@ private function addIdentifierCondition( * * Table expression and columns are not escaped and are not safe for user-input. * - * @param string $table The expression of the table on which to delete. - * @param mixed[] $identifier The deletion criteria. An associative array containing column-value pairs. - * @param int[]|string[] $types The types of identifiers. + * @param string $table Table name + * @param array $criteria Deletion criteria + * @param array|array $types Parameter types * * @return int The number of affected rows. * * @throws Exception */ - public function delete($table, array $identifier, array $types = []) + public function delete($table, array $criteria, array $types = []) { - if (empty($identifier)) { + if (empty($criteria)) { throw InvalidArgumentException::fromEmptyCriteria(); } $columns = $values = $conditions = []; - $this->addIdentifierCondition($identifier, $columns, $values, $conditions); + $this->addCriteriaCondition($criteria, $columns, $values, $conditions); return $this->executeStatement( 'DELETE FROM ' . $table . ' WHERE ' . implode(' AND ', $conditions), @@ -797,16 +797,16 @@ public function getTransactionIsolation() * * Table expression and columns are not escaped and are not safe for user-input. * - * @param string $table The expression of the table to update quoted or unquoted. - * @param mixed[] $data An associative array containing column-value pairs. - * @param mixed[] $identifier The update criteria. An associative array containing column-value pairs. - * @param int[]|string[] $types Types of the merged $data and $identifier arrays in that order. + * @param string $table Table name + * @param array $data Column-value pairs + * @param array $criteria Update criteria + * @param array|array $types Parameter types * * @return int The number of affected rows. * * @throws Exception */ - public function update($table, array $data, array $identifier, array $types = []) + public function update($table, array $data, array $criteria, array $types = []) { $columns = $values = $conditions = $set = []; @@ -816,7 +816,7 @@ public function update($table, array $data, array $identifier, array $types = [] $set[] = $columnName . ' = ?'; } - $this->addIdentifierCondition($identifier, $columns, $values, $conditions); + $this->addCriteriaCondition($criteria, $columns, $values, $conditions); if (is_string(key($types))) { $types = $this->extractTypeValues($columns, $types); @@ -833,9 +833,9 @@ public function update($table, array $data, array $identifier, array $types = [] * * Table expression and columns are not escaped and are not safe for user-input. * - * @param string $table The expression of the table to insert data into, quoted or unquoted. - * @param mixed[] $data An associative array containing column-value pairs. - * @param int[]|string[] $types Types of the inserted data. + * @param string $table Table name + * @param array $data Column-value pairs + * @param array|array $types Parameter types * * @return int The number of affected rows. * @@ -868,10 +868,10 @@ public function insert($table, array $data, array $types = []) /** * Extract ordered type list from an ordered column list and type map. * - * @param int[]|string[] $columnList - * @param int[]|string[] $types + * @param array $columnList + * @param array|array $types * - * @return int[]|string[] + * @return array|array */ private function extractTypeValues(array $columnList, array $types) { @@ -936,9 +936,9 @@ public function fetchAll($sql, array $params = [], $types = []) /** * Prepares and executes an SQL query and returns the result as an array of numeric arrays. * - * @param string $query The SQL query. - * @param array|array $params The query parameters. - * @param array|array $types The query parameter types. + * @param string $query SQL query + * @param array|array $params Query parameters + * @param array|array $types Parameter types * * @return array> * @@ -962,9 +962,9 @@ public function fetchAllNumeric(string $query, array $params = [], array $types /** * Prepares and executes an SQL query and returns the result as an array of associative arrays. * - * @param string $query The SQL query. - * @param array|array $params The query parameters. - * @param array|array $types The query parameter types. + * @param string $query SQL query + * @param array|array $params Query parameters + * @param array|array $types Parameter types * * @return array> * @@ -988,9 +988,9 @@ public function fetchAllAssociative(string $query, array $params = [], array $ty /** * Prepares and executes an SQL query and returns the result as an array of the first column values. * - * @param string $query The SQL query. - * @param array|array $params The query parameters. - * @param array|array $types The query parameter types. + * @param string $query SQL query + * @param array|array $params Query parameters + * @param array|array $types Parameter types * * @return array * @@ -1014,9 +1014,9 @@ public function fetchFirstColumn(string $query, array $params = [], array $types /** * Prepares and executes an SQL query and returns the result as an iterator over rows represented as numeric arrays. * - * @param string $query The SQL query. - * @param array|array $params The query parameters. - * @param array|array $types The query parameter types. + * @param string $query SQL query + * @param array|array $params Query parameters + * @param array|array $types Parameter types * * @return Traversable> * @@ -1043,9 +1043,9 @@ public function iterateNumeric(string $query, array $params = [], array $types = * Prepares and executes an SQL query and returns the result as an iterator over rows represented * as associative arrays. * - * @param string $query The SQL query. - * @param array|array $params The query parameters. - * @param array|array $types The query parameter types. + * @param string $query SQL query + * @param array|array $params Query parameters + * @param array|array $types Parameter types * * @return Traversable> * @@ -1071,9 +1071,9 @@ public function iterateAssociative(string $query, array $params = [], array $typ /** * Prepares and executes an SQL query and returns the result as an iterator over the first column values. * - * @param string $query The SQL query. - * @param array|array $params The query parameters. - * @param array|array $types The query parameter types. + * @param string $query SQL query + * @param array|array $params Query parameters + * @param array|array $types Parameter types * * @return Traversable * @@ -1124,10 +1124,9 @@ public function prepare($sql) * If the query is parametrized, a prepared statement is used. * If an SQLLogger is configured, the execution is logged. * - * @param string $sql The SQL query to execute. - * @param mixed[] $params The parameters to bind to the query, if any. - * @param int[]|string[] $types The types the previous parameters are in. - * @param QueryCacheProfile|null $qcp The query cache profile, optional. + * @param string $sql SQL query + * @param array|array $params Query parameters + * @param array|array $types Parameter types * * @return ResultStatement The executed statement. * @@ -1181,10 +1180,9 @@ public function executeQuery($sql, array $params = [], $types = [], ?QueryCacheP /** * Executes a caching query. * - * @param string $sql The SQL query to execute. - * @param mixed[] $params The parameters to bind to the query, if any. - * @param int[]|string[] $types The types the previous parameters are in. - * @param QueryCacheProfile $qcp The query cache profile. + * @param string $sql SQL query + * @param array|array $params Query parameters + * @param array|array $types Parameter types * * @return ResultStatement * @@ -1301,9 +1299,9 @@ public function query() * * @deprecated Use {@link executeStatement()} instead. * - * @param string $sql The SQL query. - * @param array $params The query parameters. - * @param array $types The parameter types. + * @param string $sql SQL statement + * @param array|array $params Statement parameters + * @param array|array $types Parameter types * * @return int The number of affected rows. * @@ -1326,9 +1324,9 @@ public function executeUpdate($sql, array $params = [], array $types = []) * * This method supports PDO binding types as well as DBAL mapping types. * - * @param string $sql The statement SQL - * @param array $params The query parameters - * @param array $types The parameter types + * @param string $sql SQL statement + * @param array|array $params Statement parameters + * @param array|array $types Parameter types * * @return int The number of affected rows. * @@ -1842,9 +1840,9 @@ public function convertToPHPValue($value, $type) * @internal Duck-typing used on the $stmt parameter to support driver statements as well as * raw PDOStatement instances. * - * @param \Doctrine\DBAL\Driver\Statement $stmt The statement to bind the values to. - * @param mixed[] $params The map/list of named/positional parameters. - * @param int[]|string[] $types The parameter types (PDO binding types or DBAL mapping types). + * @param \Doctrine\DBAL\Driver\Statement $stmt Prepared statement + * @param array|array $params Statement parameters + * @param array|array $types Parameter types * * @return void */ @@ -1911,10 +1909,10 @@ private function getBindingInfo($value, $type) * @internal This is a purely internal method. If you rely on this method, you are advised to * copy/paste the code as this method may change, or be removed without prior notice. * - * @param mixed[] $params - * @param int[]|string[] $types + * @param array|array $params Query parameters + * @param array|array $types Parameter types * - * @return mixed[] + * @return array|array */ public function resolveParams(array $params, array $types) { @@ -2006,8 +2004,8 @@ public function ping() /** * @internal * - * @param array|array $params - * @param array|array $types + * @param array|array $params + * @param array|array $types * * @throws Exception * diff --git a/lib/Doctrine/DBAL/Connections/PrimaryReadReplicaConnection.php b/lib/Doctrine/DBAL/Connections/PrimaryReadReplicaConnection.php index 78cb755d805..81f4accfd22 100644 --- a/lib/Doctrine/DBAL/Connections/PrimaryReadReplicaConnection.php +++ b/lib/Doctrine/DBAL/Connections/PrimaryReadReplicaConnection.php @@ -317,11 +317,11 @@ public function rollBack() /** * {@inheritDoc} */ - public function delete($table, array $identifier, array $types = []) + public function delete($table, array $criteria, array $types = []) { $this->ensureConnectedToPrimary(); - return parent::delete($table, $identifier, $types); + return parent::delete($table, $criteria, $types); } /** @@ -340,11 +340,11 @@ public function close() /** * {@inheritDoc} */ - public function update($table, array $data, array $identifier, array $types = []) + public function update($table, array $data, array $criteria, array $types = []) { $this->ensureConnectedToPrimary(); - return parent::update($table, $data, $identifier, $types); + return parent::update($table, $data, $criteria, $types); } /** diff --git a/lib/Doctrine/DBAL/Logging/SQLLogger.php b/lib/Doctrine/DBAL/Logging/SQLLogger.php index 3cb885affa5..8328a71ba5a 100644 --- a/lib/Doctrine/DBAL/Logging/SQLLogger.php +++ b/lib/Doctrine/DBAL/Logging/SQLLogger.php @@ -2,6 +2,8 @@ namespace Doctrine\DBAL\Logging; +use Doctrine\DBAL\Types\Type; + /** * Interface for SQL loggers. */ @@ -10,9 +12,9 @@ interface SQLLogger /** * Logs a SQL statement somewhere. * - * @param string $sql The SQL to be executed. - * @param mixed[]|null $params The SQL parameters. - * @param array $types The SQL parameter types. + * @param string $sql SQL statement + * @param array|array|null $params Statement parameters + * @param array|array|null $types Parameter types * * @return void */ diff --git a/lib/Doctrine/DBAL/Query/QueryBuilder.php b/lib/Doctrine/DBAL/Query/QueryBuilder.php index 1d66b9e63c6..c0c0ea58451 100644 --- a/lib/Doctrine/DBAL/Query/QueryBuilder.php +++ b/lib/Doctrine/DBAL/Query/QueryBuilder.php @@ -7,6 +7,7 @@ use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Query\Expression\CompositeExpression; use Doctrine\DBAL\Query\Expression\ExpressionBuilder; +use Doctrine\DBAL\Types\Type; use function array_filter; use function array_key_exists; @@ -88,14 +89,14 @@ class QueryBuilder /** * The query parameters. * - * @var mixed[] + * @var array|array */ private $params = []; /** * The parameter type map of this query. * - * @var int[]|string[] + * @var array|array */ private $paramTypes = []; @@ -263,9 +264,9 @@ public function getSQL() * ->setParameter(':user_id', 1); * * - * @param string|int $key The parameter position or name. - * @param mixed $value The parameter value. - * @param string|int|null $type One of the {@link ParameterType} constants. + * @param int|string $key Parameter position or name + * @param mixed $value Parameter value + * @param int|string|Type|null $type One of the {@link ParameterType} constants or DBAL type * * @return $this This QueryBuilder instance. */ @@ -294,8 +295,8 @@ public function setParameter($key, $value, $type = null) * )); * * - * @param mixed[] $params The query parameters to set. - * @param int[]|string[] $types The query parameters types to set. + * @param array|array $params Parameters to set + * @param array|array $types Parameter types * * @return $this This QueryBuilder instance. */ @@ -310,7 +311,7 @@ public function setParameters(array $params, array $types = []) /** * Gets all defined query parameters for the query being constructed indexed by parameter index or name. * - * @return mixed[] The currently defined query parameters indexed by parameter index or name. + * @return array|array The currently defined query parameters */ public function getParameters() { @@ -332,7 +333,8 @@ public function getParameter($key) /** * Gets all defined query parameter types for the query being constructed indexed by parameter index or name. * - * @return int[]|string[] The currently defined query parameter types indexed by parameter index or name. + * @return array|array The currently defined + * query parameter types */ public function getParameterTypes() { @@ -342,9 +344,9 @@ public function getParameterTypes() /** * Gets a (previously set) query parameter type of the query being constructed. * - * @param mixed $key The key (index or name) of the bound parameter type. + * @param int|string $key The key of the bound parameter type * - * @return mixed The value of the bound parameter type. + * @return int|string|Type|null The value of the bound parameter type */ public function getParameterType($key) { @@ -1291,9 +1293,9 @@ public function __toString() * * @link http://www.zetacomponents.org * - * @param mixed $value - * @param mixed $type - * @param string $placeHolder The name to bind with. The string must start with a colon ':'. + * @param mixed $value + * @param int|string|Type|null $type + * @param string $placeHolder The name to bind with. The string must start with a colon ':'. * * @return string the placeholder name used. */ @@ -1326,8 +1328,8 @@ public function createNamedParameter($value, $type = ParameterType::STRING, $pla * ->orWhere('u.username = ' . $qb->createPositionalParameter('Bar', ParameterType::STRING)) * * - * @param mixed $value - * @param int $type + * @param mixed $value + * @param int|string|Type|null $type * * @return string */ diff --git a/lib/Doctrine/DBAL/SQLParserUtils.php b/lib/Doctrine/DBAL/SQLParserUtils.php index 16ed8a812c1..5b558f01343 100644 --- a/lib/Doctrine/DBAL/SQLParserUtils.php +++ b/lib/Doctrine/DBAL/SQLParserUtils.php @@ -2,6 +2,8 @@ namespace Doctrine\DBAL; +use Doctrine\DBAL\Types\Type; + use function array_fill; use function array_fill_keys; use function array_key_exists; @@ -128,9 +130,9 @@ private static function collectPlaceholders( /** * For a positional query this method can rewrite the sql statement with regard to array parameters. * - * @param string $query The SQL query to execute. - * @param mixed[] $params The parameters to bind to the query. - * @param array $types The types the previous parameters are in. + * @param string $query SQL query + * @param mixed[] $params Query parameters + * @param array|array $types Parameter types * * @return mixed[] * diff --git a/lib/Doctrine/DBAL/Tools/Console/Command/ReservedWordsCommand.php b/lib/Doctrine/DBAL/Tools/Console/Command/ReservedWordsCommand.php index 50e6a59343a..1888efdb619 100644 --- a/lib/Doctrine/DBAL/Tools/Console/Command/ReservedWordsCommand.php +++ b/lib/Doctrine/DBAL/Tools/Console/Command/ReservedWordsCommand.php @@ -33,6 +33,7 @@ use function assert; use function count; use function implode; +use function is_array; use function is_string; use function trigger_error; @@ -149,7 +150,14 @@ protected function execute(InputInterface $input, OutputInterface $output) { $conn = $this->getConnection($input); - $keywordLists = (array) $input->getOption('list'); + $keywordLists = $input->getOption('list'); + + if (is_string($keywordLists)) { + $keywordLists = [$keywordLists]; + } elseif (! is_array($keywordLists)) { + $keywordLists = []; + } + if (! $keywordLists) { $keywordLists = [ 'mysql', diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/Db2SchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/Db2SchemaManagerTest.php index 9bc1bd1165e..8bc11a776f8 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/Db2SchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/Db2SchemaManagerTest.php @@ -2,11 +2,18 @@ namespace Doctrine\Tests\DBAL\Functional\Schema; +use Doctrine\DBAL\Platforms\AbstractPlatform; +use Doctrine\DBAL\Platforms\DB2Platform; use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Types\BooleanType; class Db2SchemaManagerTest extends SchemaManagerFunctionalTestCase { + protected function supportsPlatform(AbstractPlatform $platform): bool + { + return $platform instanceof DB2Platform; + } + public function testGetBooleanColumn(): void { $table = new Table('boolean_column_test'); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/DrizzleSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/DrizzleSchemaManagerTest.php index 0943124b86b..917e42055ff 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/DrizzleSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/DrizzleSchemaManagerTest.php @@ -2,11 +2,18 @@ namespace Doctrine\Tests\DBAL\Functional\Schema; +use Doctrine\DBAL\Platforms\AbstractPlatform; +use Doctrine\DBAL\Platforms\DrizzlePlatform; use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Types\BinaryType; class DrizzleSchemaManagerTest extends SchemaManagerFunctionalTestCase { + protected function supportsPlatform(AbstractPlatform $platform): bool + { + return $platform instanceof DrizzlePlatform; + } + public function testListTableWithBinary(): void { $tableName = 'test_binary_table'; diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php index 90a78487f19..1da8e4dbfaa 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php @@ -3,6 +3,7 @@ namespace Doctrine\Tests\DBAL\Functional\Schema; use DateTime; +use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Platforms\MariaDb1027Platform; use Doctrine\DBAL\Platforms\MySqlPlatform; use Doctrine\DBAL\Schema\Comparator; @@ -15,6 +16,11 @@ class MySqlSchemaManagerTest extends SchemaManagerFunctionalTestCase { + protected function supportsPlatform(AbstractPlatform $platform): bool + { + return $platform instanceof MySqlPlatform; + } + protected function setUp(): void { parent::setUp(); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/OracleSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/OracleSchemaManagerTest.php index 570ec8ad63e..d39b7373216 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/OracleSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/OracleSchemaManagerTest.php @@ -2,6 +2,8 @@ namespace Doctrine\Tests\DBAL\Functional\Schema; +use Doctrine\DBAL\Platforms\AbstractPlatform; +use Doctrine\DBAL\Platforms\OraclePlatform; use Doctrine\DBAL\Schema; use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Types\BinaryType; @@ -15,6 +17,11 @@ class OracleSchemaManagerTest extends SchemaManagerFunctionalTestCase /** @var bool */ private static $privilegesGranted = false; + protected function supportsPlatform(AbstractPlatform $platform): bool + { + return $platform instanceof OraclePlatform; + } + protected function setUp(): void { parent::setUp(); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/PostgreSqlSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/PostgreSqlSchemaManagerTest.php index cdf3a51245a..aadf78a8b48 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/PostgreSqlSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/PostgreSqlSchemaManagerTest.php @@ -25,6 +25,11 @@ class PostgreSqlSchemaManagerTest extends SchemaManagerFunctionalTestCase /** @var PostgreSqlSchemaManager */ protected $schemaManager; + protected function supportsPlatform(AbstractPlatform $platform): bool + { + return $platform instanceof PostgreSQL94Platform; + } + protected function tearDown(): void { parent::tearDown(); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/SQLAnywhereSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/SQLAnywhereSchemaManagerTest.php index dbce7bba895..c502a729c1e 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/SQLAnywhereSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/SQLAnywhereSchemaManagerTest.php @@ -2,12 +2,19 @@ namespace Doctrine\Tests\DBAL\Functional\Schema; +use Doctrine\DBAL\Platforms\AbstractPlatform; +use Doctrine\DBAL\Platforms\SQLAnywherePlatform; use Doctrine\DBAL\Schema\Index; use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Schema\View; class SQLAnywhereSchemaManagerTest extends SchemaManagerFunctionalTestCase { + protected function supportsPlatform(AbstractPlatform $platform): bool + { + return $platform instanceof SQLAnywherePlatform; + } + public function testCreateAndListViews(): void { $this->createTestTable('view_test_table'); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/SQLServerSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/SQLServerSchemaManagerTest.php index 045299367b6..8d6b0bb56fd 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/SQLServerSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/SQLServerSchemaManagerTest.php @@ -2,6 +2,8 @@ namespace Doctrine\Tests\DBAL\Functional\Schema; +use Doctrine\DBAL\Platforms\AbstractPlatform; +use Doctrine\DBAL\Platforms\SQLServer2012Platform; use Doctrine\DBAL\Schema\Column; use Doctrine\DBAL\Schema\ColumnDiff; use Doctrine\DBAL\Schema\Table; @@ -12,9 +14,9 @@ class SQLServerSchemaManagerTest extends SchemaManagerFunctionalTestCase { - protected function getPlatformName(): string + protected function supportsPlatform(AbstractPlatform $platform): bool { - return 'mssql'; + return $platform instanceof SQLServer2012Platform; } public function testDropColumnConstraints(): void diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php index e34ef79ec1d..8ae88a87738 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php @@ -6,6 +6,7 @@ use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Driver\Connection; use Doctrine\DBAL\Events; +use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Platforms\OraclePlatform; use Doctrine\DBAL\Schema\AbstractAsset; use Doctrine\DBAL\Schema\AbstractSchemaManager; @@ -38,11 +39,9 @@ use function array_values; use function count; use function current; -use function end; -use function explode; +use function get_class; use function in_array; use function sprintf; -use function str_replace; use function strcasecmp; use function strlen; use function strtolower; @@ -53,23 +52,16 @@ abstract class SchemaManagerFunctionalTestCase extends DbalFunctionalTestCase /** @var AbstractSchemaManager */ protected $schemaManager; - protected function getPlatformName(): string - { - $class = static::class; - $e = explode('\\', $class); - $testClass = end($e); - - return strtolower(str_replace('SchemaManagerTest', '', $testClass)); - } + abstract protected function supportsPlatform(AbstractPlatform $platform): bool; protected function setUp(): void { parent::setUp(); - $dbms = $this->getPlatformName(); + $platform = $this->connection->getDatabasePlatform(); - if ($this->connection->getDatabasePlatform()->getName() !== $dbms) { - $this->markTestSkipped(static::class . ' requires the use of ' . $dbms); + if (! $this->supportsPlatform($platform)) { + $this->markTestSkipped(sprintf('Skipping since connected to %s', get_class($platform))); } $this->schemaManager = $this->connection->getSchemaManager(); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/SqliteSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/SqliteSchemaManagerTest.php index d94a8f8dabe..dc46c35a0f3 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/SqliteSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/SqliteSchemaManagerTest.php @@ -4,6 +4,8 @@ use Doctrine\DBAL\Driver\Connection; use Doctrine\DBAL\Exception; +use Doctrine\DBAL\Platforms\AbstractPlatform; +use Doctrine\DBAL\Platforms\SqlitePlatform; use Doctrine\DBAL\Schema; use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Types\BlobType; @@ -14,6 +16,11 @@ class SqliteSchemaManagerTest extends SchemaManagerFunctionalTestCase { + protected function supportsPlatform(AbstractPlatform $platform): bool + { + return $platform instanceof SqlitePlatform; + } + /** * SQLITE does not support databases. */