diff --git a/UPGRADE.md b/UPGRADE.md index f258faa9a07..1c1c17fb04e 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -8,6 +8,18 @@ awareness about deprecated code. # Upgrade to 4.0 +## BC BREAK: converted enum-like classes to enums + +The following classes have been converted to enums: + +1. `Doctrine\DBAL\ColumnCase`, +2. `Doctrine\DBAL\LockMode`, +3. `Doctrine\DBAL\TransactionIsolationLevel`, +4. `Doctrine\DBAL\Platforms\DateIntervalUnit`, +5. `Doctrine\DBAL\Platforms\TrimMode`. + +The corresponding class constants are now instances of their enum type. + ## BC BREAK: renamed SQLite platform classes 1. `SqlitePlatform` => `SQLitePlatform` diff --git a/src/ColumnCase.php b/src/ColumnCase.php index e3a19b05a47..687a04f80e6 100644 --- a/src/ColumnCase.php +++ b/src/ColumnCase.php @@ -7,24 +7,15 @@ /** * Contains portable column case conversions. */ -final class ColumnCase +enum ColumnCase { /** * Convert column names to upper case. */ - public const UPPER = 1; + case UPPER; /** * Convert column names to lower case. */ - public const LOWER = 2; - - /** - * This class cannot be instantiated. - * - * @codeCoverageIgnore - */ - private function __construct() - { - } + case LOWER; } diff --git a/src/Connection.php b/src/Connection.php index faebaeeb2f6..7c313068ae6 100644 --- a/src/Connection.php +++ b/src/Connection.php @@ -96,10 +96,8 @@ class Connection implements ServerVersionProvider /** * The currently active transaction isolation level or NULL before it has been determined. - * - * @var TransactionIsolationLevel::*|null */ - private ?int $transactionIsolationLevel = null; + private ?TransactionIsolationLevel $transactionIsolationLevel = null; /** * The parameters used during creation of the Connection instance. @@ -501,11 +499,11 @@ public function close(): void /** * Sets the transaction isolation level. * - * @param TransactionIsolationLevel::* $level The level to set. + * @param TransactionIsolationLevel $level The level to set. * * @throws Exception */ - public function setTransactionIsolation(int $level): void + public function setTransactionIsolation(TransactionIsolationLevel $level): void { $this->transactionIsolationLevel = $level; @@ -515,11 +513,11 @@ public function setTransactionIsolation(int $level): void /** * Gets the currently active transaction isolation level. * - * @return TransactionIsolationLevel::* The current transaction isolation level. + * @return TransactionIsolationLevel The current transaction isolation level. * * @throws Exception */ - public function getTransactionIsolation(): int + public function getTransactionIsolation(): TransactionIsolationLevel { return $this->transactionIsolationLevel ??= $this->getDatabasePlatform()->getDefaultTransactionIsolationLevel(); } diff --git a/src/Exception/InvalidLockMode.php b/src/Exception/InvalidLockMode.php deleted file mode 100644 index 64e96201ab7..00000000000 --- a/src/Exception/InvalidLockMode.php +++ /dev/null @@ -1,26 +0,0 @@ -value . ')'; } public function getDateDiffExpression(string $date1, string $date2): string @@ -677,7 +677,7 @@ public function getDropUniqueConstraintSQL(string $name, string $tableName): str return $this->getDropIndexSQL($name, $tableName); } - public function getSetTransactionIsolationSQL(int $level): string + public function getSetTransactionIsolationSQL(TransactionIsolationLevel $level): string { return 'SET SESSION TRANSACTION ISOLATION LEVEL ' . $this->_getTransactionIsolationLevelSQL($level); } @@ -778,7 +778,7 @@ public function quoteStringLiteral(string $str): string return parent::quoteStringLiteral($str); } - public function getDefaultTransactionIsolationLevel(): int + public function getDefaultTransactionIsolationLevel(): TransactionIsolationLevel { return TransactionIsolationLevel::REPEATABLE_READ; } diff --git a/src/Platforms/AbstractPlatform.php b/src/Platforms/AbstractPlatform.php index c4f54f2134e..9afde034342 100644 --- a/src/Platforms/AbstractPlatform.php +++ b/src/Platforms/AbstractPlatform.php @@ -17,7 +17,6 @@ use Doctrine\DBAL\Events; use Doctrine\DBAL\Exception; use Doctrine\DBAL\Exception\ColumnLengthRequired; -use Doctrine\DBAL\Exception\InvalidLockMode; use Doctrine\DBAL\LockMode; use Doctrine\DBAL\Platforms\Exception\NoColumnsSpecifiedForTable; use Doctrine\DBAL\Platforms\Exception\NotSupported; @@ -418,12 +417,10 @@ public function getModExpression(string $dividend, string $divisor): string * Returns the SQL snippet to trim a string. * * @param string $str The expression to apply the trim to. - * @param int $mode The position of the trim (leading/trailing/both). + * @param TrimMode $mode The position of the trim. * @param string|null $char The char to trim, has to be quoted already. Defaults to space. - * - * @throws InvalidArgumentException */ - public function getTrimExpression(string $str, int $mode = TrimMode::UNSPECIFIED, ?string $char = null): string + public function getTrimExpression(string $str, TrimMode $mode = TrimMode::UNSPECIFIED, ?string $char = null): string { $tokens = []; @@ -442,14 +439,6 @@ public function getTrimExpression(string $str, int $mode = TrimMode::UNSPECIFIED case TrimMode::BOTH: $tokens[] = 'BOTH'; break; - - default: - throw new InvalidArgumentException( - sprintf( - 'The value of $mode is expected to be one of the TrimMode constants, %d given.', - $mode - ) - ); } if ($char !== null) { @@ -688,18 +677,18 @@ public function getDateSubYearsExpression(string $date, string $years): string /** * Returns the SQL for a date arithmetic expression. * - * @param string $date SQL expression representing a date to perform the arithmetic operation on. - * @param string $operator The arithmetic operator (+ or -). - * @param string $interval SQL expression representing the value of the interval that shall be calculated - * into the date. - * @param string $unit The unit of the interval that shall be calculated into the date. + * @param string $date SQL expression representing a date to perform the arithmetic operation on. + * @param string $operator The arithmetic operator (+ or -). + * @param string $interval SQL expression representing the value of the interval that shall be calculated + * into the date. + * @param DateIntervalUnit $unit The unit of the interval that shall be calculated into the date. * One of the DATE_INTERVAL_UNIT_* constants. */ abstract protected function getDateArithmeticIntervalExpression( string $date, string $operator, string $interval, - string $unit + DateIntervalUnit $unit ): string; /** @@ -753,18 +742,10 @@ public function getForUpdateSQL(): string * ANSI SQL FOR UPDATE specification. * * @param string $fromClause The FROM clause to append the hint for the given lock mode to - * @param int $lockMode One of the Doctrine\DBAL\LockMode::* constants - * @psalm-param LockMode::* $lockMode */ - public function appendLockHint(string $fromClause, int $lockMode): string + public function appendLockHint(string $fromClause, LockMode $lockMode): string { - return match ($lockMode) { - LockMode::NONE, - LockMode::OPTIMISTIC, - LockMode::PESSIMISTIC_READ, - LockMode::PESSIMISTIC_WRITE => $fromClause, - default => throw InvalidLockMode::fromLockMode($lockMode), - }; + return $fromClause; } /** @@ -1992,17 +1973,14 @@ public function getCurrentTimestampSQL(): string /** * Returns the SQL for a given transaction isolation level Connection constant. - * - * @throws InvalidArgumentException */ - protected function _getTransactionIsolationLevelSQL(int $level): string + protected function _getTransactionIsolationLevelSQL(TransactionIsolationLevel $level): string { return match ($level) { TransactionIsolationLevel::READ_UNCOMMITTED => 'READ UNCOMMITTED', TransactionIsolationLevel::READ_COMMITTED => 'READ COMMITTED', TransactionIsolationLevel::REPEATABLE_READ => 'REPEATABLE READ', TransactionIsolationLevel::SERIALIZABLE => 'SERIALIZABLE', - default => throw new InvalidArgumentException(sprintf('Invalid isolation level "%s".', $level)), }; } @@ -2068,7 +2046,7 @@ public function getDropDatabaseSQL(string $name): string /** * Returns the SQL to set the transaction isolation level. */ - abstract public function getSetTransactionIsolationSQL(int $level): string; + abstract public function getSetTransactionIsolationSQL(TransactionIsolationLevel $level): string; /** * Obtains DBMS specific SQL to be used to create datetime columns in @@ -2115,11 +2093,9 @@ public function getFloatDeclarationSQL(array $column): string /** * Gets the default transaction isolation level of the platform. * - * @see TransactionIsolationLevel - * - * @return TransactionIsolationLevel::* The default isolation level. + * @return TransactionIsolationLevel The default isolation level. */ - public function getDefaultTransactionIsolationLevel(): int + public function getDefaultTransactionIsolationLevel(): TransactionIsolationLevel { return TransactionIsolationLevel::READ_COMMITTED; } diff --git a/src/Platforms/DB2Platform.php b/src/Platforms/DB2Platform.php index 7ee0f41466a..c0ac78b6ea4 100644 --- a/src/Platforms/DB2Platform.php +++ b/src/Platforms/DB2Platform.php @@ -14,6 +14,7 @@ use Doctrine\DBAL\Schema\Identifier; use Doctrine\DBAL\Schema\Index; use Doctrine\DBAL\Schema\TableDiff; +use Doctrine\DBAL\TransactionIsolationLevel; use function array_merge; use function count; @@ -133,7 +134,7 @@ protected function getDateArithmeticIntervalExpression( string $date, string $operator, string $interval, - string $unit + DateIntervalUnit $unit ): string { switch ($unit) { case DateIntervalUnit::WEEK: @@ -147,7 +148,7 @@ protected function getDateArithmeticIntervalExpression( break; } - return $date . ' ' . $operator . ' ' . $interval . ' ' . $unit; + return $date . ' ' . $operator . ' ' . $interval . ' ' . $unit->value; } public function getDateDiffExpression(string $date1, string $date2): string @@ -195,7 +196,7 @@ public function getTruncateTableSQL(string $tableName, bool $cascade = false): s * * @throws Exception */ - public function getSetTransactionIsolationSQL(int $level): string + public function getSetTransactionIsolationSQL(TransactionIsolationLevel $level): string { throw NotSupported::new(__METHOD__); } diff --git a/src/Platforms/DateIntervalUnit.php b/src/Platforms/DateIntervalUnit.php index c1f3ca59218..ba783f37223 100644 --- a/src/Platforms/DateIntervalUnit.php +++ b/src/Platforms/DateIntervalUnit.php @@ -4,28 +4,14 @@ namespace Doctrine\DBAL\Platforms; -final class DateIntervalUnit +enum DateIntervalUnit: string { - public const SECOND = 'SECOND'; - - public const MINUTE = 'MINUTE'; - - public const HOUR = 'HOUR'; - - public const DAY = 'DAY'; - - public const WEEK = 'WEEK'; - - public const MONTH = 'MONTH'; - - public const QUARTER = 'QUARTER'; - - public const YEAR = 'YEAR'; - - /** - * @codeCoverageIgnore - */ - private function __construct() - { - } + case SECOND = 'SECOND'; + case MINUTE = 'MINUTE'; + case HOUR = 'HOUR'; + case DAY = 'DAY'; + case WEEK = 'WEEK'; + case MONTH = 'MONTH'; + case QUARTER = 'QUARTER'; + case YEAR = 'YEAR'; } diff --git a/src/Platforms/OraclePlatform.php b/src/Platforms/OraclePlatform.php index e9ad5b78cfa..acb0b00cd31 100644 --- a/src/Platforms/OraclePlatform.php +++ b/src/Platforms/OraclePlatform.php @@ -55,7 +55,7 @@ protected function getDateArithmeticIntervalExpression( string $date, string $operator, string $interval, - string $unit + DateIntervalUnit $unit ): string { switch ($unit) { case DateIntervalUnit::MONTH: @@ -174,18 +174,18 @@ public function getSequenceNextValSQL(string $sequence): string return 'SELECT ' . $sequence . '.nextval FROM DUAL'; } - public function getSetTransactionIsolationSQL(int $level): string + public function getSetTransactionIsolationSQL(TransactionIsolationLevel $level): string { return 'SET TRANSACTION ISOLATION LEVEL ' . $this->_getTransactionIsolationLevelSQL($level); } - protected function _getTransactionIsolationLevelSQL(int $level): string + protected function _getTransactionIsolationLevelSQL(TransactionIsolationLevel $level): string { return match ($level) { TransactionIsolationLevel::READ_UNCOMMITTED => 'READ UNCOMMITTED', TransactionIsolationLevel::READ_COMMITTED => 'READ COMMITTED', - TransactionIsolationLevel::REPEATABLE_READ, TransactionIsolationLevel::SERIALIZABLE => 'SERIALIZABLE', - default => parent::_getTransactionIsolationLevelSQL($level), + TransactionIsolationLevel::REPEATABLE_READ, + TransactionIsolationLevel::SERIALIZABLE => 'SERIALIZABLE', }; } diff --git a/src/Platforms/PostgreSQLPlatform.php b/src/Platforms/PostgreSQLPlatform.php index 3610cee8476..b1740a77e1f 100644 --- a/src/Platforms/PostgreSQLPlatform.php +++ b/src/Platforms/PostgreSQLPlatform.php @@ -14,6 +14,7 @@ use Doctrine\DBAL\Schema\PostgreSQLSchemaManager; use Doctrine\DBAL\Schema\Sequence; use Doctrine\DBAL\Schema\TableDiff; +use Doctrine\DBAL\TransactionIsolationLevel; use Doctrine\DBAL\Types\BinaryType; use Doctrine\DBAL\Types\BlobType; use UnexpectedValueException; @@ -94,14 +95,14 @@ protected function getDateArithmeticIntervalExpression( string $date, string $operator, string $interval, - string $unit + DateIntervalUnit $unit ): string { if ($unit === DateIntervalUnit::QUARTER) { $interval = $this->multiplyInterval($interval, 3); $unit = DateIntervalUnit::MONTH; } - return '(' . $date . ' ' . $operator . ' (' . $interval . " || ' " . $unit . "')::interval)"; + return '(' . $date . ' ' . $operator . ' (' . $interval . " || ' " . $unit->value . "')::interval)"; } public function getDateDiffExpression(string $date1, string $date2): string @@ -608,7 +609,7 @@ public function getSequenceNextValSQL(string $sequence): string return "SELECT NEXTVAL('" . $sequence . "')"; } - public function getSetTransactionIsolationSQL(int $level): string + public function getSetTransactionIsolationSQL(TransactionIsolationLevel $level): string { return 'SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL ' . $this->_getTransactionIsolationLevelSQL($level); diff --git a/src/Platforms/SQLServerPlatform.php b/src/Platforms/SQLServerPlatform.php index 416dc84558f..f858e6d580e 100644 --- a/src/Platforms/SQLServerPlatform.php +++ b/src/Platforms/SQLServerPlatform.php @@ -6,7 +6,6 @@ use Doctrine\DBAL\Connection; use Doctrine\DBAL\Exception\ColumnLengthRequired; -use Doctrine\DBAL\Exception\InvalidLockMode; use Doctrine\DBAL\LockMode; use Doctrine\DBAL\Platforms\Keywords\KeywordList; use Doctrine\DBAL\Platforms\Keywords\SQLServerKeywords; @@ -17,6 +16,7 @@ use Doctrine\DBAL\Schema\Sequence; use Doctrine\DBAL\Schema\SQLServerSchemaManager; use Doctrine\DBAL\Schema\TableDiff; +use Doctrine\DBAL\TransactionIsolationLevel; use InvalidArgumentException; use function array_merge; @@ -27,7 +27,6 @@ use function dechex; use function explode; use function implode; -use function in_array; use function is_array; use function is_bool; use function is_numeric; @@ -72,7 +71,7 @@ protected function getDateArithmeticIntervalExpression( string $date, string $operator, string $interval, - string $unit + DateIntervalUnit $unit ): string { $factorClause = ''; @@ -80,7 +79,7 @@ protected function getDateArithmeticIntervalExpression( $factorClause = '-1 * '; } - return 'DATEADD(' . $unit . ', ' . $factorClause . $interval . ', ' . $date . ')'; + return 'DATEADD(' . $unit->value . ', ' . $factorClause . $interval . ', ' . $date . ')'; } public function getDateDiffExpression(string $date1, string $date2): string @@ -791,14 +790,8 @@ public function getModExpression(string $dividend, string $divisor): string return $dividend . ' % ' . $divisor; } - public function getTrimExpression(string $str, int $mode = TrimMode::UNSPECIFIED, ?string $char = null): string + public function getTrimExpression(string $str, TrimMode $mode = TrimMode::UNSPECIFIED, ?string $char = null): string { - if (! in_array($mode, [TrimMode::UNSPECIFIED, TrimMode::LEADING, TrimMode::TRAILING, TrimMode::BOTH], true)) { - throw new InvalidArgumentException( - sprintf('The value of $mode is expected to be one of the TrimMode constants, %d given', $mode) - ); - } - if ($char === null) { return match ($mode) { TrimMode::LEADING => 'LTRIM(' . $str . ')', @@ -852,7 +845,7 @@ public function getCurrentDatabaseExpression(): string return 'DB_NAME()'; } - public function getSetTransactionIsolationSQL(int $level): string + public function getSetTransactionIsolationSQL(TransactionIsolationLevel $level): string { return 'SET TRANSACTION ISOLATION LEVEL ' . $this->_getTransactionIsolationLevelSQL($level); } @@ -1125,14 +1118,13 @@ public function getForeignKeyReferentialActionSQL(string $action): string return parent::getForeignKeyReferentialActionSQL($action); } - public function appendLockHint(string $fromClause, int $lockMode): string + public function appendLockHint(string $fromClause, LockMode $lockMode): string { return match ($lockMode) { LockMode::NONE, LockMode::OPTIMISTIC => $fromClause, LockMode::PESSIMISTIC_READ => $fromClause . ' WITH (HOLDLOCK, ROWLOCK)', LockMode::PESSIMISTIC_WRITE => $fromClause . ' WITH (UPDLOCK, ROWLOCK)', - default => throw InvalidLockMode::fromLockMode($lockMode), }; } diff --git a/src/Platforms/SQLitePlatform.php b/src/Platforms/SQLitePlatform.php index 9f4208b761d..c962ef8c41c 100644 --- a/src/Platforms/SQLitePlatform.php +++ b/src/Platforms/SQLitePlatform.php @@ -19,7 +19,6 @@ use Doctrine\DBAL\Schema\TableDiff; use Doctrine\DBAL\TransactionIsolationLevel; use Doctrine\DBAL\Types; -use InvalidArgumentException; use function array_combine; use function array_keys; @@ -60,19 +59,13 @@ public function getRegexpExpression(): string return 'REGEXP'; } - public function getTrimExpression(string $str, int $mode = TrimMode::UNSPECIFIED, ?string $char = null): string + public function getTrimExpression(string $str, TrimMode $mode = TrimMode::UNSPECIFIED, ?string $char = null): string { $trimFn = match ($mode) { TrimMode::UNSPECIFIED, TrimMode::BOTH => 'TRIM', TrimMode::LEADING => 'LTRIM', TrimMode::TRAILING => 'RTRIM', - default => throw new InvalidArgumentException( - sprintf( - 'The value of $mode is expected to be one of the TrimMode constants, %d given.', - $mode - ) - ), }; $arguments = [$str]; @@ -106,7 +99,7 @@ protected function getDateArithmeticIntervalExpression( string $date, string $operator, string $interval, - string $unit + DateIntervalUnit $unit ): string { switch ($unit) { case DateIntervalUnit::WEEK: @@ -123,7 +116,7 @@ protected function getDateArithmeticIntervalExpression( return 'DATETIME(' . $date . ',' . $this->getConcatExpression( $this->quoteStringLiteral($operator), $interval, - $this->quoteStringLiteral(' ' . $unit) + $this->quoteStringLiteral(' ' . $unit->value) ) . ')'; } @@ -145,18 +138,17 @@ public function getCurrentDatabaseExpression(): string return "''"; } - protected function _getTransactionIsolationLevelSQL(int $level): string + protected function _getTransactionIsolationLevelSQL(TransactionIsolationLevel $level): string { return match ($level) { TransactionIsolationLevel::READ_UNCOMMITTED => '0', TransactionIsolationLevel::READ_COMMITTED, TransactionIsolationLevel::REPEATABLE_READ, TransactionIsolationLevel::SERIALIZABLE => '1', - default => parent::_getTransactionIsolationLevelSQL($level), }; } - public function getSetTransactionIsolationSQL(int $level): string + public function getSetTransactionIsolationSQL(TransactionIsolationLevel $level): string { return 'PRAGMA read_uncommitted = ' . $this->_getTransactionIsolationLevelSQL($level); } diff --git a/src/Platforms/TrimMode.php b/src/Platforms/TrimMode.php index eb499ee4621..31c237543fc 100644 --- a/src/Platforms/TrimMode.php +++ b/src/Platforms/TrimMode.php @@ -4,20 +4,10 @@ namespace Doctrine\DBAL\Platforms; -final class TrimMode +enum TrimMode { - public const UNSPECIFIED = 0; - - public const LEADING = 1; - - public const TRAILING = 2; - - public const BOTH = 3; - - /** - * @codeCoverageIgnore - */ - private function __construct() - { - } + case UNSPECIFIED; + case LEADING; + case TRAILING; + case BOTH; } diff --git a/src/Portability/Driver.php b/src/Portability/Driver.php index a90c64b0b89..831fd4a514f 100644 --- a/src/Portability/Driver.php +++ b/src/Portability/Driver.php @@ -15,7 +15,7 @@ final class Driver extends AbstractDriverMiddleware { - public function __construct(DriverInterface $driver, private readonly int $mode, private readonly int $case) + public function __construct(DriverInterface $driver, private readonly int $mode, private readonly ?ColumnCase $case) { parent::__construct($driver); } @@ -34,14 +34,17 @@ public function connect(array $params): ConnectionInterface $case = null; - if ($this->case !== 0 && ($portability & Connection::PORTABILITY_FIX_CASE) !== 0) { + if ($this->case !== null && ($portability & Connection::PORTABILITY_FIX_CASE) !== 0) { $nativeConnection = $connection->getNativeConnection(); + $case = match ($this->case) { + ColumnCase::LOWER => CASE_LOWER, + ColumnCase::UPPER => CASE_UPPER, + }; + if ($nativeConnection instanceof PDO) { $portability &= ~Connection::PORTABILITY_FIX_CASE; - $nativeConnection->setAttribute(PDO::ATTR_CASE, $this->case); - } else { - $case = $this->case === ColumnCase::LOWER ? CASE_LOWER : CASE_UPPER; + $nativeConnection->setAttribute(PDO::ATTR_CASE, $case); } } diff --git a/src/Portability/Middleware.php b/src/Portability/Middleware.php index c4053f60162..b97897c978d 100644 --- a/src/Portability/Middleware.php +++ b/src/Portability/Middleware.php @@ -4,12 +4,13 @@ namespace Doctrine\DBAL\Portability; +use Doctrine\DBAL\ColumnCase; use Doctrine\DBAL\Driver as DriverInterface; use Doctrine\DBAL\Driver\Middleware as MiddlewareInterface; final class Middleware implements MiddlewareInterface { - public function __construct(private readonly int $mode, private readonly int $case) + public function __construct(private readonly int $mode, private readonly ?ColumnCase $case) { } diff --git a/src/TransactionIsolationLevel.php b/src/TransactionIsolationLevel.php index e8dc5d91814..2b094dbe84e 100644 --- a/src/TransactionIsolationLevel.php +++ b/src/TransactionIsolationLevel.php @@ -4,32 +4,10 @@ namespace Doctrine\DBAL; -final class TransactionIsolationLevel +enum TransactionIsolationLevel { - /** - * Transaction isolation level READ UNCOMMITTED. - */ - public const READ_UNCOMMITTED = 1; - - /** - * Transaction isolation level READ COMMITTED. - */ - public const READ_COMMITTED = 2; - - /** - * Transaction isolation level REPEATABLE READ. - */ - public const REPEATABLE_READ = 3; - - /** - * Transaction isolation level SERIALIZABLE. - */ - public const SERIALIZABLE = 4; - - /** - * @codeCoverageIgnore - */ - private function __construct() - { - } + case READ_UNCOMMITTED; + case READ_COMMITTED; + case REPEATABLE_READ; + case SERIALIZABLE; } diff --git a/tests/Functional/DataAccessTest.php b/tests/Functional/DataAccessTest.php index c85ff547511..c5f27f954df 100644 --- a/tests/Functional/DataAccessTest.php +++ b/tests/Functional/DataAccessTest.php @@ -14,7 +14,6 @@ use Doctrine\DBAL\Statement; use Doctrine\DBAL\Tests\FunctionalTestCase; use Doctrine\DBAL\Types\Types; -use InvalidArgumentException; use function array_change_key_case; use function date; @@ -330,10 +329,10 @@ public function testNativeArrayListSupport(): void /** * @dataProvider getTrimExpressionData */ - public function testTrimExpression(string $value, int $position, ?string $char, string $expectedResult): void + public function testTrimExpression(string $value, TrimMode $mode, ?string $char, string $expectedResult): void { $sql = 'SELECT ' . - $this->connection->getDatabasePlatform()->getTrimExpression($value, $position, $char) . ' AS trimmed ' . + $this->connection->getDatabasePlatform()->getTrimExpression($value, $mode, $char) . ' AS trimmed ' . 'FROM fetch_table'; $row = $this->connection->fetchAssociative($sql); @@ -388,12 +387,6 @@ public static function getTrimExpressionData(): iterable ]; } - public function testTrimExpressionInvalidMode(): void - { - $this->expectException(InvalidArgumentException::class); - $this->connection->getDatabasePlatform()->getTrimExpression('Trim me!', 0xBEEF); - } - /** * @dataProvider modeProvider */ diff --git a/tests/Functional/PortabilityTest.php b/tests/Functional/PortabilityTest.php index 9fe1a9c6ed2..985a3d9bd67 100644 --- a/tests/Functional/PortabilityTest.php +++ b/tests/Functional/PortabilityTest.php @@ -52,7 +52,7 @@ public function testFullFetchMode(): void * * @dataProvider caseProvider */ - public function testCaseConversion(int $case, array $expected): void + public function testCaseConversion(ColumnCase $case, array $expected): void { $this->connectWithPortability(Connection::PORTABILITY_FIX_CASE, $case); $this->createTable(); @@ -64,7 +64,7 @@ public function testCaseConversion(int $case, array $expected): void } /** - * @return iterable}> + * @return iterable}> */ public static function caseProvider(): iterable { @@ -106,7 +106,7 @@ public function assertFetchResultRow(array $row): void */ public function testFetchColumn(string $column, array $expected): void { - $this->connectWithPortability(Connection::PORTABILITY_RTRIM, 0); + $this->connectWithPortability(Connection::PORTABILITY_RTRIM, null); $this->createTable(); $result = $this->connection->executeQuery('SELECT ' . $column . ' FROM portability_table'); @@ -133,7 +133,7 @@ public static function fetchColumnProvider(): iterable public function testFetchAllNullColumn(): void { - $this->connectWithPortability(Connection::PORTABILITY_EMPTY_TO_NULL, 0); + $this->connectWithPortability(Connection::PORTABILITY_EMPTY_TO_NULL, null); $this->createTable(); $column = $this->connection->fetchFirstColumn('SELECT Test_Null FROM portability_table'); @@ -141,7 +141,7 @@ public function testFetchAllNullColumn(): void self::assertSame([null, null], $column); } - private function connectWithPortability(int $mode, int $case): void + private function connectWithPortability(int $mode, ?ColumnCase $case): void { // closing the default connection prior to 4.0.0 to prevent connection leak $this->connection->close(); diff --git a/tests/Platforms/AbstractPlatformTestCase.php b/tests/Platforms/AbstractPlatformTestCase.php index 250111e858f..e48ca40b4f1 100644 --- a/tests/Platforms/AbstractPlatformTestCase.php +++ b/tests/Platforms/AbstractPlatformTestCase.php @@ -7,7 +7,6 @@ use Doctrine\Common\EventManager; use Doctrine\DBAL\Events; use Doctrine\DBAL\Exception; -use Doctrine\DBAL\Exception\InvalidLockMode; use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Schema\Column; use Doctrine\DBAL\Schema\ColumnDiff; @@ -1368,12 +1367,6 @@ public function asciiStringSqlDeclarationDataProvider(): array ['CHAR(12)', ['length' => 12, 'fixed' => true]], ]; } - - public function testInvalidLockMode(): void - { - $this->expectException(InvalidLockMode::class); - $this->platform->appendLockHint('TABLE', 128); - } } interface GetCreateTableSqlDispatchEventListener diff --git a/tests/Platforms/SQLServerPlatformTestCase.php b/tests/Platforms/SQLServerPlatformTestCase.php index 5798a1c9358..b2884c505c1 100644 --- a/tests/Platforms/SQLServerPlatformTestCase.php +++ b/tests/Platforms/SQLServerPlatformTestCase.php @@ -1683,11 +1683,9 @@ public function testAlterTableWithSchemaSameColumnComments(): void } /** - * @psalm-param LockMode::* $lockMode - * * @dataProvider getLockHints */ - public function testAppendsLockHint(int $lockMode, string $lockHint): void + public function testAppendsLockHint(LockMode $lockMode, string $lockHint): void { $fromClause = 'FROM users'; $expectedResult = $fromClause . $lockHint; @@ -1696,7 +1694,7 @@ public function testAppendsLockHint(int $lockMode, string $lockHint): void } /** - * @return mixed[][] + * @return iterable */ public static function getLockHints(): iterable {