Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove platform parameter of wrapper Connection #5703

Merged
merged 1 commit into from
Sep 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
27 changes: 3 additions & 24 deletions src/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}

/**
Expand Down Expand Up @@ -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);

Expand Down
3 changes: 0 additions & 3 deletions src/DriverManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
* password?: string,
* path?: string,
* pdo?: \PDO,
* platform?: Platforms\AbstractPlatform,
* port?: int,
* user?: string,
* unix_socket?: string,
Expand All @@ -65,7 +64,6 @@
* password?: string,
* path?: string,
* pdo?: \PDO,
* platform?: Platforms\AbstractPlatform,
* port?: int,
* primary?: OverrideParams,
* replica?: array<OverrideParams>,
Expand Down Expand Up @@ -171,7 +169,6 @@ private function __construct()
* password?: string,
* path?: string,
* pdo?: \PDO,
* platform?: Platforms\AbstractPlatform,
* port?: int,
* primary?: OverrideParams,
* replica?: array<OverrideParams>,
Expand Down
37 changes: 0 additions & 37 deletions src/Exception/InvalidPlatformType.php

This file was deleted.

98 changes: 0 additions & 98 deletions tests/ConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
use PHPUnit\Framework\TestCase;
use Psr\Cache\CacheItemInterface;
use Psr\Cache\CacheItemPoolInterface;
use stdClass;

/**
* @requires extension pdo_mysql
Expand Down Expand Up @@ -712,103 +711,6 @@ public function testConnectionParamsArePassedToTheQueryCacheProfileInExecuteCach

(new Connection($this->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
Expand Down
14 changes: 0 additions & 14 deletions tests/DriverManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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
{
Expand Down
35 changes: 0 additions & 35 deletions tests/Exception/InvalidPlatformTypeTest.php

This file was deleted.

24 changes: 0 additions & 24 deletions tests/ExceptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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(),
);
}
}