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..85f58f30c 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": "^3.6 || ^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..7a1f49d54 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": "0b7f9b297f300c099b209a9078cda708", "packages": [ { "name": "aeon-php/calendar", @@ -183,16 +183,16 @@ }, { "name": "doctrine/cache", - "version": "2.2.0", + "version": "1.12.0", "source": { "type": "git", "url": "https://github.com/doctrine/cache.git", - "reference": "1ca8f21980e770095a31456042471a57bc4c68fb" + "reference": "92032beb419568d3b61ae645f48bbb693cc7e00e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/cache/zipball/1ca8f21980e770095a31456042471a57bc4c68fb", - "reference": "1ca8f21980e770095a31456042471a57bc4c68fb", + "url": "https://api.github.com/repos/doctrine/cache/zipball/92032beb419568d3b61ae645f48bbb693cc7e00e", + "reference": "92032beb419568d3b61ae645f48bbb693cc7e00e", "shasum": "" }, "require": { @@ -202,12 +202,18 @@ "doctrine/common": ">2.2,<2.4" }, "require-dev": { + "alcaeus/mongo-php-adapter": "^1.1", "cache/integration-tests": "dev-master", - "doctrine/coding-standard": "^9", - "phpunit/phpunit": "^7.5 || ^8.5 || ^9.5", + "doctrine/coding-standard": "^8.0", + "mongodb/mongodb": "^1.1", + "phpunit/phpunit": "^7.0 || ^8.0 || ^9.0", + "predis/predis": "~1.0", "psr/cache": "^1.0 || ^2.0 || ^3.0", - "symfony/cache": "^4.4 || ^5.4 || ^6", - "symfony/var-exporter": "^4.4 || ^5.4 || ^6" + "symfony/cache": "^4.4 || ^5.2 || ^6.0@dev", + "symfony/var-exporter": "^4.4 || ^5.2 || ^6.0@dev" + }, + "suggest": { + "alcaeus/mongo-php-adapter": "Required to use legacy MongoDB driver" }, "type": "library", "autoload": { @@ -256,7 +262,7 @@ ], "support": { "issues": "https://github.com/doctrine/cache/issues", - "source": "https://github.com/doctrine/cache/tree/2.2.0" + "source": "https://github.com/doctrine/cache/tree/1.12.0" }, "funding": [ { @@ -272,20 +278,20 @@ "type": "tidelift" } ], - "time": "2022-05-20T20:07:39+00:00" + "time": "2021-07-14T11:09:49+00:00" }, { "name": "doctrine/dbal", - "version": "3.8.0", + "version": "3.6.0", "source": { "type": "git", "url": "https://github.com/doctrine/dbal.git", - "reference": "d244f2e6e6bf32bff5174e6729b57214923ecec9" + "reference": "85b98cb23c8af471a67abfe14485da696bcabc2e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/dbal/zipball/d244f2e6e6bf32bff5174e6729b57214923ecec9", - "reference": "d244f2e6e6bf32bff5174e6729b57214923ecec9", + "url": "https://api.github.com/repos/doctrine/dbal/zipball/85b98cb23c8af471a67abfe14485da696bcabc2e", + "reference": "85b98cb23c8af471a67abfe14485da696bcabc2e", "shasum": "" }, "require": { @@ -298,17 +304,16 @@ "psr/log": "^1|^2|^3" }, "require-dev": { - "doctrine/coding-standard": "12.0.0", + "doctrine/coding-standard": "11.1.0", "fig/log-test": "^1", - "jetbrains/phpstorm-stubs": "2023.1", - "phpstan/phpstan": "1.10.56", - "phpstan/phpstan-strict-rules": "^1.5", - "phpunit/phpunit": "9.6.15", + "jetbrains/phpstorm-stubs": "2022.3", + "phpstan/phpstan": "1.9.14", + "phpstan/phpstan-strict-rules": "^1.4", + "phpunit/phpunit": "9.6.3", "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", + "squizlabs/php_codesniffer": "3.7.1", + "symfony/cache": "^5.4|^6.0", + "symfony/console": "^4.4|^5.4|^6.0", "vimeo/psalm": "4.30.0" }, "suggest": { @@ -369,7 +374,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/3.6.0" }, "funding": [ { @@ -385,7 +390,7 @@ "type": "tidelift" } ], - "time": "2024-01-25T21:44:02+00:00" + "time": "2023-02-07T22:52:03+00:00" }, { "name": "doctrine/deprecations", @@ -436,34 +441,37 @@ }, { "name": "doctrine/event-manager", - "version": "2.0.0", + "version": "1.1.1", "source": { "type": "git", "url": "https://github.com/doctrine/event-manager.git", - "reference": "750671534e0241a7c50ea5b43f67e23eb5c96f32" + "reference": "41370af6a30faa9dc0368c4a6814d596e81aba7f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/event-manager/zipball/750671534e0241a7c50ea5b43f67e23eb5c96f32", - "reference": "750671534e0241a7c50ea5b43f67e23eb5c96f32", + "url": "https://api.github.com/repos/doctrine/event-manager/zipball/41370af6a30faa9dc0368c4a6814d596e81aba7f", + "reference": "41370af6a30faa9dc0368c4a6814d596e81aba7f", "shasum": "" }, "require": { - "php": "^8.1" + "php": "^7.1 || ^8.0" }, "conflict": { - "doctrine/common": "<2.9" + "doctrine/common": "<2.9@dev" }, "require-dev": { - "doctrine/coding-standard": "^10", - "phpstan/phpstan": "^1.8.8", - "phpunit/phpunit": "^9.5", - "vimeo/psalm": "^4.28" + "doctrine/coding-standard": "^6.0", + "phpunit/phpunit": "^7.0" }, "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, "autoload": { "psr-4": { - "Doctrine\\Common\\": "src" + "Doctrine\\Common\\": "lib/Doctrine/Common" } }, "notification-url": "https://packagist.org/downloads/", @@ -507,7 +515,7 @@ ], "support": { "issues": "https://github.com/doctrine/event-manager/issues", - "source": "https://github.com/doctrine/event-manager/tree/2.0.0" + "source": "https://github.com/doctrine/event-manager/tree/1.1.x" }, "funding": [ { @@ -523,7 +531,7 @@ "type": "tidelift" } ], - "time": "2022-10-12T20:59:15+00:00" + "time": "2020-05-29T18:28:51+00:00" }, { "name": "elastic/transport", @@ -5445,7 +5453,7 @@ "minimum-stability": "dev", "stability-flags": [], "prefer-stable": true, - "prefer-lowest": false, + "prefer-lowest": true, "platform": { "php": "~8.1.0 || ~8.2.0 || ~8.3.0", "ext-bcmath": "*", 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..86b874ac9 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": "^3.6 || ^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..9f8c0480f 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) { @@ -61,7 +61,6 @@ public function extract(FlowContext $context) : \Generator if (\method_exists($countQuery, 'resetOrderBy')) { $countQuery->resetOrderBy(); } else { - /** @psalm-suppress DeprecatedMethod */ $countQuery->resetQueryPart('orderBy'); } 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..322c45797 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 $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 $types */ public static function single(Connection $connection, string $query, array $parameters = [], array $types = []) : self { @@ -42,6 +40,11 @@ public static function single(Connection $connection, string $query, array $para public function extract(FlowContext $context) : \Generator { foreach ($this->parametersSet->all() as $parameters) { + /** + * @phpstan-ignore-next-line + * + * @psalm-suppress InvalidArgument + */ foreach ($this->connection->fetchAllAssociative($this->query, $parameters, $this->types) as $row) { $signal = yield array_to_rows($row, $context->entryFactory()); 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..780880406 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,15 @@ 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 + private readonly string $queryParamName, + private readonly mixed $value, + private readonly int|ArrayParameterType|null $type = null ) { } @@ -25,7 +26,7 @@ public function toQueryParam(Rows $rows) : mixed return $this->value; } - public function type() : ?int + public function type() : int|ArrayParameterType|null { return $this->type; } 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..208f40ede 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 @@ -11,9 +11,9 @@ final class Parameter implements QueryParameter { public function __construct( - public readonly string $queryParamName, - public readonly EntryReference $ref, - public readonly int $type = ArrayParameterType::STRING, + private readonly string $queryParamName, + private readonly EntryReference $ref, + private readonly int|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() : int|ArrayParameterType|null { 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..e5d1480e8 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() : int|ArrayParameterType|null; } 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..a385e7db7 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 $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 $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..2d7986405 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->tablesExist([$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..155e6af72 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": "^3.6 || ^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..0b0b4db83 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,6 @@ use Doctrine\DBAL\Platforms\MariaDBPlatform; use Doctrine\DBAL\Platforms\MySQLPlatform; use Doctrine\DBAL\Platforms\PostgreSQLPlatform; -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 +58,6 @@ private function isPostgreSQL() : bool private function isSqlite() : bool { - return $this->platform instanceof SqlitePlatform; + return \in_array($this->platform::class, ['Doctrine\DBAL\Platforms\SqlitePlatform', 'Doctrine\DBAL\Platforms\SQLitePlatform'], true); } } 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..b7f80f27d 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,9 +23,9 @@ 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('updated_at', Type::getType(Types::DATETIME_MUTABLE), ['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..c4352e2d5 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 @@ -25,22 +25,22 @@ public function test_inserts_multiple_rows_at_once() : void new Column('name', Type::getType(Types::STRING), ['notnull' => true, 'length' => 255]), new Column('description', Type::getType(Types::STRING), ['notnull' => false]), new Column('active', Type::getType(Types::BOOLEAN), ['notnull' => true]), - new Column('updated_at', Type::getType(Types::DATETIME_IMMUTABLE), ['notnull' => true]), + new Column('updated_at', Type::getType(Types::DATETIME_MUTABLE), ['notnull' => true]), new Column('tags', Type::getType(Types::JSON), ['notnull' => true, 'platformOptions' => ['jsonb' => true]]), ], )) ->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..1f0fa9680 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 @@ -26,7 +26,7 @@ public function test_update_multiple_rows_with_all_columns_and_multiple_primary_ new Column('name', Type::getType(Types::STRING), ['notnull' => true, 'length' => 255]), new Column('description', Type::getType(Types::STRING), ['notnull' => true, 'length' => 255]), new Column('active', Type::getType(Types::BOOLEAN), ['notnull' => true]), - new Column('created_at', Type::getType(Types::DATETIME_IMMUTABLE), ['notnull' => true]), + new Column('created_at', Type::getType(Types::DATETIME_MUTABLE), ['notnull' => true]), ], )) ->setPrimaryKey(['id', 'account']) @@ -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..8e8a7f6f1 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 @@ -25,7 +25,7 @@ public function test_inserts_multiple_rows_at_once() : void new Column('name', Type::getType(Types::STRING), ['notnull' => true, 'length' => 255]), new Column('description', Type::getType(Types::STRING), ['notnull' => false]), new Column('active', Type::getType(Types::BOOLEAN), ['notnull' => true]), - new Column('updated_at', Type::getType(Types::DATETIME_IMMUTABLE), ['notnull' => true]), + new Column('updated_at', Type::getType(Types::DATETIME_MUTABLE), ['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/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..63a13454c 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,6 @@ use Doctrine\DBAL\Platforms\MySQL80Platform; use Doctrine\DBAL\Platforms\OraclePlatform; use Doctrine\DBAL\Platforms\PostgreSQLPlatform; -use Doctrine\DBAL\Platforms\SqlitePlatform; use Flow\Doctrine\Bulk\DbalPlatform; use Flow\Doctrine\Bulk\Dialect\MySQLDialect; use Flow\Doctrine\Bulk\Dialect\PostgreSQLDialect; @@ -16,6 +15,12 @@ final class DbalPlatformTest extends TestCase { + public static function provideSQLitePlatform() : iterable + { + yield 'legacy' => ['Doctrine\DBAL\Platforms\SqlitePlatform']; + yield 'new' => ['Doctrine\DBAL\Platforms\SQLitePlatform']; + } + public function test_is_mysql() : void { $platform = new DbalPlatform(new MySQL80Platform()); @@ -37,9 +42,16 @@ public function test_is_postgres_sql() : void $this->assertInstanceOf(PostgreSQLDialect::class, $platform->dialect()); } - public function test_is_sqlite_sql() : void + /** + * @dataProvider provideSQLitePlatform + */ + public function test_is_sqlite_sql(string $className) : void { - $platform = new DbalPlatform(new SqlitePlatform()); + if (\class_exists($className)) { + $platform = new DbalPlatform(new $className()); + } else { + $this->markTestSkipped('Unknown platform class: ' . $className); + } $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()) ); }