diff --git a/UPGRADE.md b/UPGRADE.md index c945adf5d0d..e46f1dc0fbf 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -1,5 +1,56 @@ # Upgrade to 3.0 +## BC BREAK: `Doctrine\DBAL\Types\Type::__toString()` removed + +Relying on string representation was discouraged and has been removed. + +## BC BREAK: Changes in the `Doctrine\DBAL\Schema` API + +- Removed unused method `Doctrine\DBAL\Schema\AbstractSchemaManager::_getPortableFunctionsList()` +- Removed unused method `Doctrine\DBAL\Schema\AbstractSchemaManager::_getPortableFunctionDefinition()` +- Removed unused method `Doctrine\DBAL\Schema\OracleSchemaManager::_getPortableFunctionDefinition()` +- Removed unused method `Doctrine\DBAL\Schema\SqliteSchemaManager::_getPortableTableIndexDefinition()` + +## BC BREAK: Removed support for DB-generated UUIDs + +The support for DB-generated UUIDs was removed as non-portable. +Please generate UUIDs on the application side (e.g. using [ramsey/uuid](https://packagist.org/packages/ramsey/uuid)). + +## BC BREAK: Changes in the `Doctrine\DBAL\Connection` API + +- The following methods have been removed as leaking internal implementation details: `::getHost()`, `::getPort()`, `::getUsername()`, `::getPassword()`. + +## BC BREAK: Changes in the `Doctrine\DBAL\Event` API + +- `ConnectionEventArgs::getDriver()`, `::getDatabasePlatform()` and `::getSchemaManager()` methods have been removed. The connection information can be obtained from the connection which is available via `::getConnection()`. +- `SchemaColumnDefinitionEventArgs::getDatabasePlatform()` and `SchemaIndexDefinitionEventArgs::getDatabasePlatform()` have been removed for the same reason as above. + +## BC BREAK: Changes in obtaining the currently selected database name + +- The `Doctrine\DBAL\Driver::getDatabase()` method has been removed. Please use `Doctrine\DBAL\Connection::getDatabase()` instead. +- `Doctrine\DBAL\Connection::getDatabase()` will always return the name of the database currently connected to, regardless of the configuration parameters and will initialize a database connection if it's not yet established. +- A call to `Doctrine\DBAL\Connection::getDatabase()`, when connected to an SQLite database, will no longer return the database file path. + +## BC BREAK: `Doctrine\DBAL\Driver::getName()` removed + +The `Doctrine\DBAL\Driver::getName()` has been removed. + +## BC BREAK Removed previously deprecated features + + * Removed `json_array` type and all associated hacks. + * Removed `Connection::TRANSACTION_*` constants. + * Removed `AbstractPlatform::DATE_INTERVAL_UNIT_*` and `AbstractPlatform::TRIM_*` constants. + * Removed `MysqlSessionInit` listener. + * Removed `MysqlPlatform::getCollationFieldDeclaration()`. + * Removed `AbstractPlatform::getIdentityColumnNullInsertSQL()`. + * Removed `Table::addUnnamedForeignKeyConstraint()` and `Table::addNamedForeignKeyConstraint()`. + * Removed `Table::renameColumn()`. + * Removed `SQLParserUtils::getPlaceholderPositions()`. + * Removed `LoggerChain::addLogger`. + * Removed `AbstractSchemaManager::getFilterSchemaAssetsExpression()`, `Configuration::getFilterSchemaAssetsExpression()` + and `Configuration::getFilterSchemaAssetsExpression()`. + * `SQLParserUtils::*_TOKEN` constants made private. + ## BC BREAK changes the `Driver::connect()` signature The method no longer accepts the `$username`, `$password` and `$driverOptions` arguments. The corresponding values are expected to be passed as the "user", "password" and "driver_options" keys of the `$params` argument respectively. diff --git a/src/Configuration.php b/src/Configuration.php index c536451ca56..f13f2fe27a5 100644 --- a/src/Configuration.php +++ b/src/Configuration.php @@ -4,9 +4,6 @@ use Doctrine\Common\Cache\Cache; use Doctrine\DBAL\Logging\SQLLogger; -use Doctrine\DBAL\Schema\AbstractAsset; - -use function preg_match; /** * Configuration container for the Doctrine DBAL. @@ -64,55 +61,6 @@ public function setResultCacheImpl(Cache $cacheImpl) $this->_attributes['resultCacheImpl'] = $cacheImpl; } - /** - * Sets the filter schema assets expression. - * - * Only include tables/sequences matching the filter expression regexp in - * schema instances generated for the active connection when calling - * {AbstractSchemaManager#createSchema()}. - * - * @deprecated Use Configuration::setSchemaAssetsFilter() instead - * - * @param string|null $filterExpression - * - * @return void - */ - public function setFilterSchemaAssetsExpression($filterExpression) - { - $this->_attributes['filterSchemaAssetsExpression'] = $filterExpression; - if ($filterExpression !== null) { - $this->_attributes['filterSchemaAssetsExpressionCallable'] = $this->buildSchemaAssetsFilterFromExpression($filterExpression); - } else { - $this->_attributes['filterSchemaAssetsExpressionCallable'] = null; - } - } - - /** - * Returns filter schema assets expression. - * - * @deprecated Use Configuration::getSchemaAssetsFilter() instead - * - * @return string|null - */ - public function getFilterSchemaAssetsExpression() - { - return $this->_attributes['filterSchemaAssetsExpression'] ?? null; - } - - /** - * @param string $filterExpression - */ - private function buildSchemaAssetsFilterFromExpression($filterExpression): callable - { - return static function ($assetName) use ($filterExpression) { - if ($assetName instanceof AbstractAsset) { - $assetName = $assetName->getName(); - } - - return preg_match($filterExpression, $assetName); - }; - } - /** * Sets the callable to use to filter schema assets. */ diff --git a/src/Connection.php b/src/Connection.php index f07d9f49151..04aec6c51a0 100644 --- a/src/Connection.php +++ b/src/Connection.php @@ -40,34 +40,6 @@ */ class Connection implements DriverConnection { - /** - * Constant for transaction isolation level READ UNCOMMITTED. - * - * @deprecated Use TransactionIsolationLevel::READ_UNCOMMITTED. - */ - public const TRANSACTION_READ_UNCOMMITTED = TransactionIsolationLevel::READ_UNCOMMITTED; - - /** - * Constant for transaction isolation level READ COMMITTED. - * - * @deprecated Use TransactionIsolationLevel::READ_COMMITTED. - */ - public const TRANSACTION_READ_COMMITTED = TransactionIsolationLevel::READ_COMMITTED; - - /** - * Constant for transaction isolation level REPEATABLE READ. - * - * @deprecated Use TransactionIsolationLevel::REPEATABLE_READ. - */ - public const TRANSACTION_REPEATABLE_READ = TransactionIsolationLevel::REPEATABLE_READ; - - /** - * Constant for transaction isolation level SERIALIZABLE. - * - * @deprecated Use TransactionIsolationLevel::SERIALIZABLE. - */ - public const TRANSACTION_SERIALIZABLE = TransactionIsolationLevel::SERIALIZABLE; - /** * Represents an array of ints to be expanded by Doctrine SQL parsing. */ @@ -225,61 +197,23 @@ public function getParams() } /** - * Gets the name of the database this Connection is connected to. - * - * @return string - */ - public function getDatabase() - { - return $this->_driver->getDatabase($this); - } - - /** - * Gets the hostname of the currently connected database. - * - * @deprecated - * - * @return string|null - */ - public function getHost() - { - return $this->params['host'] ?? null; - } - - /** - * Gets the port of the currently connected database. + * Gets the name of the currently selected database. * - * @deprecated + * @return string|null The name of the database or NULL if a database is not selected. + * The platforms which don't support the concept of a database (e.g. embedded databases) + * must always return a string as an indicator of an implicitly selected database. * - * @return mixed + * @throws DBALException */ - public function getPort() + public function getDatabase() { - return $this->params['port'] ?? null; - } + $platform = $this->getDatabasePlatform(); + $query = $platform->getDummySelectSQL($platform->getCurrentDatabaseExpression()); + $database = $this->query($query)->fetchOne(); - /** - * Gets the username used by this connection. - * - * @deprecated - * - * @return string|null - */ - public function getUsername() - { - return $this->params['user'] ?? null; - } + assert(is_string($database) || $database === null); - /** - * Gets the password used by this connection. - * - * @deprecated - * - * @return string|null - */ - public function getPassword() - { - return $this->params['password'] ?? null; + return $database; } /** diff --git a/src/Driver.php b/src/Driver.php index ec8fbfb7022..2655df46f7b 100644 --- a/src/Driver.php +++ b/src/Driver.php @@ -39,22 +39,4 @@ public function getDatabasePlatform(); * @return AbstractSchemaManager */ public function getSchemaManager(Connection $conn); - - /** - * Gets the name of the driver. - * - * @deprecated - * - * @return string The name of the driver. - */ - public function getName(); - - /** - * Gets the name of the database connected to for this driver. - * - * @deprecated Use Connection::getDatabase() instead. - * - * @return string The name of the database. - */ - public function getDatabase(Connection $conn); } diff --git a/src/Driver/AbstractDB2Driver.php b/src/Driver/AbstractDB2Driver.php index cede8da7eb0..1b3c13f3d73 100644 --- a/src/Driver/AbstractDB2Driver.php +++ b/src/Driver/AbstractDB2Driver.php @@ -12,18 +12,6 @@ */ abstract class AbstractDB2Driver implements Driver { - /** - * {@inheritdoc} - * - * @deprecated Use Connection::getDatabase() instead. - */ - public function getDatabase(Connection $conn) - { - $params = $conn->getParams(); - - return $params['dbname']; - } - /** * {@inheritdoc} */ diff --git a/src/Driver/AbstractMySQLDriver.php b/src/Driver/AbstractMySQLDriver.php index d3a165a1d7e..afebcead3a2 100644 --- a/src/Driver/AbstractMySQLDriver.php +++ b/src/Driver/AbstractMySQLDriver.php @@ -194,18 +194,6 @@ private function getMariaDbMysqlVersionNumber(string $versionString): string return $versionParts['major'] . '.' . $versionParts['minor'] . '.' . $versionParts['patch']; } - /** - * {@inheritdoc} - * - * @deprecated Use Connection::getDatabase() instead. - */ - public function getDatabase(Connection $conn) - { - $params = $conn->getParams(); - - return $params['dbname'] ?? $conn->query('SELECT DATABASE()')->fetchOne(); - } - /** * {@inheritdoc} * diff --git a/src/Driver/AbstractOracleDriver.php b/src/Driver/AbstractOracleDriver.php index bd1802f324e..7dfa46399e6 100644 --- a/src/Driver/AbstractOracleDriver.php +++ b/src/Driver/AbstractOracleDriver.php @@ -57,18 +57,6 @@ public function convertException($message, DriverException $exception) return new Exception\DriverException($message, $exception); } - /** - * {@inheritdoc} - * - * @deprecated Use Connection::getDatabase() instead. - */ - public function getDatabase(Connection $conn) - { - $params = $conn->getParams(); - - return $params['user']; - } - /** * {@inheritdoc} */ diff --git a/src/Driver/AbstractPostgreSQLDriver.php b/src/Driver/AbstractPostgreSQLDriver.php index b3b91b299d6..19d040d1174 100644 --- a/src/Driver/AbstractPostgreSQLDriver.php +++ b/src/Driver/AbstractPostgreSQLDriver.php @@ -102,18 +102,6 @@ public function createDatabasePlatformForVersion($version) return new PostgreSQL94Platform(); } - /** - * {@inheritdoc} - * - * @deprecated Use Connection::getDatabase() instead. - */ - public function getDatabase(Connection $conn) - { - $params = $conn->getParams(); - - return $params['dbname'] ?? $conn->query('SELECT CURRENT_DATABASE()')->fetchOne(); - } - /** * {@inheritdoc} */ diff --git a/src/Driver/AbstractSQLServerDriver.php b/src/Driver/AbstractSQLServerDriver.php index 97f3e3a3416..728eb745cba 100644 --- a/src/Driver/AbstractSQLServerDriver.php +++ b/src/Driver/AbstractSQLServerDriver.php @@ -12,18 +12,6 @@ */ abstract class AbstractSQLServerDriver implements Driver { - /** - * {@inheritdoc} - * - * @deprecated Use Connection::getDatabase() instead. - */ - public function getDatabase(Connection $conn) - { - $params = $conn->getParams(); - - return $params['dbname'] ?? $conn->query('SELECT DB_NAME()')->fetchOne(); - } - /** * {@inheritdoc} */ diff --git a/src/Driver/AbstractSQLiteDriver.php b/src/Driver/AbstractSQLiteDriver.php index d0ec0b687bb..3701dd9f119 100644 --- a/src/Driver/AbstractSQLiteDriver.php +++ b/src/Driver/AbstractSQLiteDriver.php @@ -77,18 +77,6 @@ public function convertException($message, DriverException $exception) return new Exception\DriverException($message, $exception); } - /** - * {@inheritdoc} - * - * @deprecated Use Connection::getDatabase() instead. - */ - public function getDatabase(Connection $conn) - { - $params = $conn->getParams(); - - return $params['path'] ?? null; - } - /** * {@inheritdoc} */ diff --git a/src/Driver/IBMDB2/DB2Driver.php b/src/Driver/IBMDB2/DB2Driver.php index 4712e144aef..79f1a0eb3eb 100644 --- a/src/Driver/IBMDB2/DB2Driver.php +++ b/src/Driver/IBMDB2/DB2Driver.php @@ -22,14 +22,4 @@ public function connect(array $params) $params['driver_options'] ?? [] ); } - - /** - * {@inheritdoc} - * - * @deprecated - */ - public function getName() - { - return 'ibm_db2'; - } } diff --git a/src/Driver/Mysqli/Driver.php b/src/Driver/Mysqli/Driver.php index c13a3f81709..34a74a86f48 100644 --- a/src/Driver/Mysqli/Driver.php +++ b/src/Driver/Mysqli/Driver.php @@ -113,12 +113,4 @@ private function withCharset(array $initializers, array $params): array return $initializers; } - - /** - * {@inheritdoc} - */ - public function getName() - { - return 'mysqli'; - } } diff --git a/src/Driver/OCI8/Driver.php b/src/Driver/OCI8/Driver.php index 88436af21ff..5f27f2579d4 100644 --- a/src/Driver/OCI8/Driver.php +++ b/src/Driver/OCI8/Driver.php @@ -37,14 +37,4 @@ protected function _constructDsn(array $params) { return $this->getEasyConnectString($params); } - - /** - * {@inheritdoc} - * - * @deprecated - */ - public function getName() - { - return 'oci8'; - } } diff --git a/src/Driver/OCI8/OCI8Statement.php b/src/Driver/OCI8/OCI8Statement.php index e05138c62b9..6f2a4fc639c 100644 --- a/src/Driver/OCI8/OCI8Statement.php +++ b/src/Driver/OCI8/OCI8Statement.php @@ -42,13 +42,6 @@ class OCI8Statement implements Statement /** @var OCI8Connection */ protected $_conn; - /** - * @deprecated - * - * @var string - */ - protected static $_PARAM = ':param'; - /** @var string[] */ protected $_paramMap = []; diff --git a/src/Driver/PDOMySql/Driver.php b/src/Driver/PDOMySql/Driver.php index 6d65a2b6686..c3db2dff11b 100644 --- a/src/Driver/PDOMySql/Driver.php +++ b/src/Driver/PDOMySql/Driver.php @@ -62,14 +62,4 @@ protected function constructPdoDsn(array $params) return $dsn; } - - /** - * {@inheritdoc} - * - * @deprecated - */ - public function getName() - { - return 'pdo_mysql'; - } } diff --git a/src/Driver/PDOOracle/Driver.php b/src/Driver/PDOOracle/Driver.php index c3bba5501f2..ae7cba12a33 100644 --- a/src/Driver/PDOOracle/Driver.php +++ b/src/Driver/PDOOracle/Driver.php @@ -52,12 +52,4 @@ private function constructPdoDsn(array $params) return $dsn; } - - /** - * {@inheritdoc} - */ - public function getName() - { - return 'pdo_oracle'; - } } diff --git a/src/Driver/PDOPgSql/Driver.php b/src/Driver/PDOPgSql/Driver.php index fbeb0b5ee11..7be5bada44e 100644 --- a/src/Driver/PDOPgSql/Driver.php +++ b/src/Driver/PDOPgSql/Driver.php @@ -107,14 +107,4 @@ private function _constructPdoDsn(array $params) return $dsn; } - - /** - * {@inheritdoc} - * - * @deprecated - */ - public function getName() - { - return 'pdo_pgsql'; - } } diff --git a/src/Driver/PDOSqlite/Driver.php b/src/Driver/PDOSqlite/Driver.php index 75bad95a9d6..1ec78a7cf38 100644 --- a/src/Driver/PDOSqlite/Driver.php +++ b/src/Driver/PDOSqlite/Driver.php @@ -69,14 +69,4 @@ protected function _constructPdoDsn(array $params) return $dsn; } - - /** - * {@inheritdoc} - * - * @deprecated - */ - public function getName() - { - return 'pdo_sqlite'; - } } diff --git a/src/Driver/PDOSqlsrv/Driver.php b/src/Driver/PDOSqlsrv/Driver.php index aa94dcf4491..e2eb6ed2ca3 100644 --- a/src/Driver/PDOSqlsrv/Driver.php +++ b/src/Driver/PDOSqlsrv/Driver.php @@ -88,14 +88,4 @@ private function getConnectionOptionsDsn(array $connectionOptions): string return $connectionOptionsDsn; } - - /** - * {@inheritdoc} - * - * @deprecated - */ - public function getName() - { - return 'pdo_sqlsrv'; - } } diff --git a/src/Driver/SQLSrv/Driver.php b/src/Driver/SQLSrv/Driver.php index 91a98cd902a..8de03a5ef01 100644 --- a/src/Driver/SQLSrv/Driver.php +++ b/src/Driver/SQLSrv/Driver.php @@ -47,14 +47,4 @@ public function connect(array $params) return new SQLSrvConnection($serverName, $driverOptions); } - - /** - * {@inheritdoc} - * - * @deprecated - */ - public function getName() - { - return 'sqlsrv'; - } } diff --git a/src/Driver/SQLSrv/SQLSrvStatement.php b/src/Driver/SQLSrv/SQLSrvStatement.php index cd1c1d5beea..7acf1853e20 100644 --- a/src/Driver/SQLSrv/SQLSrvStatement.php +++ b/src/Driver/SQLSrv/SQLSrvStatement.php @@ -70,10 +70,8 @@ final class SQLSrvStatement implements Statement /** * Append to any INSERT query to retrieve the last insert id. - * - * @deprecated This constant has been deprecated and will be made private in 3.0 */ - public const LAST_INSERT_ID_SQL = ';SELECT SCOPE_IDENTITY() AS LastInsertId;'; + private const LAST_INSERT_ID_SQL = ';SELECT SCOPE_IDENTITY() AS LastInsertId;'; /** * @param resource $conn diff --git a/src/Event/ConnectionEventArgs.php b/src/Event/ConnectionEventArgs.php index 5c71992cc05..eeddb91a5f6 100644 --- a/src/Event/ConnectionEventArgs.php +++ b/src/Event/ConnectionEventArgs.php @@ -4,9 +4,6 @@ use Doctrine\Common\EventArgs; use Doctrine\DBAL\Connection; -use Doctrine\DBAL\Driver; -use Doctrine\DBAL\Platforms\AbstractPlatform; -use Doctrine\DBAL\Schema\AbstractSchemaManager; /** * Event Arguments used when a Driver connection is established inside Doctrine\DBAL\Connection. @@ -28,34 +25,4 @@ public function getConnection() { return $this->connection; } - - /** - * @deprecated Use ConnectionEventArgs::getConnection() and Connection::getDriver() instead. - * - * @return Driver - */ - public function getDriver() - { - return $this->connection->getDriver(); - } - - /** - * @deprecated Use ConnectionEventArgs::getConnection() and Connection::getDatabasePlatform() instead. - * - * @return AbstractPlatform - */ - public function getDatabasePlatform() - { - return $this->connection->getDatabasePlatform(); - } - - /** - * @deprecated Use ConnectionEventArgs::getConnection() and Connection::getSchemaManager() instead. - * - * @return AbstractSchemaManager - */ - public function getSchemaManager() - { - return $this->connection->getSchemaManager(); - } } diff --git a/src/Event/Listeners/MysqlSessionInit.php b/src/Event/Listeners/MysqlSessionInit.php deleted file mode 100644 index 9732b4733be..00000000000 --- a/src/Event/Listeners/MysqlSessionInit.php +++ /dev/null @@ -1,63 +0,0 @@ -charset = $charset; - $this->collation = $collation; - } - - /** - * @return void - */ - public function postConnect(ConnectionEventArgs $args) - { - $statement = 'SET NAMES ' . $this->charset; - - if ($this->collation !== false) { - $statement .= ' COLLATE ' . $this->collation; - } - - $args->getConnection()->executeUpdate($statement); - } - - /** - * {@inheritdoc} - */ - public function getSubscribedEvents() - { - return [Events::postConnect]; - } -} diff --git a/src/Event/SchemaColumnDefinitionEventArgs.php b/src/Event/SchemaColumnDefinitionEventArgs.php index efde1169806..6fee61d573b 100644 --- a/src/Event/SchemaColumnDefinitionEventArgs.php +++ b/src/Event/SchemaColumnDefinitionEventArgs.php @@ -3,7 +3,6 @@ namespace Doctrine\DBAL\Event; use Doctrine\DBAL\Connection; -use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Schema\Column; /** @@ -95,14 +94,4 @@ public function getConnection() { return $this->connection; } - - /** - * @deprecated Use SchemaColumnDefinitionEventArgs::getConnection() and Connection::getDatabasePlatform() instead. - * - * @return AbstractPlatform - */ - public function getDatabasePlatform() - { - return $this->connection->getDatabasePlatform(); - } } diff --git a/src/Event/SchemaIndexDefinitionEventArgs.php b/src/Event/SchemaIndexDefinitionEventArgs.php index 317f352b87a..ea619f901a1 100644 --- a/src/Event/SchemaIndexDefinitionEventArgs.php +++ b/src/Event/SchemaIndexDefinitionEventArgs.php @@ -3,7 +3,6 @@ namespace Doctrine\DBAL\Event; use Doctrine\DBAL\Connection; -use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Schema\Index; /** @@ -81,12 +80,4 @@ public function getConnection() { return $this->connection; } - - /** - * @return AbstractPlatform - */ - public function getDatabasePlatform() - { - return $this->connection->getDatabasePlatform(); - } } diff --git a/src/Logging/LoggerChain.php b/src/Logging/LoggerChain.php index 024afae283a..27b8516e480 100644 --- a/src/Logging/LoggerChain.php +++ b/src/Logging/LoggerChain.php @@ -7,29 +7,17 @@ */ class LoggerChain implements SQLLogger { - /** @var SQLLogger[] */ + /** @var iterable */ private $loggers = []; /** - * @param SQLLogger[] $loggers + * @param iterable $loggers */ - public function __construct(array $loggers = []) + public function __construct(iterable $loggers = []) { $this->loggers = $loggers; } - /** - * Adds a logger in the chain. - * - * @deprecated Inject list of loggers via constructor instead - * - * @return void - */ - public function addLogger(SQLLogger $logger) - { - $this->loggers[] = $logger; - } - /** * {@inheritdoc} */ diff --git a/src/Platforms/AbstractPlatform.php b/src/Platforms/AbstractPlatform.php index 602437ad8bd..faec41e1768 100644 --- a/src/Platforms/AbstractPlatform.php +++ b/src/Platforms/AbstractPlatform.php @@ -71,66 +71,6 @@ abstract class AbstractPlatform public const CREATE_FOREIGNKEYS = 2; - /** - * @deprecated Use DateIntervalUnit::INTERVAL_UNIT_SECOND. - */ - public const DATE_INTERVAL_UNIT_SECOND = DateIntervalUnit::SECOND; - - /** - * @deprecated Use DateIntervalUnit::MINUTE. - */ - public const DATE_INTERVAL_UNIT_MINUTE = DateIntervalUnit::MINUTE; - - /** - * @deprecated Use DateIntervalUnit::HOUR. - */ - public const DATE_INTERVAL_UNIT_HOUR = DateIntervalUnit::HOUR; - - /** - * @deprecated Use DateIntervalUnit::DAY. - */ - public const DATE_INTERVAL_UNIT_DAY = DateIntervalUnit::DAY; - - /** - * @deprecated Use DateIntervalUnit::WEEK. - */ - public const DATE_INTERVAL_UNIT_WEEK = DateIntervalUnit::WEEK; - - /** - * @deprecated Use DateIntervalUnit::MONTH. - */ - public const DATE_INTERVAL_UNIT_MONTH = DateIntervalUnit::MONTH; - - /** - * @deprecated Use DateIntervalUnit::QUARTER. - */ - public const DATE_INTERVAL_UNIT_QUARTER = DateIntervalUnit::QUARTER; - - /** - * @deprecated Use DateIntervalUnit::QUARTER. - */ - public const DATE_INTERVAL_UNIT_YEAR = DateIntervalUnit::YEAR; - - /** - * @deprecated Use TrimMode::UNSPECIFIED. - */ - public const TRIM_UNSPECIFIED = TrimMode::UNSPECIFIED; - - /** - * @deprecated Use TrimMode::LEADING. - */ - public const TRIM_LEADING = TrimMode::LEADING; - - /** - * @deprecated Use TrimMode::TRAILING. - */ - public const TRIM_TRAILING = TrimMode::TRAILING; - - /** - * @deprecated Use TrimMode::BOTH. - */ - public const TRIM_BOTH = TrimMode::BOTH; - /** @var string[]|null */ protected $doctrineTypeMapping = null; @@ -643,20 +583,6 @@ public function getRegexpExpression() throw DBALException::notSupported(__METHOD__); } - /** - * Returns the global unique identifier expression. - * - * @deprecated Use application-generated UUIDs instead - * - * @return string - * - * @throws DBALException If not supported on this platform. - */ - public function getGuidExpression() - { - throw DBALException::notSupported(__METHOD__); - } - /** * Returns the SQL snippet to get the average value of a column. * @@ -1344,6 +1270,11 @@ public function getBitOrComparisonExpression($value1, $value2) return '(' . $value1 . ' | ' . $value2 . ')'; } + /** + * Returns the SQL expression which represents the currently selected database. + */ + abstract public function getCurrentDatabaseExpression(): string; + /** * Returns the FOR UPDATE expression. * @@ -2162,18 +2093,6 @@ protected function getRenameIndexSQL($oldIndexName, Index $index, $tableName) ]; } - /** - * Common code for alter table statement generation that updates the changed Index and Foreign Key definitions. - * - * @deprecated - * - * @return string[] - */ - protected function _getAlterTableIndexForeignKeySQL(TableDiff $diff) - { - return array_merge($this->getPreAlterTableIndexForeignKeySQL($diff), $this->getPostAlterTableIndexForeignKeySQL($diff)); - } - /** * Gets declaration of a number of fields in bulk. * @@ -2389,7 +2308,7 @@ public function getUniqueConstraintDeclarationSQL($name, Index $index) } return 'CONSTRAINT ' . $name->getQuotedName($this) . ' UNIQUE (' - . $this->getIndexFieldDeclarationListSQL($index) + . $this->getColumnsFieldDeclarationListSQL($columns) . ')' . $this->getPartialIndexSQL($index); } @@ -2435,22 +2354,23 @@ public function getCustomTypeDeclarationSQL(array $columnDef) /** * Obtains DBMS specific SQL code portion needed to set an index * declaration to be used in statements like CREATE TABLE. - * - * @param mixed[]|Index $columnsOrIndex array declaration is deprecated, prefer passing Index to this method */ - public function getIndexFieldDeclarationListSQL($columnsOrIndex): string + public function getIndexFieldDeclarationListSQL(Index $index): string { - if ($columnsOrIndex instanceof Index) { - return implode(', ', $columnsOrIndex->getQuotedColumns($this)); - } - - if (! is_array($columnsOrIndex)) { - throw new InvalidArgumentException('Fields argument should be an Index or array.'); - } + return implode(', ', $index->getQuotedColumns($this)); + } + /** + * Obtains DBMS specific SQL code portion needed to set an index + * declaration to be used in statements like CREATE TABLE. + * + * @param mixed[] $columns + */ + public function getColumnsFieldDeclarationListSQL(array $columns): string + { $ret = []; - foreach ($columnsOrIndex as $column => $definition) { + foreach ($columns as $column => $definition) { if (is_array($definition)) { $ret[] = $column; } else { @@ -3317,18 +3237,6 @@ public function hasNativeJsonType() return false; } - /** - * @deprecated - * - * @return string - * - * @todo Remove in 3.0 - */ - public function getIdentityColumnNullInsertSQL() - { - return ''; - } - /** * Whether this platform supports views. * diff --git a/src/Platforms/DB2Platform.php b/src/Platforms/DB2Platform.php index 1f18b51098e..e6e65bbf38f 100644 --- a/src/Platforms/DB2Platform.php +++ b/src/Platforms/DB2Platform.php @@ -840,6 +840,11 @@ public function getSubstringExpression($value, $from, $length = null) return 'SUBSTR(' . $value . ', ' . $from . ', ' . $length . ')'; } + public function getCurrentDatabaseExpression(): string + { + return 'CURRENT_USER'; + } + /** * {@inheritDoc} */ diff --git a/src/Platforms/MySqlPlatform.php b/src/Platforms/MySqlPlatform.php index f5260df5e5a..3b305d91051 100644 --- a/src/Platforms/MySqlPlatform.php +++ b/src/Platforms/MySqlPlatform.php @@ -79,16 +79,6 @@ public function getRegexpExpression() return 'RLIKE'; } - /** - * {@inheritDoc} - * - * @deprecated Use application-generated UUIDs instead - */ - public function getGuidExpression() - { - return 'UUID()'; - } - /** * {@inheritDoc} */ @@ -127,6 +117,11 @@ public function getDateDiffExpression($date1, $date2) return 'DATEDIFF(' . $date1 . ', ' . $date2 . ')'; } + public function getCurrentDatabaseExpression(): string + { + return 'DATABASE()'; + } + /** * {@inheritDoc} */ @@ -305,22 +300,6 @@ public function getBooleanTypeDeclarationSQL(array $field) return 'TINYINT(1)'; } - /** - * Obtain DBMS specific SQL code portion needed to set the COLLATION - * of a field declaration to be used in statements like CREATE TABLE. - * - * @deprecated Deprecated since version 2.5, Use {@link self::getColumnCollationDeclarationSQL()} instead. - * - * @param string $collation name of the collation - * - * @return string DBMS specific SQL code portion needed to set the COLLATION - * of a field declaration. - */ - public function getCollationFieldDeclaration($collation) - { - return $this->getColumnCollationDeclarationSQL($collation); - } - /** * {@inheritDoc} * diff --git a/src/Platforms/OraclePlatform.php b/src/Platforms/OraclePlatform.php index eb7e7dd3904..2d20a43178e 100644 --- a/src/Platforms/OraclePlatform.php +++ b/src/Platforms/OraclePlatform.php @@ -89,16 +89,6 @@ public function getLocateExpression($str, $substr, $startPos = false) return 'INSTR(' . $str . ', ' . $substr . ', ' . $startPos . ')'; } - /** - * {@inheritDoc} - * - * @deprecated Use application-generated UUIDs instead - */ - public function getGuidExpression() - { - return 'SYS_GUID()'; - } - /** * {@inheritdoc} */ @@ -161,6 +151,11 @@ public function getBitAndComparisonExpression($value1, $value2) return 'BITAND(' . $value1 . ', ' . $value2 . ')'; } + public function getCurrentDatabaseExpression(): string + { + return "SYS_CONTEXT('USERENV', 'CURRENT_SCHEMA')"; + } + /** * {@inheritDoc} */ diff --git a/src/Platforms/PostgreSQL94Platform.php b/src/Platforms/PostgreSQL94Platform.php index 276a6c72880..99b86070d31 100644 --- a/src/Platforms/PostgreSQL94Platform.php +++ b/src/Platforms/PostgreSQL94Platform.php @@ -139,6 +139,11 @@ public function getDateDiffExpression($date1, $date2) return '(DATE(' . $date1 . ')-DATE(' . $date2 . '))'; } + public function getCurrentDatabaseExpression(): string + { + return 'CURRENT_DATABASE()'; + } + /** * {@inheritDoc} */ @@ -1025,16 +1030,6 @@ public function getTimeTypeDeclarationSQL(array $fieldDeclaration) return 'TIME(0) WITHOUT TIME ZONE'; } - /** - * {@inheritDoc} - * - * @deprecated Use application-generated UUIDs instead - */ - public function getGuidExpression() - { - return 'UUID_GENERATE_V4()'; - } - /** * {@inheritDoc} */ @@ -1153,8 +1148,8 @@ protected function initializeDoctrineTypeMappings() 'int8' => 'bigint', 'integer' => 'integer', 'interval' => 'string', - 'json' => Type::JSON, - 'jsonb' => Type::JSON, + 'json' => 'json', + 'jsonb' => 'json', 'money' => 'decimal', 'numeric' => 'decimal', 'serial' => 'integer', diff --git a/src/Platforms/SQLServer2012Platform.php b/src/Platforms/SQLServer2012Platform.php index 38c98dac09b..6513ee2b7eb 100644 --- a/src/Platforms/SQLServer2012Platform.php +++ b/src/Platforms/SQLServer2012Platform.php @@ -1083,16 +1083,6 @@ public function getDropViewSQL($name) return 'DROP VIEW ' . $name; } - /** - * {@inheritDoc} - * - * @deprecated Use application-generated UUIDs instead - */ - public function getGuidExpression() - { - return 'NEWID()'; - } - /** * {@inheritDoc} */ @@ -1203,6 +1193,11 @@ public function getLengthExpression($column) return 'LEN(' . $column . ')'; } + public function getCurrentDatabaseExpression(): string + { + return 'DB_NAME()'; + } + /** * {@inheritDoc} */ diff --git a/src/Platforms/SqlitePlatform.php b/src/Platforms/SqlitePlatform.php index 6cdb59480c3..14e90545451 100644 --- a/src/Platforms/SqlitePlatform.php +++ b/src/Platforms/SqlitePlatform.php @@ -41,19 +41,6 @@ public function getRegexpExpression() return 'REGEXP'; } - /** - * {@inheritDoc} - * - * @deprecated Use application-generated UUIDs instead - */ - public function getGuidExpression() - { - return "HEX(RANDOMBLOB(4)) || '-' || HEX(RANDOMBLOB(2)) || '-4' || " - . "SUBSTR(HEX(RANDOMBLOB(2)), 2) || '-' || " - . "SUBSTR('89AB', 1 + (ABS(RANDOM()) % 4), 1) || " - . "SUBSTR(HEX(RANDOMBLOB(2)), 2) || '-' || HEX(RANDOMBLOB(6))"; - } - /** * @param string $type * @@ -162,6 +149,19 @@ public function getDateDiffExpression($date1, $date2) return sprintf("JULIANDAY(%s, 'start of day') - JULIANDAY(%s, 'start of day')", $date1, $date2); } + /** + * {@inheritDoc} + * + * The SQLite platform doesn't support the concept of a database, therefore, it always returns an empty string + * as an indicator of an implicitly selected database. + * + * @see \Doctrine\DBAL\Connection::getDatabase() + */ + public function getCurrentDatabaseExpression(): string + { + return "''"; + } + /** * {@inheritDoc} */ diff --git a/src/SQLParserUtils.php b/src/SQLParserUtils.php index f0536aa3727..21ad2f07116 100644 --- a/src/SQLParserUtils.php +++ b/src/SQLParserUtils.php @@ -27,40 +27,18 @@ */ class SQLParserUtils { + private const POSITIONAL_TOKEN = '\?'; + private const NAMED_TOKEN = '(?_conn->getConfiguration()->getFilterSchemaAssetsExpression(); - } - /** * Lists the tables for this connection. * @@ -678,41 +668,6 @@ protected function getPortableNamespaceDefinition(array $namespace) return $namespace; } - /** - * @deprecated - * - * @param mixed[][] $functions - * - * @return mixed[][] - */ - protected function _getPortableFunctionsList($functions) - { - $list = []; - foreach ($functions as $value) { - $value = $this->_getPortableFunctionDefinition($value); - - if (! $value) { - continue; - } - - $list[] = $value; - } - - return $list; - } - - /** - * @deprecated - * - * @param mixed[] $function - * - * @return mixed - */ - protected function _getPortableFunctionDefinition($function) - { - return $function; - } - /** * @param mixed[][] $triggers * @@ -1082,7 +1037,13 @@ public function createSchemaConfig() */ public function getSchemaSearchPaths() { - return [$this->_conn->getDatabase()]; + $database = $this->_conn->getDatabase(); + + if ($database !== null) { + return [$database]; + } + + return []; } /** diff --git a/src/Schema/Column.php b/src/Schema/Column.php index be9399a3b07..3d1a1994652 100644 --- a/src/Schema/Column.php +++ b/src/Schema/Column.php @@ -2,15 +2,12 @@ namespace Doctrine\DBAL\Schema; +use Doctrine\DBAL\Schema\Exception\UnknownColumnOption; use Doctrine\DBAL\Types\Type; use function array_merge; use function is_numeric; use function method_exists; -use function sprintf; -use function trigger_error; - -use const E_USER_DEPRECATED; /** * Object representation of a database column. @@ -78,15 +75,9 @@ public function setOptions(array $options) { foreach ($options as $name => $value) { $method = 'set' . $name; + if (! method_exists($this, $method)) { - // next major: throw an exception - @trigger_error(sprintf( - 'The "%s" column option is not supported,' . - ' setting it is deprecated and will cause an error in Doctrine DBAL 3.0', - $name - ), E_USER_DEPRECATED); - - continue; + throw UnknownColumnOption::new($name); } $this->$method($value); diff --git a/src/Schema/Comparator.php b/src/Schema/Comparator.php index 3da86050a5c..ed8f7f510d2 100644 --- a/src/Schema/Comparator.php +++ b/src/Schema/Comparator.php @@ -9,7 +9,6 @@ use function array_keys; use function array_map; use function array_merge; -use function array_shift; use function array_unique; use function assert; use function count; @@ -440,13 +439,6 @@ public function diffColumn(Column $column1, Column $column2) $changedProperties[] = $property; } - // This is a very nasty hack to make comparator work with the legacy json_array type, which should be killed in v3 - if ($this->isALegacyJsonComparison($properties1['type'], $properties2['type'])) { - array_shift($changedProperties); - - $changedProperties[] = 'comment'; - } - // Null values need to be checked additionally as they tell whether to create or drop a default value. // null != 0, null != false, null != '' etc. This affects platform's table alteration SQL generation. if ( @@ -514,21 +506,6 @@ public function diffColumn(Column $column1, Column $column2) return array_unique($changedProperties); } - /** - * TODO: kill with fire on v3.0 - * - * @deprecated - */ - private function isALegacyJsonComparison(Types\Type $one, Types\Type $other): bool - { - if (! $one instanceof Types\JsonType || ! $other instanceof Types\JsonType) { - return false; - } - - return ( ! $one instanceof Types\JsonArrayType && $other instanceof Types\JsonArrayType) - || ( ! $other instanceof Types\JsonArrayType && $one instanceof Types\JsonArrayType); - } - /** * Finds the difference between the indexes $index1 and $index2. * diff --git a/src/Schema/DB2SchemaManager.php b/src/Schema/DB2SchemaManager.php index 64bf8e5c497..e46fa47ec94 100644 --- a/src/Schema/DB2SchemaManager.php +++ b/src/Schema/DB2SchemaManager.php @@ -28,8 +28,7 @@ class DB2SchemaManager extends AbstractSchemaManager */ public function listTableNames() { - $sql = $this->_platform->getListTablesSQL(); - $sql .= ' AND CREATOR = UPPER(' . $this->_conn->quote($this->_conn->getUsername()) . ')'; + $sql = $this->_platform->getListTablesSQL() . ' AND CREATOR = CURRENT_USER'; $tables = $this->_conn->fetchAllAssociative($sql); diff --git a/src/Schema/Exception/UnknownColumnOption.php b/src/Schema/Exception/UnknownColumnOption.php new file mode 100644 index 00000000000..8cf5ac14872 --- /dev/null +++ b/src/Schema/Exception/UnknownColumnOption.php @@ -0,0 +1,22 @@ +setPlatformOption('collation', $tableColumn['collation']); } - if (in_array($column->getType()->getName(), [Types::JSON_ARRAY, Types::JSON], true)) { + if ($column->getType()->getName() === Types::JSON) { $column->setPlatformOption('jsonb', $jsonb); } diff --git a/src/Schema/SqliteSchemaManager.php b/src/Schema/SqliteSchemaManager.php index 2d56df2903a..638dcb9c74c 100644 --- a/src/Schema/SqliteSchemaManager.php +++ b/src/Schema/SqliteSchemaManager.php @@ -224,21 +224,6 @@ protected function _getPortableTableIndexesList($tableIndexes, $tableName = null return parent::_getPortableTableIndexesList($indexBuffer, $tableName); } - /** - * @deprecated - * - * @param array $tableIndex - * - * @return array - */ - protected function _getPortableTableIndexDefinition($tableIndex) - { - return [ - 'name' => $tableIndex['name'], - 'unique' => (bool) $tableIndex['unique'], - ]; - } - /** * {@inheritdoc} */ diff --git a/src/Schema/Table.php b/src/Schema/Table.php index 364504a6b1a..5bf88a563b7 100644 --- a/src/Schema/Table.php +++ b/src/Schema/Table.php @@ -302,25 +302,6 @@ public function addColumn($columnName, $typeName, array $options = []) return $column; } - /** - * Renames a Column. - * - * @deprecated - * - * @param string $oldColumnName - * @param string $newColumnName - * - * @return void - * - * @throws DBALException - */ - public function renameColumn($oldColumnName, $newColumnName) - { - throw new DBALException('Table#renameColumn() was removed, because it drops and recreates ' . - 'the column instead. There is no fix available, because a schema diff cannot reliably detect if a ' . - 'column was renamed or one column was created and another one dropped.'); - } - /** * Change Column Details. * @@ -361,55 +342,16 @@ public function dropColumn($columnName) * @param string[] $localColumnNames * @param string[] $foreignColumnNames * @param mixed[] $options - * @param string|null $constraintName + * @param string|null $name * * @return self */ - public function addForeignKeyConstraint($foreignTable, array $localColumnNames, array $foreignColumnNames, array $options = [], $constraintName = null) + public function addForeignKeyConstraint($foreignTable, array $localColumnNames, array $foreignColumnNames, array $options = [], $name = null) { - if ($constraintName === null) { - $constraintName = $this->_generateIdentifierName(array_merge((array) $this->getName(), $localColumnNames), 'fk', $this->_getMaxIdentifierLength()); + if ($name === null) { + $name = $this->_generateIdentifierName(array_merge((array) $this->getName(), $localColumnNames), 'fk', $this->_getMaxIdentifierLength()); } - return $this->addNamedForeignKeyConstraint($constraintName, $foreignTable, $localColumnNames, $foreignColumnNames, $options); - } - - /** - * Adds a foreign key constraint. - * - * Name is to be generated by the database itself. - * - * @deprecated Use {@link addForeignKeyConstraint} - * - * @param Table|string $foreignTable Table schema instance or table name - * @param string[] $localColumnNames - * @param string[] $foreignColumnNames - * @param mixed[] $options - * - * @return self - */ - public function addUnnamedForeignKeyConstraint($foreignTable, array $localColumnNames, array $foreignColumnNames, array $options = []) - { - return $this->addForeignKeyConstraint($foreignTable, $localColumnNames, $foreignColumnNames, $options); - } - - /** - * Adds a foreign key constraint with a given name. - * - * @deprecated Use {@link addForeignKeyConstraint} - * - * @param string $name - * @param Table|string $foreignTable Table schema instance or table name - * @param string[] $localColumnNames - * @param string[] $foreignColumnNames - * @param mixed[] $options - * - * @return self - * - * @throws SchemaException - */ - public function addNamedForeignKeyConstraint($name, $foreignTable, array $localColumnNames, array $foreignColumnNames, array $options = []) - { if ($foreignTable instanceof Table) { foreach ($foreignColumnNames as $columnName) { if (! $foreignTable->hasColumn($columnName)) { diff --git a/src/Schema/Visitor/Graphviz.php b/src/Schema/Visitor/Graphviz.php index e45e968134a..3628053b0d1 100644 --- a/src/Schema/Visitor/Graphviz.php +++ b/src/Schema/Visitor/Graphviz.php @@ -80,7 +80,7 @@ private function createTableLabel(Table $table) $label .= ''; $label .= ''; $label .= '' . $columnLabel . ''; - $label .= '' . strtolower($column->getType()) . ''; + $label .= '' . strtolower($column->getType()->getName()) . ''; $label .= ''; $primaryKey = $table->getPrimaryKey(); diff --git a/src/Types/JsonArrayType.php b/src/Types/JsonArrayType.php deleted file mode 100644 index 400e0ef3837..00000000000 --- a/src/Types/JsonArrayType.php +++ /dev/null @@ -1,47 +0,0 @@ - GuidType::class, Types::INTEGER => IntegerType::class, Types::JSON => JsonType::class, - Types::JSON_ARRAY => JsonArrayType::class, Types::OBJECT => ObjectType::class, Types::SIMPLE_ARRAY => SimpleArrayType::class, Types::SMALLINT => SmallIntType::class, @@ -303,23 +224,6 @@ static function (Type $type): string { ); } - /** - * @deprecated Relying on string representation is discouraged and will be removed in DBAL 3.0. - * - * @return string - */ - public function __toString() - { - $type = static::class; - $position = strrpos($type, '\\'); - - if ($position !== false) { - $type = substr($type, $position); - } - - return str_replace('Type', '', $type); - } - /** * Does working with this column require SQL conversion functions? * diff --git a/src/Types/Types.php b/src/Types/Types.php index 2ffd1061f62..cb27fe9e535 100644 --- a/src/Types/Types.php +++ b/src/Types/Types.php @@ -34,9 +34,6 @@ final class Types public const TIME_MUTABLE = 'time'; public const TIME_IMMUTABLE = 'time_immutable'; - /** @deprecated json_array type is deprecated, use {@see self::JSON} instead. */ - public const JSON_ARRAY = 'json_array'; - private function __construct() { } diff --git a/tests/ConnectionTest.php b/tests/ConnectionTest.php index f2eebddc0d0..b93ac883004 100644 --- a/tests/ConnectionTest.php +++ b/tests/ConnectionTest.php @@ -108,26 +108,6 @@ public function testGetConfiguration(): void self::assertInstanceOf(Configuration::class, $config); } - public function testGetHost(): void - { - self::assertEquals('localhost', $this->connection->getHost()); - } - - public function testGetPort(): void - { - self::assertEquals('1234', $this->connection->getPort()); - } - - public function testGetUsername(): void - { - self::assertEquals('root', $this->connection->getUsername()); - } - - public function testGetPassword(): void - { - self::assertEquals('password', $this->connection->getPassword()); - } - public function testGetDriver(): void { self::assertInstanceOf(\Doctrine\DBAL\Driver\PDOMySql\Driver::class, $this->connection->getDriver()); diff --git a/tests/Driver/AbstractDriverTest.php b/tests/Driver/AbstractDriverTest.php index 85da37382b7..0c34490cda5 100644 --- a/tests/Driver/AbstractDriverTest.php +++ b/tests/Driver/AbstractDriverTest.php @@ -142,23 +142,6 @@ public function testThrowsExceptionOnCreatingDatabasePlatformsForInvalidVersion( $this->driver->createDatabasePlatformForVersion('foo'); } - public function testReturnsDatabaseName(): void - { - $params = [ - 'user' => 'foo', - 'password' => 'bar', - 'dbname' => 'baz', - ]; - - $connection = $this->getConnectionMock(); - - $connection->expects(self::once()) - ->method('getParams') - ->will(self::returnValue($params)); - - self::assertSame($params['dbname'], $this->driver->getDatabase($connection)); - } - public function testReturnsDatabasePlatform(): void { self::assertEquals($this->createPlatform(), $this->driver->getDatabasePlatform()); diff --git a/tests/Driver/AbstractMySQLDriverTest.php b/tests/Driver/AbstractMySQLDriverTest.php index c6c1e1ebd12..fd1f309c30d 100644 --- a/tests/Driver/AbstractMySQLDriverTest.php +++ b/tests/Driver/AbstractMySQLDriverTest.php @@ -5,7 +5,6 @@ use Doctrine\DBAL\Connection; use Doctrine\DBAL\Driver; use Doctrine\DBAL\Driver\AbstractMySQLDriver; -use Doctrine\DBAL\Driver\Result; use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Platforms\MariaDb1027Platform; use Doctrine\DBAL\Platforms\MySQL57Platform; @@ -16,35 +15,6 @@ class AbstractMySQLDriverTest extends AbstractDriverTest { - public function testReturnsDatabaseName(): void - { - parent::testReturnsDatabaseName(); - - $database = 'bloo'; - $params = [ - 'user' => 'foo', - 'password' => 'bar', - ]; - - $result = $this->createMock(Result::class); - - $result->expects(self::once()) - ->method('fetchOne') - ->will(self::returnValue($database)); - - $connection = $this->getConnectionMock(); - - $connection->expects(self::once()) - ->method('getParams') - ->will(self::returnValue($params)); - - $connection->expects(self::once()) - ->method('query') - ->will(self::returnValue($result)); - - self::assertSame($database, $this->driver->getDatabase($connection)); - } - protected function createDriver(): Driver { return $this->getMockForAbstractClass(AbstractMySQLDriver::class); diff --git a/tests/Driver/AbstractOracleDriverTest.php b/tests/Driver/AbstractOracleDriverTest.php index 7be755b3b51..bfb8bb1b2f6 100644 --- a/tests/Driver/AbstractOracleDriverTest.php +++ b/tests/Driver/AbstractOracleDriverTest.php @@ -12,42 +12,6 @@ class AbstractOracleDriverTest extends AbstractDriverTest { - public function testReturnsDatabaseName(): void - { - $params = [ - 'user' => 'foo', - 'password' => 'bar', - 'dbname' => 'baz', - ]; - - $connection = $this->getConnectionMock(); - - $connection->expects(self::once()) - ->method('getParams') - ->will(self::returnValue($params)); - - self::assertSame($params['user'], $this->driver->getDatabase($connection)); - } - - public function testReturnsDatabaseNameWithConnectDescriptor(): void - { - $params = [ - 'user' => 'foo', - 'password' => 'bar', - 'connectionstring' => '(DESCRIPTION=' . - '(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521))' . - '(CONNECT_DATA=(SERVICE_NAME=baz)))', - ]; - - $connection = $this->getConnectionMock(); - - $connection->expects(self::once()) - ->method('getParams') - ->will(self::returnValue($params)); - - self::assertSame($params['user'], $this->driver->getDatabase($connection)); - } - protected function createDriver(): Driver { return $this->getMockForAbstractClass(AbstractOracleDriver::class); diff --git a/tests/Driver/AbstractPostgreSQLDriverTest.php b/tests/Driver/AbstractPostgreSQLDriverTest.php index d00bd11c847..81236e43011 100644 --- a/tests/Driver/AbstractPostgreSQLDriverTest.php +++ b/tests/Driver/AbstractPostgreSQLDriverTest.php @@ -5,7 +5,6 @@ use Doctrine\DBAL\Connection; use Doctrine\DBAL\Driver; use Doctrine\DBAL\Driver\AbstractPostgreSQLDriver; -use Doctrine\DBAL\Driver\Result; use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Platforms\PostgreSQL100Platform; use Doctrine\DBAL\Platforms\PostgreSQL94Platform; @@ -14,35 +13,6 @@ class AbstractPostgreSQLDriverTest extends AbstractDriverTest { - public function testReturnsDatabaseName(): void - { - parent::testReturnsDatabaseName(); - - $database = 'bloo'; - $params = [ - 'user' => 'foo', - 'password' => 'bar', - ]; - - $result = $this->createMock(Result::class); - - $result->expects(self::once()) - ->method('fetchOne') - ->will(self::returnValue($database)); - - $connection = $this->getConnectionMock(); - - $connection->expects(self::once()) - ->method('getParams') - ->will(self::returnValue($params)); - - $connection->expects(self::once()) - ->method('query') - ->will(self::returnValue($result)); - - self::assertSame($database, $this->driver->getDatabase($connection)); - } - protected function createDriver(): Driver { return $this->getMockForAbstractClass(AbstractPostgreSQLDriver::class); diff --git a/tests/Driver/AbstractSQLiteDriverTest.php b/tests/Driver/AbstractSQLiteDriverTest.php index 4db6e972ffe..c886b70c246 100644 --- a/tests/Driver/AbstractSQLiteDriverTest.php +++ b/tests/Driver/AbstractSQLiteDriverTest.php @@ -12,24 +12,6 @@ class AbstractSQLiteDriverTest extends AbstractDriverTest { - public function testReturnsDatabaseName(): void - { - $params = [ - 'user' => 'foo', - 'password' => 'bar', - 'dbname' => 'baz', - 'path' => 'bloo', - ]; - - $connection = $this->getConnectionMock(); - - $connection->expects(self::once()) - ->method('getParams') - ->will(self::returnValue($params)); - - self::assertSame($params['path'], $this->driver->getDatabase($connection)); - } - protected function createDriver(): Driver { return $this->getMockForAbstractClass(AbstractSQLiteDriver::class); diff --git a/tests/Driver/IBMDB2/DB2DriverTest.php b/tests/Driver/IBMDB2/DB2DriverTest.php index bdc22bce52e..c7d5947d9f5 100644 --- a/tests/Driver/IBMDB2/DB2DriverTest.php +++ b/tests/Driver/IBMDB2/DB2DriverTest.php @@ -8,11 +8,6 @@ class DB2DriverTest extends AbstractDB2DriverTest { - public function testReturnsName(): void - { - self::assertSame('ibm_db2', $this->driver->getName()); - } - protected function createDriver(): DriverInterface { return new DB2Driver(); diff --git a/tests/Driver/Mysqli/DriverTest.php b/tests/Driver/Mysqli/DriverTest.php index 3c924af6dbd..2dccd281dc7 100644 --- a/tests/Driver/Mysqli/DriverTest.php +++ b/tests/Driver/Mysqli/DriverTest.php @@ -8,11 +8,6 @@ class DriverTest extends AbstractMySQLDriverTest { - public function testReturnsName(): void - { - self::assertSame('mysqli', $this->driver->getName()); - } - protected function createDriver(): DriverInterface { return new Driver(); diff --git a/tests/Driver/OCI8/DriverTest.php b/tests/Driver/OCI8/DriverTest.php index 12fc0088f0f..3c1172d77cc 100644 --- a/tests/Driver/OCI8/DriverTest.php +++ b/tests/Driver/OCI8/DriverTest.php @@ -8,11 +8,6 @@ class DriverTest extends AbstractOracleDriverTest { - public function testReturnsName(): void - { - self::assertSame('oci8', $this->driver->getName()); - } - protected function createDriver(): DriverInterface { return new Driver(); diff --git a/tests/Driver/PDOMySql/DriverTest.php b/tests/Driver/PDOMySql/DriverTest.php index d5e1746e533..d97f03a7c30 100644 --- a/tests/Driver/PDOMySql/DriverTest.php +++ b/tests/Driver/PDOMySql/DriverTest.php @@ -8,11 +8,6 @@ class DriverTest extends AbstractMySQLDriverTest { - public function testReturnsName(): void - { - self::assertSame('pdo_mysql', $this->driver->getName()); - } - protected function createDriver(): DriverInterface { return new Driver(); diff --git a/tests/Driver/PDOOracle/DriverTest.php b/tests/Driver/PDOOracle/DriverTest.php index 2f8a48fc696..4cae38e4bbb 100644 --- a/tests/Driver/PDOOracle/DriverTest.php +++ b/tests/Driver/PDOOracle/DriverTest.php @@ -8,11 +8,6 @@ class DriverTest extends AbstractOracleDriverTest { - public function testReturnsName(): void - { - self::assertSame('pdo_oracle', $this->driver->getName()); - } - protected function createDriver(): DriverInterface { return new Driver(); diff --git a/tests/Driver/PDOPgSql/DriverTest.php b/tests/Driver/PDOPgSql/DriverTest.php index 1cd737e804c..281a10d59d3 100644 --- a/tests/Driver/PDOPgSql/DriverTest.php +++ b/tests/Driver/PDOPgSql/DriverTest.php @@ -4,77 +4,68 @@ use Doctrine\DBAL\Driver as DriverInterface; use Doctrine\DBAL\Driver\Connection; +use Doctrine\DBAL\Driver\PDOConnection; use Doctrine\DBAL\Driver\PDOPgSql\Driver; use Doctrine\DBAL\Tests\Driver\AbstractPostgreSQLDriverTest; use Doctrine\DBAL\Tests\TestUtil; use PDO; -use PDOException; use function array_merge; class DriverTest extends AbstractPostgreSQLDriverTest { - public function testReturnsName(): void + protected function setUp(): void { - self::assertSame('pdo_pgsql', $this->driver->getName()); + parent::setUp(); + + if (isset($GLOBALS['db_type']) && $GLOBALS['db_driver'] === 'pdo_pgsql') { + return; + } + + $this->markTestSkipped('Test enabled only when using pdo_pgsql specific phpunit.xml'); } /** * @group DBAL-920 */ - public function testConnectionDisablesPreparesOnPhp56(): void + public function testConnectionDisablesPrepares(): void { - $this->skipWhenNotUsingPdoPgsql(); - $connection = $this->connect([]); - try { - self::assertTrue($connection->getWrappedConnection()->getAttribute(PDO::PGSQL_ATTR_DISABLE_PREPARES)); - } catch (PDOException $ignored) { - /** @link https://bugs.php.net/bug.php?id=68371 */ - $this->markTestIncomplete('See https://bugs.php.net/bug.php?id=68371'); - } + self::assertInstanceOf(PDOConnection::class, $connection); + self::assertTrue( + $connection->getWrappedConnection()->getAttribute(PDO::PGSQL_ATTR_DISABLE_PREPARES) + ); } /** * @group DBAL-920 */ - public function testConnectionDoesNotDisablePreparesOnPhp56WhenAttributeDefined(): void + public function testConnectionDoesNotDisablePreparesWhenAttributeDefined(): void { - $this->skipWhenNotUsingPdoPgsql(); - $connection = $this->connect( [PDO::PGSQL_ATTR_DISABLE_PREPARES => false] ); - try { - self::assertNotSame( - true, - $connection->getWrappedConnection()->getAttribute(PDO::PGSQL_ATTR_DISABLE_PREPARES) - ); - } catch (PDOException $ignored) { - /** @link https://bugs.php.net/bug.php?id=68371 */ - $this->markTestIncomplete('See https://bugs.php.net/bug.php?id=68371'); - } + self::assertInstanceOf(PDOConnection::class, $connection); + self::assertNotTrue( + $connection->getWrappedConnection()->getAttribute(PDO::PGSQL_ATTR_DISABLE_PREPARES) + ); } /** * @group DBAL-920 */ - public function testConnectionDisablePreparesOnPhp56WhenDisablePreparesIsExplicitlyDefined(): void + public function testConnectionDisablePreparesWhenDisablePreparesIsExplicitlyDefined(): void { - $this->skipWhenNotUsingPdoPgsql(); - $connection = $this->connect( [PDO::PGSQL_ATTR_DISABLE_PREPARES => true] ); - try { - self::assertTrue($connection->getWrappedConnection()->getAttribute(PDO::PGSQL_ATTR_DISABLE_PREPARES)); - } catch (PDOException $ignored) { - /** @link https://bugs.php.net/bug.php?id=68371 */ - $this->markTestIncomplete('See https://bugs.php.net/bug.php?id=68371'); - } + self::assertInstanceOf(PDOConnection::class, $connection); + self::assertTrue( + $connection->getWrappedConnection()->getAttribute(PDO::PGSQL_ATTR_DISABLE_PREPARES) + ); } protected function createDriver(): DriverInterface @@ -82,15 +73,6 @@ protected function createDriver(): DriverInterface return new Driver(); } - private function skipWhenNotUsingPdoPgsql(): void - { - if (isset($GLOBALS['db_driver']) && $GLOBALS['db_driver'] === 'pdo_pgsql') { - return; - } - - $this->markTestSkipped('Test enabled only when using pdo_pgsql specific phpunit.xml'); - } - /** * @param array $driverOptions */ diff --git a/tests/Driver/PDOSqlite/DriverTest.php b/tests/Driver/PDOSqlite/DriverTest.php index cb85a5bb27b..0f27bbbcb50 100644 --- a/tests/Driver/PDOSqlite/DriverTest.php +++ b/tests/Driver/PDOSqlite/DriverTest.php @@ -8,11 +8,6 @@ class DriverTest extends AbstractSQLiteDriverTest { - public function testReturnsName(): void - { - self::assertSame('pdo_sqlite', $this->driver->getName()); - } - protected function createDriver(): DriverInterface { return new Driver(); diff --git a/tests/Driver/PDOSqlsrv/DriverTest.php b/tests/Driver/PDOSqlsrv/DriverTest.php index 3f0c60c6a32..dcffafafac3 100644 --- a/tests/Driver/PDOSqlsrv/DriverTest.php +++ b/tests/Driver/PDOSqlsrv/DriverTest.php @@ -8,11 +8,6 @@ class DriverTest extends AbstractSQLServerDriverTest { - public function testReturnsName(): void - { - self::assertSame('pdo_sqlsrv', $this->driver->getName()); - } - protected function createDriver(): DriverInterface { return new Driver(); diff --git a/tests/Driver/SQLSrv/DriverTest.php b/tests/Driver/SQLSrv/DriverTest.php index 6307b52ec68..a8a24d3aa10 100644 --- a/tests/Driver/SQLSrv/DriverTest.php +++ b/tests/Driver/SQLSrv/DriverTest.php @@ -8,11 +8,6 @@ class DriverTest extends AbstractSQLServerDriverTest { - public function testReturnsName(): void - { - self::assertSame('sqlsrv', $this->driver->getName()); - } - protected function createDriver(): DriverInterface { return new Driver(); diff --git a/tests/Events/MysqlSessionInitTest.php b/tests/Events/MysqlSessionInitTest.php deleted file mode 100644 index 0ede3f3ce83..00000000000 --- a/tests/Events/MysqlSessionInitTest.php +++ /dev/null @@ -1,31 +0,0 @@ -createMock(Connection::class); - $connectionMock->expects(self::once()) - ->method('executeUpdate') - ->with(self::equalTo('SET NAMES foo COLLATE bar')); - - $eventArgs = new ConnectionEventArgs($connectionMock); - - $listener = new MysqlSessionInit('foo', 'bar'); - $listener->postConnect($eventArgs); - } - - public function testGetSubscribedEvents(): void - { - $listener = new MysqlSessionInit(); - self::assertEquals([Events::postConnect], $listener->getSubscribedEvents()); - } -} diff --git a/tests/Functional/Driver/AbstractDriverTest.php b/tests/Functional/Driver/AbstractDriverTest.php index 86e2a73b755..7d1976a4372 100644 --- a/tests/Functional/Driver/AbstractDriverTest.php +++ b/tests/Functional/Driver/AbstractDriverTest.php @@ -53,7 +53,7 @@ public function testReturnsDatabaseNameWithoutDatabaseNameParameter(): void self::assertSame( static::getDatabaseNameForConnectionWithoutDatabaseNameParameter(), - $this->driver->getDatabase($connection) + $connection->getDatabase() ); } diff --git a/tests/Functional/Driver/PDOPgSql/DriverTest.php b/tests/Functional/Driver/PDOPgSql/DriverTest.php index 02901d16301..bfa33568934 100644 --- a/tests/Functional/Driver/PDOPgSql/DriverTest.php +++ b/tests/Functional/Driver/PDOPgSql/DriverTest.php @@ -48,7 +48,7 @@ public function testDatabaseParameters(?string $databaseName, ?string $defaultDa self::assertSame( $expectedDatabaseName, - $this->driver->getDatabase($connection) + $connection->getDatabase() ); } diff --git a/tests/Functional/Driver/PDOSqlite/DriverTest.php b/tests/Functional/Driver/PDOSqlite/DriverTest.php index 7122aca579d..c6fbf45df58 100644 --- a/tests/Functional/Driver/PDOSqlite/DriverTest.php +++ b/tests/Functional/Driver/PDOSqlite/DriverTest.php @@ -25,6 +25,11 @@ protected function setUp(): void self::markTestSkipped('pdo_sqlite only test.'); } + public function testReturnsDatabaseNameWithoutDatabaseNameParameter(): void + { + self::markTestSkipped('SQLite does not support the concept of a database.'); + } + protected function createDriver(): DriverInterface { return new Driver(); diff --git a/tests/Functional/Schema/OracleSchemaManagerTest.php b/tests/Functional/Schema/OracleSchemaManagerTest.php index 9fc59409355..956b34f97a4 100644 --- a/tests/Functional/Schema/OracleSchemaManagerTest.php +++ b/tests/Functional/Schema/OracleSchemaManagerTest.php @@ -236,7 +236,7 @@ public function testListTableColumnsSameTableNamesInDifferentSchemas(): void $otherTable->addColumn('id', Types::STRING); TestUtil::getPrivilegedConnection()->getSchemaManager()->dropAndCreateTable($otherTable); - $columns = $this->schemaManager->listTableColumns($table->getName(), $this->connection->getUsername()); + $columns = $this->schemaManager->listTableColumns($table->getName(), $this->connection->getDatabase()); self::assertCount(7, $columns); } diff --git a/tests/Functional/Schema/PostgreSqlSchemaManagerTest.php b/tests/Functional/Schema/PostgreSqlSchemaManagerTest.php index c5a20110e02..67325a59d8d 100644 --- a/tests/Functional/Schema/PostgreSqlSchemaManagerTest.php +++ b/tests/Functional/Schema/PostgreSqlSchemaManagerTest.php @@ -18,6 +18,7 @@ use function array_map; use function array_pop; use function count; +use function preg_match; use function strtolower; class PostgreSqlSchemaManagerTest extends SchemaManagerFunctionalTestCase @@ -164,7 +165,7 @@ public function testTableWithSchema(): void $column = $nestedSchemaTable->addColumn('id', 'integer'); $column->setAutoincrement(true); $nestedSchemaTable->setPrimaryKey(['id']); - $nestedSchemaTable->addUnnamedForeignKeyConstraint($nestedRelatedTable, ['id'], ['id']); + $nestedSchemaTable->addForeignKeyConstraint($nestedRelatedTable, ['id'], ['id']); $this->schemaManager->createTable($nestedRelatedTable); $this->schemaManager->createTable($nestedSchemaTable); @@ -217,11 +218,15 @@ public function testFilterSchemaExpression(): void $column = $testTable->addColumn('id', 'integer'); $this->schemaManager->createTable($testTable); - $this->connection->getConfiguration()->setFilterSchemaAssetsExpression('#^dbal204_#'); + $this->connection->getConfiguration()->setSchemaAssetsFilter(static function (string $name): bool { + return preg_match('#^dbal204_#', $name) === 1; + }); $names = $this->schemaManager->listTableNames(); self::assertCount(2, $names); - $this->connection->getConfiguration()->setFilterSchemaAssetsExpression('#^dbal204_test#'); + $this->connection->getConfiguration()->setSchemaAssetsFilter(static function (string $name): bool { + return preg_match('#^dbal204_test#', $name) === 1; + }); $names = $this->schemaManager->listTableNames(); self::assertCount(1, $names); } @@ -403,10 +408,7 @@ public function testPartialIndexes(): void self::assertSame('(id IS NULL)', $onlineTable->getIndex('simple_partial_index')->getOption('where')); } - /** - * @dataProvider jsonbColumnTypeProvider - */ - public function testJsonbColumn(string $type): void + public function testJsonbColumn(): void { if (! $this->schemaManager->getDatabasePlatform() instanceof PostgreSQL94Platform) { $this->markTestSkipped('Requires PostgresSQL 9.4+'); @@ -415,26 +417,15 @@ public function testJsonbColumn(string $type): void } $table = new Schema\Table('test_jsonb'); - $table->addColumn('foo', $type)->setPlatformOption('jsonb', true); + $table->addColumn('foo', Types::JSON)->setPlatformOption('jsonb', true); $this->schemaManager->dropAndCreateTable($table); $columns = $this->schemaManager->listTableColumns('test_jsonb'); - self::assertSame($type, $columns['foo']->getType()->getName()); + self::assertSame(Types::JSON, $columns['foo']->getType()->getName()); self::assertTrue(true, $columns['foo']->getPlatformOption('jsonb')); } - /** - * @return mixed[][] - */ - public function jsonbColumnTypeProvider(): array - { - return [ - [Types::JSON], - [Types::JSON_ARRAY], - ]; - } - /** * @group DBAL-2427 */ diff --git a/tests/Functional/Schema/SchemaManagerFunctionalTestCase.php b/tests/Functional/Schema/SchemaManagerFunctionalTestCase.php index f0ed94d17a5..f887f5f1a7b 100644 --- a/tests/Functional/Schema/SchemaManagerFunctionalTestCase.php +++ b/tests/Functional/Schema/SchemaManagerFunctionalTestCase.php @@ -1309,129 +1309,6 @@ public function testDoesNotListIndexesImplicitlyCreatedByForeignKeys(): void self::assertArrayHasKey('idx_3d6c147fdc58d6c', $indexes); } - /** - * @after - */ - public function removeJsonArrayTable(): void - { - if (! $this->schemaManager->tablesExist(['json_array_test'])) { - return; - } - - $this->schemaManager->dropTable('json_array_test'); - } - - /** - * @group 2782 - * @group 6654 - */ - public function testComparatorShouldReturnFalseWhenLegacyJsonArrayColumnHasComment(): void - { - $table = new Table('json_array_test'); - $table->addColumn('parameters', 'json_array'); - - $this->schemaManager->createTable($table); - - $comparator = new Comparator(); - $tableDiff = $comparator->diffTable($this->schemaManager->listTableDetails('json_array_test'), $table); - - self::assertFalse($tableDiff); - } - - /** - * @group 2782 - * @group 6654 - */ - public function testComparatorShouldModifyOnlyTheCommentWhenUpdatingFromJsonArrayTypeOnLegacyPlatforms(): void - { - if ($this->schemaManager->getDatabasePlatform()->hasNativeJsonType()) { - $this->markTestSkipped('This test is only supported on platforms that do not have native JSON type.'); - } - - $table = new Table('json_array_test'); - $table->addColumn('parameters', 'json_array'); - - $this->schemaManager->createTable($table); - - $table = new Table('json_array_test'); - $table->addColumn('parameters', 'json'); - - $comparator = new Comparator(); - $tableDiff = $comparator->diffTable($this->schemaManager->listTableDetails('json_array_test'), $table); - - self::assertInstanceOf(TableDiff::class, $tableDiff); - - $changedColumn = $tableDiff->changedColumns['parameters'] ?? $tableDiff->changedColumns['PARAMETERS']; - - self::assertSame(['comment'], $changedColumn->changedProperties); - } - - /** - * @group 2782 - * @group 6654 - */ - public function testComparatorShouldAddCommentToLegacyJsonArrayTypeThatDoesNotHaveIt(): void - { - if (! $this->schemaManager->getDatabasePlatform()->hasNativeJsonType()) { - $this->markTestSkipped('This test is only supported on platforms that have native JSON type.'); - } - - $this->connection->executeQuery('CREATE TABLE json_array_test (parameters JSON NOT NULL)'); - - $table = new Table('json_array_test'); - $table->addColumn('parameters', 'json_array'); - - $comparator = new Comparator(); - $tableDiff = $comparator->diffTable($this->schemaManager->listTableDetails('json_array_test'), $table); - - self::assertInstanceOf(TableDiff::class, $tableDiff); - self::assertSame(['comment'], $tableDiff->changedColumns['parameters']->changedProperties); - } - - /** - * @group 2782 - * @group 6654 - */ - public function testComparatorShouldReturnAllChangesWhenUsingLegacyJsonArrayType(): void - { - if (! $this->schemaManager->getDatabasePlatform()->hasNativeJsonType()) { - $this->markTestSkipped('This test is only supported on platforms that have native JSON type.'); - } - - $this->connection->executeQuery('CREATE TABLE json_array_test (parameters JSON DEFAULT NULL)'); - - $table = new Table('json_array_test'); - $table->addColumn('parameters', 'json_array'); - - $comparator = new Comparator(); - $tableDiff = $comparator->diffTable($this->schemaManager->listTableDetails('json_array_test'), $table); - - self::assertInstanceOf(TableDiff::class, $tableDiff); - self::assertSame(['notnull', 'comment'], $tableDiff->changedColumns['parameters']->changedProperties); - } - - /** - * @group 2782 - * @group 6654 - */ - public function testComparatorShouldReturnAllChangesWhenUsingLegacyJsonArrayTypeEvenWhenPlatformHasJsonSupport(): void - { - if (! $this->schemaManager->getDatabasePlatform()->hasNativeJsonType()) { - $this->markTestSkipped('This test is only supported on platforms that have native JSON type.'); - } - - $this->connection->executeQuery('CREATE TABLE json_array_test (parameters JSON DEFAULT NULL)'); - - $table = new Table('json_array_test'); - $table->addColumn('parameters', 'json_array'); - - $comparator = new Comparator(); - $tableDiff = $comparator->diffTable($this->schemaManager->listTableDetails('json_array_test'), $table); - - self::assertInstanceOf(TableDiff::class, $tableDiff); - self::assertSame(['notnull', 'comment'], $tableDiff->changedColumns['parameters']->changedProperties); - } - /** * @group 2782 * @group 6654 diff --git a/tests/Functional/Ticket/DBAL421Test.php b/tests/Functional/Ticket/DBAL421Test.php deleted file mode 100644 index 8ed1bd45021..00000000000 --- a/tests/Functional/Ticket/DBAL421Test.php +++ /dev/null @@ -1,54 +0,0 @@ -connection->getDatabasePlatform()->getName(); - if (in_array($platform, ['mysql', 'sqlite'])) { - return; - } - - $this->markTestSkipped('Currently restricted to MySQL and SQLite.'); - } - - public function testGuidShouldMatchPattern(): void - { - $guid = $this->connection->query($this->getSelectGuidSql())->fetchOne(); - $pattern = '/[0-9A-F]{8}\-[0-9A-F]{4}\-[0-9A-F]{4}\-[8-9A-B][0-9A-F]{3}\-[0-9A-F]{12}/i'; - self::assertEquals(1, preg_match($pattern, $guid), 'GUID does not match pattern'); - } - - /** - * This test does (of course) not proof that all generated GUIDs are - * random, it should however provide some basic confidence. - */ - public function testGuidShouldBeRandom(): void - { - $statement = $this->connection->prepare($this->getSelectGuidSql()); - $guids = []; - - for ($i = 0; $i < 99; $i++) { - $guid = $statement->execute()->fetchFirstColumn(); - self::assertNotContains($guid, $guids, 'Duplicate GUID detected'); - $guids[] = $guid; - } - } - - private function getSelectGuidSql(): string - { - return 'SELECT ' . $this->connection->getDatabasePlatform()->getGuidExpression(); - } -} diff --git a/tests/Functional/TypeConversionTest.php b/tests/Functional/TypeConversionTest.php index 43adcf32f6b..ac2324d2eb8 100644 --- a/tests/Functional/TypeConversionTest.php +++ b/tests/Functional/TypeConversionTest.php @@ -32,7 +32,7 @@ protected function setUp(): void $table->addColumn('test_time', 'time', ['notnull' => false]); $table->addColumn('test_text', 'text', ['notnull' => false]); $table->addColumn('test_array', 'array', ['notnull' => false]); - $table->addColumn('test_json_array', 'json_array', ['notnull' => false]); + $table->addColumn('test_json', 'json', ['notnull' => false]); $table->addColumn('test_object', 'object', ['notnull' => false]); $table->addColumn('test_float', 'float', ['notnull' => false]); $table->addColumn('test_decimal', 'decimal', ['notnull' => false, 'scale' => 2, 'precision' => 10]); @@ -165,7 +165,7 @@ public static function toArrayProvider(): iterable { return [ 'array' => ['array', ['foo' => 'bar']], - 'json_array' => ['json_array', ['foo' => 'bar']], + 'json' => ['json', ['foo' => 'bar']], ]; } diff --git a/tests/Logging/LoggerChainTest.php b/tests/Logging/LoggerChainTest.php index 3dd30f309d5..c3f03cf870c 100644 --- a/tests/Logging/LoggerChainTest.php +++ b/tests/Logging/LoggerChainTest.php @@ -32,13 +32,10 @@ public function testStopQuery(): void */ private function createChain(string $method, ...$args): LoggerChain { - $chain = new LoggerChain([ + return new LoggerChain([ + $this->createLogger($method, ...$args), $this->createLogger($method, ...$args), ]); - - $chain->addLogger($this->createLogger($method, ...$args)); - - return $chain; } /** diff --git a/tests/Platforms/AbstractPlatformTestCase.php b/tests/Platforms/AbstractPlatformTestCase.php index 3207b5ecd2a..f0962036ed2 100644 --- a/tests/Platforms/AbstractPlatformTestCase.php +++ b/tests/Platforms/AbstractPlatformTestCase.php @@ -857,7 +857,7 @@ public function testReturnsJsonTypeDeclarationSQL(): void $column = [ 'length' => 666, 'notnull' => true, - 'type' => Type::getType('json_array'), + 'type' => Type::getType('json'), ]; self::assertSame( diff --git a/tests/Platforms/AbstractPostgreSQLPlatformTestCase.php b/tests/Platforms/AbstractPostgreSQLPlatformTestCase.php index 3871aa903b8..041c5031be4 100644 --- a/tests/Platforms/AbstractPostgreSQLPlatformTestCase.php +++ b/tests/Platforms/AbstractPostgreSQLPlatformTestCase.php @@ -589,7 +589,7 @@ public function testDroppingConstraintsBeforeColumns(): void $oldTable = clone $newTable; $oldTable->addColumn('parent_id', 'integer'); - $oldTable->addUnnamedForeignKeyConstraint('mytable', ['parent_id'], ['id']); + $oldTable->addForeignKeyConstraint('mytable', ['parent_id'], ['id']); $comparator = new Comparator(); $tableDiff = $comparator->diffTable($oldTable, $newTable); diff --git a/tests/Platforms/PostgreSQL94PlatformTest.php b/tests/Platforms/PostgreSQL94PlatformTest.php index 1cb3e99f75b..1e5f4ff56d9 100644 --- a/tests/Platforms/PostgreSQL94PlatformTest.php +++ b/tests/Platforms/PostgreSQL94PlatformTest.php @@ -5,7 +5,7 @@ use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Platforms\PostgreSQL94Platform; use Doctrine\DBAL\Schema\Table; -use Doctrine\DBAL\Types\Type; +use Doctrine\DBAL\Types\Types; class PostgreSQL94PlatformTest extends AbstractPostgreSQLPlatformTestCase { @@ -84,9 +84,9 @@ public function testReturnsSmallIntTypeDeclarationSQL(): void public function testInitializesJsonTypeMapping(): void { self::assertTrue($this->platform->hasDoctrineTypeMappingFor('json')); - self::assertEquals(Type::JSON, $this->platform->getDoctrineTypeMapping('json')); + self::assertEquals(Types::JSON, $this->platform->getDoctrineTypeMapping('json')); self::assertTrue($this->platform->hasDoctrineTypeMappingFor('jsonb')); - self::assertEquals(Type::JSON, $this->platform->getDoctrineTypeMapping('jsonb')); + self::assertEquals(Types::JSON, $this->platform->getDoctrineTypeMapping('jsonb')); } /** diff --git a/tests/SQLParserUtilsTest.php b/tests/SQLParserUtilsTest.php index fa4aa89a58a..3dc6f38d8a0 100644 --- a/tests/SQLParserUtilsTest.php +++ b/tests/SQLParserUtilsTest.php @@ -7,6 +7,7 @@ use Doctrine\DBAL\SQLParserUtils; use Doctrine\DBAL\SQLParserUtilsException; use PHPUnit\Framework\TestCase; +use ReflectionMethod; /** * @group DBAL-78 @@ -17,55 +18,66 @@ class SQLParserUtilsTest extends TestCase /** * @return mixed[][] */ - public static function dataGetPlaceholderPositions(): iterable + public static function dataGetPlaceholderPositionalPositions(): iterable { return [ // none - ['SELECT * FROM Foo', true, []], - ['SELECT * FROM Foo', false, []], + ['SELECT * FROM Foo', []], // Positionals - ['SELECT ?', true, [7]], - ['SELECT * FROM Foo WHERE bar IN (?, ?, ?)', true, [32, 35, 38]], - ['SELECT ? FROM ?', true, [7, 14]], - ['SELECT "?" FROM foo', true, []], - ["SELECT '?' FROM foo", true, []], - ['SELECT `?` FROM foo', true, []], // Ticket DBAL-552 - ['SELECT [?] FROM foo', true, []], - ["SELECT 'Doctrine\DBAL?' FROM foo", true, []], // Ticket DBAL-558 - ['SELECT "Doctrine\DBAL?" FROM foo', true, []], // Ticket DBAL-558 - ['SELECT `Doctrine\DBAL?` FROM foo', true, []], // Ticket DBAL-558 - ['SELECT [Doctrine\DBAL?] FROM foo', true, []], // Ticket DBAL-558 - ['SELECT "?" FROM foo WHERE bar = ?', true, [32]], - ["SELECT '?' FROM foo WHERE bar = ?", true, [32]], - ['SELECT `?` FROM foo WHERE bar = ?', true, [32]], // Ticket DBAL-552 - ['SELECT [?] FROM foo WHERE bar = ?', true, [32]], - ['SELECT * FROM foo WHERE jsonb_exists_any(foo.bar, ARRAY[?])', true, [56]], // Ticket GH-2295 - ["SELECT 'Doctrine\DBAL?' FROM foo WHERE bar = ?", true, [45]], // Ticket DBAL-558 - ['SELECT "Doctrine\DBAL?" FROM foo WHERE bar = ?', true, [45]], // Ticket DBAL-558 - ['SELECT `Doctrine\DBAL?` FROM foo WHERE bar = ?', true, [45]], // Ticket DBAL-558 - ['SELECT [Doctrine\DBAL?] FROM foo WHERE bar = ?', true, [45]], // Ticket DBAL-558 - ["SELECT * FROM FOO WHERE bar = 'it\\'s a trap? \\\\' OR bar = ?\nAND baz = \"\\\"quote\\\" me on it? \\\\\" OR baz = ?", true, [58, 104]], - ['SELECT * FROM foo WHERE foo = ? AND bar = ?', true, [1 => 42, 0 => 30]], // explicit keys + ['SELECT ?', [7]], + ['SELECT * FROM Foo WHERE bar IN (?, ?, ?)', [32, 35, 38]], + ['SELECT ? FROM ?', [7, 14]], + ['SELECT "?" FROM foo', []], + ["SELECT '?' FROM foo", []], + ['SELECT `?` FROM foo', []], // Ticket DBAL-552 + ['SELECT [?] FROM foo', []], + ["SELECT 'Doctrine\DBAL?' FROM foo", []], // Ticket DBAL-558 + ['SELECT "Doctrine\DBAL?" FROM foo', []], // Ticket DBAL-558 + ['SELECT `Doctrine\DBAL?` FROM foo', []], // Ticket DBAL-558 + ['SELECT [Doctrine\DBAL?] FROM foo', []], // Ticket DBAL-558 + ['SELECT "?" FROM foo WHERE bar = ?', [32]], + ["SELECT '?' FROM foo WHERE bar = ?", [32]], + ['SELECT `?` FROM foo WHERE bar = ?', [32]], // Ticket DBAL-552 + ['SELECT [?] FROM foo WHERE bar = ?', [32]], + ['SELECT * FROM foo WHERE jsonb_exists_any(foo.bar, ARRAY[?])', [56]], // Ticket GH-2295 + ["SELECT 'Doctrine\DBAL?' FROM foo WHERE bar = ?", [45]], // Ticket DBAL-558 + ['SELECT "Doctrine\DBAL?" FROM foo WHERE bar = ?', [45]], // Ticket DBAL-558 + ['SELECT `Doctrine\DBAL?` FROM foo WHERE bar = ?', [45]], // Ticket DBAL-558 + ['SELECT [Doctrine\DBAL?] FROM foo WHERE bar = ?', [45]], // Ticket DBAL-558 + ["SELECT * FROM FOO WHERE bar = 'it\\'s a trap? \\\\' OR bar = ?\nAND baz = \"\\\"quote\\\" me on it? \\\\\" OR baz = ?", [58, 104]], + ['SELECT * FROM foo WHERE foo = ? AND bar = ?', [1 => 42, 0 => 30]], // explicit keys + + ]; + } + + /** + * @return mixed[][] + */ + public function dataGetPlaceholderNamedPositions(): iterable + { + return [ + // none + ['SELECT * FROM Foo', []], // named - ['SELECT :foo FROM :bar', false, [7 => 'foo', 17 => 'bar']], - ['SELECT * FROM Foo WHERE bar IN (:name1, :name2)', false, [32 => 'name1', 40 => 'name2']], - ['SELECT ":foo" FROM Foo WHERE bar IN (:name1, :name2)', false, [37 => 'name1', 45 => 'name2']], - ["SELECT ':foo' FROM Foo WHERE bar IN (:name1, :name2)", false, [37 => 'name1', 45 => 'name2']], - ['SELECT :foo_id', false, [7 => 'foo_id']], // Ticket DBAL-231 - ['SELECT @rank := 1', false, []], // Ticket DBAL-398 - ['SELECT @rank := 1 AS rank, :foo AS foo FROM :bar', false, [27 => 'foo', 44 => 'bar']], // Ticket DBAL-398 - ['SELECT * FROM Foo WHERE bar > :start_date AND baz > :start_date', false, [30 => 'start_date', 52 => 'start_date']], // Ticket GH-113 - ['SELECT foo::date as date FROM Foo WHERE bar > :start_date AND baz > :start_date', false, [46 => 'start_date', 68 => 'start_date']], // Ticket GH-259 - ['SELECT `d.ns:col_name` FROM my_table d WHERE `d.date` >= :param1', false, [57 => 'param1']], // Ticket DBAL-552 - ['SELECT [d.ns:col_name] FROM my_table d WHERE [d.date] >= :param1', false, [57 => 'param1']], // Ticket DBAL-552 - ['SELECT * FROM foo WHERE jsonb_exists_any(foo.bar, ARRAY[:foo])', false, [56 => 'foo']], // Ticket GH-2295 - ['SELECT * FROM foo WHERE jsonb_exists_any(foo.bar, array[:foo])', false, [56 => 'foo']], - ['SELECT table.field1, ARRAY[\'3\'] FROM schema.table table WHERE table.f1 = :foo AND ARRAY[\'3\']', false, [73 => 'foo']], - ['SELECT table.field1, ARRAY[\'3\']::integer[] FROM schema.table table WHERE table.f1 = :foo AND ARRAY[\'3\']::integer[]', false, [84 => 'foo']], - ['SELECT table.field1, ARRAY[:foo] FROM schema.table table WHERE table.f1 = :bar AND ARRAY[\'3\']', false, [27 => 'foo', 74 => 'bar']], - ['SELECT table.field1, ARRAY[:foo]::integer[] FROM schema.table table WHERE table.f1 = :bar AND ARRAY[\'3\']::integer[]', false, [27 => 'foo', 85 => 'bar']], + ['SELECT :foo FROM :bar', [7 => 'foo', 17 => 'bar']], + ['SELECT * FROM Foo WHERE bar IN (:name1, :name2)', [32 => 'name1', 40 => 'name2']], + ['SELECT ":foo" FROM Foo WHERE bar IN (:name1, :name2)', [37 => 'name1', 45 => 'name2']], + ["SELECT ':foo' FROM Foo WHERE bar IN (:name1, :name2)", [37 => 'name1', 45 => 'name2']], + ['SELECT :foo_id', [7 => 'foo_id']], // Ticket DBAL-231 + ['SELECT @rank := 1', []], // Ticket DBAL-398 + ['SELECT @rank := 1 AS rank, :foo AS foo FROM :bar', [27 => 'foo', 44 => 'bar']], // Ticket DBAL-398 + ['SELECT * FROM Foo WHERE bar > :start_date AND baz > :start_date', [30 => 'start_date', 52 => 'start_date']], // Ticket GH-113 + ['SELECT foo::date as date FROM Foo WHERE bar > :start_date AND baz > :start_date', [46 => 'start_date', 68 => 'start_date']], // Ticket GH-259 + ['SELECT `d.ns:col_name` FROM my_table d WHERE `d.date` >= :param1', [57 => 'param1']], // Ticket DBAL-552 + ['SELECT [d.ns:col_name] FROM my_table d WHERE [d.date] >= :param1', [57 => 'param1']], // Ticket DBAL-552 + ['SELECT * FROM foo WHERE jsonb_exists_any(foo.bar, ARRAY[:foo])', [56 => 'foo']], // Ticket GH-2295 + ['SELECT * FROM foo WHERE jsonb_exists_any(foo.bar, array[:foo])', [56 => 'foo']], + ['SELECT table.field1, ARRAY[\'3\'] FROM schema.table table WHERE table.f1 = :foo AND ARRAY[\'3\']', [73 => 'foo']], + ['SELECT table.field1, ARRAY[\'3\']::integer[] FROM schema.table table WHERE table.f1 = :foo AND ARRAY[\'3\']::integer[]', [84 => 'foo']], + ['SELECT table.field1, ARRAY[:foo] FROM schema.table table WHERE table.f1 = :bar AND ARRAY[\'3\']', [27 => 'foo', 74 => 'bar']], + ['SELECT table.field1, ARRAY[:foo]::integer[] FROM schema.table table WHERE table.f1 = :bar AND ARRAY[\'3\']::integer[]', [27 => 'foo', 85 => 'bar']], [ <<<'SQLDATA' SELECT * FROM foo WHERE @@ -77,31 +89,45 @@ public static function dataGetPlaceholderPositions(): iterable OR bar=:a_param3 SQLDATA , - false, [ 74 => 'a_param1', 91 => 'a_param2', 190 => 'a_param3', ], ], - ["SELECT data.age AS age, data.id AS id, data.name AS name, data.id AS id FROM test_data data WHERE (data.description LIKE :condition_0 ESCAPE '\\\\') AND (data.description LIKE :condition_1 ESCAPE '\\\\') ORDER BY id ASC", false, [121 => 'condition_0', 174 => 'condition_1']], - ['SELECT data.age AS age, data.id AS id, data.name AS name, data.id AS id FROM test_data data WHERE (data.description LIKE :condition_0 ESCAPE "\\\\") AND (data.description LIKE :condition_1 ESCAPE "\\\\") ORDER BY id ASC', false, [121 => 'condition_0', 174 => 'condition_1']], - ['SELECT data.age AS age, data.id AS id, data.name AS name, data.id AS id FROM test_data data WHERE (data.description LIKE :condition_0 ESCAPE "\\\\") AND (data.description LIKE :condition_1 ESCAPE \'\\\\\') ORDER BY id ASC', false, [121 => 'condition_0', 174 => 'condition_1']], - ['SELECT data.age AS age, data.id AS id, data.name AS name, data.id AS id FROM test_data data WHERE (data.description LIKE :condition_0 ESCAPE `\\\\`) AND (data.description LIKE :condition_1 ESCAPE `\\\\`) ORDER BY id ASC', false, [121 => 'condition_0', 174 => 'condition_1']], - ['SELECT data.age AS age, data.id AS id, data.name AS name, data.id AS id FROM test_data data WHERE (data.description LIKE :condition_0 ESCAPE \'\\\\\') AND (data.description LIKE :condition_1 ESCAPE `\\\\`) ORDER BY id ASC', false, [121 => 'condition_0', 174 => 'condition_1']], - ["SELECT * FROM Foo WHERE (foo.bar LIKE :condition_0 ESCAPE '\') AND (foo.baz = :condition_1) AND (foo.bak LIKE :condition_2 ESCAPE '\')", false, [38 => 'condition_0', 78 => 'condition_1', 110 => 'condition_2']], + ["SELECT data.age AS age, data.id AS id, data.name AS name, data.id AS id FROM test_data data WHERE (data.description LIKE :condition_0 ESCAPE '\\\\') AND (data.description LIKE :condition_1 ESCAPE '\\\\') ORDER BY id ASC", [121 => 'condition_0', 174 => 'condition_1']], + ['SELECT data.age AS age, data.id AS id, data.name AS name, data.id AS id FROM test_data data WHERE (data.description LIKE :condition_0 ESCAPE "\\\\") AND (data.description LIKE :condition_1 ESCAPE "\\\\") ORDER BY id ASC', [121 => 'condition_0', 174 => 'condition_1']], + ['SELECT data.age AS age, data.id AS id, data.name AS name, data.id AS id FROM test_data data WHERE (data.description LIKE :condition_0 ESCAPE "\\\\") AND (data.description LIKE :condition_1 ESCAPE \'\\\\\') ORDER BY id ASC', [121 => 'condition_0', 174 => 'condition_1']], + ['SELECT data.age AS age, data.id AS id, data.name AS name, data.id AS id FROM test_data data WHERE (data.description LIKE :condition_0 ESCAPE `\\\\`) AND (data.description LIKE :condition_1 ESCAPE `\\\\`) ORDER BY id ASC', [121 => 'condition_0', 174 => 'condition_1']], + ['SELECT data.age AS age, data.id AS id, data.name AS name, data.id AS id FROM test_data data WHERE (data.description LIKE :condition_0 ESCAPE \'\\\\\') AND (data.description LIKE :condition_1 ESCAPE `\\\\`) ORDER BY id ASC', [121 => 'condition_0', 174 => 'condition_1']], + ["SELECT * FROM Foo WHERE (foo.bar LIKE :condition_0 ESCAPE '\') AND (foo.baz = :condition_1) AND (foo.bak LIKE :condition_2 ESCAPE '\')", [38 => 'condition_0', 78 => 'condition_1', 110 => 'condition_2']], ]; } /** * @param int[] $expectedParamPos * - * @dataProvider dataGetPlaceholderPositions + * @dataProvider dataGetPlaceholderPositionalPositions */ - public function testGetPlaceholderPositions(string $query, bool $isPositional, array $expectedParamPos): void + public function testGetPositionalPlaceholderPositions(string $query, array $expectedParamPos): void { - $actualParamPos = SQLParserUtils::getPlaceholderPositions($query, $isPositional); - self::assertEquals($expectedParamPos, $actualParamPos); + $reflection = new ReflectionMethod(SQLParserUtils::class, 'getPositionalPlaceholderPositions'); + $reflection->setAccessible(true); + + self::assertEquals($expectedParamPos, $reflection->invoke(null, $query)); + } + + /** + * @param string[] $expectedParamPos + * + * @dataProvider dataGetPlaceholderNamedPositions + */ + public function testGetNamedPlaceholderPositions(string $query, array $expectedParamPos): void + { + $reflection = new ReflectionMethod(SQLParserUtils::class, 'getNamedPlaceholderPositions'); + $reflection->setAccessible(true); + + self::assertEquals($expectedParamPos, $reflection->invoke(null, $query)); } /** diff --git a/tests/Schema/ColumnTest.php b/tests/Schema/ColumnTest.php index 5c1d3d20197..58cf263c2cf 100644 --- a/tests/Schema/ColumnTest.php +++ b/tests/Schema/ColumnTest.php @@ -6,6 +6,7 @@ use Doctrine\DBAL\Platforms\SqlitePlatform; use Doctrine\DBAL\Platforms\SQLServer2012Platform; use Doctrine\DBAL\Schema\Column; +use Doctrine\DBAL\Schema\Exception\UnknownColumnOption; use Doctrine\DBAL\Types\Type; use Doctrine\DBAL\Types\Types; use PHPUnit\Framework\TestCase; @@ -66,7 +67,8 @@ public function testToArray(): void */ public function testSettingUnknownOptionIsStillSupported(): void { - $this->expectNotToPerformAssertions(); + self::expectException(UnknownColumnOption::class); + self::expectExceptionMessage('The "unknown_option" column option is not supported.'); new Column('foo', $this->createMock(Type::class), ['unknown_option' => 'bar']); } @@ -77,6 +79,9 @@ public function testSettingUnknownOptionIsStillSupported(): void */ public function testOptionsShouldNotBeIgnored(): void { + self::expectException(UnknownColumnOption::class); + self::expectExceptionMessage('The "unknown_option" column option is not supported.'); + $col1 = new Column('bar', Type::getType(Types::INTEGER), ['unknown_option' => 'bar', 'notnull' => true]); self::assertTrue($col1->getNotnull()); diff --git a/tests/Schema/ComparatorTest.php b/tests/Schema/ComparatorTest.php index be0c654a127..685d982ecb8 100644 --- a/tests/Schema/ComparatorTest.php +++ b/tests/Schema/ComparatorTest.php @@ -680,11 +680,11 @@ public function testCompareForeignKeyBasedOnPropertiesNotName(): void { $tableA = new Table('foo'); $tableA->addColumn('id', 'integer'); - $tableA->addNamedForeignKeyConstraint('foo_constraint', 'bar', ['id'], ['id']); + $tableA->addForeignKeyConstraint('bar', ['id'], ['id'], [], 'foo_constraint'); $tableB = new Table('foo'); $tableB->addColumn('ID', 'integer'); - $tableB->addNamedForeignKeyConstraint('bar_constraint', 'bar', ['id'], ['id']); + $tableB->addForeignKeyConstraint('bar', ['id'], ['id'], [], 'bar_constraint'); $c = new Comparator(); $tableDiff = $c->diffTable($tableA, $tableB); diff --git a/tests/Schema/DB2SchemaManagerTest.php b/tests/Schema/DB2SchemaManagerTest.php index 4bad6a115c1..82c99bd0c58 100644 --- a/tests/Schema/DB2SchemaManagerTest.php +++ b/tests/Schema/DB2SchemaManagerTest.php @@ -12,6 +12,7 @@ use PHPUnit\Framework\TestCase; use function in_array; +use function preg_match; /** * @covers \Doctrine\DBAL\Schema\DB2SchemaManager @@ -44,8 +45,10 @@ protected function setUp(): void */ public function testListTableNamesFiltersAssetNamesCorrectly(): void { - $this->conn->getConfiguration()->setFilterSchemaAssetsExpression('/^(?!T_)/'); - $this->conn->expects(self::once())->method('fetchAllAssociative')->will(self::returnValue([ + $this->conn->getConfiguration()->setSchemaAssetsFilter(static function (string $name): bool { + return preg_match('/^(?!T_)/', $name) === 1; + }); + $this->conn->expects(self::once())->method('fetchAllAssociative')->will($this->returnValue([ ['name' => 'FOO'], ['name' => 'T_FOO'], ['name' => 'BAR'], @@ -61,35 +64,6 @@ public function testListTableNamesFiltersAssetNamesCorrectly(): void ); } - /** - * @group DBAL-2701 - */ - public function testAssetFilteringSetsACallable(): void - { - $filterExpression = '/^(?!T_)/'; - $this->conn->getConfiguration()->setFilterSchemaAssetsExpression($filterExpression); - $this->conn->expects(self::once())->method('fetchAllAssociative')->will(self::returnValue([ - ['name' => 'FOO'], - ['name' => 'T_FOO'], - ['name' => 'BAR'], - ['name' => 'T_BAR'], - ])); - - self::assertSame( - [ - 'FOO', - 'BAR', - ], - $this->manager->listTableNames() - ); - - $callable = $this->conn->getConfiguration()->getSchemaAssetsFilter(); - self::assertIsCallable($callable); - - // BC check: Test that regexp expression is still preserved & accessible. - self::assertEquals($filterExpression, $this->conn->getConfiguration()->getFilterSchemaAssetsExpression()); - } - public function testListTableNamesFiltersAssetNamesCorrectlyWithCallable(): void { $accepted = ['T_FOO', 'T_BAR']; @@ -111,79 +85,5 @@ public function testListTableNamesFiltersAssetNamesCorrectlyWithCallable(): void ], $this->manager->listTableNames() ); - - self::assertNull($this->conn->getConfiguration()->getFilterSchemaAssetsExpression()); - } - - public function testSettingNullExpressionWillResetCallable(): void - { - $accepted = ['T_FOO', 'T_BAR']; - $this->conn->getConfiguration()->setSchemaAssetsFilter(static function ($assetName) use ($accepted) { - return in_array($assetName, $accepted); - }); - $this->conn->expects(self::any())->method('quote'); - $this->conn->expects($this->atLeastOnce())->method('fetchAllAssociative')->will(self::returnValue([ - ['name' => 'FOO'], - ['name' => 'T_FOO'], - ['name' => 'BAR'], - ['name' => 'T_BAR'], - ])); - - self::assertSame( - [ - 'T_FOO', - 'T_BAR', - ], - $this->manager->listTableNames() - ); - - $this->conn->getConfiguration()->setFilterSchemaAssetsExpression(null); - - self::assertSame( - [ - 'FOO', - 'T_FOO', - 'BAR', - 'T_BAR', - ], - $this->manager->listTableNames() - ); - - self::assertNull($this->conn->getConfiguration()->getSchemaAssetsFilter()); - } - - public function testSettingNullAsCallableClearsExpression(): void - { - $filterExpression = '/^(?!T_)/'; - $this->conn->getConfiguration()->setFilterSchemaAssetsExpression($filterExpression); - - $this->conn->expects(self::exactly(2))->method('fetchAllAssociative')->will(self::returnValue([ - ['name' => 'FOO'], - ['name' => 'T_FOO'], - ['name' => 'BAR'], - ['name' => 'T_BAR'], - ])); - - self::assertSame( - [ - 'FOO', - 'BAR', - ], - $this->manager->listTableNames() - ); - - $this->conn->getConfiguration()->setSchemaAssetsFilter(null); - - self::assertSame( - [ - 'FOO', - 'T_FOO', - 'BAR', - 'T_BAR', - ], - $this->manager->listTableNames() - ); - - $this->assertNull($this->conn->getConfiguration()->getFilterSchemaAssetsExpression()); } } diff --git a/tests/Schema/MySqlInheritCharsetTest.php b/tests/Schema/MySqlInheritCharsetTest.php index b71d7550302..39a804de542 100644 --- a/tests/Schema/MySqlInheritCharsetTest.php +++ b/tests/Schema/MySqlInheritCharsetTest.php @@ -8,6 +8,7 @@ use Doctrine\DBAL\Configuration; use Doctrine\DBAL\Connection; use Doctrine\DBAL\Driver; +use Doctrine\DBAL\Driver\Connection as DriverConnection; use Doctrine\DBAL\Platforms\MySqlPlatform; use Doctrine\DBAL\Schema\Column; use Doctrine\DBAL\Schema\MySqlSchemaManager; @@ -74,11 +75,15 @@ public function testTableOptions(): void private function getTableOptionsForOverride(array $overrideOptions = []): array { $eventManager = new EventManager(); - $driverMock = $this->createMock(Driver::class); - $platform = new MySqlPlatform(); - $connOptions = array_merge(['platform' => $platform], $overrideOptions); - $conn = new Connection($connOptions, $driverMock, new Configuration(), $eventManager); - $manager = new MySqlSchemaManager($conn, $platform); + + $driverMock = $this->createMock(Driver::class); + $driverMock->method('connect') + ->willReturn($this->createMock(DriverConnection::class)); + + $platform = new MySqlPlatform(); + $connOptions = array_merge(['platform' => $platform], $overrideOptions); + $conn = new Connection($connOptions, $driverMock, new Configuration(), $eventManager); + $manager = new MySqlSchemaManager($conn, $platform); $schemaConfig = $manager->createSchemaConfig(); diff --git a/tests/Schema/MySqlSchemaManagerTest.php b/tests/Schema/MySqlSchemaManagerTest.php index 30e412aa1be..1c51da05918 100644 --- a/tests/Schema/MySqlSchemaManagerTest.php +++ b/tests/Schema/MySqlSchemaManagerTest.php @@ -42,7 +42,7 @@ protected function setUp(): void public function testCompositeForeignKeys(): void { $this->conn->expects(self::once())->method('fetchAllAssociative')->will(self::returnValue($this->getFKDefinition())); - $fkeys = $this->manager->listTableForeignKeys('dummy'); + $fkeys = $this->manager->listTableForeignKeys('dummy', 'dummy'); self::assertCount(1, $fkeys, 'Table has to have one foreign key.'); self::assertInstanceOf(ForeignKeyConstraint::class, $fkeys[0]); diff --git a/tests/Schema/Platforms/MySQLSchemaTest.php b/tests/Schema/Platforms/MySQLSchemaTest.php index 1ac46f0449c..353107a14fe 100644 --- a/tests/Schema/Platforms/MySQLSchemaTest.php +++ b/tests/Schema/Platforms/MySQLSchemaTest.php @@ -51,7 +51,7 @@ public function testGenerateForeignKeySQL(): void { $tableOld = new Table('test'); $tableOld->addColumn('foo_id', 'integer'); - $tableOld->addUnnamedForeignKeyConstraint('test_foreign', ['foo_id'], ['foo_id']); + $tableOld->addForeignKeyConstraint('test_foreign', ['foo_id'], ['foo_id']); $sqls = []; foreach ($tableOld->getForeignKeys() as $fk) { diff --git a/tests/TestUtil.php b/tests/TestUtil.php index 9b3e91ce709..2e01d580ea3 100644 --- a/tests/TestUtil.php +++ b/tests/TestUtil.php @@ -5,6 +5,7 @@ use Doctrine\DBAL\Connection; use Doctrine\DBAL\DriverManager; use Doctrine\DBAL\Platforms\AbstractPlatform; +use Doctrine\DBAL\Platforms\OraclePlatform; use PHPUnit\Framework\Assert; use function array_keys; @@ -87,7 +88,12 @@ private static function initializeDatabase(): void $platform = $privConn->getDatabasePlatform(); if ($platform->supportsCreateDropDatabase()) { - $dbname = $testConn->getDatabase(); + if (! $platform instanceof OraclePlatform) { + $dbname = $testConnParams['dbname']; + } else { + $dbname = $testConnParams['user']; + } + $testConn->close(); $privConn->getSchemaManager()->dropAndCreateDatabase($dbname); diff --git a/tests/Types/JsonArrayTest.php b/tests/Types/JsonArrayTest.php deleted file mode 100644 index d90b8970fc0..00000000000 --- a/tests/Types/JsonArrayTest.php +++ /dev/null @@ -1,82 +0,0 @@ -platform = $this->createMock(AbstractPlatform::class); - $this->type = Type::getType('json_array'); - } - - public function testReturnsBindingType(): void - { - self::assertSame(ParameterType::STRING, $this->type->getBindingType()); - } - - public function testReturnsName(): void - { - self::assertSame(Types::JSON_ARRAY, $this->type->getName()); - } - - public function testReturnsSQLDeclaration(): void - { - $this->platform->expects(self::once()) - ->method('getJsonTypeDeclarationSQL') - ->willReturn('TEST_JSON'); - - self::assertSame('TEST_JSON', $this->type->getSQLDeclaration([], $this->platform)); - } - - public function testJsonNullConvertsToPHPValue(): void - { - self::assertSame([], $this->type->convertToPHPValue(null, $this->platform)); - } - - public function testJsonEmptyStringConvertsToPHPValue(): void - { - self::assertSame([], $this->type->convertToPHPValue('', $this->platform)); - } - - public function testJsonStringConvertsToPHPValue(): void - { - $value = ['foo' => 'bar', 'bar' => 'foo']; - $databaseValue = json_encode($value); - $phpValue = $this->type->convertToPHPValue($databaseValue, $this->platform); - - self::assertEquals($value, $phpValue); - } - - public function testJsonResourceConvertsToPHPValue(): void - { - $value = ['foo' => 'bar', 'bar' => 'foo']; - $databaseValue = fopen('data://text/plain;base64,' . base64_encode(json_encode($value)), 'r'); - $phpValue = $this->type->convertToPHPValue($databaseValue, $this->platform); - - self::assertSame($value, $phpValue); - } - - public function testRequiresSQLCommentHint(): void - { - self::assertTrue($this->type->requiresSQLCommentHint($this->platform)); - } -}