diff --git a/lib/Doctrine/DBAL/Cache/ArrayStatement.php b/lib/Doctrine/DBAL/Cache/ArrayStatement.php index cd2984c2b73..a935f8d3e63 100644 --- a/lib/Doctrine/DBAL/Cache/ArrayStatement.php +++ b/lib/Doctrine/DBAL/Cache/ArrayStatement.php @@ -5,8 +5,8 @@ namespace Doctrine\DBAL\Cache; use ArrayIterator; -use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Driver\ResultStatement; +use Doctrine\DBAL\Exception\InvalidColumnIndex; use Doctrine\DBAL\FetchMode; use InvalidArgumentException; use IteratorAggregate; @@ -149,7 +149,7 @@ public function fetchColumn($columnIndex = 0) } if (! array_key_exists($columnIndex, $row)) { - throw DBALException::invalidColumnIndex($columnIndex, count($row)); + throw InvalidColumnIndex::new($columnIndex, count($row)); } return $row[$columnIndex]; diff --git a/lib/Doctrine/DBAL/Cache/CacheException.php b/lib/Doctrine/DBAL/Cache/CacheException.php index 5ad3d3f7aac..787e02f12e3 100644 --- a/lib/Doctrine/DBAL/Cache/CacheException.php +++ b/lib/Doctrine/DBAL/Cache/CacheException.php @@ -8,19 +8,4 @@ class CacheException extends DBALException { - /** - * @return \Doctrine\DBAL\Cache\CacheException - */ - public static function noCacheKey() - { - return new self('No cache key was set.'); - } - - /** - * @return \Doctrine\DBAL\Cache\CacheException - */ - public static function noResultDriverConfigured() - { - return new self('Trying to cache a query but no result driver is configured.'); - } } diff --git a/lib/Doctrine/DBAL/Cache/Exception/NoCacheKey.php b/lib/Doctrine/DBAL/Cache/Exception/NoCacheKey.php new file mode 100644 index 00000000000..fa15d5cc7d9 --- /dev/null +++ b/lib/Doctrine/DBAL/Cache/Exception/NoCacheKey.php @@ -0,0 +1,15 @@ +cacheKey === null) { - throw CacheException::noCacheKey(); + throw NoCacheKey::new(); } return $this->cacheKey; diff --git a/lib/Doctrine/DBAL/Cache/ResultCacheStatement.php b/lib/Doctrine/DBAL/Cache/ResultCacheStatement.php index 49906264885..7d7a1018bbf 100644 --- a/lib/Doctrine/DBAL/Cache/ResultCacheStatement.php +++ b/lib/Doctrine/DBAL/Cache/ResultCacheStatement.php @@ -6,8 +6,8 @@ use ArrayIterator; use Doctrine\Common\Cache\Cache; -use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Driver\ResultStatement; +use Doctrine\DBAL\Exception\InvalidColumnIndex; use Doctrine\DBAL\FetchMode; use InvalidArgumentException; use IteratorAggregate; @@ -184,7 +184,7 @@ public function fetchColumn($columnIndex = 0) } if (! array_key_exists($columnIndex, $row)) { - throw DBALException::invalidColumnIndex($columnIndex, count($row)); + throw InvalidColumnIndex::new($columnIndex, count($row)); } return $row[$columnIndex]; diff --git a/lib/Doctrine/DBAL/Connection.php b/lib/Doctrine/DBAL/Connection.php index 746e463e436..d63e9c0b992 100644 --- a/lib/Doctrine/DBAL/Connection.php +++ b/lib/Doctrine/DBAL/Connection.php @@ -8,6 +8,7 @@ use Doctrine\Common\EventManager; use Doctrine\DBAL\Cache\ArrayStatement; use Doctrine\DBAL\Cache\CacheException; +use Doctrine\DBAL\Cache\Exception\NoResultDriverConfigured; use Doctrine\DBAL\Cache\QueryCacheProfile; use Doctrine\DBAL\Cache\ResultCacheStatement; use Doctrine\DBAL\Driver\Connection as DriverConnection; @@ -16,7 +17,13 @@ use Doctrine\DBAL\Driver\ResultStatement; use Doctrine\DBAL\Driver\ServerInfoAwareConnection; use Doctrine\DBAL\Driver\Statement as DriverStatement; +use Doctrine\DBAL\Exception\CommitFailedRollbackOnly; +use Doctrine\DBAL\Exception\EmptyCriteriaNotAllowed; use Doctrine\DBAL\Exception\InvalidArgumentException; +use Doctrine\DBAL\Exception\InvalidPlatformType; +use Doctrine\DBAL\Exception\MayNotAlterNestedTransactionWithSavepointsInTransaction; +use Doctrine\DBAL\Exception\NoActiveTransaction; +use Doctrine\DBAL\Exception\SavepointsNotSupported; use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Query\Expression\ExpressionBuilder; use Doctrine\DBAL\Query\QueryBuilder; @@ -198,7 +205,7 @@ public function __construct( if (isset($params['platform'])) { if (! $params['platform'] instanceof Platforms\AbstractPlatform) { - throw DBALException::invalidPlatformType($params['platform']); + throw InvalidPlatformType::new($params['platform']); } $this->platform = $params['platform']; @@ -642,7 +649,7 @@ private function addIdentifierCondition( public function delete($tableExpression, array $identifier, array $types = []) { if (empty($identifier)) { - throw InvalidArgumentException::fromEmptyCriteria(); + throw EmptyCriteriaNotAllowed::new(); } $columns = $values = $conditions = []; @@ -912,10 +919,10 @@ public function executeQuery(string $query, array $params = [], $types = [], ?Qu */ public function executeCacheQuery($query, $params, $types, QueryCacheProfile $qcp) : ResultStatement { - $resultCache = $qcp->getResultCacheDriver() ?? $this->_config->getResultCacheImpl(); + $resultCache = $qcp->getResultCacheDriver() ?: $this->_config->getResultCacheImpl(); if ($resultCache === null) { - throw CacheException::noResultDriverConfigured(); + throw NoResultDriverConfigured::new(); } [$cacheKey, $realKey] = $qcp->generateCacheKeys($query, $params, $types, $this->getParams()); @@ -1122,11 +1129,11 @@ public function transactional(Closure $func) public function setNestTransactionsWithSavepoints($nestTransactionsWithSavepoints) { if ($this->transactionNestingLevel > 0) { - throw ConnectionException::mayNotAlterNestedTransactionWithSavepointsInTransaction(); + throw MayNotAlterNestedTransactionWithSavepointsInTransaction::new(); } if (! $this->getDatabasePlatform()->supportsSavepoints()) { - throw ConnectionException::savepointsNotSupported(); + throw SavepointsNotSupported::new(); } $this->nestTransactionsWithSavepoints = (bool) $nestTransactionsWithSavepoints; @@ -1188,11 +1195,10 @@ public function beginTransaction() : void public function commit() : void { if ($this->transactionNestingLevel === 0) { - throw ConnectionException::noActiveTransaction(); + throw NoActiveTransaction::new(); } - if ($this->isRollbackOnly) { - throw ConnectionException::commitFailedRollbackOnly(); + throw CommitFailedRollbackOnly::new(); } $connection = $this->getWrappedConnection(); @@ -1251,7 +1257,7 @@ private function commitAll() : void public function rollBack() : void { if ($this->transactionNestingLevel === 0) { - throw ConnectionException::noActiveTransaction(); + throw NoActiveTransaction::new(); } $connection = $this->getWrappedConnection(); @@ -1295,7 +1301,7 @@ public function rollBack() : void public function createSavepoint($savepoint) { if (! $this->getDatabasePlatform()->supportsSavepoints()) { - throw ConnectionException::savepointsNotSupported(); + throw SavepointsNotSupported::new(); } $this->getWrappedConnection()->exec($this->platform->createSavePoint($savepoint)); @@ -1313,7 +1319,7 @@ public function createSavepoint($savepoint) public function releaseSavepoint($savepoint) { if (! $this->getDatabasePlatform()->supportsSavepoints()) { - throw ConnectionException::savepointsNotSupported(); + throw SavepointsNotSupported::new(); } if (! $this->platform->supportsReleaseSavepoints()) { @@ -1335,7 +1341,7 @@ public function releaseSavepoint($savepoint) public function rollbackSavepoint($savepoint) { if (! $this->getDatabasePlatform()->supportsSavepoints()) { - throw ConnectionException::savepointsNotSupported(); + throw SavepointsNotSupported::new(); } $this->getWrappedConnection()->exec($this->platform->rollbackSavePoint($savepoint)); @@ -1380,7 +1386,7 @@ public function getSchemaManager() public function setRollbackOnly() { if ($this->transactionNestingLevel === 0) { - throw ConnectionException::noActiveTransaction(); + throw NoActiveTransaction::new(); } $this->isRollbackOnly = true; } @@ -1395,7 +1401,7 @@ public function setRollbackOnly() public function isRollbackOnly() { if ($this->transactionNestingLevel === 0) { - throw ConnectionException::noActiveTransaction(); + throw NoActiveTransaction::new(); } return $this->isRollbackOnly; diff --git a/lib/Doctrine/DBAL/ConnectionException.php b/lib/Doctrine/DBAL/ConnectionException.php index 94207b01bd9..c7051042929 100644 --- a/lib/Doctrine/DBAL/ConnectionException.php +++ b/lib/Doctrine/DBAL/ConnectionException.php @@ -6,35 +6,4 @@ class ConnectionException extends DBALException { - /** - * @return \Doctrine\DBAL\ConnectionException - */ - public static function commitFailedRollbackOnly() - { - return new self('Transaction commit failed because the transaction has been marked for rollback only.'); - } - - /** - * @return \Doctrine\DBAL\ConnectionException - */ - public static function noActiveTransaction() - { - return new self('There is no active transaction.'); - } - - /** - * @return \Doctrine\DBAL\ConnectionException - */ - public static function savepointsNotSupported() - { - return new self('Savepoints are not supported by this driver.'); - } - - /** - * @return \Doctrine\DBAL\ConnectionException - */ - public static function mayNotAlterNestedTransactionWithSavepointsInTransaction() - { - return new self('May not alter the nested transaction with savepoints behavior while a transaction is open.'); - } } diff --git a/lib/Doctrine/DBAL/DBALException.php b/lib/Doctrine/DBAL/DBALException.php index e909980534b..99ca5b35f39 100644 --- a/lib/Doctrine/DBAL/DBALException.php +++ b/lib/Doctrine/DBAL/DBALException.php @@ -7,130 +7,19 @@ use Doctrine\DBAL\Driver\DriverException as DriverExceptionInterface; use Doctrine\DBAL\Driver\ExceptionConverterDriver; use Doctrine\DBAL\Exception\DriverException; -use Doctrine\DBAL\Platforms\AbstractPlatform; -use Doctrine\DBAL\Types\Type; use Exception; use Throwable; use function array_map; use function bin2hex; -use function get_class; -use function gettype; use function implode; -use function is_object; use function is_resource; use function is_string; use function json_encode; use function preg_replace; -use function spl_object_hash; use function sprintf; class DBALException extends Exception { - /** - * @param string $method - * - * @return \Doctrine\DBAL\DBALException - */ - public static function notSupported($method) - { - return new self(sprintf("Operation '%s' is not supported by platform.", $method)); - } - - public static function invalidPlatformSpecified() : self - { - return new self( - "Invalid 'platform' option specified, need to give an instance of " . AbstractPlatform::class . '.' - ); - } - - /** - * @param mixed $invalidPlatform - */ - public static function invalidPlatformType($invalidPlatform) : self - { - if (is_object($invalidPlatform)) { - return new self( - sprintf( - "Option 'platform' must be a subtype of '%s', instance of '%s' given", - AbstractPlatform::class, - get_class($invalidPlatform) - ) - ); - } - - return new self( - sprintf( - "Option 'platform' must be an object and subtype of '%s'. Got '%s'", - AbstractPlatform::class, - gettype($invalidPlatform) - ) - ); - } - - /** - * Returns a new instance for an invalid specified platform version. - * - * @param string $version The invalid platform version given. - * @param string $expectedFormat The expected platform version format. - * - * @return DBALException - */ - public static function invalidPlatformVersionSpecified($version, $expectedFormat) - { - return new self( - sprintf( - 'Invalid platform version "%s" specified. ' . - 'The platform version has to be specified in the format: "%s".', - $version, - $expectedFormat - ) - ); - } - - /** - * @return \Doctrine\DBAL\DBALException - */ - public static function invalidPdoInstance() - { - return new self( - "The 'pdo' option was used in DriverManager::getConnection() but no " . - 'instance of PDO was given.' - ); - } - - /** - * @param string|null $url The URL that was provided in the connection parameters (if any). - * - * @return \Doctrine\DBAL\DBALException - */ - public static function driverRequired($url = null) - { - if ($url) { - return new self( - sprintf( - "The options 'driver' or 'driverClass' are mandatory if a connection URL without scheme " . - 'is given to DriverManager::getConnection(). Given URL: %s', - $url - ) - ); - } - - return new self("The options 'driver' or 'driverClass' are mandatory if no PDO " . - 'instance is given to DriverManager::getConnection().'); - } - - /** - * @param string $unknownDriverName - * @param string[] $knownDrivers - * - * @return \Doctrine\DBAL\DBALException - */ - public static function unknownDriver($unknownDriverName, array $knownDrivers) - { - return new self("The given 'driver' " . $unknownDriverName . ' is unknown, ' . - 'Doctrine currently supports only the following drivers: ' . implode(', ', $knownDrivers)); - } - /** * @param string $sql * @param mixed[] $params @@ -196,111 +85,4 @@ private static function formatParameters(array $params) return $json; }, $params)) . ']'; } - - /** - * @param string $wrapperClass - * - * @return \Doctrine\DBAL\DBALException - */ - public static function invalidWrapperClass($wrapperClass) - { - return new self("The given 'wrapperClass' " . $wrapperClass . ' has to be a ' . - 'subtype of \Doctrine\DBAL\Connection.'); - } - - /** - * @param string $driverClass - * - * @return \Doctrine\DBAL\DBALException - */ - public static function invalidDriverClass($driverClass) - { - return new self("The given 'driverClass' " . $driverClass . ' has to implement the ' . Driver::class . ' interface.'); - } - - /** - * @param string $tableName - * - * @return \Doctrine\DBAL\DBALException - */ - public static function invalidTableName($tableName) - { - return new self('Invalid table name specified: ' . $tableName); - } - - /** - * @param string $tableName - * - * @return \Doctrine\DBAL\DBALException - */ - public static function noColumnsSpecifiedForTable($tableName) - { - return new self('No columns specified for table ' . $tableName); - } - - /** - * @return \Doctrine\DBAL\DBALException - */ - public static function limitOffsetInvalid() - { - return new self('Invalid Offset in Limit Query, it has to be larger than or equal to 0.'); - } - - /** - * @param string $name - * - * @return \Doctrine\DBAL\DBALException - */ - public static function typeExists($name) - { - return new self('Type ' . $name . ' already exists.'); - } - - /** - * @param string $name - * - * @return \Doctrine\DBAL\DBALException - */ - public static function unknownColumnType($name) - { - return new self('Unknown column type "' . $name . '" requested. Any Doctrine type that you use has ' . - 'to be registered with \Doctrine\DBAL\Types\Type::addType(). You can get a list of all the ' . - 'known types with \Doctrine\DBAL\Types\Type::getTypesMap(). If this error occurs during database ' . - 'introspection then you might have forgotten to register all database types for a Doctrine Type. Use ' . - 'AbstractPlatform#registerDoctrineTypeMapping() or have your custom types implement ' . - 'Type#getMappedDatabaseTypes(). If the type name is empty you might ' . - 'have a problem with the cache or forgot some mapping information.'); - } - - /** - * @param string $name - * - * @return \Doctrine\DBAL\DBALException - */ - public static function typeNotFound($name) - { - return new self('Type to be overwritten ' . $name . ' does not exist.'); - } - - public static function typeNotRegistered(Type $type) : self - { - return new self(sprintf('Type of the class %s@%s is not registered.', get_class($type), spl_object_hash($type))); - } - - public static function typeAlreadyRegistered(Type $type) : self - { - return new self( - sprintf('Type of the class %s@%s is already registered.', get_class($type), spl_object_hash($type)) - ); - } - - public static function invalidColumnIndex(int $index, int $count) : self - { - return new self(sprintf( - 'Invalid column index %d. The statement result contains %d column%s.', - $index, - $count, - $count === 1 ? '' : 's' - )); - } } diff --git a/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php b/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php index c876723d7ab..be0074ce0f4 100644 --- a/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php +++ b/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php @@ -8,6 +8,7 @@ use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Driver; use Doctrine\DBAL\Exception; +use Doctrine\DBAL\Platforms\Exception\InvalidPlatformVersion; use Doctrine\DBAL\Platforms\MariaDb1027Platform; use Doctrine\DBAL\Platforms\MySQL57Platform; use Doctrine\DBAL\Platforms\MySQL80Platform; @@ -148,7 +149,7 @@ private function getOracleMysqlVersionNumber(string $versionString) : string $versionString, $versionParts )) { - throw DBALException::invalidPlatformVersionSpecified( + throw InvalidPlatformVersion::new( $versionString, '..' ); @@ -179,7 +180,7 @@ private function getMariaDbMysqlVersionNumber(string $versionString) : string $versionString, $versionParts )) { - throw DBALException::invalidPlatformVersionSpecified( + throw InvalidPlatformVersion::new( $versionString, '^(?:5\.5\.5-)?(mariadb-)?..' ); diff --git a/lib/Doctrine/DBAL/Driver/AbstractPostgreSQLDriver.php b/lib/Doctrine/DBAL/Driver/AbstractPostgreSQLDriver.php index ea62f8e3603..726d4cce38e 100644 --- a/lib/Doctrine/DBAL/Driver/AbstractPostgreSQLDriver.php +++ b/lib/Doctrine/DBAL/Driver/AbstractPostgreSQLDriver.php @@ -5,9 +5,9 @@ namespace Doctrine\DBAL\Driver; use Doctrine\DBAL\Connection; -use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Driver; use Doctrine\DBAL\Exception; +use Doctrine\DBAL\Platforms\Exception\InvalidPlatformVersion; use Doctrine\DBAL\Platforms\PostgreSQL100Platform; use Doctrine\DBAL\Platforms\PostgreSQL94Platform; use Doctrine\DBAL\Platforms\PostgreSqlPlatform; @@ -82,7 +82,7 @@ public function convertException($message, DriverException $exception) public function createDatabasePlatformForVersion($version) { if (! preg_match('/^(?P\d+)(?:\.(?P\d+)(?:\.(?P\d+))?)?/', $version, $versionParts)) { - throw DBALException::invalidPlatformVersionSpecified( + throw InvalidPlatformVersion::new( $version, '..' ); diff --git a/lib/Doctrine/DBAL/Driver/AbstractSQLAnywhereDriver.php b/lib/Doctrine/DBAL/Driver/AbstractSQLAnywhereDriver.php index ebca7b1934e..2acb5777d1d 100644 --- a/lib/Doctrine/DBAL/Driver/AbstractSQLAnywhereDriver.php +++ b/lib/Doctrine/DBAL/Driver/AbstractSQLAnywhereDriver.php @@ -5,9 +5,9 @@ namespace Doctrine\DBAL\Driver; use Doctrine\DBAL\Connection; -use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Driver; use Doctrine\DBAL\Exception; +use Doctrine\DBAL\Platforms\Exception\InvalidPlatformVersion; use Doctrine\DBAL\Platforms\SQLAnywherePlatform; use Doctrine\DBAL\Schema\SQLAnywhereSchemaManager; use Doctrine\DBAL\VersionAwarePlatformDriver; @@ -73,7 +73,7 @@ public function createDatabasePlatformForVersion($version) $version, $versionParts )) { - throw DBALException::invalidPlatformVersionSpecified( + throw InvalidPlatformVersion::new( $version, '...' ); diff --git a/lib/Doctrine/DBAL/Driver/AbstractSQLServerDriver.php b/lib/Doctrine/DBAL/Driver/AbstractSQLServerDriver.php index dc22ebd5bb1..960484d9629 100644 --- a/lib/Doctrine/DBAL/Driver/AbstractSQLServerDriver.php +++ b/lib/Doctrine/DBAL/Driver/AbstractSQLServerDriver.php @@ -5,8 +5,8 @@ namespace Doctrine\DBAL\Driver; use Doctrine\DBAL\Connection; -use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Driver; +use Doctrine\DBAL\Platforms\Exception\InvalidPlatformVersion; use Doctrine\DBAL\Platforms\SQLServer2012Platform; use Doctrine\DBAL\Platforms\SQLServerPlatform; use Doctrine\DBAL\Schema\SQLServerSchemaManager; @@ -29,7 +29,7 @@ public function createDatabasePlatformForVersion($version) $version, $versionParts )) { - throw DBALException::invalidPlatformVersionSpecified( + throw InvalidPlatformVersion::new( $version, '...' ); diff --git a/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php b/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php index f2633d95d65..c4f6d0c7d3a 100644 --- a/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php +++ b/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php @@ -4,9 +4,9 @@ namespace Doctrine\DBAL\Driver\IBMDB2; -use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Driver\Statement; use Doctrine\DBAL\Driver\StatementIterator; +use Doctrine\DBAL\Exception\InvalidColumnIndex; use Doctrine\DBAL\FetchMode; use Doctrine\DBAL\ParameterType; use IteratorAggregate; @@ -318,7 +318,7 @@ public function fetchColumn($columnIndex = 0) } if (! array_key_exists($columnIndex, $row)) { - throw DBALException::invalidColumnIndex($columnIndex, count($row)); + throw InvalidColumnIndex::new($columnIndex, count($row)); } return $row[$columnIndex]; diff --git a/lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php b/lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php index bb07e5a9a95..9dd8e456dcd 100644 --- a/lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php +++ b/lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php @@ -4,11 +4,11 @@ namespace Doctrine\DBAL\Driver\Mysqli; -use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Driver\DriverException; use Doctrine\DBAL\Driver\Statement; use Doctrine\DBAL\Driver\StatementIterator; use Doctrine\DBAL\Exception\InvalidArgumentException; +use Doctrine\DBAL\Exception\InvalidColumnIndex; use Doctrine\DBAL\FetchMode; use Doctrine\DBAL\ParameterType; use IteratorAggregate; @@ -382,7 +382,7 @@ public function fetchColumn($columnIndex = 0) } if (! array_key_exists($columnIndex, $row)) { - throw DBALException::invalidColumnIndex($columnIndex, count($row)); + throw InvalidColumnIndex::new($columnIndex, count($row)); } return $row[$columnIndex]; diff --git a/lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php b/lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php index c4dfdddeacd..b06ab3ae51e 100644 --- a/lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php +++ b/lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php @@ -4,9 +4,9 @@ namespace Doctrine\DBAL\Driver\OCI8; -use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Driver\Statement; use Doctrine\DBAL\Driver\StatementIterator; +use Doctrine\DBAL\Exception\InvalidColumnIndex; use Doctrine\DBAL\FetchMode; use Doctrine\DBAL\ParameterType; use InvalidArgumentException; @@ -488,7 +488,7 @@ public function fetchColumn($columnIndex = 0) } if (! array_key_exists($columnIndex, $row)) { - throw DBALException::invalidColumnIndex($columnIndex, count($row)); + throw InvalidColumnIndex::new($columnIndex, count($row)); } return $row[$columnIndex]; diff --git a/lib/Doctrine/DBAL/Driver/PDOStatement.php b/lib/Doctrine/DBAL/Driver/PDOStatement.php index 411cf8222c8..cfcbb92cf31 100644 --- a/lib/Doctrine/DBAL/Driver/PDOStatement.php +++ b/lib/Doctrine/DBAL/Driver/PDOStatement.php @@ -4,7 +4,7 @@ namespace Doctrine\DBAL\Driver; -use Doctrine\DBAL\DBALException; +use Doctrine\DBAL\Exception\InvalidColumnIndex; use Doctrine\DBAL\FetchMode; use Doctrine\DBAL\ParameterType; use IteratorAggregate; @@ -186,7 +186,7 @@ public function fetchColumn($columnIndex = 0) $columnCount = $this->columnCount(); if ($columnIndex < 0 || $columnIndex >= $columnCount) { - throw DBALException::invalidColumnIndex($columnIndex, $columnCount); + throw InvalidColumnIndex::new($columnIndex, $columnCount); } } diff --git a/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereStatement.php b/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereStatement.php index c8afb177f46..8e5c59fb1f5 100644 --- a/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereStatement.php +++ b/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereStatement.php @@ -4,9 +4,9 @@ namespace Doctrine\DBAL\Driver\SQLAnywhere; -use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Driver\Statement; use Doctrine\DBAL\Driver\StatementIterator; +use Doctrine\DBAL\Exception\InvalidColumnIndex; use Doctrine\DBAL\FetchMode; use Doctrine\DBAL\ParameterType; use IteratorAggregate; @@ -260,7 +260,7 @@ public function fetchColumn($columnIndex = 0) } if (! array_key_exists($columnIndex, $row)) { - throw DBALException::invalidColumnIndex($columnIndex, count($row)); + throw InvalidColumnIndex::new($columnIndex, count($row)); } } diff --git a/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvStatement.php b/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvStatement.php index ad572e81e30..4cb8c65d9e7 100644 --- a/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvStatement.php +++ b/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvStatement.php @@ -4,9 +4,9 @@ namespace Doctrine\DBAL\Driver\SQLSrv; -use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Driver\Statement; use Doctrine\DBAL\Driver\StatementIterator; +use Doctrine\DBAL\Exception\InvalidColumnIndex; use Doctrine\DBAL\FetchMode; use Doctrine\DBAL\ParameterType; use IteratorAggregate; @@ -389,7 +389,7 @@ public function fetchColumn($columnIndex = 0) } if (! array_key_exists($columnIndex, $row)) { - throw DBALException::invalidColumnIndex($columnIndex, count($row)); + throw InvalidColumnIndex::new($columnIndex, count($row)); } return $row[$columnIndex]; diff --git a/lib/Doctrine/DBAL/DriverManager.php b/lib/Doctrine/DBAL/DriverManager.php index 33cbff22972..4a16ee1735c 100644 --- a/lib/Doctrine/DBAL/DriverManager.php +++ b/lib/Doctrine/DBAL/DriverManager.php @@ -15,6 +15,11 @@ use Doctrine\DBAL\Driver\PDOSqlsrv\Driver as PDOSQLSrvDriver; use Doctrine\DBAL\Driver\SQLAnywhere\Driver as SQLAnywhereDriver; use Doctrine\DBAL\Driver\SQLSrv\Driver as SQLSrvDriver; +use Doctrine\DBAL\Exception\DriverRequired; +use Doctrine\DBAL\Exception\InvalidDriverClass; +use Doctrine\DBAL\Exception\InvalidPdoInstance; +use Doctrine\DBAL\Exception\InvalidWrapperClass; +use Doctrine\DBAL\Exception\UnknownDriver; use PDO; use function array_keys; use function array_map; @@ -172,7 +177,7 @@ public static function getConnection( // check for existing pdo object if (isset($params['pdo']) && ! $params['pdo'] instanceof PDO) { - throw DBALException::invalidPdoInstance(); + throw InvalidPdoInstance::new(); } if (isset($params['pdo'])) { @@ -189,7 +194,7 @@ public static function getConnection( $wrapperClass = Connection::class; if (isset($params['wrapperClass'])) { if (! is_subclass_of($params['wrapperClass'], $wrapperClass)) { - throw DBALException::invalidWrapperClass($params['wrapperClass']); + throw InvalidWrapperClass::new($params['wrapperClass']); } $wrapperClass = $params['wrapperClass']; @@ -221,18 +226,18 @@ private static function _checkParams(array $params) : void // driver if (! isset($params['driver']) && ! isset($params['driverClass'])) { - throw DBALException::driverRequired(); + throw DriverRequired::new(); } // check validity of parameters // driver if (isset($params['driver']) && ! isset(self::$_driverMap[$params['driver']])) { - throw DBALException::unknownDriver($params['driver'], array_keys(self::$_driverMap)); + throw UnknownDriver::new($params['driver'], array_keys(self::$_driverMap)); } if (isset($params['driverClass']) && ! in_array(Driver::class, class_implements($params['driverClass'], true))) { - throw DBALException::invalidDriverClass($params['driverClass']); + throw InvalidDriverClass::new($params['driverClass']); } } @@ -433,7 +438,7 @@ private static function parseDatabaseUrlScheme(array $url, array $params) : arra // If a schemeless connection URL is given, we require a default driver or default custom driver // as connection parameter. if (! isset($params['driverClass']) && ! isset($params['driver'])) { - throw DBALException::driverRequired($params['url']); + throw DriverRequired::new($params['url']); } return $params; diff --git a/lib/Doctrine/DBAL/Exception/CommitFailedRollbackOnly.php b/lib/Doctrine/DBAL/Exception/CommitFailedRollbackOnly.php new file mode 100644 index 00000000000..dd53e900711 --- /dev/null +++ b/lib/Doctrine/DBAL/Exception/CommitFailedRollbackOnly.php @@ -0,0 +1,15 @@ +getColumns()) === 0) { - throw DBALException::noColumnsSpecifiedForTable($table->getName()); + throw NoColumnsSpecifiedForTable::new($table->getName()); } $tableName = $table->getQuotedName($this); @@ -1553,7 +1556,7 @@ public function getCommentOnColumnSQL($tableName, $columnName, $comment) public function getInlineColumnCommentSQL($comment) { if (! $this->supportsInlineColumnComments()) { - throw DBALException::notSupported(__METHOD__); + throw NotSupported::new(__METHOD__); } return 'COMMENT ' . $this->quoteStringLiteral($comment); @@ -1624,7 +1627,7 @@ public function getCreateTemporaryTableSnippetSQL() */ public function getCreateSequenceSQL(Sequence $sequence) { - throw DBALException::notSupported(__METHOD__); + throw NotSupported::new(__METHOD__); } /** @@ -1636,7 +1639,7 @@ public function getCreateSequenceSQL(Sequence $sequence) */ public function getAlterSequenceSQL(Sequence $sequence) { - throw DBALException::notSupported(__METHOD__); + throw NotSupported::new(__METHOD__); } /** @@ -1762,7 +1765,7 @@ public function getCreatePrimaryKeySQL(Index $index, $table) */ public function getCreateSchemaSQL($schemaName) { - throw DBALException::notSupported(__METHOD__); + throw NotSupported::new(__METHOD__); } /** @@ -1831,7 +1834,7 @@ public function getCreateForeignKeySQL(ForeignKeyConstraint $foreignKey, $table) */ public function getAlterTableSQL(TableDiff $diff) { - throw DBALException::notSupported(__METHOD__); + throw NotSupported::new(__METHOD__); } /** @@ -2650,7 +2653,7 @@ protected function _getTransactionIsolationLevelSQL($level) */ public function getListDatabasesSQL() { - throw DBALException::notSupported(__METHOD__); + throw NotSupported::new(__METHOD__); } /** @@ -2662,7 +2665,7 @@ public function getListDatabasesSQL() */ public function getListNamespacesSQL() { - throw DBALException::notSupported(__METHOD__); + throw NotSupported::new(__METHOD__); } /** @@ -2674,7 +2677,7 @@ public function getListNamespacesSQL() */ public function getListSequencesSQL($database) { - throw DBALException::notSupported(__METHOD__); + throw NotSupported::new(__METHOD__); } /** @@ -2686,7 +2689,7 @@ public function getListSequencesSQL($database) */ public function getListTableConstraintsSQL($table) { - throw DBALException::notSupported(__METHOD__); + throw NotSupported::new(__METHOD__); } /** @@ -2699,7 +2702,7 @@ public function getListTableConstraintsSQL($table) */ public function getListTableColumnsSQL($table, $database = null) { - throw DBALException::notSupported(__METHOD__); + throw NotSupported::new(__METHOD__); } /** @@ -2709,7 +2712,7 @@ public function getListTableColumnsSQL($table, $database = null) */ public function getListTablesSQL() { - throw DBALException::notSupported(__METHOD__); + throw NotSupported::new(__METHOD__); } /** @@ -2719,7 +2722,7 @@ public function getListTablesSQL() */ public function getListUsersSQL() { - throw DBALException::notSupported(__METHOD__); + throw NotSupported::new(__METHOD__); } /** @@ -2733,7 +2736,7 @@ public function getListUsersSQL() */ public function getListViewsSQL($database) { - throw DBALException::notSupported(__METHOD__); + throw NotSupported::new(__METHOD__); } /** @@ -2755,7 +2758,7 @@ public function getListViewsSQL($database) */ public function getListTableIndexesSQL($table, $currentDatabase = null) { - throw DBALException::notSupported(__METHOD__); + throw NotSupported::new(__METHOD__); } /** @@ -2767,7 +2770,7 @@ public function getListTableIndexesSQL($table, $currentDatabase = null) */ public function getListTableForeignKeysSQL($table) { - throw DBALException::notSupported(__METHOD__); + throw NotSupported::new(__METHOD__); } /** @@ -2780,7 +2783,7 @@ public function getListTableForeignKeysSQL($table) */ public function getCreateViewSQL($name, $sql) { - throw DBALException::notSupported(__METHOD__); + throw NotSupported::new(__METHOD__); } /** @@ -2792,7 +2795,7 @@ public function getCreateViewSQL($name, $sql) */ public function getDropViewSQL($name) { - throw DBALException::notSupported(__METHOD__); + throw NotSupported::new(__METHOD__); } /** @@ -2806,7 +2809,7 @@ public function getDropViewSQL($name) */ public function getDropSequenceSQL($sequence) { - throw DBALException::notSupported(__METHOD__); + throw NotSupported::new(__METHOD__); } /** @@ -2818,7 +2821,7 @@ public function getDropSequenceSQL($sequence) */ public function getSequenceNextValSQL($sequenceName) { - throw DBALException::notSupported(__METHOD__); + throw NotSupported::new(__METHOD__); } /** @@ -2832,7 +2835,7 @@ public function getSequenceNextValSQL($sequenceName) */ public function getCreateDatabaseSQL($database) { - throw DBALException::notSupported(__METHOD__); + throw NotSupported::new(__METHOD__); } /** @@ -2846,7 +2849,7 @@ public function getCreateDatabaseSQL($database) */ public function getSetTransactionIsolationSQL($level) { - throw DBALException::notSupported(__METHOD__); + throw NotSupported::new(__METHOD__); } /** @@ -2861,7 +2864,7 @@ public function getSetTransactionIsolationSQL($level) */ public function getDateTimeTypeDeclarationSQL(array $fieldDeclaration) { - throw DBALException::notSupported(__METHOD__); + throw NotSupported::new(__METHOD__); } /** @@ -2888,7 +2891,7 @@ public function getDateTimeTzTypeDeclarationSQL(array $fieldDeclaration) */ public function getDateTypeDeclarationSQL(array $fieldDeclaration) { - throw DBALException::notSupported(__METHOD__); + throw NotSupported::new(__METHOD__); } /** @@ -2903,7 +2906,7 @@ public function getDateTypeDeclarationSQL(array $fieldDeclaration) */ public function getTimeTypeDeclarationSQL(array $fieldDeclaration) { - throw DBALException::notSupported(__METHOD__); + throw NotSupported::new(__METHOD__); } /** @@ -3001,7 +3004,7 @@ public function getSequencePrefix($tableName, $schemaName = null) */ public function getIdentitySequenceName($tableName, $columnName) { - throw DBALException::notSupported(__METHOD__); + throw NotSupported::new(__METHOD__); } /** @@ -3135,7 +3138,7 @@ public function canEmulateSchemas() */ public function getDefaultSchemaName() { - throw DBALException::notSupported(__METHOD__); + throw NotSupported::new(__METHOD__); } /** @@ -3451,7 +3454,7 @@ final public function getReservedKeywordsList() $class = $this->getReservedKeywordsClass(); $keywords = new $class(); if (! $keywords instanceof KeywordList) { - throw DBALException::notSupported(__METHOD__); + throw NotSupported::new(__METHOD__); } // Store the instance so it doesn't need to be generated on every request. @@ -3469,7 +3472,7 @@ final public function getReservedKeywordsList() */ protected function getReservedKeywordsClass() { - throw DBALException::notSupported(__METHOD__); + throw NotSupported::new(__METHOD__); } /** diff --git a/lib/Doctrine/DBAL/Platforms/DB2Platform.php b/lib/Doctrine/DBAL/Platforms/DB2Platform.php index b0ff5ab15ce..2bdd3d2737a 100644 --- a/lib/Doctrine/DBAL/Platforms/DB2Platform.php +++ b/lib/Doctrine/DBAL/Platforms/DB2Platform.php @@ -4,7 +4,7 @@ namespace Doctrine\DBAL\Platforms; -use Doctrine\DBAL\DBALException; +use Doctrine\DBAL\Platforms\Exception\NotSupported; use Doctrine\DBAL\Schema\ColumnDiff; use Doctrine\DBAL\Schema\Identifier; use Doctrine\DBAL\Schema\Index; @@ -483,7 +483,7 @@ public function getCurrentTimestampSQL() public function getIndexDeclarationSQL($name, Index $index) { // Index declaration in statements like CREATE TABLE is not supported. - throw DBALException::notSupported(__METHOD__); + throw NotSupported::new(__METHOD__); } /** diff --git a/lib/Doctrine/DBAL/Platforms/Exception/InvalidPlatformVersion.php b/lib/Doctrine/DBAL/Platforms/Exception/InvalidPlatformVersion.php new file mode 100644 index 00000000000..34874301301 --- /dev/null +++ b/lib/Doctrine/DBAL/Platforms/Exception/InvalidPlatformVersion.php @@ -0,0 +1,28 @@ +sqlParts['join'] as $fromAlias => $joins) { if (! isset($knownAliases[$fromAlias])) { - throw QueryException::unknownAlias($fromAlias, array_keys($knownAliases)); + throw UnknownAlias::new($fromAlias, array_keys($knownAliases)); } } } @@ -1314,7 +1316,7 @@ private function getSQLForJoins($fromAlias, array &$knownAliases) if (isset($this->sqlParts['join'][$fromAlias])) { foreach ($this->sqlParts['join'][$fromAlias] as $join) { if (array_key_exists($join['joinAlias'], $knownAliases)) { - throw QueryException::nonUniqueAlias($join['joinAlias'], array_keys($knownAliases)); + throw NonUniqueAlias::new($join['joinAlias'], array_keys($knownAliases)); } $sql .= ' ' . strtoupper($join['joinType']) . ' JOIN ' . $join['joinTable'] . ' ' . $join['joinAlias'] diff --git a/lib/Doctrine/DBAL/Query/QueryException.php b/lib/Doctrine/DBAL/Query/QueryException.php index b692557051d..de28829f8e5 100644 --- a/lib/Doctrine/DBAL/Query/QueryException.php +++ b/lib/Doctrine/DBAL/Query/QueryException.php @@ -5,33 +5,7 @@ namespace Doctrine\DBAL\Query; use Doctrine\DBAL\DBALException; -use function implode; class QueryException extends DBALException { - /** - * @param string $alias - * @param string[] $registeredAliases - * - * @return \Doctrine\DBAL\Query\QueryException - */ - public static function unknownAlias($alias, $registeredAliases) - { - return new self("The given alias '" . $alias . "' is not part of " . - 'any FROM or JOIN clause table. The currently registered ' . - 'aliases are: ' . implode(', ', $registeredAliases) . '.'); - } - - /** - * @param string $alias - * @param string[] $registeredAliases - * - * @return \Doctrine\DBAL\Query\QueryException - */ - public static function nonUniqueAlias($alias, $registeredAliases) - { - return new self("The given alias '" . $alias . "' is not unique " . - 'in FROM and JOIN clause table. The currently registered ' . - 'aliases are: ' . implode(', ', $registeredAliases) . '.'); - } } diff --git a/lib/Doctrine/DBAL/SQLParserUtils.php b/lib/Doctrine/DBAL/SQLParserUtils.php index 279dded3799..3c5d92b8a2f 100644 --- a/lib/Doctrine/DBAL/SQLParserUtils.php +++ b/lib/Doctrine/DBAL/SQLParserUtils.php @@ -4,6 +4,8 @@ namespace Doctrine\DBAL; +use Doctrine\DBAL\Exception\MissingSQLParam; +use Doctrine\DBAL\Exception\MissingSQLType; use const PREG_OFFSET_CAPTURE; use function array_fill; use function array_key_exists; @@ -285,9 +287,9 @@ private static function extractParam($paramName, $paramsOrTypes, $isParam, $defa } if ($isParam) { - throw SQLParserUtilsException::missingParam($paramName); + throw MissingSQLParam::new($paramName); } - throw SQLParserUtilsException::missingType($paramName); + throw MissingSQLType::new($paramName); } } diff --git a/lib/Doctrine/DBAL/SQLParserUtilsException.php b/lib/Doctrine/DBAL/SQLParserUtilsException.php index e2d8bbac65d..afb27530488 100644 --- a/lib/Doctrine/DBAL/SQLParserUtilsException.php +++ b/lib/Doctrine/DBAL/SQLParserUtilsException.php @@ -4,30 +4,9 @@ namespace Doctrine\DBAL; -use function sprintf; - /** * Doctrine\DBAL\ConnectionException */ class SQLParserUtilsException extends DBALException { - /** - * @param string $paramName - * - * @return \Doctrine\DBAL\SQLParserUtilsException - */ - public static function missingParam($paramName) - { - return new self(sprintf('Value for :%1$s not found in params array. Params array key should be "%1$s"', $paramName)); - } - - /** - * @param string $typeName - * - * @return \Doctrine\DBAL\SQLParserUtilsException - */ - public static function missingType($typeName) - { - return new self(sprintf('Value for :%1$s not found in types array. Types array key should be "%1$s"', $typeName)); - } } diff --git a/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php b/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php index d3e38a3d161..69af7a5eadc 100644 --- a/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php @@ -11,6 +11,7 @@ use Doctrine\DBAL\Event\SchemaIndexDefinitionEventArgs; use Doctrine\DBAL\Events; use Doctrine\DBAL\Platforms\AbstractPlatform; +use Doctrine\DBAL\Platforms\Exception\NotSupported; use Throwable; use function array_filter; use function array_intersect; @@ -773,7 +774,7 @@ protected function _getPortableSequencesList($sequences) */ protected function _getPortableSequenceDefinition($sequence) { - throw DBALException::notSupported('Sequences'); + throw NotSupported::new('Sequences'); } /** diff --git a/lib/Doctrine/DBAL/Schema/Exception/ColumnAlreadyExists.php b/lib/Doctrine/DBAL/Schema/Exception/ColumnAlreadyExists.php new file mode 100644 index 00000000000..6205bd3120d --- /dev/null +++ b/lib/Doctrine/DBAL/Schema/Exception/ColumnAlreadyExists.php @@ -0,0 +1,19 @@ +getName(), + implode(', ', $foreignKey->getColumns()), + $foreignKey->getForeignTableName(), + implode(', ', $foreignKey->getForeignColumns()) + ) + ); + } +} diff --git a/lib/Doctrine/DBAL/Schema/Exception/NamespaceAlreadyExists.php b/lib/Doctrine/DBAL/Schema/Exception/NamespaceAlreadyExists.php new file mode 100644 index 00000000000..641d82e8222 --- /dev/null +++ b/lib/Doctrine/DBAL/Schema/Exception/NamespaceAlreadyExists.php @@ -0,0 +1,19 @@ +getFullQualifiedName($this->getName()); if (isset($this->_tables[$tableName])) { - throw SchemaException::tableAlreadyExists($tableName); + throw TableAlreadyExists::new($tableName); } if ($namespaceName !== null @@ -128,7 +133,7 @@ protected function _addSequence(Sequence $sequence) $seqName = $sequence->getFullQualifiedName($this->getName()); if (isset($this->_sequences[$seqName])) { - throw SchemaException::sequenceAlreadyExists($seqName); + throw SequenceAlreadyExists::new($seqName); } if ($namespaceName !== null @@ -171,7 +176,7 @@ public function getTable($tableName) { $tableName = $this->getFullQualifiedAssetName($tableName); if (! isset($this->_tables[$tableName])) { - throw SchemaException::tableDoesNotExist($tableName); + throw TableDoesNotExist::new($tableName); } return $this->_tables[$tableName]; @@ -270,7 +275,7 @@ public function getSequence($sequenceName) { $sequenceName = $this->getFullQualifiedAssetName($sequenceName); if (! $this->hasSequence($sequenceName)) { - throw SchemaException::sequenceDoesNotExist($sequenceName); + throw SequenceDoesNotExist::new($sequenceName); } return $this->_sequences[$sequenceName]; @@ -298,7 +303,7 @@ public function createNamespace($namespaceName) $unquotedNamespaceName = strtolower($this->getUnquotedAssetName($namespaceName)); if (isset($this->namespaces[$unquotedNamespaceName])) { - throw SchemaException::namespaceAlreadyExists($unquotedNamespaceName); + throw NamespaceAlreadyExists::new($unquotedNamespaceName); } $this->namespaces[$unquotedNamespaceName] = $namespaceName; diff --git a/lib/Doctrine/DBAL/Schema/SchemaException.php b/lib/Doctrine/DBAL/Schema/SchemaException.php index 1271e9db0a6..84101b2f071 100644 --- a/lib/Doctrine/DBAL/Schema/SchemaException.php +++ b/lib/Doctrine/DBAL/Schema/SchemaException.php @@ -5,8 +5,6 @@ namespace Doctrine\DBAL\Schema; use Doctrine\DBAL\DBALException; -use function implode; -use function sprintf; class SchemaException extends DBALException { @@ -22,180 +20,4 @@ class SchemaException extends DBALException public const FOREIGNKEY_DOESNT_EXIST = 100; public const CONSTRAINT_DOESNT_EXIST = 110; public const NAMESPACE_ALREADY_EXISTS = 120; - - /** - * @param string $tableName - * - * @return \Doctrine\DBAL\Schema\SchemaException - */ - public static function tableDoesNotExist($tableName) - { - return new self("There is no table with name '" . $tableName . "' in the schema.", self::TABLE_DOESNT_EXIST); - } - - /** - * @param string $indexName - * - * @return \Doctrine\DBAL\Schema\SchemaException - */ - public static function indexNameInvalid($indexName) - { - return new self( - sprintf('Invalid index-name %s given, has to be [a-zA-Z0-9_]', $indexName), - self::INDEX_INVALID_NAME - ); - } - - /** - * @param string $indexName - * @param string $table - * - * @return \Doctrine\DBAL\Schema\SchemaException - */ - public static function indexDoesNotExist($indexName, $table) - { - return new self( - sprintf("Index '%s' does not exist on table '%s'.", $indexName, $table), - self::INDEX_DOESNT_EXIST - ); - } - - /** - * @param string $indexName - * @param string $table - * - * @return \Doctrine\DBAL\Schema\SchemaException - */ - public static function indexAlreadyExists($indexName, $table) - { - return new self( - sprintf("An index with name '%s' was already defined on table '%s'.", $indexName, $table), - self::INDEX_ALREADY_EXISTS - ); - } - - /** - * @param string $columnName - * @param string $table - * - * @return \Doctrine\DBAL\Schema\SchemaException - */ - public static function columnDoesNotExist($columnName, $table) - { - return new self( - sprintf("There is no column with name '%s' on table '%s'.", $columnName, $table), - self::COLUMN_DOESNT_EXIST - ); - } - - /** - * @param string $namespaceName - * - * @return \Doctrine\DBAL\Schema\SchemaException - */ - public static function namespaceAlreadyExists($namespaceName) - { - return new self( - sprintf("The namespace with name '%s' already exists.", $namespaceName), - self::NAMESPACE_ALREADY_EXISTS - ); - } - - /** - * @param string $tableName - * - * @return \Doctrine\DBAL\Schema\SchemaException - */ - public static function tableAlreadyExists($tableName) - { - return new self("The table with name '" . $tableName . "' already exists.", self::TABLE_ALREADY_EXISTS); - } - - /** - * @param string $tableName - * @param string $columnName - * - * @return \Doctrine\DBAL\Schema\SchemaException - */ - public static function columnAlreadyExists($tableName, $columnName) - { - return new self( - "The column '" . $columnName . "' on table '" . $tableName . "' already exists.", - self::COLUMN_ALREADY_EXISTS - ); - } - - /** - * @param string $sequenceName - * - * @return \Doctrine\DBAL\Schema\SchemaException - */ - public static function sequenceAlreadyExists($sequenceName) - { - return new self("The sequence '" . $sequenceName . "' already exists.", self::SEQUENCE_ALREADY_EXISTS); - } - - /** - * @param string $sequenceName - * - * @return \Doctrine\DBAL\Schema\SchemaException - */ - public static function sequenceDoesNotExist($sequenceName) - { - return new self("There exists no sequence with the name '" . $sequenceName . "'.", self::SEQUENCE_DOENST_EXIST); - } - - /** - * @param string $constraintName - * @param string $table - * - * @return self - */ - public static function uniqueConstraintDoesNotExist($constraintName, $table) - { - return new self(sprintf( - 'There exists no unique constraint with the name "%s" on table "%s".', - $constraintName, - $table - ), self::CONSTRAINT_DOESNT_EXIST); - } - - /** - * @param string $fkName - * @param string $table - * - * @return \Doctrine\DBAL\Schema\SchemaException - */ - public static function foreignKeyDoesNotExist($fkName, $table) - { - return new self( - sprintf("There exists no foreign key with the name '%s' on table '%s'.", $fkName, $table), - self::FOREIGNKEY_DOESNT_EXIST - ); - } - - /** - * @return \Doctrine\DBAL\Schema\SchemaException - */ - public static function namedForeignKeyRequired(Table $localTable, ForeignKeyConstraint $foreignKey) - { - return new self( - 'The performed schema operation on ' . $localTable->getName() . ' requires a named foreign key, ' . - 'but the given foreign key from (' . implode(', ', $foreignKey->getColumns()) . ') onto foreign table ' . - "'" . $foreignKey->getForeignTableName() . "' (" . implode(', ', $foreignKey->getForeignColumns()) . ') is currently ' . - 'unnamed.' - ); - } - - /** - * @param string $changeName - * - * @return \Doctrine\DBAL\Schema\SchemaException - */ - public static function alterTableChangeNotSupported($changeName) - { - return new self( - sprintf("Alter table change not supported, given '%s'", $changeName) - ); - } } diff --git a/lib/Doctrine/DBAL/Schema/Table.php b/lib/Doctrine/DBAL/Schema/Table.php index a3e0d8b3dc3..4983d3effb2 100644 --- a/lib/Doctrine/DBAL/Schema/Table.php +++ b/lib/Doctrine/DBAL/Schema/Table.php @@ -5,6 +5,14 @@ namespace Doctrine\DBAL\Schema; use Doctrine\DBAL\DBALException; +use Doctrine\DBAL\Schema\Exception\ColumnAlreadyExists; +use Doctrine\DBAL\Schema\Exception\ColumnDoesNotExist; +use Doctrine\DBAL\Schema\Exception\ForeignKeyDoesNotExist; +use Doctrine\DBAL\Schema\Exception\IndexAlreadyExists; +use Doctrine\DBAL\Schema\Exception\IndexDoesNotExist; +use Doctrine\DBAL\Schema\Exception\IndexNameInvalid; +use Doctrine\DBAL\Schema\Exception\InvalidTableName; +use Doctrine\DBAL\Schema\Exception\UniqueConstraintDoesNotExist; use Doctrine\DBAL\Schema\Visitor\Visitor; use Doctrine\DBAL\Types\Type; use function array_keys; @@ -66,7 +74,7 @@ public function __construct( array $options = [] ) { if (strlen($tableName) === 0) { - throw DBALException::invalidTableName($tableName); + throw InvalidTableName::new($tableName); } $this->_setName($tableName); @@ -185,7 +193,7 @@ public function dropIndex($indexName) $indexName = $this->normalizeIdentifier($indexName); if (! $this->hasIndex($indexName)) { - throw SchemaException::indexDoesNotExist($indexName, $this->_name); + throw IndexDoesNotExist::new($indexName, $this->_name); } unset($this->_indexes[$indexName]); @@ -233,11 +241,11 @@ public function renameIndex($oldIndexName, $newIndexName = null) } if (! $this->hasIndex($oldIndexName)) { - throw SchemaException::indexDoesNotExist($oldIndexName, $this->_name); + throw IndexDoesNotExist::new($oldIndexName, $this->_name); } if ($this->hasIndex($normalizedNewIndexName)) { - throw SchemaException::indexAlreadyExists($normalizedNewIndexName, $this->_name); + throw IndexAlreadyExists::new($normalizedNewIndexName, $this->_name); } $oldIndex = $this->_indexes[$oldIndexName]; @@ -409,14 +417,14 @@ public function addNamedForeignKeyConstraint($name, $foreignTable, array $localC if ($foreignTable instanceof Table) { foreach ($foreignColumnNames as $columnName) { if (! $foreignTable->hasColumn($columnName)) { - throw SchemaException::columnDoesNotExist($columnName, $foreignTable->getName()); + throw ColumnDoesNotExist::new($columnName, $foreignTable->getName()); } } } foreach ($localColumnNames as $columnName) { if (! $this->hasColumn($columnName)) { - throw SchemaException::columnDoesNotExist($columnName, $this->_name); + throw ColumnDoesNotExist::new($columnName, $this->_name); } } @@ -472,7 +480,7 @@ public function getForeignKey($constraintName) $constraintName = $this->normalizeIdentifier($constraintName); if (! $this->hasForeignKey($constraintName)) { - throw SchemaException::foreignKeyDoesNotExist($constraintName, $this->_name); + throw ForeignKeyDoesNotExist::new($constraintName, $this->_name); } return $this->_fkConstraints[$constraintName]; @@ -492,7 +500,7 @@ public function removeForeignKey($constraintName) $constraintName = $this->normalizeIdentifier($constraintName); if (! $this->hasForeignKey($constraintName)) { - throw SchemaException::foreignKeyDoesNotExist($constraintName, $this->_name); + throw ForeignKeyDoesNotExist::new($constraintName, $this->_name); } unset($this->_fkConstraints[$constraintName]); @@ -526,7 +534,7 @@ public function getUniqueConstraint($constraintName) $constraintName = $this->normalizeIdentifier($constraintName); if (! $this->hasUniqueConstraint($constraintName)) { - throw SchemaException::uniqueConstraintDoesNotExist($constraintName, $this->_name); + throw UniqueConstraintDoesNotExist::new($constraintName, $this->_name); } return $this->_uniqueConstraints[$constraintName]; @@ -546,7 +554,7 @@ public function removeUniqueConstraint($constraintName) $constraintName = $this->normalizeIdentifier($constraintName); if (! $this->hasUniqueConstraint($constraintName)) { - throw SchemaException::uniqueConstraintDoesNotExist($constraintName, $this->_name); + throw UniqueConstraintDoesNotExist::new($constraintName, $this->_name); } unset($this->_uniqueConstraints[$constraintName]); @@ -611,7 +619,7 @@ public function getColumn($columnName) $columnName = $this->normalizeIdentifier($columnName); if (! $this->hasColumn($columnName)) { - throw SchemaException::columnDoesNotExist($columnName, $this->_name); + throw ColumnDoesNotExist::new($columnName, $this->_name); } return $this->_columns[$columnName]; @@ -685,7 +693,7 @@ public function getIndex($indexName) $indexName = $this->normalizeIdentifier($indexName); if (! $this->hasIndex($indexName)) { - throw SchemaException::indexDoesNotExist($indexName, $this->_name); + throw IndexDoesNotExist::new($indexName, $this->_name); } return $this->_indexes[$indexName]; @@ -809,7 +817,7 @@ protected function _addColumn(Column $column) $columnName = $this->normalizeIdentifier($columnName); if (isset($this->_columns[$columnName])) { - throw SchemaException::columnAlreadyExists($this->getName(), $columnName); + throw ColumnAlreadyExists::new($this->getName(), $columnName); } $this->_columns[$columnName] = $column; @@ -839,7 +847,7 @@ protected function _addIndex(Index $indexCandidate) if ((isset($this->_indexes[$indexName]) && ! in_array($indexName, $replacedImplicitIndexes, true)) || ($this->_primaryKeyName !== false && $indexCandidate->isPrimary()) ) { - throw SchemaException::indexAlreadyExists($indexName, $this->_name); + throw IndexAlreadyExists::new($indexName, $this->_name); } foreach ($replacedImplicitIndexes as $name) { @@ -968,7 +976,7 @@ private function normalizeIdentifier($identifier) private function _createUniqueConstraint(array $columns, $indexName, array $flags = [], array $options = []) { if (preg_match('(([^a-zA-Z0-9_]+))', $this->normalizeIdentifier($indexName))) { - throw SchemaException::indexNameInvalid($indexName); + throw IndexNameInvalid::new($indexName); } foreach ($columns as $index => $value) { @@ -979,7 +987,7 @@ private function _createUniqueConstraint(array $columns, $indexName, array $flag } if (! $this->hasColumn($columnName)) { - throw SchemaException::columnDoesNotExist($columnName, $this->_name); + throw ColumnDoesNotExist::new($columnName, $this->_name); } } @@ -1001,7 +1009,7 @@ private function _createUniqueConstraint(array $columns, $indexName, array $flag private function _createIndex(array $columns, $indexName, $isUnique, $isPrimary, array $flags = [], array $options = []) { if (preg_match('(([^a-zA-Z0-9_]+))', $this->normalizeIdentifier($indexName))) { - throw SchemaException::indexNameInvalid($indexName); + throw IndexNameInvalid::new($indexName); } foreach ($columns as $index => $value) { @@ -1012,7 +1020,7 @@ private function _createIndex(array $columns, $indexName, $isUnique, $isPrimary, } if (! $this->hasColumn($columnName)) { - throw SchemaException::columnDoesNotExist($columnName, $this->_name); + throw ColumnDoesNotExist::new($columnName, $this->_name); } } diff --git a/lib/Doctrine/DBAL/Schema/Visitor/DropSchemaSqlCollector.php b/lib/Doctrine/DBAL/Schema/Visitor/DropSchemaSqlCollector.php index 6e6b1e62f2e..59d8e04a851 100644 --- a/lib/Doctrine/DBAL/Schema/Visitor/DropSchemaSqlCollector.php +++ b/lib/Doctrine/DBAL/Schema/Visitor/DropSchemaSqlCollector.php @@ -5,8 +5,8 @@ namespace Doctrine\DBAL\Schema\Visitor; use Doctrine\DBAL\Platforms\AbstractPlatform; +use Doctrine\DBAL\Schema\Exception\NamedForeignKeyRequired; use Doctrine\DBAL\Schema\ForeignKeyConstraint; -use Doctrine\DBAL\Schema\SchemaException; use Doctrine\DBAL\Schema\Sequence; use Doctrine\DBAL\Schema\Table; use SplObjectStorage; @@ -49,7 +49,7 @@ public function acceptTable(Table $table) public function acceptForeignKey(Table $localTable, ForeignKeyConstraint $fkConstraint) { if (strlen($fkConstraint->getName()) === 0) { - throw SchemaException::namedForeignKeyRequired($localTable, $fkConstraint); + throw NamedForeignKeyRequired::new($localTable, $fkConstraint); } $this->constraints->attach($fkConstraint, $localTable); diff --git a/lib/Doctrine/DBAL/Sharding/Exception/ActiveTransaction.php b/lib/Doctrine/DBAL/Sharding/Exception/ActiveTransaction.php new file mode 100644 index 00000000000..3f21667986d --- /dev/null +++ b/lib/Doctrine/DBAL/Sharding/Exception/ActiveTransaction.php @@ -0,0 +1,15 @@ +getParams(); if (! isset($params['sharding']['federationName'])) { - throw ShardingException::missingDefaultFederationName(); + throw MissingDefaultFederationName::new(); } if (! isset($params['sharding']['distributionKey'])) { - throw ShardingException::missingDefaultDistributionKey(); + throw MissingDefaultDistributionKey::new(); } if (! isset($params['sharding']['distributionType'])) { - throw ShardingException::missingDistributionType(); + throw MissingDistributionType::new(); } $this->federationName = $params['sharding']['federationName']; @@ -108,7 +112,7 @@ public function setFilteringEnabled($flag) public function selectGlobal() { if ($this->conn->isTransactionActive()) { - throw ShardingException::activeTransaction(); + throw ActiveTransaction::new(); } $sql = 'USE FEDERATION ROOT WITH RESET'; @@ -122,7 +126,7 @@ public function selectGlobal() public function selectShard($distributionValue) { if ($this->conn->isTransactionActive()) { - throw ShardingException::activeTransaction(); + throw ActiveTransaction::new(); } $platform = $this->conn->getDatabasePlatform(); diff --git a/lib/Doctrine/DBAL/Sharding/ShardingException.php b/lib/Doctrine/DBAL/Sharding/ShardingException.php index 3e6c91c3844..cbf7a76bf79 100644 --- a/lib/Doctrine/DBAL/Sharding/ShardingException.php +++ b/lib/Doctrine/DBAL/Sharding/ShardingException.php @@ -11,51 +11,4 @@ */ class ShardingException extends DBALException { - /** - * @return \Doctrine\DBAL\Sharding\ShardingException - */ - public static function notImplemented() - { - return new self('This functionality is not implemented with this sharding provider.', 1331557937); - } - - /** - * @return \Doctrine\DBAL\Sharding\ShardingException - */ - public static function missingDefaultFederationName() - { - return new self('SQLAzure requires a federation name to be set during sharding configuration.', 1332141280); - } - - /** - * @return \Doctrine\DBAL\Sharding\ShardingException - */ - public static function missingDefaultDistributionKey() - { - return new self('SQLAzure requires a distribution key to be set during sharding configuration.', 1332141329); - } - - /** - * @return \Doctrine\DBAL\Sharding\ShardingException - */ - public static function activeTransaction() - { - return new self('Cannot switch shard during an active transaction.', 1332141766); - } - - /** - * @return \Doctrine\DBAL\Sharding\ShardingException - */ - public static function noShardDistributionValue() - { - return new self('You have to specify a string or integer as shard distribution value.', 1332142103); - } - - /** - * @return \Doctrine\DBAL\Sharding\ShardingException - */ - public static function missingDistributionType() - { - return new self("You have to specify a sharding distribution type such as 'integer', 'string', 'guid'."); - } } diff --git a/lib/Doctrine/DBAL/Types/ArrayType.php b/lib/Doctrine/DBAL/Types/ArrayType.php index 8b4f2e7d044..39b4ae51a5e 100644 --- a/lib/Doctrine/DBAL/Types/ArrayType.php +++ b/lib/Doctrine/DBAL/Types/ArrayType.php @@ -5,6 +5,7 @@ namespace Doctrine\DBAL\Types; use Doctrine\DBAL\Platforms\AbstractPlatform; +use Doctrine\DBAL\Types\Exception\ValueNotConvertible; use function is_resource; use function restore_error_handler; use function serialize; @@ -45,8 +46,8 @@ public function convertToPHPValue($value, AbstractPlatform $platform) $value = is_resource($value) ? stream_get_contents($value) : $value; - set_error_handler(function (int $code, string $message) : void { - throw ConversionException::conversionFailedUnserialization($this->getName(), $message); + set_error_handler(function (int $code, string $message) use ($value) : void { + throw ValueNotConvertible::new($value, $this->getName(), $message); }); try { diff --git a/lib/Doctrine/DBAL/Types/BinaryType.php b/lib/Doctrine/DBAL/Types/BinaryType.php index b4a50d104af..5dbd3bafc60 100644 --- a/lib/Doctrine/DBAL/Types/BinaryType.php +++ b/lib/Doctrine/DBAL/Types/BinaryType.php @@ -6,6 +6,7 @@ use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Platforms\AbstractPlatform; +use Doctrine\DBAL\Types\Exception\ValueNotConvertible; use function is_resource; use function is_string; use function stream_get_contents; @@ -37,7 +38,7 @@ public function convertToPHPValue($value, AbstractPlatform $platform) } if (! is_string($value)) { - throw ConversionException::conversionFailed($value, Types::BINARY); + throw ValueNotConvertible::new($value, self::BINARY); } return $value; diff --git a/lib/Doctrine/DBAL/Types/BlobType.php b/lib/Doctrine/DBAL/Types/BlobType.php index cfb5c292897..00e19ad08e9 100644 --- a/lib/Doctrine/DBAL/Types/BlobType.php +++ b/lib/Doctrine/DBAL/Types/BlobType.php @@ -6,6 +6,7 @@ use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Platforms\AbstractPlatform; +use Doctrine\DBAL\Types\Exception\ValueNotConvertible; use function assert; use function fopen; use function fseek; @@ -44,7 +45,7 @@ public function convertToPHPValue($value, AbstractPlatform $platform) } if (! is_resource($value)) { - throw ConversionException::conversionFailed($value, Types::BLOB); + throw ValueNotConvertible::new($value, self::BLOB); } return $value; diff --git a/lib/Doctrine/DBAL/Types/ConversionException.php b/lib/Doctrine/DBAL/Types/ConversionException.php index 325c8c2d3f8..aa588102cbd 100644 --- a/lib/Doctrine/DBAL/Types/ConversionException.php +++ b/lib/Doctrine/DBAL/Types/ConversionException.php @@ -5,108 +5,10 @@ namespace Doctrine\DBAL\Types; use Doctrine\DBAL\DBALException; -use Throwable; -use function get_class; -use function gettype; -use function implode; -use function is_object; -use function is_scalar; -use function is_string; -use function sprintf; -use function strlen; -use function substr; /** * Conversion Exception is thrown when the database to PHP conversion fails. */ class ConversionException extends DBALException { - /** - * Thrown when a Database to Doctrine Type Conversion fails. - * - * @param mixed $value - * @param string $toType - * - * @return \Doctrine\DBAL\Types\ConversionException - */ - public static function conversionFailed($value, $toType) - { - $value = is_string($value) && strlen($value) > 32 ? substr($value, 0, 20) . '...' : $value; - - return new self('Could not convert database value "' . $value . '" to Doctrine Type ' . $toType); - } - - /** - * Thrown when a Database to Doctrine Type Conversion fails and we can make a statement - * about the expected format. - * - * @param mixed $value - * @param string $toType - * @param string $expectedFormat - * - * @return \Doctrine\DBAL\Types\ConversionException - */ - public static function conversionFailedFormat($value, $toType, $expectedFormat, ?Throwable $previous = null) - { - $value = is_string($value) && strlen($value) > 32 ? substr($value, 0, 20) . '...' : $value; - - return new self( - 'Could not convert database value "' . $value . '" to Doctrine Type ' . - $toType . '. Expected format: ' . $expectedFormat, - 0, - $previous - ); - } - - /** - * Thrown when the PHP value passed to the converter was not of the expected type. - * - * @param mixed $value - * @param string $toType - * @param string[] $possibleTypes - * - * @return \Doctrine\DBAL\Types\ConversionException - */ - public static function conversionFailedInvalidType($value, $toType, array $possibleTypes) - { - $actualType = is_object($value) ? get_class($value) : gettype($value); - - if (is_scalar($value)) { - return new self(sprintf( - "Could not convert PHP value '%s' of type '%s' to type '%s'. Expected one of the following types: %s", - $value, - $actualType, - $toType, - implode(', ', $possibleTypes) - )); - } - - return new self(sprintf( - "Could not convert PHP value of type '%s' to type '%s'. Expected one of the following types: %s", - $actualType, - $toType, - implode(', ', $possibleTypes) - )); - } - - public static function conversionFailedSerialization($value, $format, $error) - { - $actualType = is_object($value) ? get_class($value) : gettype($value); - - return new self(sprintf( - "Could not convert PHP type '%s' to '%s', as an '%s' error was triggered by the serialization", - $actualType, - $format, - $error - )); - } - - public static function conversionFailedUnserialization(string $format, string $error) : self - { - return new self(sprintf( - "Could not convert database value to '%s' as an error was triggered by the unserialization: '%s'", - $format, - $error - )); - } } diff --git a/lib/Doctrine/DBAL/Types/DateImmutableType.php b/lib/Doctrine/DBAL/Types/DateImmutableType.php index e824513a5b7..0a3e9c69853 100644 --- a/lib/Doctrine/DBAL/Types/DateImmutableType.php +++ b/lib/Doctrine/DBAL/Types/DateImmutableType.php @@ -6,6 +6,8 @@ use DateTimeImmutable; use Doctrine\DBAL\Platforms\AbstractPlatform; +use Doctrine\DBAL\Types\Exception\InvalidFormat; +use Doctrine\DBAL\Types\Exception\InvalidType; /** * Immutable type of {@see DateType}. @@ -33,7 +35,7 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform) return $value->format($platform->getDateFormatString()); } - throw ConversionException::conversionFailedInvalidType( + throw InvalidType::new( $value, $this->getName(), ['null', DateTimeImmutable::class] @@ -52,7 +54,7 @@ public function convertToPHPValue($value, AbstractPlatform $platform) $dateTime = DateTimeImmutable::createFromFormat('!' . $platform->getDateFormatString(), $value); if (! $dateTime) { - throw ConversionException::conversionFailedFormat( + throw InvalidFormat::new( $value, $this->getName(), $platform->getDateFormatString() diff --git a/lib/Doctrine/DBAL/Types/DateIntervalType.php b/lib/Doctrine/DBAL/Types/DateIntervalType.php index af9cb25ce2c..9fa5f3913a7 100644 --- a/lib/Doctrine/DBAL/Types/DateIntervalType.php +++ b/lib/Doctrine/DBAL/Types/DateIntervalType.php @@ -6,6 +6,8 @@ use DateInterval; use Doctrine\DBAL\Platforms\AbstractPlatform; +use Doctrine\DBAL\Types\Exception\InvalidFormat; +use Doctrine\DBAL\Types\Exception\InvalidType; use Throwable; use function substr; @@ -47,7 +49,7 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform) return $value->format(self::FORMAT); } - throw ConversionException::conversionFailedInvalidType($value, $this->getName(), ['null', 'DateInterval']); + throw InvalidType::new($value, $this->getName(), ['null', 'DateInterval']); } /** @@ -75,7 +77,7 @@ public function convertToPHPValue($value, AbstractPlatform $platform) return $interval; } catch (Throwable $exception) { - throw ConversionException::conversionFailedFormat($value, $this->getName(), self::FORMAT, $exception); + throw InvalidFormat::new($value, $this->getName(), self::FORMAT, $exception); } } diff --git a/lib/Doctrine/DBAL/Types/DateTimeImmutableType.php b/lib/Doctrine/DBAL/Types/DateTimeImmutableType.php index 4ed1a32cf77..95c8fb0595b 100644 --- a/lib/Doctrine/DBAL/Types/DateTimeImmutableType.php +++ b/lib/Doctrine/DBAL/Types/DateTimeImmutableType.php @@ -6,6 +6,8 @@ use DateTimeImmutable; use Doctrine\DBAL\Platforms\AbstractPlatform; +use Doctrine\DBAL\Types\Exception\InvalidFormat; +use Doctrine\DBAL\Types\Exception\InvalidType; use function date_create_immutable; /** @@ -34,7 +36,7 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform) return $value->format($platform->getDateTimeFormatString()); } - throw ConversionException::conversionFailedInvalidType( + throw InvalidType::new( $value, $this->getName(), ['null', DateTimeImmutable::class] @@ -57,7 +59,7 @@ public function convertToPHPValue($value, AbstractPlatform $platform) } if (! $dateTime) { - throw ConversionException::conversionFailedFormat( + throw InvalidFormat::new( $value, $this->getName(), $platform->getDateTimeFormatString() diff --git a/lib/Doctrine/DBAL/Types/DateTimeType.php b/lib/Doctrine/DBAL/Types/DateTimeType.php index 4d0d26095ff..271ee43d78b 100644 --- a/lib/Doctrine/DBAL/Types/DateTimeType.php +++ b/lib/Doctrine/DBAL/Types/DateTimeType.php @@ -7,6 +7,8 @@ use DateTime; use DateTimeInterface; use Doctrine\DBAL\Platforms\AbstractPlatform; +use Doctrine\DBAL\Types\Exception\InvalidFormat; +use Doctrine\DBAL\Types\Exception\InvalidType; use function date_create; /** @@ -43,7 +45,7 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform) return $value->format($platform->getDateTimeFormatString()); } - throw ConversionException::conversionFailedInvalidType($value, $this->getName(), ['null', 'DateTime']); + throw InvalidType::new($value, $this->getName(), ['null', 'DateTime']); } /** @@ -62,7 +64,7 @@ public function convertToPHPValue($value, AbstractPlatform $platform) } if (! $val) { - throw ConversionException::conversionFailedFormat($value, $this->getName(), $platform->getDateTimeFormatString()); + throw InvalidFormat::new($value, $this->getName(), $platform->getDateTimeFormatString()); } return $val; diff --git a/lib/Doctrine/DBAL/Types/DateTimeTzImmutableType.php b/lib/Doctrine/DBAL/Types/DateTimeTzImmutableType.php index 7320faf7e73..98941d1f9fd 100644 --- a/lib/Doctrine/DBAL/Types/DateTimeTzImmutableType.php +++ b/lib/Doctrine/DBAL/Types/DateTimeTzImmutableType.php @@ -6,6 +6,8 @@ use DateTimeImmutable; use Doctrine\DBAL\Platforms\AbstractPlatform; +use Doctrine\DBAL\Types\Exception\InvalidFormat; +use Doctrine\DBAL\Types\Exception\InvalidType; /** * Immutable type of {@see DateTimeTzType}. @@ -33,7 +35,7 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform) return $value->format($platform->getDateTimeTzFormatString()); } - throw ConversionException::conversionFailedInvalidType( + throw InvalidType::new( $value, $this->getName(), ['null', DateTimeImmutable::class] @@ -52,7 +54,7 @@ public function convertToPHPValue($value, AbstractPlatform $platform) $dateTime = DateTimeImmutable::createFromFormat($platform->getDateTimeTzFormatString(), $value); if (! $dateTime) { - throw ConversionException::conversionFailedFormat( + throw InvalidFormat::new( $value, $this->getName(), $platform->getDateTimeTzFormatString() diff --git a/lib/Doctrine/DBAL/Types/DateTimeTzType.php b/lib/Doctrine/DBAL/Types/DateTimeTzType.php index 5f0785cb878..da07628572f 100644 --- a/lib/Doctrine/DBAL/Types/DateTimeTzType.php +++ b/lib/Doctrine/DBAL/Types/DateTimeTzType.php @@ -7,6 +7,8 @@ use DateTime; use DateTimeInterface; use Doctrine\DBAL\Platforms\AbstractPlatform; +use Doctrine\DBAL\Types\Exception\InvalidFormat; +use Doctrine\DBAL\Types\Exception\InvalidType; /** * DateTime type saving additional timezone information. @@ -55,7 +57,7 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform) return $value->format($platform->getDateTimeTzFormatString()); } - throw ConversionException::conversionFailedInvalidType($value, $this->getName(), ['null', 'DateTime']); + throw InvalidType::new($value, $this->getName(), ['null', 'DateTime']); } /** @@ -69,7 +71,7 @@ public function convertToPHPValue($value, AbstractPlatform $platform) $val = DateTime::createFromFormat($platform->getDateTimeTzFormatString(), $value); if (! $val) { - throw ConversionException::conversionFailedFormat($value, $this->getName(), $platform->getDateTimeTzFormatString()); + throw InvalidFormat::new($value, $this->getName(), $platform->getDateTimeTzFormatString()); } return $val; diff --git a/lib/Doctrine/DBAL/Types/DateType.php b/lib/Doctrine/DBAL/Types/DateType.php index b449fc9540f..a91249833bb 100644 --- a/lib/Doctrine/DBAL/Types/DateType.php +++ b/lib/Doctrine/DBAL/Types/DateType.php @@ -7,6 +7,8 @@ use DateTime; use DateTimeInterface; use Doctrine\DBAL\Platforms\AbstractPlatform; +use Doctrine\DBAL\Types\Exception\InvalidFormat; +use Doctrine\DBAL\Types\Exception\InvalidType; /** * Type that maps an SQL DATE to a PHP Date object. @@ -42,7 +44,7 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform) return $value->format($platform->getDateFormatString()); } - throw ConversionException::conversionFailedInvalidType($value, $this->getName(), ['null', 'DateTime']); + throw InvalidType::new($value, $this->getName(), ['null', 'DateTime']); } /** @@ -56,7 +58,7 @@ public function convertToPHPValue($value, AbstractPlatform $platform) $val = DateTime::createFromFormat('!' . $platform->getDateFormatString(), $value); if (! $val) { - throw ConversionException::conversionFailedFormat($value, $this->getName(), $platform->getDateFormatString()); + throw InvalidFormat::new($value, $this->getName(), $platform->getDateFormatString()); } return $val; diff --git a/lib/Doctrine/DBAL/Types/Exception/InvalidFormat.php b/lib/Doctrine/DBAL/Types/Exception/InvalidFormat.php new file mode 100644 index 00000000000..7f2a92b2657 --- /dev/null +++ b/lib/Doctrine/DBAL/Types/Exception/InvalidFormat.php @@ -0,0 +1,36 @@ + 32 ? substr($value, 0, 20) . '...' : $value, + $toType, + $expectedFormat ?? '' + ), + 0, + $previous + ); + } +} diff --git a/lib/Doctrine/DBAL/Types/Exception/InvalidType.php b/lib/Doctrine/DBAL/Types/Exception/InvalidType.php new file mode 100644 index 00000000000..4200d6c5040 --- /dev/null +++ b/lib/Doctrine/DBAL/Types/Exception/InvalidType.php @@ -0,0 +1,52 @@ + 32 ? substr($value, 0, 20) . '...' : $value, + $toType + ) + ); + } +} diff --git a/lib/Doctrine/DBAL/Types/JsonType.php b/lib/Doctrine/DBAL/Types/JsonType.php index d4731129bf9..2f8da886da5 100644 --- a/lib/Doctrine/DBAL/Types/JsonType.php +++ b/lib/Doctrine/DBAL/Types/JsonType.php @@ -5,6 +5,8 @@ namespace Doctrine\DBAL\Types; use Doctrine\DBAL\Platforms\AbstractPlatform; +use Doctrine\DBAL\Types\Exception\SerializationFailed; +use Doctrine\DBAL\Types\Exception\ValueNotConvertible; use const JSON_ERROR_NONE; use function is_resource; use function json_decode; @@ -38,7 +40,7 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform) $encoded = json_encode($value); if (json_last_error() !== JSON_ERROR_NONE) { - throw ConversionException::conversionFailedSerialization($value, 'json', json_last_error_msg()); + throw SerializationFailed::new($value, 'json', json_last_error_msg()); } return $encoded; @@ -60,7 +62,7 @@ public function convertToPHPValue($value, AbstractPlatform $platform) $val = json_decode($value, true); if (json_last_error() !== JSON_ERROR_NONE) { - throw ConversionException::conversionFailed($value, $this->getName()); + throw ValueNotConvertible::new($value, $this->getName()); } return $val; diff --git a/lib/Doctrine/DBAL/Types/ObjectType.php b/lib/Doctrine/DBAL/Types/ObjectType.php index 3af15fe8f39..8b842cb5eb1 100644 --- a/lib/Doctrine/DBAL/Types/ObjectType.php +++ b/lib/Doctrine/DBAL/Types/ObjectType.php @@ -5,6 +5,7 @@ namespace Doctrine\DBAL\Types; use Doctrine\DBAL\Platforms\AbstractPlatform; +use Doctrine\DBAL\Types\Exception\ValueNotConvertible; use function is_resource; use function restore_error_handler; use function serialize; @@ -44,8 +45,8 @@ public function convertToPHPValue($value, AbstractPlatform $platform) $value = is_resource($value) ? stream_get_contents($value) : $value; - set_error_handler(function (int $code, string $message) : void { - throw ConversionException::conversionFailedUnserialization($this->getName(), $message); + set_error_handler(function (int $code, string $message) use ($value) : void { + throw ValueNotConvertible::new($value, $this->getName(), $message); }); try { diff --git a/lib/Doctrine/DBAL/Types/TimeImmutableType.php b/lib/Doctrine/DBAL/Types/TimeImmutableType.php index 96cc5a35652..010a6ba3670 100644 --- a/lib/Doctrine/DBAL/Types/TimeImmutableType.php +++ b/lib/Doctrine/DBAL/Types/TimeImmutableType.php @@ -6,6 +6,8 @@ use DateTimeImmutable; use Doctrine\DBAL\Platforms\AbstractPlatform; +use Doctrine\DBAL\Types\Exception\InvalidFormat; +use Doctrine\DBAL\Types\Exception\InvalidType; /** * Immutable type of {@see TimeType}. @@ -33,7 +35,7 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform) return $value->format($platform->getTimeFormatString()); } - throw ConversionException::conversionFailedInvalidType( + throw InvalidType::new( $value, $this->getName(), ['null', DateTimeImmutable::class] @@ -52,7 +54,7 @@ public function convertToPHPValue($value, AbstractPlatform $platform) $dateTime = DateTimeImmutable::createFromFormat('!' . $platform->getTimeFormatString(), $value); if (! $dateTime) { - throw ConversionException::conversionFailedFormat( + throw InvalidFormat::new( $value, $this->getName(), $platform->getTimeFormatString() diff --git a/lib/Doctrine/DBAL/Types/TimeType.php b/lib/Doctrine/DBAL/Types/TimeType.php index b1df33440f5..26ee7e01231 100644 --- a/lib/Doctrine/DBAL/Types/TimeType.php +++ b/lib/Doctrine/DBAL/Types/TimeType.php @@ -7,6 +7,8 @@ use DateTime; use DateTimeInterface; use Doctrine\DBAL\Platforms\AbstractPlatform; +use Doctrine\DBAL\Types\Exception\InvalidFormat; +use Doctrine\DBAL\Types\Exception\InvalidType; /** * Type that maps an SQL TIME to a PHP DateTime object. @@ -42,7 +44,7 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform) return $value->format($platform->getTimeFormatString()); } - throw ConversionException::conversionFailedInvalidType($value, $this->getName(), ['null', 'DateTime']); + throw InvalidType::new($value, $this->getName(), ['null', 'DateTime']); } /** @@ -56,7 +58,7 @@ public function convertToPHPValue($value, AbstractPlatform $platform) $val = DateTime::createFromFormat('!' . $platform->getTimeFormatString(), $value); if (! $val) { - throw ConversionException::conversionFailedFormat($value, $this->getName(), $platform->getTimeFormatString()); + throw InvalidFormat::new($value, $this->getName(), $platform->getTimeFormatString()); } return $val; diff --git a/lib/Doctrine/DBAL/Types/TypeRegistry.php b/lib/Doctrine/DBAL/Types/TypeRegistry.php index 7e8093cf749..1250bc18189 100644 --- a/lib/Doctrine/DBAL/Types/TypeRegistry.php +++ b/lib/Doctrine/DBAL/Types/TypeRegistry.php @@ -5,6 +5,11 @@ namespace Doctrine\DBAL\Types; use Doctrine\DBAL\DBALException; +use Doctrine\DBAL\Types\Exception\TypeAlreadyRegistered; +use Doctrine\DBAL\Types\Exception\TypeNotFound; +use Doctrine\DBAL\Types\Exception\TypeNotRegistered; +use Doctrine\DBAL\Types\Exception\TypesAlreadyExists; +use Doctrine\DBAL\Types\Exception\UnknownColumnType; use function array_search; use function in_array; @@ -27,7 +32,7 @@ final class TypeRegistry public function get(string $name) : Type { if (! isset($this->instances[$name])) { - throw DBALException::unknownColumnType($name); + throw UnknownColumnType::new($name); } return $this->instances[$name]; @@ -43,7 +48,7 @@ public function lookupName(Type $type) : string $name = $this->findTypeName($type); if ($name === null) { - throw DBALException::typeNotRegistered($type); + throw TypeNotRegistered::new($type); } return $name; @@ -65,11 +70,11 @@ public function has(string $name) : bool public function register(string $name, Type $type) : void { if (isset($this->instances[$name])) { - throw DBALException::typeExists($name); + throw TypesAlreadyExists::new($name); } if ($this->findTypeName($type) !== null) { - throw DBALException::typeAlreadyRegistered($type); + throw TypeAlreadyRegistered::new($type); } $this->instances[$name] = $type; @@ -83,11 +88,11 @@ public function register(string $name, Type $type) : void public function override(string $name, Type $type) : void { if (! isset($this->instances[$name])) { - throw DBALException::typeNotFound($name); + throw TypeNotFound::new($name); } if (! in_array($this->findTypeName($type), [$name, null], true)) { - throw DBALException::typeAlreadyRegistered($type); + throw TypeAlreadyRegistered::new($type); } $this->instances[$name] = $type; diff --git a/lib/Doctrine/DBAL/Types/VarDateTimeImmutableType.php b/lib/Doctrine/DBAL/Types/VarDateTimeImmutableType.php index d74dfe48721..e0f17cef3bb 100644 --- a/lib/Doctrine/DBAL/Types/VarDateTimeImmutableType.php +++ b/lib/Doctrine/DBAL/Types/VarDateTimeImmutableType.php @@ -6,6 +6,8 @@ use DateTimeImmutable; use Doctrine\DBAL\Platforms\AbstractPlatform; +use Doctrine\DBAL\Types\Exception\InvalidType; +use Doctrine\DBAL\Types\Exception\ValueNotConvertible; use function date_create_immutable; /** @@ -34,7 +36,7 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform) return $value->format($platform->getDateTimeFormatString()); } - throw ConversionException::conversionFailedInvalidType( + throw InvalidType::new( $value, $this->getName(), ['null', DateTimeImmutable::class] @@ -53,7 +55,7 @@ public function convertToPHPValue($value, AbstractPlatform $platform) $dateTime = date_create_immutable($value); if (! $dateTime) { - throw ConversionException::conversionFailed($value, $this->getName()); + throw ValueNotConvertible::new($value, $this->getName()); } return $dateTime; diff --git a/lib/Doctrine/DBAL/Types/VarDateTimeType.php b/lib/Doctrine/DBAL/Types/VarDateTimeType.php index fe431da91e8..e3ad78126fe 100644 --- a/lib/Doctrine/DBAL/Types/VarDateTimeType.php +++ b/lib/Doctrine/DBAL/Types/VarDateTimeType.php @@ -6,6 +6,7 @@ use DateTime; use Doctrine\DBAL\Platforms\AbstractPlatform; +use Doctrine\DBAL\Types\Exception\ValueNotConvertible; use function date_create; /** @@ -28,7 +29,7 @@ public function convertToPHPValue($value, AbstractPlatform $platform) $val = date_create($value); if (! $val) { - throw ConversionException::conversionFailed($value, $this->getName()); + throw ValueNotConvertible::new($value, $this->getName()); } return $val; diff --git a/tests/Doctrine/Tests/DBAL/DBALExceptionTest.php b/tests/Doctrine/Tests/DBAL/DBALExceptionTest.php index de251cdceac..22f6c30de38 100644 --- a/tests/Doctrine/Tests/DBAL/DBALExceptionTest.php +++ b/tests/Doctrine/Tests/DBAL/DBALExceptionTest.php @@ -8,6 +8,8 @@ use Doctrine\DBAL\Driver; use Doctrine\DBAL\Driver\DriverException as InnerDriverException; use Doctrine\DBAL\Exception\DriverException; +use Doctrine\DBAL\Exception\DriverRequired; +use Doctrine\DBAL\Exception\InvalidPlatformType; use Doctrine\Tests\DbalTestCase; use Exception; use stdClass; @@ -54,7 +56,7 @@ public function getSQLState() : ?string public function testDriverRequiredWithUrl() { $url = 'mysql://localhost'; - $exception = DBALException::driverRequired($url); + $exception = DriverRequired::new($url); self::assertInstanceOf(DBALException::class, $exception); self::assertSame( @@ -72,7 +74,7 @@ public function testDriverRequiredWithUrl() */ public function testInvalidPlatformTypeObject() : void { - $exception = DBALException::invalidPlatformType(new stdClass()); + $exception = InvalidPlatformType::new(new stdClass()); self::assertSame( "Option 'platform' must be a subtype of 'Doctrine\DBAL\Platforms\AbstractPlatform', instance of 'stdClass' given", @@ -85,7 +87,7 @@ public function testInvalidPlatformTypeObject() : void */ public function testInvalidPlatformTypeScalar() : void { - $exception = DBALException::invalidPlatformType('some string'); + $exception = InvalidPlatformType::new('some string'); self::assertSame( "Option 'platform' must be an object and subtype of 'Doctrine\DBAL\Platforms\AbstractPlatform'. Got 'string'", diff --git a/tests/Doctrine/Tests/DBAL/Exception/DriverRequiredTest.php b/tests/Doctrine/Tests/DBAL/Exception/DriverRequiredTest.php new file mode 100644 index 00000000000..ccde18475ea --- /dev/null +++ b/tests/Doctrine/Tests/DBAL/Exception/DriverRequiredTest.php @@ -0,0 +1,29 @@ +getMessage() + ); + } +} diff --git a/tests/Doctrine/Tests/DBAL/Exception/InvalidArgumentExceptionTest.php b/tests/Doctrine/Tests/DBAL/Exception/EmptyCriteriaNotAllowedTest.php similarity index 54% rename from tests/Doctrine/Tests/DBAL/Exception/InvalidArgumentExceptionTest.php rename to tests/Doctrine/Tests/DBAL/Exception/EmptyCriteriaNotAllowedTest.php index b545fbefd4a..acd1fe876a3 100644 --- a/tests/Doctrine/Tests/DBAL/Exception/InvalidArgumentExceptionTest.php +++ b/tests/Doctrine/Tests/DBAL/Exception/EmptyCriteriaNotAllowedTest.php @@ -4,19 +4,15 @@ namespace Doctrine\Tests\DBAL\Exception; +use Doctrine\DBAL\Exception\EmptyCriteriaNotAllowed; use Doctrine\DBAL\Exception\InvalidArgumentException; use PHPUnit\Framework\TestCase; -/** - * Tests for {@see \Doctrine\DBAL\Exception\InvalidArgumentException} - * - * @covers \Doctrine\DBAL\Exception\InvalidArgumentException - */ -class InvalidArgumentExceptionTest extends TestCase +class EmptyCriteriaNotAllowedTest extends TestCase { - public function testFromEmptyCriteria() + public function testNew() : void { - $exception = InvalidArgumentException::fromEmptyCriteria(); + $exception = EmptyCriteriaNotAllowed::new(); self::assertInstanceOf(InvalidArgumentException::class, $exception); self::assertSame('Empty criteria was used, expected non-empty criteria', $exception->getMessage()); diff --git a/tests/Doctrine/Tests/DBAL/Exception/InvalidColumnIndexTest.php b/tests/Doctrine/Tests/DBAL/Exception/InvalidColumnIndexTest.php new file mode 100644 index 00000000000..ec55bad9cd2 --- /dev/null +++ b/tests/Doctrine/Tests/DBAL/Exception/InvalidColumnIndexTest.php @@ -0,0 +1,28 @@ +getMessage()); + } + + public function testNewPlural() : void + { + $exception = InvalidColumnIndex::new(5, 2); + + self::assertInstanceOf(DBALException::class, $exception); + self::assertSame('Invalid column index 5. The statement result contains 2 columns.', $exception->getMessage()); + } +} diff --git a/tests/Doctrine/Tests/DBAL/Exception/InvalidPlatformTypeTest.php b/tests/Doctrine/Tests/DBAL/Exception/InvalidPlatformTypeTest.php new file mode 100644 index 00000000000..35f69a70f63 --- /dev/null +++ b/tests/Doctrine/Tests/DBAL/Exception/InvalidPlatformTypeTest.php @@ -0,0 +1,38 @@ +getMessage() + ); + } + + /** + * @group #2821 + */ + public function testInvalidPlatformTypeScalar() : void + { + $exception = InvalidPlatformType::new('some string'); + + self::assertSame( + "Option 'platform' must be an object and subtype of 'Doctrine\DBAL\Platforms\AbstractPlatform'. Got 'string'", + $exception->getMessage() + ); + } +} diff --git a/tests/Doctrine/Tests/DBAL/Types/ConversionExceptionTest.php b/tests/Doctrine/Tests/DBAL/Types/ConversionExceptionTest.php index 6c6dd71e727..37622f4d884 100644 --- a/tests/Doctrine/Tests/DBAL/Types/ConversionExceptionTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/ConversionExceptionTest.php @@ -5,6 +5,8 @@ namespace Doctrine\Tests\DBAL\Types; use Doctrine\DBAL\Types\ConversionException; +use Doctrine\DBAL\Types\Exception\InvalidFormat; +use Doctrine\DBAL\Types\Exception\InvalidType; use Exception; use PHPUnit\Framework\TestCase; use stdClass; @@ -19,7 +21,7 @@ class ConversionExceptionTest extends TestCase */ public function testConversionFailedInvalidTypeWithScalar($scalarValue) { - $exception = ConversionException::conversionFailedInvalidType($scalarValue, 'foo', ['bar', 'baz']); + $exception = InvalidType::new($scalarValue, 'foo', ['bar', 'baz']); self::assertInstanceOf(ConversionException::class, $exception); self::assertRegExp( @@ -36,7 +38,7 @@ public function testConversionFailedInvalidTypeWithScalar($scalarValue) */ public function testConversionFailedInvalidTypeWithNonScalar($nonScalar) { - $exception = ConversionException::conversionFailedInvalidType($nonScalar, 'foo', ['bar', 'baz']); + $exception = InvalidType::new($nonScalar, 'foo', ['bar', 'baz']); self::assertInstanceOf(ConversionException::class, $exception); self::assertRegExp( @@ -50,7 +52,7 @@ public function testConversionFailedFormatPreservesPreviousException() { $previous = new Exception(); - $exception = ConversionException::conversionFailedFormat('foo', 'bar', 'baz', $previous); + $exception = InvalidFormat::new('foo', 'bar', 'baz', $previous); self::assertInstanceOf(ConversionException::class, $exception); self::assertSame($previous, $exception->getPrevious()); diff --git a/tests/Doctrine/Tests/DBAL/Types/Exception/TypeAlreadyRegisteredTest.php b/tests/Doctrine/Tests/DBAL/Types/Exception/TypeAlreadyRegisteredTest.php new file mode 100644 index 00000000000..29074c56b75 --- /dev/null +++ b/tests/Doctrine/Tests/DBAL/Types/Exception/TypeAlreadyRegisteredTest.php @@ -0,0 +1,22 @@ +getMessage()) === 1); + } +} diff --git a/tests/Doctrine/Tests/DBAL/Types/Exception/TypeNotRegisteredTest.php b/tests/Doctrine/Tests/DBAL/Types/Exception/TypeNotRegisteredTest.php new file mode 100644 index 00000000000..844814d448b --- /dev/null +++ b/tests/Doctrine/Tests/DBAL/Types/Exception/TypeNotRegisteredTest.php @@ -0,0 +1,22 @@ +getMessage()) === 1); + } +} diff --git a/tests/Doctrine/Tests/DBAL/Types/ObjectTest.php b/tests/Doctrine/Tests/DBAL/Types/ObjectTest.php index 49d30757c5d..19fe13d6cd4 100644 --- a/tests/Doctrine/Tests/DBAL/Types/ObjectTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/ObjectTest.php @@ -41,6 +41,7 @@ public function testConversionFailure() { $this->expectException(ConversionException::class); $this->expectExceptionMessage("Could not convert database value to 'object' as an error was triggered by the unserialization: 'unserialize(): Error at offset 0 of 7 bytes'"); + $this->type->convertToPHPValue('abcdefg', $this->platform); } diff --git a/tests/Doctrine/Tests/DBAL/Types/TypeRegistryTest.php b/tests/Doctrine/Tests/DBAL/Types/TypeRegistryTest.php index 14cd7497385..d9a249b63b4 100644 --- a/tests/Doctrine/Tests/DBAL/Types/TypeRegistryTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/TypeRegistryTest.php @@ -7,6 +7,7 @@ use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Types\BinaryType; use Doctrine\DBAL\Types\BlobType; +use Doctrine\DBAL\Types\Exception\TypeNotRegistered; use Doctrine\DBAL\Types\StringType; use Doctrine\DBAL\Types\TextType; use Doctrine\DBAL\Types\TypeRegistry; @@ -64,7 +65,7 @@ public function testLookupName() : void $this->registry->lookupName($this->otherTestType) ); - $this->expectException(DBALException::class); + $this->expectException(TypeNotRegistered::class); $this->registry->lookupName(new TextType()); }