From bafa3e343c6026ee255d4b4ad6796dfafb7136c9 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Tue, 20 Apr 2021 15:01:44 -0700 Subject: [PATCH 1/3] [GH-4613] Use utf8mb4 instead of utf8 for testing connection charset --- .../Tests/DBAL/Functional/MasterSlaveConnectionTest.php | 2 +- .../Tests/DBAL/Functional/PrimaryReadReplicaConnectionTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Doctrine/Tests/DBAL/Functional/MasterSlaveConnectionTest.php b/tests/Doctrine/Tests/DBAL/Functional/MasterSlaveConnectionTest.php index ae99ddf6b6e..b063e8334d2 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/MasterSlaveConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/MasterSlaveConnectionTest.php @@ -72,7 +72,7 @@ private function createMasterSlaveConnectionParams(bool $keepSlave = false): arr public function testInheritCharsetFromMaster(): void { $charsets = [ - 'utf8', + 'utf8mb4', 'latin1', ]; diff --git a/tests/Doctrine/Tests/DBAL/Functional/PrimaryReadReplicaConnectionTest.php b/tests/Doctrine/Tests/DBAL/Functional/PrimaryReadReplicaConnectionTest.php index e5303cd5d71..d7c5d90b9a5 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/PrimaryReadReplicaConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/PrimaryReadReplicaConnectionTest.php @@ -73,7 +73,7 @@ private function createPrimaryReadReplicaConnectionParams(bool $keepReplica = fa public function testInheritCharsetFromPrimary(): void { $charsets = [ - 'utf8', + 'utf8mb4', 'latin1', ]; From 1187692461a5ee94f33cbc4ef8d938c19093669d Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Fri, 30 Apr 2021 14:41:43 +0200 Subject: [PATCH 2/3] Display metrics of 3.1 instead of 3.0 --- README.md | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index f936180712e..43caa5a5335 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ # Doctrine DBAL -| [4.0-dev][4.0] | [3.0][3.0] | [2.13][2.13] | +| [4.0-dev][4.0] | [3.1][3.1] | [2.13][2.13] | |:----------------:|:----------:|:----------:| -| [![GitHub Actions][GA 4.0 image]][GA 4.0] | [![GitHub Actions][GA 3.0 image]][GA 3.0] | [![GitHub Actions][GA 2.13 image]][GA 2.13] | -| [![AppVeyor][AppVeyor 4.0 image]][AppVeyor 4.0] | [![AppVeyor][AppVeyor 3.0 image]][AppVeyor 3.0] | [![AppVeyor][AppVeyor 2.13 image]][AppVeyor 2.13] | -| [![Code Coverage][Coverage image]][CodeCov 4.0] | [![Code Coverage][Coverage 3.0 image]][CodeCov 3.0] | [![Code Coverage][Coverage 2.13 image]][CodeCov 2.13] | +| [![GitHub Actions][GA 4.0 image]][GA 4.0] | [![GitHub Actions][GA 3.1 image]][GA 3.1] | [![GitHub Actions][GA 2.13 image]][GA 2.13] | +| [![AppVeyor][AppVeyor 4.0 image]][AppVeyor 4.0] | [![AppVeyor][AppVeyor 3.1 image]][AppVeyor 3.1] | [![AppVeyor][AppVeyor 2.13 image]][AppVeyor 2.13] | +| [![Code Coverage][Coverage image]][CodeCov 4.0] | [![Code Coverage][Coverage 3.1 image]][CodeCov 3.1] | [![Code Coverage][Coverage 2.13 image]][CodeCov 2.13] | | N/A | [![Code Coverage][TypeCov 3.1 image]][TypeCov 3.1] | N/A | Powerful database abstraction layer with many features for database schema introspection, schema management and PDO abstraction. @@ -23,13 +23,13 @@ Powerful database abstraction layer with many features for database schema intro [GA 4.0]: https://github.com/doctrine/dbal/actions?query=workflow%3A%22Continuous+Integration%22+branch%3A4.0.x [GA 4.0 image]: https://github.com/doctrine/dbal/workflows/Continuous%20Integration/badge.svg - [Coverage 3.0 image]: https://codecov.io/gh/doctrine/dbal/branch/3.0.x/graph/badge.svg - [3.0]: https://github.com/doctrine/dbal/tree/3.0.x - [CodeCov 3.0]: https://codecov.io/gh/doctrine/dbal/branch/3.0.x - [AppVeyor 3.0]: https://ci.appveyor.com/project/doctrine/dbal/branch/3.0.x - [AppVeyor 3.0 image]: https://ci.appveyor.com/api/projects/status/i88kitq8qpbm0vie/branch/3.0.x?svg=true - [GA 3.0]: https://github.com/doctrine/dbal/actions?query=workflow%3A%22Continuous+Integration%22+branch%3A3.0.x - [GA 3.0 image]: https://github.com/doctrine/dbal/workflows/Continuous%20Integration/badge.svg?branch=3.0.x + [Coverage 3.1 image]: https://codecov.io/gh/doctrine/dbal/branch/3.1.x/graph/badge.svg + [3.1]: https://github.com/doctrine/dbal/tree/3.1.x + [CodeCov 3.1]: https://codecov.io/gh/doctrine/dbal/branch/3.1.x + [AppVeyor 3.1]: https://ci.appveyor.com/project/doctrine/dbal/branch/3.1.x + [AppVeyor 3.1 image]: https://ci.appveyor.com/api/projects/status/i88kitq8qpbm0vie/branch/3.1.x?svg=true + [GA 3.1]: https://github.com/doctrine/dbal/actions?query=workflow%3A%22Continuous+Integration%22+branch%3A3.1.x + [GA 3.1 image]: https://github.com/doctrine/dbal/workflows/Continuous%20Integration/badge.svg?branch=3.1.x [Coverage 2.13 image]: https://codecov.io/gh/doctrine/dbal/branch/2.13.x/graph/badge.svg [2.13]: https://github.com/doctrine/dbal/tree/2.13.x From cf258128d73ba94ca10fb4274ee45a4929648309 Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Thu, 29 Apr 2021 09:56:16 +0200 Subject: [PATCH 3/3] Support Doctrine Cache 2 --- composer.json | 3 ++- .../Tests/DBAL/Functional/ConnectionTest.php | 21 ++++++++++++++-- .../Tests/DBAL/Functional/ResultCacheTest.php | 25 ++++++++++++++++--- 3 files changed, 42 insertions(+), 7 deletions(-) diff --git a/composer.json b/composer.json index fff4319797f..4fa76294ba7 100644 --- a/composer.json +++ b/composer.json @@ -34,7 +34,7 @@ "require": { "php": "^7.1 || ^8", "ext-pdo": "*", - "doctrine/cache": "^1.0", + "doctrine/cache": "^1.0|^2.0", "doctrine/deprecations": "^0.5.3", "doctrine/event-manager": "^1.0" }, @@ -44,6 +44,7 @@ "phpstan/phpstan": "0.12.81", "phpunit/phpunit": "^7.5.20|^8.5|9.5.0", "squizlabs/php_codesniffer": "3.6.0", + "symfony/cache": "^4.4", "symfony/console": "^2.0.5|^3.0|^4.0|^5.0", "vimeo/psalm": "4.6.4" }, diff --git a/tests/Doctrine/Tests/DBAL/Functional/ConnectionTest.php b/tests/Doctrine/Tests/DBAL/Functional/ConnectionTest.php index 61128bdf6bd..b1423f353ac 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/ConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/ConnectionTest.php @@ -3,6 +3,8 @@ namespace Doctrine\Tests\DBAL\Functional; use Doctrine\Common\Cache\ArrayCache; +use Doctrine\Common\Cache\Cache; +use Doctrine\Common\Cache\Psr6\DoctrineProvider; use Doctrine\DBAL\Cache\QueryCacheProfile; use Doctrine\DBAL\Connection; use Doctrine\DBAL\ConnectionException; @@ -19,8 +21,10 @@ use Exception; use PDO; use RuntimeException; +use Symfony\Component\Cache\Adapter\ArrayAdapter; use Throwable; +use function class_exists; use function file_exists; use function in_array; use function unlink; @@ -389,7 +393,7 @@ public function testResultCompatibilityWhenExecutingQueryWithQueryCacheParam(): $this->connection->getDatabasePlatform()->getDummySelectSQL(), [], [], - new QueryCacheProfile(1, 'cacheKey', new ArrayCache()) + new QueryCacheProfile(1, 'cacheKey', $this->getArrayCache()) ); self::assertInstanceOf(Result::class, $result); @@ -402,10 +406,23 @@ public function testResultCompatibilityWhenExecutingCacheQuery(): void $this->connection->getDatabasePlatform()->getDummySelectSQL(), [], [], - new QueryCacheProfile(1, 'cacheKey', new ArrayCache()) + new QueryCacheProfile(1, 'cacheKey', $this->getArrayCache()) ); self::assertInstanceOf(Result::class, $result); self::assertInstanceOf(Driver\ResultStatement::class, $result); } + + private function getArrayCache(): Cache + { + if (class_exists(DoctrineProvider::class)) { + return DoctrineProvider::wrap(new ArrayAdapter()); + } + + if (class_exists(ArrayCache::class)) { + return new ArrayCache(); + } + + self::fail('Cannot instantiate cache backend.'); + } } diff --git a/tests/Doctrine/Tests/DBAL/Functional/ResultCacheTest.php b/tests/Doctrine/Tests/DBAL/Functional/ResultCacheTest.php index f2e12203343..66113557ec5 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/ResultCacheTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/ResultCacheTest.php @@ -3,17 +3,21 @@ namespace Doctrine\Tests\DBAL\Functional; use Doctrine\Common\Cache\ArrayCache; +use Doctrine\Common\Cache\Cache; +use Doctrine\Common\Cache\Psr6\DoctrineProvider; use Doctrine\DBAL\Cache\QueryCacheProfile; use Doctrine\DBAL\Driver; use Doctrine\DBAL\FetchMode; use Doctrine\DBAL\Logging\DebugStack; use Doctrine\DBAL\Schema\Table; use Doctrine\Tests\DbalFunctionalTestCase; +use Symfony\Component\Cache\Adapter\ArrayAdapter; use function array_change_key_case; use function array_merge; use function array_shift; use function array_values; +use function class_exists; use function is_array; use const CASE_LOWER; @@ -49,7 +53,7 @@ protected function setUp(): void $config = $this->connection->getConfiguration(); $config->setSQLLogger($this->sqlLogger = new DebugStack()); - $cache = new ArrayCache(); + $cache = $this->getArrayCache(); $config->setResultCacheImpl($cache); } @@ -217,7 +221,7 @@ public function testDontFinishNoCache(): void */ public function testFetchingAllRowsSavesCache(callable $fetchAll): void { - $layerCache = new ArrayCache(); + $layerCache = $this->getArrayCache(); $stmt = $this->connection->executeQuery( 'SELECT * FROM caching WHERE test_int > 500', @@ -266,7 +270,7 @@ public function testFetchAllColumn(): void $query = $this->connection->getDatabasePlatform() ->getDummySelectSQL('1'); - $qcp = new QueryCacheProfile(0, null, new ArrayCache()); + $qcp = new QueryCacheProfile(0, null, $this->getArrayCache()); $stmt = $this->connection->executeCacheQuery($query, [], [], $qcp); $stmt->fetchAll(FetchMode::COLUMN); @@ -339,7 +343,7 @@ public function testChangeCacheImpl(): void $this->hydrateStmt($stmt); - $secondCache = new ArrayCache(); + $secondCache = $this->getArrayCache(); $stmt = $this->connection->executeQuery( 'SELECT * FROM caching WHERE test_int > 500', @@ -381,4 +385,17 @@ private function hydrateStmtIterator(Driver\ResultStatement $stmt, int $fetchMod return $data; } + + private function getArrayCache(): Cache + { + if (class_exists(DoctrineProvider::class)) { + return DoctrineProvider::wrap(new ArrayAdapter()); + } + + if (class_exists(ArrayCache::class)) { + return new ArrayCache(); + } + + self::fail('Cannot instantiate cache backend.'); + } }