diff --git a/UPGRADE.md b/UPGRADE.md index 84e864e4000..4b39948eca7 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -8,6 +8,10 @@ awareness about deprecated code. # Upgrade to 4.0 +## BC BREAK: removed support for the "platform" parameter of the wrapper `Connection`. + +The support for the "platform" parameter of the wrapper `Connection` has been removed. + ## BC BREAK: removed support for "unique" and "check" column properties. The "unique" and "check" column properties are no longer supported. diff --git a/src/Connection.php b/src/Connection.php index 55c0aef49b3..091f0f73607 100644 --- a/src/Connection.php +++ b/src/Connection.php @@ -20,7 +20,6 @@ use Doctrine\DBAL\Exception\CommitFailedRollbackOnly; use Doctrine\DBAL\Exception\ConnectionLost; use Doctrine\DBAL\Exception\DriverException; -use Doctrine\DBAL\Exception\InvalidPlatformType; use Doctrine\DBAL\Exception\NoActiveTransaction; use Doctrine\DBAL\Exception\SavepointsNotSupported; use Doctrine\DBAL\Platforms\AbstractPlatform; @@ -134,25 +133,8 @@ public function __construct( ) { $this->_config = $config ?? new Configuration(); $this->_eventManager = $eventManager ?? new EventManager(); - - if (isset($params['platform'])) { - if (! $params['platform'] instanceof Platforms\AbstractPlatform) { - throw InvalidPlatformType::new($params['platform']); - } - - Deprecation::trigger( - 'doctrine/dbal', - 'https://github.com/doctrine/dbal/pull/5699', - 'The "platform" connection parameter is deprecated.' - . ' Use a driver middleware that would instantiate the platform instead.', - ); - - $this->platform = $params['platform']; - $this->platform->setEventManager($this->_eventManager); - } - - $this->params = $params; - $this->autoCommit = $this->_config->getAutoCommit(); + $this->params = $params; + $this->autoCommit = $this->_config->getAutoCommit(); } /** @@ -880,10 +862,7 @@ public function executeCacheQuery(string $sql, array $params, array $types, Quer throw NoResultDriverConfigured::new(); } - $connectionParams = $this->params; - unset($connectionParams['platform']); - - [$cacheKey, $realKey] = $qcp->generateCacheKeys($sql, $params, $types, $connectionParams); + [$cacheKey, $realKey] = $qcp->generateCacheKeys($sql, $params, $types, $this->params); $item = $resultCache->getItem($cacheKey); diff --git a/src/DriverManager.php b/src/DriverManager.php index 6e9d995d6b7..bcb72b1c695 100644 --- a/src/DriverManager.php +++ b/src/DriverManager.php @@ -44,7 +44,6 @@ * password?: string, * path?: string, * pdo?: \PDO, - * platform?: Platforms\AbstractPlatform, * port?: int, * user?: string, * unix_socket?: string, @@ -65,7 +64,6 @@ * password?: string, * path?: string, * pdo?: \PDO, - * platform?: Platforms\AbstractPlatform, * port?: int, * primary?: OverrideParams, * replica?: array, @@ -171,7 +169,6 @@ private function __construct() * password?: string, * path?: string, * pdo?: \PDO, - * platform?: Platforms\AbstractPlatform, * port?: int, * primary?: OverrideParams, * replica?: array, diff --git a/src/Exception/InvalidPlatformType.php b/src/Exception/InvalidPlatformType.php deleted file mode 100644 index b9313122576..00000000000 --- a/src/Exception/InvalidPlatformType.php +++ /dev/null @@ -1,37 +0,0 @@ -params, $driver))->executeCacheQuery($query, $params, $types, $queryCacheProfileMock); } - - public function testShouldNotPassPlatformInParamsToTheQueryCacheProfileInExecuteCacheQuery(): void - { - $cacheItemMock = $this->createMock(CacheItemInterface::class); - $cacheItemMock->method('isHit')->willReturn(true); - $cacheItemMock->method('get')->willReturn(['realKey' => []]); - - $resultCacheMock = $this->createMock(CacheItemPoolInterface::class); - - $resultCacheMock - ->expects(self::atLeastOnce()) - ->method('getItem') - ->with('cacheKey') - ->willReturn($cacheItemMock); - - $queryCacheProfileMock = $this->createMock(QueryCacheProfile::class); - - $queryCacheProfileMock - ->method('getResultCache') - ->willReturn($resultCacheMock); - - $query = 'SELECT 1'; - - $connectionParams = $this->params; - - $queryCacheProfileMock - ->expects(self::once()) - ->method('generateCacheKeys') - ->with($query, [], [], $connectionParams) - ->willReturn(['cacheKey', 'realKey']); - - $connectionParams['platform'] = $this->createMock(AbstractPlatform::class); - - $driver = $this->createMock(Driver::class); - - (new Connection($connectionParams, $driver))->executeCacheQuery($query, [], [], $queryCacheProfileMock); - } - - /** @psalm-suppress InvalidArgument */ - public function testThrowsExceptionWhenInValidPlatformSpecified(): void - { - $connectionParams = $this->params; - $connectionParams['platform'] = new stdClass(); - - $driver = $this->createMock(Driver::class); - - $this->expectException(Exception::class); - - new Connection($connectionParams, $driver); - } - - public function testExecuteCacheQueryStripsPlatformFromConnectionParamsBeforeGeneratingCacheKeys(): void - { - $driver = $this->createMock(Driver::class); - - $platform = $this->createMock(AbstractPlatform::class); - - $queryCacheProfile = $this->createMock(QueryCacheProfile::class); - - $resultCache = $this->createMock(CacheItemPoolInterface::class); - - $queryCacheProfile - ->method('getResultCache') - ->willReturn($resultCache); - - $cacheItemMock = $this->createMock(CacheItemInterface::class); - $cacheItemMock->method('isHit')->willReturn(true); - $cacheItemMock->method('get')->willReturn(['realKey' => []]); - - $resultCache - ->expects(self::atLeastOnce()) - ->method('getItem') - ->with('cacheKey') - ->willReturn($cacheItemMock); - - $query = 'SELECT 1'; - - $params = [ - 'dbname' => 'foo', - 'platform' => $platform, - ]; - - $paramsWithoutPlatform = $params; - unset($paramsWithoutPlatform['platform']); - - $queryCacheProfile - ->expects(self::once()) - ->method('generateCacheKeys') - ->with($query, [], [], $paramsWithoutPlatform) - ->willReturn(['cacheKey', 'realKey']); - - $connection = new Connection($params, $driver); - - self::assertSame($params, $connection->getParams()); - - $connection->executeCacheQuery($query, [], [], $queryCacheProfile); - } } interface ConnectDispatchEventListener diff --git a/tests/DriverManagerTest.php b/tests/DriverManagerTest.php index 6fc0d616569..4fe99ef6bba 100644 --- a/tests/DriverManagerTest.php +++ b/tests/DriverManagerTest.php @@ -11,7 +11,6 @@ use Doctrine\DBAL\Driver\SQLSrv\Driver as SQLSrvDriver; use Doctrine\DBAL\DriverManager; use Doctrine\DBAL\Exception; -use Doctrine\DBAL\Platforms\AbstractPlatform; use PHPUnit\Framework\TestCase; use stdClass; @@ -37,19 +36,6 @@ public function testInvalidDriver(): void DriverManager::getConnection(['driver' => 'invalid_driver']); } - /** @requires extension pdo_sqlite */ - public function testCustomPlatform(): void - { - $platform = $this->createMock(AbstractPlatform::class); - $options = [ - 'url' => 'sqlite::memory:', - 'platform' => $platform, - ]; - - $conn = DriverManager::getConnection($options); - self::assertSame($platform, $conn->getDatabasePlatform()); - } - /** @requires extension pdo_sqlite */ public function testCustomWrapper(): void { diff --git a/tests/Exception/InvalidPlatformTypeTest.php b/tests/Exception/InvalidPlatformTypeTest.php deleted file mode 100644 index 0c3b1a6c7e0..00000000000 --- a/tests/Exception/InvalidPlatformTypeTest.php +++ /dev/null @@ -1,35 +0,0 @@ -getMessage(), - ); - } - - /** @group #2821 */ - public function testInvalidPlatformTypeScalar(): void - { - $exception = InvalidPlatformType::new('some string'); - - self::assertSame( - 'Option "platform" must be an object and subtype of ' . AbstractPlatform::class . '. Got string.', - $exception->getMessage(), - ); - } -} diff --git a/tests/ExceptionTest.php b/tests/ExceptionTest.php index ffea14412b0..35b257aaa58 100644 --- a/tests/ExceptionTest.php +++ b/tests/ExceptionTest.php @@ -5,10 +5,7 @@ namespace Doctrine\DBAL\Tests; use Doctrine\DBAL\Exception\DriverRequired; -use Doctrine\DBAL\Exception\InvalidPlatformType; -use Doctrine\DBAL\Platforms\AbstractPlatform; use PHPUnit\Framework\TestCase; -use stdClass; use function sprintf; @@ -28,25 +25,4 @@ public function testDriverRequiredWithUrl(): void $exception->getMessage(), ); } - - public function testInvalidPlatformTypeObject(): void - { - $exception = InvalidPlatformType::new(new stdClass()); - - self::assertSame( - 'Option "platform" must be a subtype of Doctrine\DBAL\Platforms\AbstractPlatform, ' - . 'instance of stdClass given.', - $exception->getMessage(), - ); - } - - public function testInvalidPlatformTypeScalar(): void - { - $exception = InvalidPlatformType::new('some string'); - - self::assertSame( - 'Option "platform" must be an object and subtype of ' . AbstractPlatform::class . '. Got string.', - $exception->getMessage(), - ); - } }