From 89fd916c4b85a54bfc471876e349efb22b641225 Mon Sep 17 00:00:00 2001 From: Joseph Bielawski Date: Thu, 8 Feb 2024 17:29:12 +0100 Subject: [PATCH] Support Doctrine DBAL 4, drop support for version 3.x --- .github/workflows/test-suite.yml | 4 +- composer.json | 2 +- composer.lock | 219 ++---------------- phpunit.xml | 2 +- .../etl-adapter-doctrine/composer.json | 1 + .../Adapter/Doctrine/DbalDataFrameFactory.php | 1 + .../Doctrine/DbalLimitOffsetExtractor.php | 10 +- .../Adapter/Doctrine/DbalQueryExtractor.php | 10 +- .../ETL/Adapter/Doctrine/LiteralParameter.php | 8 +- .../Flow/ETL/Adapter/Doctrine/Parameter.php | 4 +- .../ETL/Adapter/Doctrine/QueryParameter.php | 6 +- .../Flow/ETL/Adapter/Doctrine/functions.php | 10 +- .../src/Flow/ETL/DSL/Dbal.php | 6 +- .../Tests/Context/DatabaseContext.php | 30 +-- .../Tests/Context/InsertQueryCounter.php | 24 +- .../Doctrine/Tests/IntegrationTestCase.php | 16 +- src/lib/doctrine-dbal-bulk/composer.json | 2 +- .../src/Flow/Doctrine/Bulk/BulkData.php | 5 +- .../src/Flow/Doctrine/Bulk/DbalPlatform.php | 4 +- .../Flow/Doctrine/Bulk/TableDefinition.php | 10 +- .../Bulk/Tests/Context/DatabaseContext.php | 2 +- .../Tests/Integration/MySqlBulkInsertTest.php | 8 +- .../Integration/PostgreSqlBulkInsertTest.php | 6 +- .../Integration/PostgreSqlBulkUpdateTest.php | 10 +- .../Integration/SqliteBulkInsertTest.php | 6 +- .../Bulk/Tests/MysqlIntegrationTestCase.php | 3 +- .../Tests/PostgreSqlIntegrationTestCase.php | 3 +- .../Bulk/Tests/SqliteIntegrationTestCase.php | 3 +- .../Doctrine/Bulk/Tests/Unit/BulkDataTest.php | 17 +- .../Bulk/Tests/Unit/DbalPlatformTest.php | 4 +- .../Bulk/Tests/Unit/TableDefinitionTest.php | 6 +- 31 files changed, 132 insertions(+), 310 deletions(-) diff --git a/.github/workflows/test-suite.yml b/.github/workflows/test-suite.yml index 8b6385300..8d4a6fc94 100644 --- a/.github/workflows/test-suite.yml +++ b/.github/workflows/test-suite.yml @@ -210,9 +210,9 @@ jobs: - name: "Test" run: "composer test" env: - PGSQL_DATABASE_URL: postgresql://postgres:postgres@127.0.0.1:${{ job.services.postgres.ports[5432] }}/postgres?serverVersion=11&charset=utf8 + PGSQL_DATABASE_URL: pgsql://postgres:postgres@127.0.0.1:${{ job.services.postgres.ports[5432] }}/postgres?serverVersion=11&charset=utf8 MYSQL_DATABASE_URL: mysql://mysql:mysql@127.0.0.1:${{ job.services.mysql.ports[3306] }}/mysql FLOW_LOCAL_FILESYSTEM_CACHE_DIR: "./var/cache/${{ matrix.php-version }}-${{ matrix.dependencies }}" - name: "Run Examples" - run: "php examples/run.php" \ No newline at end of file + run: "php examples/run.php" diff --git a/composer.json b/composer.json index 9f3a4b863..cdcff9db9 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,7 @@ "ext-zlib": "*", "composer-runtime-api": "^2.1", "coduo/php-humanizer": "^4.0", - "doctrine/dbal": "^3.6", + "doctrine/dbal": "^4.0", "elasticsearch/elasticsearch": "^7.6|^8.0", "flix-tech/avro-php": "~4.2.0 || ~4.3.0", "google/apiclient": "^2.13", diff --git a/composer.lock b/composer.lock index fb03c5e1e..7f8b10684 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "1d0b7c3ac2049a5f683028381583325f", + "content-hash": "d84586442a86d4b042e93ce2755bfddf", "packages": [ { "name": "aeon-php/calendar", @@ -181,142 +181,44 @@ }, "time": "2022-06-07T18:50:44+00:00" }, - { - "name": "doctrine/cache", - "version": "2.2.0", - "source": { - "type": "git", - "url": "https://github.com/doctrine/cache.git", - "reference": "1ca8f21980e770095a31456042471a57bc4c68fb" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/doctrine/cache/zipball/1ca8f21980e770095a31456042471a57bc4c68fb", - "reference": "1ca8f21980e770095a31456042471a57bc4c68fb", - "shasum": "" - }, - "require": { - "php": "~7.1 || ^8.0" - }, - "conflict": { - "doctrine/common": ">2.2,<2.4" - }, - "require-dev": { - "cache/integration-tests": "dev-master", - "doctrine/coding-standard": "^9", - "phpunit/phpunit": "^7.5 || ^8.5 || ^9.5", - "psr/cache": "^1.0 || ^2.0 || ^3.0", - "symfony/cache": "^4.4 || ^5.4 || ^6", - "symfony/var-exporter": "^4.4 || ^5.4 || ^6" - }, - "type": "library", - "autoload": { - "psr-4": { - "Doctrine\\Common\\Cache\\": "lib/Doctrine/Common/Cache" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Guilherme Blanco", - "email": "guilhermeblanco@gmail.com" - }, - { - "name": "Roman Borschel", - "email": "roman@code-factory.org" - }, - { - "name": "Benjamin Eberlei", - "email": "kontakt@beberlei.de" - }, - { - "name": "Jonathan Wage", - "email": "jonwage@gmail.com" - }, - { - "name": "Johannes Schmitt", - "email": "schmittjoh@gmail.com" - } - ], - "description": "PHP Doctrine Cache library is a popular cache implementation that supports many different drivers such as redis, memcache, apc, mongodb and others.", - "homepage": "https://www.doctrine-project.org/projects/cache.html", - "keywords": [ - "abstraction", - "apcu", - "cache", - "caching", - "couchdb", - "memcached", - "php", - "redis", - "xcache" - ], - "support": { - "issues": "https://github.com/doctrine/cache/issues", - "source": "https://github.com/doctrine/cache/tree/2.2.0" - }, - "funding": [ - { - "url": "https://www.doctrine-project.org/sponsorship.html", - "type": "custom" - }, - { - "url": "https://www.patreon.com/phpdoctrine", - "type": "patreon" - }, - { - "url": "https://tidelift.com/funding/github/packagist/doctrine%2Fcache", - "type": "tidelift" - } - ], - "time": "2022-05-20T20:07:39+00:00" - }, { "name": "doctrine/dbal", - "version": "3.8.0", + "version": "4.0.0", "source": { "type": "git", "url": "https://github.com/doctrine/dbal.git", - "reference": "d244f2e6e6bf32bff5174e6729b57214923ecec9" + "reference": "53df8c432978b716a805143eb701436d54ec705e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/dbal/zipball/d244f2e6e6bf32bff5174e6729b57214923ecec9", - "reference": "d244f2e6e6bf32bff5174e6729b57214923ecec9", + "url": "https://api.github.com/repos/doctrine/dbal/zipball/53df8c432978b716a805143eb701436d54ec705e", + "reference": "53df8c432978b716a805143eb701436d54ec705e", "shasum": "" }, "require": { - "composer-runtime-api": "^2", - "doctrine/cache": "^1.11|^2.0", "doctrine/deprecations": "^0.5.3|^1", - "doctrine/event-manager": "^1|^2", - "php": "^7.4 || ^8.0", + "php": "^8.1", "psr/cache": "^1|^2|^3", "psr/log": "^1|^2|^3" }, "require-dev": { "doctrine/coding-standard": "12.0.0", "fig/log-test": "^1", - "jetbrains/phpstorm-stubs": "2023.1", - "phpstan/phpstan": "1.10.56", + "jetbrains/phpstorm-stubs": "2023.2", + "phpstan/phpstan": "1.10.57", + "phpstan/phpstan-phpunit": "1.3.15", "phpstan/phpstan-strict-rules": "^1.5", - "phpunit/phpunit": "9.6.15", + "phpunit/phpunit": "10.5.9", "psalm/plugin-phpunit": "0.18.4", "slevomat/coding-standard": "8.13.1", "squizlabs/php_codesniffer": "3.8.1", - "symfony/cache": "^5.4|^6.0|^7.0", - "symfony/console": "^4.4|^5.4|^6.0|^7.0", - "vimeo/psalm": "4.30.0" + "symfony/cache": "^6.3.8|^7.0", + "symfony/console": "^5.4|^6.3|^7.0", + "vimeo/psalm": "5.16.0" }, "suggest": { "symfony/console": "For helpful console commands such as SQL execution and import of files." }, - "bin": [ - "bin/doctrine-dbal" - ], "type": "library", "autoload": { "psr-4": { @@ -369,7 +271,7 @@ ], "support": { "issues": "https://github.com/doctrine/dbal/issues", - "source": "https://github.com/doctrine/dbal/tree/3.8.0" + "source": "https://github.com/doctrine/dbal/tree/4.0.0" }, "funding": [ { @@ -385,7 +287,7 @@ "type": "tidelift" } ], - "time": "2024-01-25T21:44:02+00:00" + "time": "2024-02-03T19:11:19+00:00" }, { "name": "doctrine/deprecations", @@ -434,97 +336,6 @@ }, "time": "2024-01-30T19:34:25+00:00" }, - { - "name": "doctrine/event-manager", - "version": "2.0.0", - "source": { - "type": "git", - "url": "https://github.com/doctrine/event-manager.git", - "reference": "750671534e0241a7c50ea5b43f67e23eb5c96f32" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/doctrine/event-manager/zipball/750671534e0241a7c50ea5b43f67e23eb5c96f32", - "reference": "750671534e0241a7c50ea5b43f67e23eb5c96f32", - "shasum": "" - }, - "require": { - "php": "^8.1" - }, - "conflict": { - "doctrine/common": "<2.9" - }, - "require-dev": { - "doctrine/coding-standard": "^10", - "phpstan/phpstan": "^1.8.8", - "phpunit/phpunit": "^9.5", - "vimeo/psalm": "^4.28" - }, - "type": "library", - "autoload": { - "psr-4": { - "Doctrine\\Common\\": "src" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Guilherme Blanco", - "email": "guilhermeblanco@gmail.com" - }, - { - "name": "Roman Borschel", - "email": "roman@code-factory.org" - }, - { - "name": "Benjamin Eberlei", - "email": "kontakt@beberlei.de" - }, - { - "name": "Jonathan Wage", - "email": "jonwage@gmail.com" - }, - { - "name": "Johannes Schmitt", - "email": "schmittjoh@gmail.com" - }, - { - "name": "Marco Pivetta", - "email": "ocramius@gmail.com" - } - ], - "description": "The Doctrine Event Manager is a simple PHP event system that was built to be used with the various Doctrine projects.", - "homepage": "https://www.doctrine-project.org/projects/event-manager.html", - "keywords": [ - "event", - "event dispatcher", - "event manager", - "event system", - "events" - ], - "support": { - "issues": "https://github.com/doctrine/event-manager/issues", - "source": "https://github.com/doctrine/event-manager/tree/2.0.0" - }, - "funding": [ - { - "url": "https://www.doctrine-project.org/sponsorship.html", - "type": "custom" - }, - { - "url": "https://www.patreon.com/phpdoctrine", - "type": "patreon" - }, - { - "url": "https://tidelift.com/funding/github/packagist/doctrine%2Fevent-manager", - "type": "tidelift" - } - ], - "time": "2022-10-12T20:59:15+00:00" - }, { "name": "elastic/transport", "version": "v8.8.0", diff --git a/phpunit.xml b/phpunit.xml index 3313d16e7..41b8073f2 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -15,7 +15,7 @@ - + diff --git a/src/adapter/etl-adapter-doctrine/composer.json b/src/adapter/etl-adapter-doctrine/composer.json index 089d952de..4b20a0ffd 100644 --- a/src/adapter/etl-adapter-doctrine/composer.json +++ b/src/adapter/etl-adapter-doctrine/composer.json @@ -14,6 +14,7 @@ ], "require": { "php": "~8.1.0 || ~8.2.0 || ~8.3.0", + "doctrine/dbal": "^4.0", "flow-php/doctrine-dbal-bulk": "^0.5.0 || 1.x-dev", "flow-php/etl": "^0.5.0 || 1.x-dev" }, diff --git a/src/adapter/etl-adapter-doctrine/src/Flow/ETL/Adapter/Doctrine/DbalDataFrameFactory.php b/src/adapter/etl-adapter-doctrine/src/Flow/ETL/Adapter/Doctrine/DbalDataFrameFactory.php index af492288c..3754c5b05 100644 --- a/src/adapter/etl-adapter-doctrine/src/Flow/ETL/Adapter/Doctrine/DbalDataFrameFactory.php +++ b/src/adapter/etl-adapter-doctrine/src/Flow/ETL/Adapter/Doctrine/DbalDataFrameFactory.php @@ -55,6 +55,7 @@ public function from(Rows $rows) : DataFrame } } + /** @psalm-suppress InvalidArgument */ return (new Flow())->extract(\Flow\ETL\Adapter\Doctrine\dbal_from_query($this->connection(), $this->query, $parameters, $types)); } diff --git a/src/adapter/etl-adapter-doctrine/src/Flow/ETL/Adapter/Doctrine/DbalLimitOffsetExtractor.php b/src/adapter/etl-adapter-doctrine/src/Flow/ETL/Adapter/Doctrine/DbalLimitOffsetExtractor.php index 45b1c0ea8..a40a497ad 100644 --- a/src/adapter/etl-adapter-doctrine/src/Flow/ETL/Adapter/Doctrine/DbalLimitOffsetExtractor.php +++ b/src/adapter/etl-adapter-doctrine/src/Flow/ETL/Adapter/Doctrine/DbalLimitOffsetExtractor.php @@ -36,7 +36,7 @@ public static function table( } $queryBuilder = $connection->createQueryBuilder() - ->select($table->columns ?: '*') + ->select(...$table->columns ?: ['*']) ->from($table->name); foreach ($orderBy as $order) { @@ -57,13 +57,7 @@ public function extract(FlowContext $context) : \Generator $total = $this->maximum; } else { $countQuery = (clone $this->queryBuilder)->select('COUNT(*)'); - - if (\method_exists($countQuery, 'resetOrderBy')) { - $countQuery->resetOrderBy(); - } else { - /** @psalm-suppress DeprecatedMethod */ - $countQuery->resetQueryPart('orderBy'); - } + $countQuery->resetOrderBy(); $total = (int) $this->connection->fetchOne( $countQuery->getSQL(), diff --git a/src/adapter/etl-adapter-doctrine/src/Flow/ETL/Adapter/Doctrine/DbalQueryExtractor.php b/src/adapter/etl-adapter-doctrine/src/Flow/ETL/Adapter/Doctrine/DbalQueryExtractor.php index b5f48eb0d..54f458a0c 100644 --- a/src/adapter/etl-adapter-doctrine/src/Flow/ETL/Adapter/Doctrine/DbalQueryExtractor.php +++ b/src/adapter/etl-adapter-doctrine/src/Flow/ETL/Adapter/Doctrine/DbalQueryExtractor.php @@ -5,21 +5,19 @@ namespace Flow\ETL\Adapter\Doctrine; use function Flow\ETL\DSL\array_to_rows; +use Doctrine\DBAL\ArrayParameterType; use Doctrine\DBAL\Connection; +use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Types\Type; use Flow\ETL\Extractor; use Flow\ETL\FlowContext; final class DbalQueryExtractor implements Extractor { - /** - * @var ParametersSet - */ private readonly ParametersSet $parametersSet; /** - * @param null|ParametersSet $parametersSet - * @param array|array $types + * @param array|string, ArrayParameterType|ParameterType|string|Type> $types */ public function __construct( private readonly Connection $connection, @@ -32,7 +30,7 @@ public function __construct( /** * @param array|list $parameters - * @param array|array $types + * @param array|string, ArrayParameterType|ParameterType|string|Type> $types */ public static function single(Connection $connection, string $query, array $parameters = [], array $types = []) : self { diff --git a/src/adapter/etl-adapter-doctrine/src/Flow/ETL/Adapter/Doctrine/LiteralParameter.php b/src/adapter/etl-adapter-doctrine/src/Flow/ETL/Adapter/Doctrine/LiteralParameter.php index 3c3a851dd..00060de00 100644 --- a/src/adapter/etl-adapter-doctrine/src/Flow/ETL/Adapter/Doctrine/LiteralParameter.php +++ b/src/adapter/etl-adapter-doctrine/src/Flow/ETL/Adapter/Doctrine/LiteralParameter.php @@ -4,14 +4,14 @@ namespace Flow\ETL\Adapter\Doctrine; +use Doctrine\DBAL\ArrayParameterType; use Flow\ETL\Rows; final class LiteralParameter implements QueryParameter { public function __construct( public readonly string $queryParamName, - public readonly mixed $value, - public readonly ?int $type = null + public readonly mixed $value ) { } @@ -25,8 +25,8 @@ public function toQueryParam(Rows $rows) : mixed return $this->value; } - public function type() : ?int + public function type() : ?ArrayParameterType { - return $this->type; + return null; } } diff --git a/src/adapter/etl-adapter-doctrine/src/Flow/ETL/Adapter/Doctrine/Parameter.php b/src/adapter/etl-adapter-doctrine/src/Flow/ETL/Adapter/Doctrine/Parameter.php index b1eac6fc5..e94d44919 100644 --- a/src/adapter/etl-adapter-doctrine/src/Flow/ETL/Adapter/Doctrine/Parameter.php +++ b/src/adapter/etl-adapter-doctrine/src/Flow/ETL/Adapter/Doctrine/Parameter.php @@ -13,7 +13,7 @@ final class Parameter implements QueryParameter public function __construct( public readonly string $queryParamName, public readonly EntryReference $ref, - public readonly int $type = ArrayParameterType::STRING, + public readonly ArrayParameterType $type = ArrayParameterType::STRING, ) { } @@ -42,7 +42,7 @@ public function toQueryParam(Rows $rows) : mixed return $rows->reduceToArray($this->ref); } - public function type() : ?int + public function type() : ?ArrayParameterType { return $this->type; } diff --git a/src/adapter/etl-adapter-doctrine/src/Flow/ETL/Adapter/Doctrine/QueryParameter.php b/src/adapter/etl-adapter-doctrine/src/Flow/ETL/Adapter/Doctrine/QueryParameter.php index ce0bea081..636e5e607 100644 --- a/src/adapter/etl-adapter-doctrine/src/Flow/ETL/Adapter/Doctrine/QueryParameter.php +++ b/src/adapter/etl-adapter-doctrine/src/Flow/ETL/Adapter/Doctrine/QueryParameter.php @@ -4,13 +4,17 @@ namespace Flow\ETL\Adapter\Doctrine; +use Doctrine\DBAL\ArrayParameterType; use Flow\ETL\Rows; interface QueryParameter { public function queryParamName() : string; + /** + * @return null|array|bool|float|int|string + */ public function toQueryParam(Rows $rows) : mixed; - public function type() : ?int; + public function type() : ?ArrayParameterType; } diff --git a/src/adapter/etl-adapter-doctrine/src/Flow/ETL/Adapter/Doctrine/functions.php b/src/adapter/etl-adapter-doctrine/src/Flow/ETL/Adapter/Doctrine/functions.php index 9782496ea..883031a0e 100644 --- a/src/adapter/etl-adapter-doctrine/src/Flow/ETL/Adapter/Doctrine/functions.php +++ b/src/adapter/etl-adapter-doctrine/src/Flow/ETL/Adapter/Doctrine/functions.php @@ -4,7 +4,9 @@ namespace Flow\ETL\Adapter\Doctrine; +use Doctrine\DBAL\ArrayParameterType as DbalArrayType; use Doctrine\DBAL\Connection; +use Doctrine\DBAL\ParameterType as DbalParameterType; use Doctrine\DBAL\Query\QueryBuilder; use Doctrine\DBAL\Types\Type as DbalType; use Flow\ETL\DataFrameFactory; @@ -78,10 +80,8 @@ function from_dbal_limit_offset_qb( } /** - * @param Connection $connection - * @param string $query * @param null|ParametersSet $parameters_set - each one parameters array will be evaluated as new query - * @param array|array $types + * @param array|string, DbalArrayType|DbalParameterType|DbalType|string> $types * * @return Extractor */ @@ -100,10 +100,8 @@ function dbal_from_queries( } /** - * @param Connection $connection - * @param string $query * @param array|list $parameters - * @param array|array $types + * @param array|string, DbalArrayType|DbalParameterType|DbalType|string> $types * * @return Extractor */ diff --git a/src/adapter/etl-adapter-doctrine/src/Flow/ETL/DSL/Dbal.php b/src/adapter/etl-adapter-doctrine/src/Flow/ETL/DSL/Dbal.php index 780c8e87f..3440310e0 100644 --- a/src/adapter/etl-adapter-doctrine/src/Flow/ETL/DSL/Dbal.php +++ b/src/adapter/etl-adapter-doctrine/src/Flow/ETL/DSL/Dbal.php @@ -4,7 +4,9 @@ namespace Flow\ETL\DSL; +use Doctrine\DBAL\ArrayParameterType; use Doctrine\DBAL\Connection; +use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Query\QueryBuilder; use Doctrine\DBAL\Types\Type; use Flow\ETL\Adapter\Doctrine\DbalDataFrameFactory; @@ -94,7 +96,7 @@ final public static function from_limit_offset_qb( * @param Connection $connection * @param string $query * @param null|ParametersSet $parameters_set - each one parameters array will be evaluated as new query - * @param array|array $types + * @param array|string, ArrayParameterType|ParameterType|string|Type> $types * * @return Extractor */ @@ -116,7 +118,7 @@ final public static function from_queries( * @param Connection $connection * @param string $query * @param array|list $parameters - * @param array|array $types + * @param array|string, ArrayParameterType|ParameterType|string|Type> $types * * @return Extractor */ diff --git a/src/adapter/etl-adapter-doctrine/tests/Flow/ETL/Adapter/Doctrine/Tests/Context/DatabaseContext.php b/src/adapter/etl-adapter-doctrine/tests/Flow/ETL/Adapter/Doctrine/Tests/Context/DatabaseContext.php index 2c3849558..ca2864f52 100644 --- a/src/adapter/etl-adapter-doctrine/tests/Flow/ETL/Adapter/Doctrine/Tests/Context/DatabaseContext.php +++ b/src/adapter/etl-adapter-doctrine/tests/Flow/ETL/Adapter/Doctrine/Tests/Context/DatabaseContext.php @@ -5,18 +5,14 @@ namespace Flow\ETL\Adapter\Doctrine\Tests\Context; use Doctrine\DBAL\Connection; -use Doctrine\DBAL\Logging\SQLLogger; use Doctrine\DBAL\Schema\Table; final class DatabaseContext { - private readonly SQLLogger $sqlLogger; - - public function __construct(private readonly Connection $connection) - { - $this->sqlLogger = new InsertQueryCounter(); - - $this->connection->getConfiguration()->setSQLLogger($this->sqlLogger); + public function __construct( + private readonly Connection $connection, + private readonly InsertQueryCounter $logger + ) { } public function connection() : Connection @@ -26,11 +22,9 @@ public function connection() : Connection public function createTable(Table $table) : void { - $schemaManager = $this - ->connection - ->getSchemaManager(); + $schemaManager = $this->connection->createSchemaManager(); - if ($schemaManager->tablesExist($table->getName())) { + if ($schemaManager->tableExists($table->getName())) { $schemaManager->dropTable($table->getName()); } @@ -39,8 +33,10 @@ public function createTable(Table $table) : void public function dropAllTables() : void { - foreach ($this->connection->getSchemaManager()->listTables() as $table) { - $this->connection->getSchemaManager()->dropTable($table->getName()); + $schemaManager = $this->connection->createSchemaManager(); + + foreach ($schemaManager->listTables() as $table) { + $schemaManager->dropTable($table->getName()); } } @@ -51,11 +47,7 @@ public function insert(string $tableName, array $data, array $types = []) : void public function numberOfExecutedInsertQueries() : int { - if ($this->sqlLogger instanceof InsertQueryCounter) { - return $this->sqlLogger->count; - } - - return 0; + return $this->logger->count; } public function selectAll(string $tableName) : array diff --git a/src/adapter/etl-adapter-doctrine/tests/Flow/ETL/Adapter/Doctrine/Tests/Context/InsertQueryCounter.php b/src/adapter/etl-adapter-doctrine/tests/Flow/ETL/Adapter/Doctrine/Tests/Context/InsertQueryCounter.php index f6b8312b9..211ebb01d 100644 --- a/src/adapter/etl-adapter-doctrine/tests/Flow/ETL/Adapter/Doctrine/Tests/Context/InsertQueryCounter.php +++ b/src/adapter/etl-adapter-doctrine/tests/Flow/ETL/Adapter/Doctrine/Tests/Context/InsertQueryCounter.php @@ -4,20 +4,30 @@ namespace Flow\ETL\Adapter\Doctrine\Tests\Context; -use Doctrine\DBAL\Logging\SQLLogger; +use Psr\Log\AbstractLogger; +use Psr\Log\LoggerAwareInterface; +use Psr\Log\LoggerAwareTrait; +use Psr\Log\NullLogger; -final class InsertQueryCounter implements SQLLogger +final class InsertQueryCounter extends AbstractLogger implements LoggerAwareInterface { + use LoggerAwareTrait; + public int $count = 0; - public function startQuery($sql, ?array $params = null, ?array $types = null) : void + public function __construct() { - if (\stripos(\trim($sql), 'INSERT') === 0) { - $this->count++; - } + $this->logger = new NullLogger(); } - public function stopQuery() : void + public function log($level, $message, array $context = []) : void { + if (!isset($context['sql'])) { + return; + } + + if (\str_starts_with(\trim($context['sql']), 'INSERT')) { + $this->count++; + } } } diff --git a/src/adapter/etl-adapter-doctrine/tests/Flow/ETL/Adapter/Doctrine/Tests/IntegrationTestCase.php b/src/adapter/etl-adapter-doctrine/tests/Flow/ETL/Adapter/Doctrine/Tests/IntegrationTestCase.php index f35aa1cd8..25181e8b3 100644 --- a/src/adapter/etl-adapter-doctrine/tests/Flow/ETL/Adapter/Doctrine/Tests/IntegrationTestCase.php +++ b/src/adapter/etl-adapter-doctrine/tests/Flow/ETL/Adapter/Doctrine/Tests/IntegrationTestCase.php @@ -4,8 +4,12 @@ namespace Flow\ETL\Adapter\Doctrine\Tests; +use Doctrine\DBAL\Configuration; use Doctrine\DBAL\DriverManager; +use Doctrine\DBAL\Logging\Middleware; +use Doctrine\DBAL\Tools\DsnParser; use Flow\ETL\Adapter\Doctrine\Tests\Context\DatabaseContext; +use Flow\ETL\Adapter\Doctrine\Tests\Context\InsertQueryCounter; use PHPUnit\Framework\TestCase; abstract class IntegrationTestCase extends TestCase @@ -14,7 +18,15 @@ abstract class IntegrationTestCase extends TestCase protected function setUp() : void { - $this->pgsqlDatabaseContext = new DatabaseContext(DriverManager::getConnection($this->connectionParams())); + $logger = new InsertQueryCounter(); + + $this->pgsqlDatabaseContext = new DatabaseContext( + DriverManager::getConnection( + $this->connectionParams(), + (new Configuration())->setMiddlewares([new Middleware($logger)]) + ), + $logger + ); } protected function tearDown() : void @@ -24,6 +36,6 @@ protected function tearDown() : void protected function connectionParams() : array { - return ['url' => \getenv('PGSQL_DATABASE_URL')]; + return (new DsnParser(['postgresql' => 'pdo_pgsql']))->parse(\getenv('PGSQL_DATABASE_URL') ?: ''); } } diff --git a/src/lib/doctrine-dbal-bulk/composer.json b/src/lib/doctrine-dbal-bulk/composer.json index 6c8f27719..83bee1b81 100644 --- a/src/lib/doctrine-dbal-bulk/composer.json +++ b/src/lib/doctrine-dbal-bulk/composer.json @@ -12,7 +12,7 @@ ], "require": { "php": "~8.1.0 || ~8.2.0 || ~8.3.0", - "doctrine/dbal": "^3.6" + "doctrine/dbal": "^4.0" }, "autoload": { "psr-4": { diff --git a/src/lib/doctrine-dbal-bulk/src/Flow/Doctrine/Bulk/BulkData.php b/src/lib/doctrine-dbal-bulk/src/Flow/Doctrine/Bulk/BulkData.php index 58b8b109f..bb9fca015 100644 --- a/src/lib/doctrine-dbal-bulk/src/Flow/Doctrine/Bulk/BulkData.php +++ b/src/lib/doctrine-dbal-bulk/src/Flow/Doctrine/Bulk/BulkData.php @@ -4,6 +4,7 @@ namespace Flow\Doctrine\Bulk; +use Doctrine\DBAL\Types\Type; use Doctrine\DBAL\Types\Types; use Flow\Doctrine\Bulk\Exception\RuntimeException; @@ -109,8 +110,6 @@ public function sqlRows() : array * ] * * @return array - * - * @psalm-suppress DeprecatedMethod */ public function toSqlParameters(TableDefinition $table) : array { @@ -122,7 +121,7 @@ public function toSqlParameters(TableDefinition $table) : array */ foreach ($row as $column => $entry) { $rows[$index][$column . '_' . $index] = match (\gettype($entry)) { - 'string' => match ($table->dbalColumn($column)->getType()->getName()) { + 'string' => match (Type::getTypeRegistry()->lookupName($table->dbalColumn($column)->getType())) { Types::JSON, 'json_array' => \json_decode($entry, true, 512, JSON_THROW_ON_ERROR), Types::DATETIME_IMMUTABLE, Types::DATETIMETZ_IMMUTABLE, diff --git a/src/lib/doctrine-dbal-bulk/src/Flow/Doctrine/Bulk/DbalPlatform.php b/src/lib/doctrine-dbal-bulk/src/Flow/Doctrine/Bulk/DbalPlatform.php index 39a59533f..d95a31f83 100644 --- a/src/lib/doctrine-dbal-bulk/src/Flow/Doctrine/Bulk/DbalPlatform.php +++ b/src/lib/doctrine-dbal-bulk/src/Flow/Doctrine/Bulk/DbalPlatform.php @@ -6,7 +6,7 @@ use Doctrine\DBAL\Platforms\MariaDBPlatform; use Doctrine\DBAL\Platforms\MySQLPlatform; use Doctrine\DBAL\Platforms\PostgreSQLPlatform; -use Doctrine\DBAL\Platforms\SqlitePlatform; +use Doctrine\DBAL\Platforms\SQLitePlatform; use Flow\Doctrine\Bulk\Dialect\Dialect; use Flow\Doctrine\Bulk\Dialect\MySQLDialect; use Flow\Doctrine\Bulk\Dialect\PostgreSQLDialect; @@ -59,6 +59,6 @@ private function isPostgreSQL() : bool private function isSqlite() : bool { - return $this->platform instanceof SqlitePlatform; + return $this->platform instanceof SQLitePlatform; } } diff --git a/src/lib/doctrine-dbal-bulk/src/Flow/Doctrine/Bulk/TableDefinition.php b/src/lib/doctrine-dbal-bulk/src/Flow/Doctrine/Bulk/TableDefinition.php index aabf337ac..141de16be 100644 --- a/src/lib/doctrine-dbal-bulk/src/Flow/Doctrine/Bulk/TableDefinition.php +++ b/src/lib/doctrine-dbal-bulk/src/Flow/Doctrine/Bulk/TableDefinition.php @@ -6,6 +6,7 @@ use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Schema\Column; +use Doctrine\DBAL\Types\Type; use Flow\Doctrine\Bulk\Exception\RuntimeException; final class TableDefinition @@ -15,11 +16,8 @@ final class TableDefinition */ private array $columns; - private string $name; - - public function __construct(string $name, Column ...$columns) + public function __construct(private readonly string $name, Column ...$columns) { - $this->name = $name; $this->columns = $columns; } @@ -43,8 +41,6 @@ public function dbalColumn(string $columnName) : Column * @throws RuntimeException * * @return array - * - * @psalm-suppress DeprecatedMethod */ public function dbalTypes(BulkData $bulkData) : array { @@ -54,7 +50,7 @@ public function dbalTypes(BulkData $bulkData) : array $dbColumn = $this->dbalColumn($columnName); for ($i = 0; $i < $bulkData->count(); $i++) { - $types[$columnName . '_' . $i] = $dbColumn->getType()->getName(); + $types[$columnName . '_' . $i] = Type::getTypeRegistry()->lookupName($dbColumn->getType()); } } diff --git a/src/lib/doctrine-dbal-bulk/tests/Flow/Doctrine/Bulk/Tests/Context/DatabaseContext.php b/src/lib/doctrine-dbal-bulk/tests/Flow/Doctrine/Bulk/Tests/Context/DatabaseContext.php index 946f38f85..1fc25151b 100644 --- a/src/lib/doctrine-dbal-bulk/tests/Flow/Doctrine/Bulk/Tests/Context/DatabaseContext.php +++ b/src/lib/doctrine-dbal-bulk/tests/Flow/Doctrine/Bulk/Tests/Context/DatabaseContext.php @@ -22,7 +22,7 @@ public function createTable(Table $table) : void { $schemaManager = $this->connection->createSchemaManager(); - if ($schemaManager->tablesExist($table->getName())) { + if ($schemaManager->tablesExist([$table->getName()])) { $schemaManager->dropTable($table->getName()); } diff --git a/src/lib/doctrine-dbal-bulk/tests/Flow/Doctrine/Bulk/Tests/Integration/MySqlBulkInsertTest.php b/src/lib/doctrine-dbal-bulk/tests/Flow/Doctrine/Bulk/Tests/Integration/MySqlBulkInsertTest.php index 23bb37690..bfa5aae8d 100644 --- a/src/lib/doctrine-dbal-bulk/tests/Flow/Doctrine/Bulk/Tests/Integration/MySqlBulkInsertTest.php +++ b/src/lib/doctrine-dbal-bulk/tests/Flow/Doctrine/Bulk/Tests/Integration/MySqlBulkInsertTest.php @@ -23,7 +23,7 @@ public function test_inserts_multiple_rows_at_once() : void new Column('id', Type::getType(Types::STRING), ['notnull' => true, 'length' => 255]), new Column('age', Type::getType(Types::INTEGER), ['notnull' => true]), new Column('name', Type::getType(Types::STRING), ['notnull' => true, 'length' => 255]), - new Column('description', Type::getType(Types::STRING), ['notnull' => false]), + new Column('description', Type::getType(Types::STRING), ['notnull' => false, 'length' => 255]), new Column('active', Type::getType(Types::BOOLEAN), ['notnull' => true]), new Column('updated_at', Type::getType(Types::DATETIME_IMMUTABLE), ['notnull' => true]), new Column('tags', Type::getType(Types::JSON), ['notnull' => true, 'platformOptions' => ['jsonb' => true]]), @@ -36,9 +36,9 @@ public function test_inserts_multiple_rows_at_once() : void $this->databaseContext->connection(), $table, new BulkData([ - ['id' => $id1 = \bin2hex(\random_bytes(5)), 'age' => 20, 'name' => 'Name One', 'description' => 'Description One', 'active' => false, 'updated_at' => $date1 = new \DateTimeImmutable(), 'tags' => \json_encode(['a', 'b', 'c'])], - ['id' => $id2 = \bin2hex(\random_bytes(5)), 'age' => 30, 'name' => 'Name Two', 'description' => null, 'active' => true, 'updated_at' => $date2 = new \DateTimeImmutable(), 'tags' => \json_encode(['a', 'b', 'c'])], - ['id' => $id3 = \bin2hex(\random_bytes(5)), 'age' => 40, 'name' => 'Name Three', 'description' => 'Description Three', 'active' => false, 'updated_at' => $date3 = new \DateTimeImmutable(), 'tags' => \json_encode(['a', 'b', 'c'])], + ['id' => $id1 = \bin2hex(\random_bytes(5)), 'age' => 20, 'name' => 'Name One', 'description' => 'Description One', 'active' => false, 'updated_at' => $date1 = new \DateTime(), 'tags' => \json_encode(['a', 'b', 'c'])], + ['id' => $id2 = \bin2hex(\random_bytes(5)), 'age' => 30, 'name' => 'Name Two', 'description' => null, 'active' => true, 'updated_at' => $date2 = new \DateTime(), 'tags' => \json_encode(['a', 'b', 'c'])], + ['id' => $id3 = \bin2hex(\random_bytes(5)), 'age' => 40, 'name' => 'Name Three', 'description' => 'Description Three', 'active' => false, 'updated_at' => $date3 = new \DateTime(), 'tags' => \json_encode(['a', 'b', 'c'])], ]) ); diff --git a/src/lib/doctrine-dbal-bulk/tests/Flow/Doctrine/Bulk/Tests/Integration/PostgreSqlBulkInsertTest.php b/src/lib/doctrine-dbal-bulk/tests/Flow/Doctrine/Bulk/Tests/Integration/PostgreSqlBulkInsertTest.php index 87d59b976..d25cbdf87 100644 --- a/src/lib/doctrine-dbal-bulk/tests/Flow/Doctrine/Bulk/Tests/Integration/PostgreSqlBulkInsertTest.php +++ b/src/lib/doctrine-dbal-bulk/tests/Flow/Doctrine/Bulk/Tests/Integration/PostgreSqlBulkInsertTest.php @@ -32,15 +32,15 @@ public function test_inserts_multiple_rows_at_once() : void ->setPrimaryKey(['id']) ); - $date1 = new \DateTimeImmutable(); + $date1 = new \DateTime(); Bulk::create()->insert( $this->databaseContext->connection(), $table, new BulkData([ ['id' => $id1 = \bin2hex(\random_bytes(5)), 'age' => 20, 'name' => 'Name One', 'description' => 'Description One', 'active' => false, 'updated_at' => $date1->format(\DateTimeInterface::ATOM), 'tags' => \json_encode(['a', 'b', 'c'])], - ['id' => $id2 = \bin2hex(\random_bytes(5)), 'age' => 30, 'name' => 'Name Two', 'description' => null, 'active' => true, 'updated_at' => $date2 = new \DateTimeImmutable(), 'tags' => \json_encode(['a', 'b', 'c'])], - ['id' => $id3 = \bin2hex(\random_bytes(5)), 'age' => 40, 'name' => 'Name Three', 'description' => 'Description Three', 'active' => false, 'updated_at' => $date3 = new \DateTimeImmutable(), 'tags' => \json_encode(['a', 'b', 'c'])], + ['id' => $id2 = \bin2hex(\random_bytes(5)), 'age' => 30, 'name' => 'Name Two', 'description' => null, 'active' => true, 'updated_at' => $date2 = new \DateTime(), 'tags' => \json_encode(['a', 'b', 'c'])], + ['id' => $id3 = \bin2hex(\random_bytes(5)), 'age' => 40, 'name' => 'Name Three', 'description' => 'Description Three', 'active' => false, 'updated_at' => $date3 = new \DateTime(), 'tags' => \json_encode(['a', 'b', 'c'])], ]) ); diff --git a/src/lib/doctrine-dbal-bulk/tests/Flow/Doctrine/Bulk/Tests/Integration/PostgreSqlBulkUpdateTest.php b/src/lib/doctrine-dbal-bulk/tests/Flow/Doctrine/Bulk/Tests/Integration/PostgreSqlBulkUpdateTest.php index 2cdd44a69..f0105b03b 100644 --- a/src/lib/doctrine-dbal-bulk/tests/Flow/Doctrine/Bulk/Tests/Integration/PostgreSqlBulkUpdateTest.php +++ b/src/lib/doctrine-dbal-bulk/tests/Flow/Doctrine/Bulk/Tests/Integration/PostgreSqlBulkUpdateTest.php @@ -36,9 +36,9 @@ public function test_update_multiple_rows_with_all_columns_and_multiple_primary_ $this->databaseContext->connection(), $table, new BulkData([ - ['id' => 1, 'account' => 'Bob', 'name' => 'Name One', 'description' => 'Description One', 'active' => false, 'created_at' => new \DateTimeImmutable('2021-01-01 10:00:00')], - ['id' => 2, 'account' => 'Bob', 'name' => 'Name Two', 'description' => 'Description Two', 'active' => true, 'created_at' => new \DateTimeImmutable('2021-01-01 10:00:00')], - ['id' => 3, 'account' => 'Joe', 'name' => 'Name Three', 'description' => 'Description Three', 'active' => false, 'created_at' => new \DateTimeImmutable('2021-01-01 10:00:00')], + ['id' => 1, 'account' => 'Bob', 'name' => 'Name One', 'description' => 'Description One', 'active' => false, 'created_at' => new \DateTime('2021-01-01 10:00:00')], + ['id' => 2, 'account' => 'Bob', 'name' => 'Name Two', 'description' => 'Description Two', 'active' => true, 'created_at' => new \DateTime('2021-01-01 10:00:00')], + ['id' => 3, 'account' => 'Joe', 'name' => 'Name Three', 'description' => 'Description Three', 'active' => false, 'created_at' => new \DateTime('2021-01-01 10:00:00')], ]) ); @@ -46,8 +46,8 @@ public function test_update_multiple_rows_with_all_columns_and_multiple_primary_ $this->databaseContext->connection(), $table, new BulkData([ - ['id' => 2, 'account' => 'Bob', 'name' => 'Changed name Two', 'description' => 'Changed description Two', 'active' => false, 'created_at' => new \DateTimeImmutable('2021-01-02 10:00:00')], - ['id' => 3, 'account' => 'Joe', 'name' => 'Changed name Three', 'description' => 'Changed description Three', 'active' => true, 'created_at' => new \DateTimeImmutable('2021-01-02 20:00:00')], + ['id' => 2, 'account' => 'Bob', 'name' => 'Changed name Two', 'description' => 'Changed description Two', 'active' => false, 'created_at' => new \DateTime('2021-01-02 10:00:00')], + ['id' => 3, 'account' => 'Joe', 'name' => 'Changed name Three', 'description' => 'Changed description Three', 'active' => true, 'created_at' => new \DateTime('2021-01-02 20:00:00')], ]), [ 'primary_key_columns' => [ diff --git a/src/lib/doctrine-dbal-bulk/tests/Flow/Doctrine/Bulk/Tests/Integration/SqliteBulkInsertTest.php b/src/lib/doctrine-dbal-bulk/tests/Flow/Doctrine/Bulk/Tests/Integration/SqliteBulkInsertTest.php index 6edf283c1..0900f36d2 100644 --- a/src/lib/doctrine-dbal-bulk/tests/Flow/Doctrine/Bulk/Tests/Integration/SqliteBulkInsertTest.php +++ b/src/lib/doctrine-dbal-bulk/tests/Flow/Doctrine/Bulk/Tests/Integration/SqliteBulkInsertTest.php @@ -36,9 +36,9 @@ public function test_inserts_multiple_rows_at_once() : void $this->databaseContext->connection(), $table, new BulkData([ - ['id' => $id1 = \bin2hex(\random_bytes(5)), 'age' => 20, 'name' => 'Name One', 'description' => 'Description One', 'active' => false, 'updated_at' => $date1 = new \DateTimeImmutable(), 'tags' => \json_encode(['a', 'b', 'c'])], - ['id' => $id2 = \bin2hex(\random_bytes(5)), 'age' => 30, 'name' => 'Name Two', 'description' => null, 'active' => true, 'updated_at' => $date2 = new \DateTimeImmutable(), 'tags' => \json_encode(['a', 'b', 'c'])], - ['id' => $id3 = \bin2hex(\random_bytes(5)), 'age' => 40, 'name' => 'Name Three', 'description' => 'Description Three', 'active' => false, 'updated_at' => $date3 = new \DateTimeImmutable(), 'tags' => \json_encode(['a', 'b', 'c'])], + ['id' => $id1 = \bin2hex(\random_bytes(5)), 'age' => 20, 'name' => 'Name One', 'description' => 'Description One', 'active' => false, 'updated_at' => $date1 = new \DateTime(), 'tags' => \json_encode(['a', 'b', 'c'])], + ['id' => $id2 = \bin2hex(\random_bytes(5)), 'age' => 30, 'name' => 'Name Two', 'description' => null, 'active' => true, 'updated_at' => $date2 = new \DateTime(), 'tags' => \json_encode(['a', 'b', 'c'])], + ['id' => $id3 = \bin2hex(\random_bytes(5)), 'age' => 40, 'name' => 'Name Three', 'description' => 'Description Three', 'active' => false, 'updated_at' => $date3 = new \DateTime(), 'tags' => \json_encode(['a', 'b', 'c'])], ]) ); diff --git a/src/lib/doctrine-dbal-bulk/tests/Flow/Doctrine/Bulk/Tests/MysqlIntegrationTestCase.php b/src/lib/doctrine-dbal-bulk/tests/Flow/Doctrine/Bulk/Tests/MysqlIntegrationTestCase.php index 34c43b1f7..3ef0c8e6d 100644 --- a/src/lib/doctrine-dbal-bulk/tests/Flow/Doctrine/Bulk/Tests/MysqlIntegrationTestCase.php +++ b/src/lib/doctrine-dbal-bulk/tests/Flow/Doctrine/Bulk/Tests/MysqlIntegrationTestCase.php @@ -7,6 +7,7 @@ use Doctrine\DBAL\Configuration; use Doctrine\DBAL\DriverManager; use Doctrine\DBAL\Logging\Middleware; +use Doctrine\DBAL\Tools\DsnParser; use Flow\Doctrine\Bulk\Tests\Context\DatabaseContext; abstract class MysqlIntegrationTestCase extends IntegrationTestCase @@ -15,7 +16,7 @@ protected function setUp() : void { $this->databaseContext = new DatabaseContext( DriverManager::getConnection( - ['url' => \getenv('MYSQL_DATABASE_URL')], + (new DsnParser(['mysql' => 'pdo_mysql']))->parse(\getenv('MYSQL_DATABASE_URL') ?: ''), (new Configuration())->setMiddlewares([new Middleware($this->logger)]) ) ); diff --git a/src/lib/doctrine-dbal-bulk/tests/Flow/Doctrine/Bulk/Tests/PostgreSqlIntegrationTestCase.php b/src/lib/doctrine-dbal-bulk/tests/Flow/Doctrine/Bulk/Tests/PostgreSqlIntegrationTestCase.php index bb1974740..8b1bad180 100644 --- a/src/lib/doctrine-dbal-bulk/tests/Flow/Doctrine/Bulk/Tests/PostgreSqlIntegrationTestCase.php +++ b/src/lib/doctrine-dbal-bulk/tests/Flow/Doctrine/Bulk/Tests/PostgreSqlIntegrationTestCase.php @@ -7,6 +7,7 @@ use Doctrine\DBAL\Configuration; use Doctrine\DBAL\DriverManager; use Doctrine\DBAL\Logging\Middleware; +use Doctrine\DBAL\Tools\DsnParser; use Flow\Doctrine\Bulk\Tests\Context\DatabaseContext; abstract class PostgreSqlIntegrationTestCase extends IntegrationTestCase @@ -15,7 +16,7 @@ protected function setUp() : void { $this->databaseContext = new DatabaseContext( DriverManager::getConnection( - ['url' => \getenv('PGSQL_DATABASE_URL')], + (new DsnParser(['pgsql' => 'pdo_pgsql']))->parse(\getenv('PGSQL_DATABASE_URL') ?: ''), (new Configuration())->setMiddlewares([new Middleware($this->logger)]) ) ); diff --git a/src/lib/doctrine-dbal-bulk/tests/Flow/Doctrine/Bulk/Tests/SqliteIntegrationTestCase.php b/src/lib/doctrine-dbal-bulk/tests/Flow/Doctrine/Bulk/Tests/SqliteIntegrationTestCase.php index e85e380cc..4217b48f6 100644 --- a/src/lib/doctrine-dbal-bulk/tests/Flow/Doctrine/Bulk/Tests/SqliteIntegrationTestCase.php +++ b/src/lib/doctrine-dbal-bulk/tests/Flow/Doctrine/Bulk/Tests/SqliteIntegrationTestCase.php @@ -7,6 +7,7 @@ use Doctrine\DBAL\Configuration; use Doctrine\DBAL\DriverManager; use Doctrine\DBAL\Logging\Middleware; +use Doctrine\DBAL\Tools\DsnParser; use Flow\Doctrine\Bulk\Tests\Context\DatabaseContext; abstract class SqliteIntegrationTestCase extends IntegrationTestCase @@ -15,7 +16,7 @@ protected function setUp() : void { $this->databaseContext = new DatabaseContext( DriverManager::getConnection( - ['url' => \getenv('SQLITE_DATABASE_URL')], + (new DsnParser(['sqlite' => 'pdo_sqlite']))->parse(\getenv('SQLITE_DATABASE_URL') ?: ''), (new Configuration())->setMiddlewares([new Middleware($this->logger)]) ) ); diff --git a/src/lib/doctrine-dbal-bulk/tests/Flow/Doctrine/Bulk/Tests/Unit/BulkDataTest.php b/src/lib/doctrine-dbal-bulk/tests/Flow/Doctrine/Bulk/Tests/Unit/BulkDataTest.php index be814dc06..9515dce11 100644 --- a/src/lib/doctrine-dbal-bulk/tests/Flow/Doctrine/Bulk/Tests/Unit/BulkDataTest.php +++ b/src/lib/doctrine-dbal-bulk/tests/Flow/Doctrine/Bulk/Tests/Unit/BulkDataTest.php @@ -5,9 +5,8 @@ namespace Flow\Doctrine\Bulk\Tests\Unit; use Doctrine\DBAL\Schema\Column; -use Doctrine\DBAL\Types\IntegerType; -use Doctrine\DBAL\Types\JsonType; -use Doctrine\DBAL\Types\StringType; +use Doctrine\DBAL\Types\Type; +use Doctrine\DBAL\Types\Types; use Flow\Doctrine\Bulk\BulkData; use Flow\Doctrine\Bulk\Columns; use Flow\Doctrine\Bulk\TableDefinition; @@ -83,6 +82,8 @@ public function test_returns_all_sql_parameters_as_one_dimensional_array_with_pl ], ]); + $registry = Type::getTypeRegistry(); + $this->assertEquals( [ 'date_0' => 'today', @@ -99,11 +100,11 @@ public function test_returns_all_sql_parameters_as_one_dimensional_array_with_pl $bulkData->toSqlParameters( new TableDefinition( 'test', - new Column('date', new StringType()), - new Column('title', new StringType()), - new Column('description', new StringType()), - new Column('quantity', new IntegerType()), - new Column('errors', new JsonType()), + new Column('date', $registry->get(Types::STRING)), + new Column('title', $registry->get(Types::STRING)), + new Column('description', $registry->get(Types::STRING)), + new Column('quantity', $registry->get(Types::INTEGER)), + new Column('errors', $registry->get(Types::JSON)), ) ) ); diff --git a/src/lib/doctrine-dbal-bulk/tests/Flow/Doctrine/Bulk/Tests/Unit/DbalPlatformTest.php b/src/lib/doctrine-dbal-bulk/tests/Flow/Doctrine/Bulk/Tests/Unit/DbalPlatformTest.php index 50a7135e0..fbbb54763 100644 --- a/src/lib/doctrine-dbal-bulk/tests/Flow/Doctrine/Bulk/Tests/Unit/DbalPlatformTest.php +++ b/src/lib/doctrine-dbal-bulk/tests/Flow/Doctrine/Bulk/Tests/Unit/DbalPlatformTest.php @@ -6,7 +6,7 @@ use Doctrine\DBAL\Platforms\MySQL80Platform; use Doctrine\DBAL\Platforms\OraclePlatform; use Doctrine\DBAL\Platforms\PostgreSQLPlatform; -use Doctrine\DBAL\Platforms\SqlitePlatform; +use Doctrine\DBAL\Platforms\SQLitePlatform; use Flow\Doctrine\Bulk\DbalPlatform; use Flow\Doctrine\Bulk\Dialect\MySQLDialect; use Flow\Doctrine\Bulk\Dialect\PostgreSQLDialect; @@ -39,7 +39,7 @@ public function test_is_postgres_sql() : void public function test_is_sqlite_sql() : void { - $platform = new DbalPlatform(new SqlitePlatform()); + $platform = new DbalPlatform(new SQLitePlatform()); $this->assertInstanceOf(SqliteDialect::class, $platform->dialect()); } diff --git a/src/lib/doctrine-dbal-bulk/tests/Flow/Doctrine/Bulk/Tests/Unit/TableDefinitionTest.php b/src/lib/doctrine-dbal-bulk/tests/Flow/Doctrine/Bulk/Tests/Unit/TableDefinitionTest.php index 749b27fc5..0f2e90521 100644 --- a/src/lib/doctrine-dbal-bulk/tests/Flow/Doctrine/Bulk/Tests/Unit/TableDefinitionTest.php +++ b/src/lib/doctrine-dbal-bulk/tests/Flow/Doctrine/Bulk/Tests/Unit/TableDefinitionTest.php @@ -4,7 +4,7 @@ namespace Flow\Doctrine\Bulk\Tests\Unit; -use Doctrine\DBAL\Platforms\PostgreSQL100Platform; +use Doctrine\DBAL\Platforms\PostgreSQLPlatform; use Doctrine\DBAL\Schema\Column; use Doctrine\DBAL\Types\Type; use Flow\Doctrine\Bulk\BulkData; @@ -26,13 +26,13 @@ public function test_getting_sql_typed_placeholders() : void $table = new TableDefinition( 'test', new Column('id', Type::getType('integer')), - new Column('name', Type::getType('string')), + new Column('name', Type::getType('string'), ['length' => 255]), new Column('updated_at', Type::getType('datetime_immutable')), ); $this->assertSame( '(CAST(:id_0 as INT),CAST(:name_0 as VARCHAR(255)),CAST(:updated_at_0 as TIMESTAMP(0) WITHOUT TIME ZONE)),(CAST(:id_1 as INT),CAST(:name_1 as VARCHAR(255)),CAST(:updated_at_1 as TIMESTAMP(0) WITHOUT TIME ZONE))', - $table->toSqlCastedPlaceholders($data, new PostgreSQL100Platform()) + $table->toSqlCastedPlaceholders($data, new PostgreSQLPlatform()) ); }