diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 7ef719f..87dc173 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -49,7 +49,7 @@ jobs: - uses: ramsey/composer-install@v2 - # Remark: --prefer-source is needed for "Doctrine\Tests\DBAL\Platforms\AbstractPlatformTestCase" + # Remark: --prefer-source is needed for "Doctrine\DBAL\Tests\Platforms\AbstractPlatformTestCase" - name: Install doctrine/dbal from source run: | rm -rf vendor/doctrine/dbal diff --git a/composer.json b/composer.json index bac9020..c43b1af 100644 --- a/composer.json +++ b/composer.json @@ -16,8 +16,8 @@ "prefer-stable": true, "require": { "php": "^8.0|^8.1|^8.2|^8.3", - "doctrine/dbal": "^2", - "crate/crate-pdo": "^2" + "doctrine/dbal": "^4.0.0", + "crate/crate-pdo": "dev-main" }, "autoload": { "psr-0": { @@ -26,17 +26,28 @@ }, "require-dev": { "phpunit/phpunit": "^9.0", - "squizlabs/php_codesniffer": "^3.5" + "squizlabs/php_codesniffer": "^3.5", + "phpstan/phpstan": "*", + "phpstan/phpstan-deprecation-rules": "^1.2" }, "autoload-dev": { "psr-0": { - "Crate\\Test": "test", - "Doctrine\\Tests": "vendor/doctrine/dbal/tests" + "Crate\\Test": "test" + }, + "psr-4": { + "Doctrine\\DBAL\\Tests\\": "vendor/doctrine/dbal/tests" } }, + "repositories": [{ + "type": "vcs", + "url": "/Users/julianmartin/Projects/crate-pdo" + }], "config": { "preferred-install": { "doctrine/dbal": "source" + }, + "allow-plugins": { + "phpstan/extension-installer": true } }, "scripts": { diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon new file mode 100644 index 0000000..38465a9 --- /dev/null +++ b/phpstan-baseline.neon @@ -0,0 +1,756 @@ +parameters: + ignoreErrors: + - + message: "#^Method Crate\\\\DBAL\\\\Driver\\\\PDOCrate\\\\Driver\\:\\:constructPdoDsn\\(\\) has parameter \\$params with no value type specified in iterable type array\\.$#" + count: 1 + path: src/Crate/DBAL/Driver/PDOCrate/Driver.php + + - + message: "#^Method Crate\\\\DBAL\\\\Driver\\\\PDOCrate\\\\Driver\\:\\:getDatabase\\(\\) should return string but returns null\\.$#" + count: 1 + path: src/Crate/DBAL/Driver/PDOCrate/Driver.php + + - + message: "#^Method Crate\\\\DBAL\\\\Driver\\\\PDOCrate\\\\PDOConnection\\:\\:__construct\\(\\) has parameter \\$options with no value type specified in iterable type array\\.$#" + count: 1 + path: src/Crate/DBAL/Driver/PDOCrate/PDOConnection.php + + - + message: "#^Parameter \\#2 \\$username of method Crate\\\\PDO\\\\PDO\\:\\:__construct\\(\\) expects null, string\\|null given\\.$#" + count: 1 + path: src/Crate/DBAL/Driver/PDOCrate/PDOConnection.php + + - + message: "#^Parameter \\#3 \\$passwd of method Crate\\\\PDO\\\\PDO\\:\\:__construct\\(\\) expects null, string\\|null given\\.$#" + count: 1 + path: src/Crate/DBAL/Driver/PDOCrate/PDOConnection.php + + - + message: "#^Call to an undefined method Doctrine\\\\DBAL\\\\Platforms\\\\AbstractPlatform\\:\\:getTableOptionsSQL\\(\\)\\.$#" + count: 1 + path: src/Crate/DBAL/Schema/CrateSchemaManager.php + + - + message: "#^Cannot access offset 'clustered_by' on array\\\\|false\\.$#" + count: 1 + path: src/Crate/DBAL/Schema/CrateSchemaManager.php + + - + message: "#^Cannot access offset 'column_policy' on array\\\\|false\\.$#" + count: 1 + path: src/Crate/DBAL/Schema/CrateSchemaManager.php + + - + message: "#^Cannot access offset 'number_of_replicas' on array\\\\|false\\.$#" + count: 1 + path: src/Crate/DBAL/Schema/CrateSchemaManager.php + + - + message: "#^Cannot access offset 'number_of_shards' on array\\\\|false\\.$#" + count: 1 + path: src/Crate/DBAL/Schema/CrateSchemaManager.php + + - + message: "#^Cannot access offset 'partitioned_by' on array\\\\|false\\.$#" + count: 1 + path: src/Crate/DBAL/Schema/CrateSchemaManager.php + + - + message: "#^Cannot access offset 'settings' on array\\\\|false\\.$#" + count: 1 + path: src/Crate/DBAL/Schema/CrateSchemaManager.php + + - + message: "#^Method Crate\\\\DBAL\\\\Schema\\\\CrateSchemaManager\\:\\:flatten\\(\\) has parameter \\$array with no value type specified in iterable type array\\.$#" + count: 1 + path: src/Crate/DBAL/Schema/CrateSchemaManager.php + + - + message: "#^Method Crate\\\\DBAL\\\\Schema\\\\CrateSchemaManager\\:\\:flatten\\(\\) return type has no value type specified in iterable type array\\.$#" + count: 1 + path: src/Crate/DBAL/Schema/CrateSchemaManager.php + + - + message: "#^Parameter \\#5 \\$idGeneratorType of class Doctrine\\\\DBAL\\\\Schema\\\\Table constructor expects int, array given\\.$#" + count: 1 + path: src/Crate/DBAL/Schema/CrateSchemaManager.php + + - + message: "#^Method Crate\\\\DBAL\\\\Types\\\\ArrayType\\:\\:getArrayTypeDeclarationSQL\\(\\) has parameter \\$field with no value type specified in iterable type array\\.$#" + count: 1 + path: src/Crate/DBAL/Types/ArrayType.php + + - + message: "#^Method Crate\\\\DBAL\\\\Types\\\\ArrayType\\:\\:getArrayTypeDeclarationSQL\\(\\) has parameter \\$options with no value type specified in iterable type array\\.$#" + count: 1 + path: src/Crate/DBAL/Types/ArrayType.php + + - + message: "#^Method Crate\\\\DBAL\\\\Types\\\\ArrayType\\:\\:getSQLDeclaration\\(\\) has parameter \\$fieldDeclaration with no value type specified in iterable type array\\.$#" + count: 1 + path: src/Crate/DBAL/Types/ArrayType.php + + - + message: "#^Method Crate\\\\DBAL\\\\Types\\\\MapType\\:\\:getMapTypeDeclarationSQL\\(\\) has parameter \\$field with no value type specified in iterable type array\\.$#" + count: 1 + path: src/Crate/DBAL/Types/MapType.php + + - + message: "#^Method Crate\\\\DBAL\\\\Types\\\\MapType\\:\\:getMapTypeDeclarationSQL\\(\\) has parameter \\$options with no value type specified in iterable type array\\.$#" + count: 1 + path: src/Crate/DBAL/Types/MapType.php + + - + message: "#^Method Crate\\\\DBAL\\\\Types\\\\MapType\\:\\:getSQLDeclaration\\(\\) has parameter \\$fieldDeclaration with no value type specified in iterable type array\\.$#" + count: 1 + path: src/Crate/DBAL/Types/MapType.php + + - + message: "#^Method Crate\\\\DBAL\\\\Types\\\\TimestampType\\:\\:getSQLDeclaration\\(\\) has parameter \\$fieldDeclaration with no value type specified in iterable type array\\.$#" + count: 1 + path: src/Crate/DBAL/Types/TimestampType.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\Functional\\\\BindingTestCase\\:\\:testBindNamedParam\\(\\) has no return type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Functional/BindingTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\Functional\\\\BindingTestCase\\:\\:testBindNamedValue\\(\\) has no return type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Functional/BindingTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\Functional\\\\BindingTestCase\\:\\:testBindPositionalParam\\(\\) has no return type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Functional/BindingTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\Functional\\\\BindingTestCase\\:\\:testBindPositionalValue\\(\\) has no return type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Functional/BindingTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\Functional\\\\BindingTestCase\\:\\:testBindTimestamp\\(\\) has no return type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Functional/BindingTest.php + + - + message: "#^Call to an undefined method Doctrine\\\\DBAL\\\\Driver\\\\Connection\\:\\:getAttribute\\(\\)\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Functional/ConnectionTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\Functional\\\\ConnectionTestCase\\:\\:testBasicAuthConnection\\(\\) has no return type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Functional/ConnectionTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\Functional\\\\ConnectionTestCase\\:\\:testConnect\\(\\) has no return type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Functional/ConnectionTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\Functional\\\\ConnectionTestCase\\:\\:testGetConnection\\(\\) has no return type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Functional/ConnectionTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\Functional\\\\ConnectionTestCase\\:\\:testGetDriver\\(\\) has no return type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Functional/ConnectionTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\Functional\\\\ConnectionTestCase\\:\\:testStatement\\(\\) has no return type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Functional/ConnectionTest.php + + - + message: "#^Call to an undefined method Doctrine\\\\DBAL\\\\ForwardCompatibility\\\\DriverResultStatement\\|Doctrine\\\\DBAL\\\\ForwardCompatibility\\\\DriverStatement\\:\\:execute\\(\\)\\.$#" + count: 2 + path: test/Crate/Test/DBAL/Functional/DataAccessTest.php + + - + message: "#^Cannot access offset 0 on array\\\\|false\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Functional/DataAccessTest.php + + - + message: "#^Cannot access offset 1 on array\\\\|false\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Functional/DataAccessTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\Functional\\\\DataAccessTestCase\\:\\:setupFixture\\(\\) has no return type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Functional/DataAccessTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\Functional\\\\DataAccessTestCase\\:\\:setupFixture\\(\\) is unused\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Functional/DataAccessTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\Functional\\\\DataAccessTestCase\\:\\:testBitComparisonExpressionSupport\\(\\) has no return type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Functional/DataAccessTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\Functional\\\\DataAccessTestCase\\:\\:testDateArithmetics\\(\\) has no return type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Functional/DataAccessTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\Functional\\\\DataAccessTestCase\\:\\:testEmptyFetchColumnReturnsFalse\\(\\) has no return type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Functional/DataAccessTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\Functional\\\\DataAccessTestCase\\:\\:testExecuteQueryBindDateTimeType\\(\\) has no return type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Functional/DataAccessTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\Functional\\\\DataAccessTestCase\\:\\:testExecuteUpdateBindDateTimeType\\(\\) has no return type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Functional/DataAccessTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\Functional\\\\DataAccessTestCase\\:\\:testFetchAll\\(\\) has no return type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Functional/DataAccessTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\Functional\\\\DataAccessTestCase\\:\\:testFetchAllStyleColumn\\(\\) has no return type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Functional/DataAccessTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\Functional\\\\DataAccessTestCase\\:\\:testFetchAllSupportFetchClass\\(\\) has no return type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Functional/DataAccessTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\Functional\\\\DataAccessTestCase\\:\\:testFetchArray\\(\\) has no return type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Functional/DataAccessTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\Functional\\\\DataAccessTestCase\\:\\:testFetchBoth\\(\\) has no return type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Functional/DataAccessTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\Functional\\\\DataAccessTestCase\\:\\:testFetchColumn\\(\\) has no return type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Functional/DataAccessTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\Functional\\\\DataAccessTestCase\\:\\:testFetchRow\\(\\) has no return type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Functional/DataAccessTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\Functional\\\\DataAccessTestCase\\:\\:testNativeArrayListSupport\\(\\) has no return type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Functional/DataAccessTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\Functional\\\\DataAccessTestCase\\:\\:testPrepareQueryBindValueDateTimeType\\(\\) has no return type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Functional/DataAccessTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\Functional\\\\DataAccessTestCase\\:\\:testPrepareWithBindParam\\(\\) has no return type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Functional/DataAccessTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\Functional\\\\DataAccessTestCase\\:\\:testPrepareWithBindValue\\(\\) has no return type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Functional/DataAccessTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\Functional\\\\DataAccessTestCase\\:\\:testPrepareWithExecuteParams\\(\\) has no return type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Functional/DataAccessTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\Functional\\\\DataAccessTestCase\\:\\:testPrepareWithFetchAll\\(\\) has no return type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Functional/DataAccessTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\Functional\\\\DataAccessTestCase\\:\\:testPrepareWithFetchAllBoth\\(\\) has no return type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Functional/DataAccessTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\Functional\\\\DataAccessTestCase\\:\\:testPrepareWithFetchColumn\\(\\) has no return type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Functional/DataAccessTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\Functional\\\\DataAccessTestCase\\:\\:testPrepareWithIterator\\(\\) has no return type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Functional/DataAccessTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\Functional\\\\DataAccessTestCase\\:\\:testPrepareWithQuoted\\(\\) has no return type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Functional/DataAccessTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\Functional\\\\DataAccessTestCase\\:\\:testQuoteSQLInjection\\(\\) has no return type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Functional/DataAccessTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\Functional\\\\DataAccessTestCase\\:\\:testSetDefaultFetchMode\\(\\) has no return type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Functional/DataAccessTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\Functional\\\\DataAccessTestCase\\:\\:testSetFetchModeClassFetch\\(\\) has no return type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Functional/DataAccessTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\Functional\\\\DataAccessTestCase\\:\\:testSetFetchModeClassFetchAll\\(\\) has no return type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Functional/DataAccessTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\Functional\\\\DataAccessTestCase\\:\\:testSetFetchModeOnDbalStatement\\(\\) has no return type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Functional/DataAccessTest.php + + - + message: "#^Property Crate\\\\Test\\\\DBAL\\\\Functional\\\\DataAccessTestCase\\:\\:\\$generated has no type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Functional/DataAccessTest.php + + - + message: "#^Unreachable statement \\- code above always terminates\\.$#" + count: 5 + path: test/Crate/Test/DBAL/Functional/DataAccessTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\Functional\\\\ModifyLimitQueryTest\\:\\:assertLimitResult\\(\\) has no return type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Functional/ModifyLimitQueryTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\Functional\\\\ModifyLimitQueryTest\\:\\:assertLimitResult\\(\\) has parameter \\$expectedResults with no type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Functional/ModifyLimitQueryTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\Functional\\\\ModifyLimitQueryTest\\:\\:assertLimitResult\\(\\) has parameter \\$limit with no type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Functional/ModifyLimitQueryTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\Functional\\\\ModifyLimitQueryTest\\:\\:assertLimitResult\\(\\) has parameter \\$offset with no type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Functional/ModifyLimitQueryTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\Functional\\\\ModifyLimitQueryTest\\:\\:assertLimitResult\\(\\) has parameter \\$sql with no type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Functional/ModifyLimitQueryTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\Functional\\\\ModifyLimitQueryTest\\:\\:testModifyLimitQueryGroupBy\\(\\) has no return type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Functional/ModifyLimitQueryTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\Functional\\\\ModifyLimitQueryTest\\:\\:testModifyLimitQueryOrderBy\\(\\) has no return type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Functional/ModifyLimitQueryTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\Functional\\\\ModifyLimitQueryTest\\:\\:testModifyLimitQuerySimpleQuery\\(\\) has no return type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Functional/ModifyLimitQueryTest.php + + - + message: "#^Property Crate\\\\Test\\\\DBAL\\\\Functional\\\\ModifyLimitQueryTest\\:\\:\\$tableCreated has no type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Functional/ModifyLimitQueryTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\Functional\\\\NamedParametersTest\\:\\:testTicket\\(\\) has no return type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Functional/NamedParametersTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\Functional\\\\NamedParametersTest\\:\\:testTicket\\(\\) has parameter \\$expected with no value type specified in iterable type array\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Functional/NamedParametersTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\Functional\\\\NamedParametersTest\\:\\:testTicket\\(\\) has parameter \\$params with no value type specified in iterable type array\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Functional/NamedParametersTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\Functional\\\\NamedParametersTest\\:\\:testTicket\\(\\) has parameter \\$types with no value type specified in iterable type array\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Functional/NamedParametersTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\Functional\\\\NamedParametersTest\\:\\:ticketProvider\\(\\) has no return type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Functional/NamedParametersTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\Functional\\\\Schema\\\\SchemaManagerTest\\:\\:assertHasTable\\(\\) has no return type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Functional/Schema/SchemaManagerTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\Functional\\\\Schema\\\\SchemaManagerTest\\:\\:assertHasTable\\(\\) has parameter \\$tableName with no type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Functional/Schema/SchemaManagerTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\Functional\\\\Schema\\\\SchemaManagerTest\\:\\:assertHasTable\\(\\) has parameter \\$tables with no type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Functional/Schema/SchemaManagerTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\Functional\\\\Schema\\\\SchemaManagerTest\\:\\:createListTableColumns\\(\\) has no return type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Functional/Schema/SchemaManagerTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\Functional\\\\Schema\\\\SchemaManagerTest\\:\\:createTestTable\\(\\) has no return type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Functional/Schema/SchemaManagerTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\Functional\\\\Schema\\\\SchemaManagerTest\\:\\:createTestTable\\(\\) has parameter \\$data with no value type specified in iterable type array\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Functional/Schema/SchemaManagerTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\Functional\\\\Schema\\\\SchemaManagerTest\\:\\:getTestCompositeTable\\(\\) has no return type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Functional/Schema/SchemaManagerTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\Functional\\\\Schema\\\\SchemaManagerTest\\:\\:getTestCompositeTable\\(\\) has parameter \\$name with no type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Functional/Schema/SchemaManagerTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\Functional\\\\Schema\\\\SchemaManagerTest\\:\\:getTestTable\\(\\) has no return type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Functional/Schema/SchemaManagerTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\Functional\\\\Schema\\\\SchemaManagerTest\\:\\:getTestTable\\(\\) has parameter \\$name with no type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Functional/Schema/SchemaManagerTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\Functional\\\\Schema\\\\SchemaManagerTest\\:\\:getTestTable\\(\\) has parameter \\$options with no type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Functional/Schema/SchemaManagerTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\Functional\\\\Schema\\\\SchemaManagerTest\\:\\:testCreateSchema\\(\\) has no return type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Functional/Schema/SchemaManagerTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\Functional\\\\Schema\\\\SchemaManagerTest\\:\\:testListTableColumns\\(\\) has no return type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Functional/Schema/SchemaManagerTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\Functional\\\\Schema\\\\SchemaManagerTest\\:\\:testListTableIndexes\\(\\) has no return type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Functional/Schema/SchemaManagerTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\Functional\\\\Schema\\\\SchemaManagerTest\\:\\:testListTables\\(\\) has no return type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Functional/Schema/SchemaManagerTest.php + + - + message: "#^Parameter \\#5 \\$idGeneratorType of class Doctrine\\\\DBAL\\\\Schema\\\\Table constructor expects int, false given\\.$#" + count: 2 + path: test/Crate/Test/DBAL/Functional/Schema/SchemaManagerTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\Functional\\\\TableOptionsTest\\:\\:testAdditionalTableOptions\\(\\) has no return type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Functional/TableOptionsTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\Functional\\\\TableOptionsTest\\:\\:testGetAdditionalTableOptions\\(\\) has no return type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Functional/TableOptionsTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\Functional\\\\TableOptionsTest\\:\\:testPartitionColumnsNotArray\\(\\) has no return type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Functional/TableOptionsTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\Functional\\\\TypeConversionTestCase\\:\\:testArrayType\\(\\) has no return type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Functional/TypeConversionTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\Functional\\\\TypeConversionTestCase\\:\\:testArrayTypeInvalid\\(\\) has no return type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Functional/TypeConversionTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\Functional\\\\TypeConversionTestCase\\:\\:testArrayTypeNullValue\\(\\) has no return type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Functional/TypeConversionTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\Functional\\\\TypeConversionTestCase\\:\\:testMapType\\(\\) has no return type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Functional/TypeConversionTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\Functional\\\\TypeConversionTestCase\\:\\:testMapTypeInvalid\\(\\) has no return type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Functional/TypeConversionTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\Functional\\\\TypeConversionTestCase\\:\\:testMapTypeNullValue\\(\\) has no return type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Functional/TypeConversionTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\Functional\\\\TypeConversionTestCase\\:\\:testTimestampType\\(\\) has no return type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Functional/TypeConversionTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\Functional\\\\TypeConversionTestCase\\:\\:testTimestampTypeNull\\(\\) has no return type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Functional/TypeConversionTest.php + + - + message: "#^Property Crate\\\\Test\\\\DBAL\\\\Functional\\\\TypeConversionTestCase\\:\\:\\$platform has no type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Functional/TypeConversionTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\Functional\\\\Types\\\\MapTypeTest\\:\\:testStrictMapTableCreationWithSchemaManager\\(\\) has no return type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Functional/Types/MapTypeTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\Functional\\\\WriteTest\\:\\:insertRows\\(\\) has no return type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Functional/WriteTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\Functional\\\\WriteTest\\:\\:testDelete\\(\\) has no return type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Functional/WriteTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\Functional\\\\WriteTest\\:\\:testExecuteUpdate\\(\\) has no return type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Functional/WriteTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\Functional\\\\WriteTest\\:\\:testExecuteUpdateFirstTypeIsNull\\(\\) has no return type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Functional/WriteTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\Functional\\\\WriteTest\\:\\:testExecuteUpdateWithTypes\\(\\) has no return type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Functional/WriteTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\Functional\\\\WriteTest\\:\\:testInsert\\(\\) has no return type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Functional/WriteTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\Functional\\\\WriteTest\\:\\:testPrepareRowCountReturnsAffectedRows\\(\\) has no return type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Functional/WriteTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\Functional\\\\WriteTest\\:\\:testPrepareWithDbalTypeNames\\(\\) has no return type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Functional/WriteTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\Functional\\\\WriteTest\\:\\:testPrepareWithDbalTypes\\(\\) has no return type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Functional/WriteTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\Functional\\\\WriteTest\\:\\:testPrepareWithPdoTypes\\(\\) has no return type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Functional/WriteTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\Functional\\\\WriteTest\\:\\:testUpdate\\(\\) has no return type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Functional/WriteTest.php + + - + message: "#^Property Crate\\\\Test\\\\DBAL\\\\Functional\\\\WriteTest\\:\\:\\$generated has no type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Functional/WriteTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\PDOCrate\\\\DriverTest\\:\\:testCreatePlatformForVersionGreaterEquals_4\\(\\) has no return type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/PDOCrate/DriverTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\PDOCrate\\\\DriverTest\\:\\:testCreatePlatformForVersionLess_0_57\\(\\) has no return type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/PDOCrate/DriverTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\PDOCrate\\\\DriverTest\\:\\:testCreatePlatformForVersionLess_4\\(\\) has no return type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/PDOCrate/DriverTest.php + + - + message: "#^Call to method expects\\(\\) on an unknown class GetAlterTableSqlDispatchEvenListener\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Platforms/CratePlatformTest.php + + - + message: "#^Class Crate\\\\Test\\\\DBAL\\\\Platforms\\\\CratePlatformTest extends generic class Doctrine\\\\Tests\\\\DBAL\\\\Platforms\\\\AbstractPlatformTestCase but does not specify its types\\: T$#" + count: 1 + path: test/Crate/Test/DBAL/Platforms/CratePlatformTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\Platforms\\\\CratePlatformTest\\:\\:getGenerateTableWithMultiColumnIndexSql\\(\\) has no return type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Platforms/CratePlatformTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\Platforms\\\\CratePlatformTest\\:\\:getSQLDeclaration\\(\\) has no return type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Platforms/CratePlatformTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\Platforms\\\\CratePlatformTest\\:\\:testConvertBooleans\\(\\) has no return type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Platforms/CratePlatformTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\Platforms\\\\CratePlatformTest\\:\\:testCreateDatabases\\(\\) has no return type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Platforms/CratePlatformTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\Platforms\\\\CratePlatformTest\\:\\:testDropDatabases\\(\\) has no return type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Platforms/CratePlatformTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\Platforms\\\\CratePlatformTest\\:\\:testGenerateArraySQLDeclaration\\(\\) has no return type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Platforms/CratePlatformTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\Platforms\\\\CratePlatformTest\\:\\:testGenerateBlobTypeGeneration\\(\\) has no return type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Platforms/CratePlatformTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\Platforms\\\\CratePlatformTest\\:\\:testGenerateDateDiffExpression\\(\\) has no return type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Platforms/CratePlatformTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\Platforms\\\\CratePlatformTest\\:\\:testGenerateNowExpression\\(\\) has no return type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Platforms/CratePlatformTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\Platforms\\\\CratePlatformTest\\:\\:testGenerateObjectSQLDeclaration\\(\\) has no return type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Platforms/CratePlatformTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\Platforms\\\\CratePlatformTest\\:\\:testGenerateRegexExpression\\(\\) has no return type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Platforms/CratePlatformTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\Platforms\\\\CratePlatformTest\\:\\:testGenerateSubstrExpression\\(\\) has no return type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Platforms/CratePlatformTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\Platforms\\\\CratePlatformTest\\:\\:testGenerateTableSql\\(\\) has no return type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Platforms/CratePlatformTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\Platforms\\\\CratePlatformTest\\:\\:testGenerateTableSqlWithoutColumns\\(\\) has no return type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Platforms/CratePlatformTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\Platforms\\\\CratePlatformTest\\:\\:testGenerateTableWithMultiColumnIndex\\(\\) has no return type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Platforms/CratePlatformTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\Platforms\\\\CratePlatformTest\\:\\:testGeneratesDecimalTypeDeclarationSQL\\(\\) has parameter \\$expectedSql with no type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Platforms/CratePlatformTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\Platforms\\\\CratePlatformTest\\:\\:testListDatabases\\(\\) has no return type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Platforms/CratePlatformTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\Platforms\\\\CratePlatformTest\\:\\:testPlatformSupport\\(\\) has no return type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Platforms/CratePlatformTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\Platforms\\\\CratePlatformTest\\:\\:testReadLockSQL\\(\\) has no return type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Platforms/CratePlatformTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\Platforms\\\\CratePlatformTest\\:\\:testSQLResultCasting\\(\\) has no return type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Platforms/CratePlatformTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\Platforms\\\\CratePlatformTest\\:\\:testTruncateTableSQL\\(\\) has no return type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Platforms/CratePlatformTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\Platforms\\\\CratePlatformTest\\:\\:testUniqueConstraintInCustomSchemaOptions\\(\\) has no return type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Platforms/CratePlatformTest.php + + - + message: "#^Method Crate\\\\Test\\\\DBAL\\\\Platforms\\\\CratePlatformTest\\:\\:testUnsupportedUniqueIndexConstraint\\(\\) has no return type specified\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Platforms/CratePlatformTest.php + + - + message: "#^Parameter \\#1 \\$className of method PHPUnit\\\\Framework\\\\TestCase\\:\\:getMockBuilder\\(\\) expects class\\-string\\, string given\\.$#" + count: 1 + path: test/Crate/Test/DBAL/Platforms/CratePlatformTest.php diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..a32fc2f --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,8 @@ +includes: + - phpstan-baseline.neon + - vendor/phpstan/phpstan-deprecation-rules/rules.neon + +parameters: + level: 7 + paths: + - src diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 1dfd578..c763367 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,21 +1,11 @@ - - - ./test/Crate/Test - - - - ./src - - + + + + ./src + + + + ./test/Crate/Test + diff --git a/src/Crate/DBAL/Driver/PDOCrate/CrateStatement.php b/src/Crate/DBAL/Driver/PDOCrate/CrateException.php similarity index 79% rename from src/Crate/DBAL/Driver/PDOCrate/CrateStatement.php rename to src/Crate/DBAL/Driver/PDOCrate/CrateException.php index fb26dac..e2f3217 100644 --- a/src/Crate/DBAL/Driver/PDOCrate/CrateStatement.php +++ b/src/Crate/DBAL/Driver/PDOCrate/CrateException.php @@ -22,14 +22,12 @@ namespace Crate\DBAL\Driver\PDOCrate; -use Doctrine\DBAL\Driver\PDOStatementImplementations; -use Doctrine\DBAL\Driver\Statement as StatementInterface; -use Crate\PDO\PDOStatement; +use Doctrine\DBAL\Exception\DriverException; -/** - * @internal - */ -class CrateStatement extends PDOStatement implements StatementInterface +class CrateException extends DriverException { - use PDOStatementImplementations; + public static function notSupported(string $method): self + { + return new self(sprintf("Operation '%s' is not supported by platform.", $method)); + } } diff --git a/src/Crate/DBAL/Driver/PDOCrate/Driver.php b/src/Crate/DBAL/Driver/PDOCrate/Driver.php index a424f4f..5e4024b 100644 --- a/src/Crate/DBAL/Driver/PDOCrate/Driver.php +++ b/src/Crate/DBAL/Driver/PDOCrate/Driver.php @@ -25,10 +25,17 @@ use Crate\DBAL\Platforms\CratePlatform; use Crate\DBAL\Platforms\CratePlatform4; use Crate\DBAL\Schema\CrateSchemaManager; +use Crate\PDO\PDOCrateDB; +use Crate\PDO\PDOStatement; use Doctrine\DBAL\Connection; -use Doctrine\DBAL\VersionAwarePlatformDriver; +use Doctrine\DBAL\Driver\API\ExceptionConverter; +use Doctrine\DBAL\Driver\Exception; +use Doctrine\DBAL\Exception\DriverException; +use Doctrine\DBAL\Platforms\AbstractPlatform; +use Doctrine\DBAL\Query; +use Doctrine\DBAL\ServerVersionProvider; -class Driver implements \Doctrine\DBAL\Driver, VersionAwarePlatformDriver +class Driver implements \Doctrine\DBAL\Driver { const VERSION = '4.0.2'; const NAME = 'crate'; @@ -38,11 +45,17 @@ class Driver implements \Doctrine\DBAL\Driver, VersionAwarePlatformDriver /** * {@inheritDoc} - * @return PDOConnection The database connection. + * @return \Doctrine\DBAL\Driver\PDO\Connection The database connection. */ - public function connect(array $params, $username = null, $password = null, array $driverOptions = array()) + public function connect(array $params): \Doctrine\DBAL\Driver\PDO\Connection { - return new PDOConnection($this->constructPdoDsn($params), $username, $password, $driverOptions); + $driverOptions = $params['driverOptions'] ?? []; + + $pdo = new PDOCrateDB($this->constructPdoDsn($params), $params['user'] ?? null, $params['password'] ?? null, $driverOptions); + $pdo->setAttribute(PDOCrateDB::ATTR_STATEMENT_CLASS, PDOStatement::class); + $pdo->setAttribute(PDOCrateDB::ATTR_ERRMODE, PDOCrateDB::ERRMODE_EXCEPTION); + + return new \Doctrine\DBAL\Driver\PDO\Connection($pdo); } /** @@ -66,17 +79,26 @@ private function constructPdoDsn(array $params) /** * {@inheritDoc} */ - public function getDatabasePlatform() + public function getDatabasePlatform(ServerVersionProvider $versionProvider): AbstractPlatform { - return new CratePlatform(); + $version = $versionProvider->getServerVersion(); + + if (version_compare($version, self::VERSION_057, "<")) { + return new CratePlatform(); + } + if (version_compare($version, self::VERSION_4, "<")) { + return new CratePlatform1(); + } + + return new CratePlatform4(); } /** * {@inheritDoc} */ - public function getSchemaManager(Connection $conn) + public function getSchemaManager(Connection $conn, AbstractPlatform $platform) { - return new CrateSchemaManager($conn); + return new CrateSchemaManager($conn, $platform); } /** @@ -98,14 +120,12 @@ public function getDatabase(Connection $conn) /** * {@inheritDoc} */ - public function createDatabasePlatformForVersion($version) + public function getExceptionConverter(): ExceptionConverter { - if (version_compare($version, self::VERSION_057, "<")) { - return new CratePlatform(); - } elseif (version_compare($version, self::VERSION_4, "<")) { - return new CratePlatform1(); - } else { - return new CratePlatform4(); - } + return new Class implements ExceptionConverter { + public function convert(Exception $exception, ?Query $query): DriverException { + return new CrateException($exception, $query); + } + }; } } diff --git a/src/Crate/DBAL/Platforms/CratePlatform.php b/src/Crate/DBAL/Platforms/CratePlatform.php index a18e5ce..3208f90 100644 --- a/src/Crate/DBAL/Platforms/CratePlatform.php +++ b/src/Crate/DBAL/Platforms/CratePlatform.php @@ -21,20 +21,27 @@ */ namespace Crate\DBAL\Platforms; +use Crate\DBAL\Platforms\Keywords\CrateKeywords; +use Crate\DBAL\Schema\CrateSchemaManager; use Crate\DBAL\Types\MapType; use Crate\DBAL\Types\TimestampType; -use Doctrine\DBAL\DBALException; +use Doctrine\DBAL\Connection; use Doctrine\DBAL\Event\SchemaCreateTableColumnEventArgs; use Doctrine\DBAL\Event\SchemaCreateTableEventArgs; use Doctrine\DBAL\Events; use Doctrine\DBAL\Platforms\AbstractPlatform; +use Doctrine\DBAL\Platforms\DateIntervalUnit; +use Doctrine\DBAL\Platforms\Keywords\KeywordList; use Doctrine\DBAL\Schema\Identifier; use Doctrine\DBAL\Schema\Index; use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Schema\TableDiff; +use Doctrine\DBAL\TransactionIsolationLevel; use Doctrine\DBAL\Types\Type; use Doctrine\DBAL\Schema\ForeignKeyConstraint; +use Doctrine\DBAL\Types\Types; use InvalidArgumentException; +use Crate\DBAL\Types\ArrayType; class CratePlatform extends AbstractPlatform { @@ -48,21 +55,28 @@ class CratePlatform extends AbstractPlatform */ public function __construct() { - parent::__construct(); $this->initializeDoctrineTypeMappings(); + if (!Type::hasType(MapType::NAME)) { - Type::addType(MapType::NAME, 'Crate\DBAL\Types\MapType'); + Type::addType(MapType::NAME, MapType::class); + + $this->registerDoctrineTypeMapping(10, MapType::NAME); } if (!Type::hasType(TimestampType::NAME)) { - Type::addType(TimestampType::NAME, 'Crate\DBAL\Types\TimestampType'); + Type::addType(TimestampType::NAME, TimestampType::class); + } + + if (!Type::hasType(ArrayType::NAME)) { + Type::addType(ArrayType::NAME, ArrayType::class); + $this->registerDoctrineTypeMapping(9, ArrayType::NAME); } - Type::overrideType('array', 'Crate\DBAL\Types\ArrayType'); + } /** * {@inheritDoc} */ - public function getSubstringExpression($value, $from = 0, $length = null) + public function getSubstringExpression($value, $from = 0, $length = null): string { if ($length === null) { return 'SUBSTR(' . $value . ', ' . $from . ')'; @@ -76,13 +90,13 @@ public function getSubstringExpression($value, $from = 0, $length = null) */ public function getNowExpression() { - throw DBALException::notSupported(__METHOD__); + throw Exception::notSupported(__METHOD__); } /** * {@inheritDoc} */ - public function getRegexpExpression() + public function getRegexpExpression(): string { return 'LIKE'; } @@ -90,34 +104,15 @@ public function getRegexpExpression() /** * {@inheritDoc} */ - public function getDateDiffExpression($date1, $date2) + public function getDateDiffExpression($date1, $date2): string { - throw DBALException::notSupported(__METHOD__); + throw Exception::notSupported(__METHOD__); } /** * {@inheritDoc} */ - public function supportsSequences() - { - return false; - } - - /** - * If we want to support Schemas, we need to implement - * getListNamespacesSQL and getCreateSchemaSQL methods - * - * {@inheritDoc} - */ - public function supportsSchemas() - { - return false; - } - - /** - * {@inheritDoc} - */ - public function supportsIdentityColumns() + public function supportsIdentityColumns(): bool { return true; } @@ -125,15 +120,7 @@ public function supportsIdentityColumns() /** * {@inheritDoc} */ - public function supportsIndexes() - { - return false; - } - - /** - * {@inheritDoc} - */ - public function supportsCommentOnStatement() + public function supportsIndexes(): bool { return false; } @@ -141,7 +128,7 @@ public function supportsCommentOnStatement() /** * {@inheritDoc} */ - public function supportsForeignKeyConstraints() + public function supportsForeignKeyConstraints(): bool { return false; } @@ -149,7 +136,7 @@ public function supportsForeignKeyConstraints() /** * {@inheritDoc} */ - public function supportsForeignKeyOnUpdate() + public function supportsViews(): bool { return false; } @@ -157,25 +144,9 @@ public function supportsForeignKeyOnUpdate() /** * {@inheritDoc} */ - public function supportsViews() + public function getListDatabasesSQL(): string { - return false; - } - - /** - * {@inheritDoc} - */ - public function prefersSequences() - { - return false; - } - - /** - * {@inheritDoc} - */ - public function getListDatabasesSQL() - { - throw DBALException::notSupported(__METHOD__); + throw Exception::notSupported(__METHOD__); } /** @@ -251,42 +222,42 @@ protected function getTableWhereClauseFormat() /** * {@inheritDoc} */ - public function getAlterTableSQL(TableDiff $diff) + public function getAlterTableSQL(TableDiff $diff): array { $sql = array(); $commentsSQL = array(); $columnSql = array(); - foreach ($diff->addedColumns as $column) { + foreach ($diff->getAddedColumns() as $column) { if ($this->onSchemaAlterTableAddColumn($column, $diff, $columnSql)) { continue; } $query = 'ADD ' . $this->getColumnDeclarationSQL($column->getQuotedName($this), $column->toArray()); $sql[] = 'ALTER TABLE ' . $diff->name . ' ' . $query; - if ($comment = $this->getColumnComment($column)) { + if ($comment = $column->getComment()) { $commentsSQL[] = $this->getCommentOnColumnSQL($diff->name, $column->getName(), $comment); } } - if (count($diff->removedColumns) > 0) { - throw DBALException::notSupported("Alter Table: drop columns"); + if (count($diff->getDroppedColumns()) > 0) { + throw Exception::notSupported("Alter Table: drop columns"); } - if (count($diff->changedColumns) > 0) { - throw DBALException::notSupported("Alter Table: change column options"); + if (count($diff->getChangedColumns()) > 0) { + throw Exception::notSupported("Alter Table: change column options"); } - if (count($diff->renamedColumns) > 0) { - throw DBALException::notSupported("Alter Table: rename columns"); + if (count($diff->getRenamedColumns()) > 0) { + throw Exception::notSupported("Alter Table: rename columns"); } $tableSql = array(); if (!$this->onSchemaAlterTable($diff, $tableSql)) { if ($diff->newName !== false) { - throw DBALException::notSupported("Alter Table: rename table"); + throw Exception::notSupported("Alter Table: rename table"); } - $sql = array_merge($sql, $this->_getAlterTableIndexForeignKeySQL($diff), $commentsSQL); + $sql = array_merge($sql, $this->getPreAlterTableIndexForeignKeySQL($diff), $this->getPostAlterTableIndexForeignKeySQL($diff), $commentsSQL); } return array_merge($sql, $tableSql, $columnSql); @@ -295,10 +266,10 @@ public function getAlterTableSQL(TableDiff $diff) /** * {@inheritDoc} */ - public function getColumnDeclarationSQL($name, array $column) + public function getColumnDeclarationSQL($name, array $column): string { if (isset($column['columnDefinition'])) { - $columnDef = $this->getCustomTypeDeclarationSQL($column); + $columnDef = $column['columnDefinition']; } else { $typeDecl = $column['type']->getSqlDeclaration($column, $this); $columnDef = $typeDecl; @@ -311,17 +282,18 @@ public function getColumnDeclarationSQL($name, array $column) * Generate table index column declaration * @codeCoverageIgnore */ - public function getIndexDeclarationSQL($name, Index $index) + public function getIndexDeclarationSQL(Index $index): string { $columns = $index->getQuotedColumns($this); - $name = new Identifier($name); + $name = new Identifier($index->getName()); if (count($columns) == 0) { throw new \InvalidArgumentException("Incomplete definition. 'columns' required."); } + $index = new Index($name->getQuotedName($this), $columns); return 'INDEX ' . $name->getQuotedName($this) . - ' USING FULLTEXT ('. $this->getIndexFieldDeclarationListSQL($columns) . ')'; + ' USING FULLTEXT ('. $this->getIndexFieldDeclarationListSQL($index) . ')'; } /** @@ -329,7 +301,7 @@ public function getIndexDeclarationSQL($name, Index $index) * * Crate wants boolean values converted to the strings 'true'/'false'. */ - public function convertBooleans($item) + public function convertBooleans($item): mixed { if (is_array($item)) { foreach ($item as $key => $value) { @@ -353,7 +325,7 @@ public function convertBooleans($item) /** * {@inheritDoc} */ - public function getBooleanTypeDeclarationSQL(array $field) + public function getBooleanTypeDeclarationSQL(array $field): string { return 'BOOLEAN'; } @@ -361,7 +333,7 @@ public function getBooleanTypeDeclarationSQL(array $field) /** * {@inheritDoc} */ - public function getIntegerTypeDeclarationSQL(array $field) + public function getIntegerTypeDeclarationSQL(array $field): string { return 'INTEGER'; } @@ -369,7 +341,7 @@ public function getIntegerTypeDeclarationSQL(array $field) /** * {@inheritDoc} */ - public function getBigIntTypeDeclarationSQL(array $field) + public function getBigIntTypeDeclarationSQL(array $field): string { return 'LONG'; } @@ -377,7 +349,7 @@ public function getBigIntTypeDeclarationSQL(array $field) /** * {@inheritDoc} */ - public function getSmallIntTypeDeclarationSQL(array $field) + public function getSmallIntTypeDeclarationSQL(array $field): string { return 'SHORT'; } @@ -385,7 +357,7 @@ public function getSmallIntTypeDeclarationSQL(array $field) /** * {@inheritDoc} */ - public function getFloatDeclarationSQL(array $field) + public function getFloatDeclarationSQL(array $field): string { return 'DOUBLE'; } @@ -393,7 +365,7 @@ public function getFloatDeclarationSQL(array $field) /** * {@inheritDoc} */ - public function getDecimalTypeDeclarationSQL(array $columnDef) + public function getDecimalTypeDeclarationSQL(array $columnDef): string { return 'DOUBLE'; } @@ -401,7 +373,7 @@ public function getDecimalTypeDeclarationSQL(array $columnDef) /** * {@inheritDoc} */ - public function getDateTimeTypeDeclarationSQL(array $fieldDeclaration) + public function getDateTimeTypeDeclarationSQL(array $fieldDeclaration): string { return 'TIMESTAMP'; } @@ -409,7 +381,7 @@ public function getDateTimeTypeDeclarationSQL(array $fieldDeclaration) /** * {@inheritDoc} */ - public function getDateTimeTzTypeDeclarationSQL(array $fieldDeclaration) + public function getDateTimeTzTypeDeclarationSQL(array $fieldDeclaration): string { return 'TIMESTAMP'; } @@ -417,7 +389,7 @@ public function getDateTimeTzTypeDeclarationSQL(array $fieldDeclaration) /** * {@inheritDoc} */ - public function getDateTypeDeclarationSQL(array $fieldDeclaration) + public function getDateTypeDeclarationSQL(array $fieldDeclaration): string { return 'TIMESTAMP'; } @@ -425,7 +397,7 @@ public function getDateTypeDeclarationSQL(array $fieldDeclaration) /** * {@inheritDoc} */ - public function getTimeTypeDeclarationSQL(array $fieldDeclaration) + public function getTimeTypeDeclarationSQL(array $fieldDeclaration): string { return 'TIMESTAMP'; } @@ -433,7 +405,7 @@ public function getTimeTypeDeclarationSQL(array $fieldDeclaration) /** * {@inheritDoc} */ - protected function _getCommonIntegerTypeDeclarationSQL(array $columnDef) + protected function _getCommonIntegerTypeDeclarationSQL(array $columnDef): string { return ''; } @@ -441,15 +413,15 @@ protected function _getCommonIntegerTypeDeclarationSQL(array $columnDef) /** * {@inheritDoc} */ - protected function getVarcharTypeDeclarationSQLSnippet($length, $fixed) + protected function getVarcharTypeDeclarationSQLSnippet(int|null $length): string { - return 'STRING'; + return Types::STRING; } /** * {@inheritDoc} */ - public function getClobTypeDeclarationSQL(array $field) + public function getClobTypeDeclarationSQL(array $field): string { return 'STRING'; } @@ -469,13 +441,14 @@ public function getName() */ public function getSQLResultCasing($column) { + return strtolower($column); } /** * {@inheritDoc} */ - public function getDateTimeTzFormatString() + public function getDateTimeTzFormatString(): string { return self::TIMESTAMP_FORMAT_TZ; } @@ -483,7 +456,7 @@ public function getDateTimeTzFormatString() /** * {@inheritDoc} */ - public function getDateTimeFormatString() + public function getDateTimeFormatString(): string { return self::TIMESTAMP_FORMAT; } @@ -491,7 +464,7 @@ public function getDateTimeFormatString() /** * {@inheritDoc} */ - public function getDateFormatString() + public function getDateFormatString(): string { return self::TIMESTAMP_FORMAT; } @@ -499,7 +472,7 @@ public function getDateFormatString() /** * {@inheritDoc} */ - public function getTimeFormatString() + public function getTimeFormatString(): string { return self::TIMESTAMP_FORMAT; } @@ -507,9 +480,9 @@ public function getTimeFormatString() /** * {@inheritDoc} */ - public function getTruncateTableSQL($tableName, $cascade = false) + public function getTruncateTableSQL($tableName, $cascade = false): string { - throw DBALException::notSupported(__METHOD__); + throw Exception::notSupported(__METHOD__); } /** @@ -517,13 +490,13 @@ public function getTruncateTableSQL($tableName, $cascade = false) */ public function getReadLockSQL() { - throw DBALException::notSupported(__METHOD__); + throw Exception::notSupported(__METHOD__); } /** * {@inheritDoc} */ - protected function initializeDoctrineTypeMappings() + protected function initializeDoctrineTypeMappings(): void { $this->doctrineTypeMapping = array( 'short' => 'smallint', @@ -544,7 +517,7 @@ protected function initializeDoctrineTypeMappings() /** * {@inheritDoc} */ - public function getDoctrineTypeMapping($dbType) + public function getDoctrineTypeMapping($dbType): string { // typed arrays will always end up in the same generic php array type if (substr_compare($dbType, 'array', -5) === 0) { @@ -565,17 +538,9 @@ public function getVarcharMaxLength() /** * {@inheritDoc} */ - protected function getReservedKeywordsClass() + public function getBlobTypeDeclarationSQL(array $field): string { - return 'Crate\DBAL\Platforms\Keywords\CrateKeywords'; - } - - /** - * {@inheritDoc} - */ - public function getBlobTypeDeclarationSQL(array $field) - { - throw DBALException::notSupported(__METHOD__); + throw Exception::notSupported(__METHOD__); } /** @@ -588,7 +553,7 @@ public function getBlobTypeDeclarationSQL(array $field) * * @return array The sequence of SQL statements. */ - public function getCreateTableSQL(Table $table, $createFlags = self::CREATE_INDEXES) + public function getCreateTableSQL(Table $table, $createFlags = self::CREATE_INDEXES): array { if (!is_int($createFlags)) { $msg = "Second argument of CratePlatform::getCreateTableSQL() has to be integer."; @@ -596,7 +561,7 @@ public function getCreateTableSQL(Table $table, $createFlags = self::CREATE_INDE } if (count($table->getColumns()) === 0) { - throw DBALException::noColumnsSpecifiedForTable($table->getName()); + throw Exception::noColumnsSpecifiedForTable($table->getName()); } $tableName = $table->getQuotedName($this); @@ -615,7 +580,7 @@ public function getCreateTableSQL(Table $table, $createFlags = self::CREATE_INDE }, $index->getColumns()); $options['primary_index'] = $index; } elseif ($index->isUnique()) { - throw DBALException::notSupported( + throw Exception::notSupported( "Unique constraints are not supported. Use `primary key` instead" ); } else { @@ -628,30 +593,9 @@ public function getCreateTableSQL(Table $table, $createFlags = self::CREATE_INDE $columns = array(); foreach ($table->getColumns() as $column) { - if (null !== $this->_eventManager && - $this->_eventManager->hasListeners(Events::onSchemaCreateTableColumn) - ) { - $eventArgs = new SchemaCreateTableColumnEventArgs($column, $table, $this); - $this->_eventManager->dispatchEvent(Events::onSchemaCreateTableColumn, $eventArgs); - - $columnSql = array_merge($columnSql, $eventArgs->getSql()); - - if ($eventArgs->isDefaultPrevented()) { - continue; - } - } $columns[$column->getQuotedName($this)] = self::prepareColumnData($this, $column, $options['primary']); } - if (null !== $this->_eventManager && $this->_eventManager->hasListeners(Events::onSchemaCreateTable)) { - $eventArgs = new SchemaCreateTableEventArgs($table, $columns, $options, $this); - $this->_eventManager->dispatchEvent(Events::onSchemaCreateTable, $eventArgs); - - if ($eventArgs->isDefaultPrevented()) { - return array_merge($eventArgs->getSql(), $columnSql); - } - } - $sql = $this->_getCreateTableSQL($tableName, $columns, $options); if ($this->supportsCommentOnStatement()) { foreach ($table->getColumns() as $column) { @@ -671,7 +615,7 @@ public function getCreateTableSQL(Table $table, $createFlags = self::CREATE_INDE /** * {@inheritDoc} */ - protected function _getCreateTableSQL($name, array $columns, array $options = array()) + protected function _getCreateTableSQL($name, array $columns, array $options = array()): array { $columnListSql = $this->getColumnDeclarationListSQL($columns); @@ -685,9 +629,9 @@ protected function _getCreateTableSQL($name, array $columns, array $options = ar $columnListSql .= ', ' . $this->getIndexDeclarationSQL($index, $definition); } } - + if (isset($options['foreignKeys'])) { - throw DBALException::notSupported("Create Table: foreign keys"); + throw Exception::notSupported("Create Table: foreign keys"); } $query = 'CREATE TABLE ' . $name . ' (' . $columnListSql . ')'; @@ -774,15 +718,15 @@ private function buildPartitionOptions(array $options) /** * @param \Doctrine\DBAL\Schema\Column $column The name of the table. - * @param array List of primary key column names + * @param array $primaries List of primary key column names * * @return array The column data as associative array. - * @throws DBALException + * @throws Exception */ public static function prepareColumnData(AbstractPlatform $platform, $column, $primaries = array()) { - if ($column->hasCustomSchemaOption("unique") ? $column->getCustomSchemaOption("unique") : false) { - throw DBALException::notSupported("Unique constraints are not supported. Use `primary key` instead"); + if ($column->hasPlatformOption("unique") ? $column->hasPlatformOption("unique") : false) { + throw Exception::notSupported("Unique constraints are not supported. Use `primary key` instead"); } $columnData = array(); @@ -794,7 +738,7 @@ public static function prepareColumnData(AbstractPlatform $platform, $column, $p $columnData['unique'] = false; $columnData['version'] = $column->hasPlatformOption("version") ? $column->getPlatformOption("version") : false; - if (strtolower($columnData['type']) == $platform->getVarcharTypeDeclarationSQLSnippet(0, false) + if ($columnData['type'] == $platform->getVarcharTypeDeclarationSQLSnippet(0, false) && $columnData['length'] === null) { $columnData['length'] = 255; } @@ -805,7 +749,6 @@ public static function prepareColumnData(AbstractPlatform $platform, $column, $p $columnData['default'] = $column->getDefault(); $columnData['columnDefinition'] = $column->getColumnDefinition(); $columnData['autoincrement'] = $column->getAutoincrement(); - $columnData['comment'] = $platform->getColumnComment($column); $columnData['platformOptions'] = $column->getPlatformOptions(); if (in_array($column->getName(), $primaries)) { @@ -817,33 +760,33 @@ public static function prepareColumnData(AbstractPlatform $platform, $column, $p /** * {@inheritDoc} */ - public function getCreateDatabaseSQL($database) + public function getCreateDatabaseSQL($database): string { - throw DBALException::notSupported(__METHOD__); + throw Exception::notSupported(__METHOD__); } /** * {@inheritDoc} */ - public function getDropDatabaseSQL($database) + public function getDropDatabaseSQL($database): string { - throw DBALException::notSupported(__METHOD__); + throw Exception::notSupported(__METHOD__); } - + /** * {@inheritDoc} */ - public function getCreateForeignKeySQL(ForeignKeyConstraint $foreignKey, $table) + public function getCreateForeignKeySQL(ForeignKeyConstraint $foreignKey, $table): string { - throw DBALException::notSupported(__METHOD__); + throw Exception::notSupported(__METHOD__); } - + /** * {@inheritDoc} */ - public function getGuidTypeDeclarationSQL(array $field) + public function getGuidTypeDeclarationSQL(array $field): string { - throw DBALException::notSupported(__METHOD__); + throw Exception::notSupported(__METHOD__); } /** @@ -858,4 +801,42 @@ public function getTableOptionsSQL(string $table) : string "FROM information_schema.tables c " . "WHERE " . $this->getTableWhereClause($table); } + + /** + * {@inheritDoc} + */ + public function getCurrentDatabaseExpression(): string + { + return 'current_database()'; + } + + public function createSchemaManager(Connection $connection): CrateSchemaManager + { + return new CrateSchemaManager($connection, $this); + } + + public function getLocateExpression(string $string, string $substring, ?string $start = null): string + { + throw Exception::notSupported(__METHOD__); + } + + protected function getDateArithmeticIntervalExpression(string $date, string $operator, string $interval, DateIntervalUnit $unit,): string + { + throw Exception::notSupported(__METHOD__); + } + + public function getListViewsSQL(string $database): string + { + throw Exception::notSupported(__METHOD__); + } + + public function getSetTransactionIsolationSQL(TransactionIsolationLevel $level): string + { + throw Exception::notSupported(__METHOD__); + } + + protected function createReservedKeywordsList(): KeywordList + { + return new CrateKeywords(); + } } diff --git a/src/Crate/DBAL/Platforms/CratePlatform4.php b/src/Crate/DBAL/Platforms/CratePlatform4.php index f57390a..c7e2780 100644 --- a/src/Crate/DBAL/Platforms/CratePlatform4.php +++ b/src/Crate/DBAL/Platforms/CratePlatform4.php @@ -27,7 +27,7 @@ class CratePlatform4 extends CratePlatform1 /** * {@inheritDoc} */ - protected function initializeDoctrineTypeMappings() + protected function initializeDoctrineTypeMappings(): void { $this->doctrineTypeMapping = array( 'integer' => 'integer', @@ -54,7 +54,7 @@ protected function initializeDoctrineTypeMappings() /** * {@inheritDoc} */ - public function getBigIntTypeDeclarationSQL(array $field) + public function getBigIntTypeDeclarationSQL(array $field): string { return 'BIGINT'; } @@ -62,7 +62,7 @@ public function getBigIntTypeDeclarationSQL(array $field) /** * {@inheritDoc} */ - public function getSmallIntTypeDeclarationSQL(array $field) + public function getSmallIntTypeDeclarationSQL(array $field): string { return 'SMALLINT'; } @@ -70,7 +70,7 @@ public function getSmallIntTypeDeclarationSQL(array $field) /** * {@inheritDoc} */ - public function getFloatDeclarationSQL(array $field) + public function getFloatDeclarationSQL(array $field): string { return 'DOUBLE PRECISION'; } @@ -78,7 +78,7 @@ public function getFloatDeclarationSQL(array $field) /** * {@inheritDoc} */ - protected function getVarcharTypeDeclarationSQLSnippet($length, $fixed) + protected function getVarcharTypeDeclarationSQLSnippet(int|null $length): string { return 'TEXT'; } @@ -86,7 +86,7 @@ protected function getVarcharTypeDeclarationSQLSnippet($length, $fixed) /** * {@inheritDoc} */ - public function getClobTypeDeclarationSQL(array $field) + public function getClobTypeDeclarationSQL(array $field): string { return 'TEXT'; } diff --git a/src/Crate/DBAL/Driver/PDOCrate/PDOConnection.php b/src/Crate/DBAL/Platforms/Exception.php similarity index 53% rename from src/Crate/DBAL/Driver/PDOCrate/PDOConnection.php rename to src/Crate/DBAL/Platforms/Exception.php index fd19863..a4ef04e 100644 --- a/src/Crate/DBAL/Driver/PDOCrate/PDOConnection.php +++ b/src/Crate/DBAL/Platforms/Exception.php @@ -20,33 +20,14 @@ * software solely pursuant to the terms of the relevant commercial agreement. */ -namespace Crate\DBAL\Driver\PDOCrate; +namespace Crate\DBAL\Platforms; -use Crate\PDO\PDO; -use Doctrine\DBAL\Driver\ServerInfoAwareConnection; +use Doctrine\DBAL\Exception as DoctrineException; -class PDOConnection extends PDO implements ServerInfoAwareConnection +class Exception extends \Exception implements DoctrineException { - /** - * @param string $dsn - * @param string $user - * @param string $password - * @param array $options - */ - public function __construct($dsn, $user = null, $password = null, array $options = null) + public static function notSupported(string $method): self { - parent::__construct($dsn, $user, $password, $options); - $this->setAttribute(PDO::ATTR_STATEMENT_CLASS, CrateStatement::class); - $this->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); - } - - /** - * Checks whether a query is required to retrieve the database server version. - * - * @return boolean True if a query is required to retrieve the database server version, false otherwise. - */ - public function requiresQueryForServerVersion() - { - return false; + return new self(sprintf("Operation '%s' is not supported by platform.", $method)); } } diff --git a/src/Crate/DBAL/Platforms/Keywords/CrateKeywords.php b/src/Crate/DBAL/Platforms/Keywords/CrateKeywords.php index 18a435b..9d3d208 100644 --- a/src/Crate/DBAL/Platforms/Keywords/CrateKeywords.php +++ b/src/Crate/DBAL/Platforms/Keywords/CrateKeywords.php @@ -30,7 +30,7 @@ public function getName() return 'Crate'; } - protected function getKeywords() + protected function getKeywords(): array { return array( 'ALL', diff --git a/src/Crate/DBAL/Schema/CrateSchemaManager.php b/src/Crate/DBAL/Schema/CrateSchemaManager.php index b4dbd11..410b86b 100644 --- a/src/Crate/DBAL/Schema/CrateSchemaManager.php +++ b/src/Crate/DBAL/Schema/CrateSchemaManager.php @@ -21,8 +21,13 @@ */ namespace Crate\DBAL\Schema; +use Crate\DBAL\Platforms\Exception; +use Doctrine\DBAL\Result; use Doctrine\DBAL\Schema\AbstractSchemaManager; use Doctrine\DBAL\Schema\Column; +use Doctrine\DBAL\Schema\ForeignKeyConstraint; +use Doctrine\DBAL\Schema\View; +use Doctrine\DBAL\Statement; use Doctrine\DBAL\Types\Type; use Doctrine\DBAL\Schema\Table; @@ -32,7 +37,7 @@ class CrateSchemaManager extends AbstractSchemaManager * {@inheritdoc} * */ - protected function _getPortableTableIndexesList($tableIndexes, $tableName = null) + protected function _getPortableTableIndexesList(array $tableIndexes, string $tableName = null): array { $buffer = []; foreach ($tableIndexes as $row) { @@ -51,7 +56,7 @@ protected function _getPortableTableIndexesList($tableIndexes, $tableName = null /** * {@inheritDoc} */ - protected function _getPortableTableColumnDefinition($tableColumn) + protected function _getPortableTableColumnDefinition(array $tableColumn): Column { $tableColumn = array_change_key_case($tableColumn, CASE_LOWER); @@ -105,7 +110,7 @@ private function flatten(array $array, string $prefix = '') : array $result = array(); foreach ($array as $key => $value) { if (is_array($value)) { - $result = $result + self::flatten($value, $prefix . $key . '.'); + $result = $result + $this->flatten($value, $prefix . $key . '.'); } else { $result[$prefix . $key] = $value; } @@ -122,14 +127,59 @@ public function listTableDetails($tableName) : Table $indexes = $this->listTableIndexes($tableName); $options = []; - $s = $this->_conn->fetchAssoc($this->_platform->getTableOptionsSQL($tableName)); + $s = $this->_conn->fetchAssociative($this->_platform->getTableOptionsSQL($tableName)); $options['sharding_routing_column'] = $s['clustered_by']; $options['sharding_num_shards'] = $s['number_of_shards']; $options['partition_columns'] = $s['partitioned_by']; - $options['table_options'] = self::flatten($s['settings']); + $options['table_options'] = $this->flatten($s['settings']); $options['table_options']['number_of_replicas'] = $s['number_of_replicas']; $options['table_options']['column_policy'] = $s['column_policy']; return new Table($tableName, $columns, $indexes, [], [], $options); } + + public function listTableNames() : array + { + return ['doc']; + } + + protected function selectTableNames(string $databaseName): Result + { + return $this->_conn->exec($this->_platform->getListTablesSQL()); + } + + protected function selectTableColumns(string $databaseName, ?string $tableName = null): Result + { + return $this->listTableColumns($tableName); + } + + protected function selectIndexColumns(string $databaseName, ?string $tableName = null): Result + { + throw Exception::notSupported(__METHOD__); + } + + protected function selectForeignKeyColumns(string $databaseName, ?string $tableName = null): Result + { + throw Exception::notSupported(__METHOD__); + } + + protected function fetchTableOptionsByTable(string $databaseName, ?string $tableName = null): array + { + throw Exception::notSupported(__METHOD__); + } + + protected function _getPortableTableDefinition(array $table): string + { + throw Exception::notSupported(__METHOD__); + } + + protected function _getPortableViewDefinition(array $view): View + { + throw Exception::notSupported(__METHOD__); + } + + protected function _getPortableTableForeignKeyDefinition(array $tableForeignKey): ForeignKeyConstraint + { + throw Exception::notSupported(__METHOD__); + } } diff --git a/src/Crate/DBAL/Types/ArrayType.php b/src/Crate/DBAL/Types/ArrayType.php index 346ebaa..99142e2 100644 --- a/src/Crate/DBAL/Types/ArrayType.php +++ b/src/Crate/DBAL/Types/ArrayType.php @@ -22,9 +22,11 @@ namespace Crate\DBAL\Types; -use Crate\PDO\PDO; +use Crate\PDO\PDOCrateDB; +use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Types\Type; use Doctrine\DBAL\Platforms\AbstractPlatform; +use Doctrine\DBAL\Types\Types; /** * Type that maps a PHP sequential array to an array SQL type. @@ -45,18 +47,7 @@ public function getName() return self::NAME; } - /** - * Gets the (preferred) binding type for values of this type that - * can be used when binding parameters to prepared statements. - * - * @return integer - */ - public function getBindingType() - { - return PDO::PARAM_ARRAY; - } - - public function convertToDatabaseValue($value, AbstractPlatform $platform) + public function convertToDatabaseValue($value, AbstractPlatform $platform): mixed { if (!is_array($value) || (count($value) > 0 && !(array_keys($value) === range(0, count($value) - 1)))) { return null; @@ -64,7 +55,12 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform) return $value; } - public function convertToPHPValue($value, AbstractPlatform $platform) + public function convertToDatabaseValueSQL(string $sqlExpr, AbstractPlatform $platform): string + { + return parent::convertToDatabaseValueSQL($sqlExpr, $platform); // TODO: Change the autogenerated stub + } + + public function convertToPHPValue($value, AbstractPlatform $platform): mixed { return $value; } @@ -77,7 +73,7 @@ public function convertToPHPValue($value, AbstractPlatform $platform) * @return string * @throws \Doctrine\DBAL\DBALException */ - public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) + public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform): string { $options = !array_key_exists('platformOptions', $fieldDeclaration) ? array() : $fieldDeclaration['platformOptions']; @@ -96,7 +92,7 @@ public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $pla */ public function getArrayTypeDeclarationSQL(AbstractPlatform $platform, array $field, array $options) { - $type = array_key_exists('type', $options) ? $options['type'] : Type::STRING; + $type = array_key_exists('type', $options) ? $options['type'] : Types::STRING; return 'ARRAY ( ' . Type::getType($type)->getSQLDeclaration($field, $platform) . ' )'; } } diff --git a/src/Crate/DBAL/Types/MapType.php b/src/Crate/DBAL/Types/MapType.php index bc6869e..ca675a6 100644 --- a/src/Crate/DBAL/Types/MapType.php +++ b/src/Crate/DBAL/Types/MapType.php @@ -23,7 +23,8 @@ namespace Crate\DBAL\Types; use Crate\DBAL\Platforms\CratePlatform; -use Crate\PDO\PDO; +use Crate\PDO\PDOCrateDB; +use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Types\Type; use Doctrine\DBAL\Platforms\AbstractPlatform; @@ -51,27 +52,16 @@ public function getName() return self::NAME; } - /** - * Gets the (preferred) binding type for values of this type that - * can be used when binding parameters to prepared statements. - * - * @return integer - */ - public function getBindingType() - { - return PDO::PARAM_OBJECT; - } - - public function convertToDatabaseValue($value, AbstractPlatform $platform) + public function convertToDatabaseValue($value, AbstractPlatform $platform): mixed { if (!is_array($value) || (count($value) > 0 && !(array_keys($value) !== range(0, count($value) - 1)))) { return null; } - return $value; + return (array) $value; } - public function convertToPHPValue($value, AbstractPlatform $platform) + public function convertToPHPValue($value, AbstractPlatform $platform): mixed { return $value == null ?: (array) $value; } @@ -82,9 +72,9 @@ public function convertToPHPValue($value, AbstractPlatform $platform) * @param array $fieldDeclaration The field declaration. * @param AbstractPlatform $platform The currently used database platform. * @return string - * @throws \Doctrine\DBAL\DBALException + * @throws \Doctrine\DBAL\Exception */ - public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) + public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform): string { $options = !array_key_exists('platformOptions', $fieldDeclaration) ? array() : $fieldDeclaration['platformOptions']; diff --git a/src/Crate/DBAL/Types/TimestampType.php b/src/Crate/DBAL/Types/TimestampType.php index 1e17fb3..0a779a1 100644 --- a/src/Crate/DBAL/Types/TimestampType.php +++ b/src/Crate/DBAL/Types/TimestampType.php @@ -31,8 +31,8 @@ class TimestampType extends Type { - const NAME = 'timestamp'; - const S_TO_MS = 1000; + public const NAME = 'timestamp'; + public const S_TO_MS = 1000; /** * Gets the name of this type. @@ -44,13 +44,13 @@ public function getName() return self::NAME; } - public function convertToDatabaseValue($value, AbstractPlatform $platform) + public function convertToDatabaseValue($value, AbstractPlatform $platform): mixed { return ($value !== null && $value instanceof DateTime) ? $value->getTimestamp()*self::S_TO_MS : null; } - public function convertToPHPValue($value, AbstractPlatform $platform) + public function convertToPHPValue($value, AbstractPlatform $platform): mixed { if ($value === null || $value instanceof DateTime) { return $value; @@ -73,7 +73,7 @@ public function convertToPHPValue($value, AbstractPlatform $platform) * @param array $fieldDeclaration The field declaration. * @param AbstractPlatform $platform The currently used database platform. */ - public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) + public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform): string { return $platform->getDateTimeTypeDeclarationSQL($fieldDeclaration); } diff --git a/test/Crate/Test/DBAL/DBALFunctionalTestCase.php b/test/Crate/Test/DBAL/DBALFunctionalTestCase.php index 435eacb..bd72fd2 100644 --- a/test/Crate/Test/DBAL/DBALFunctionalTestCase.php +++ b/test/Crate/Test/DBAL/DBALFunctionalTestCase.php @@ -26,6 +26,7 @@ use PHPUnit\Framework\AssertionFailedError; use PHPUnit\Framework\TestCase; use Throwable; +use Crate\DBAL\Driver\PDOCrate\Driver; abstract class DBALFunctionalTestCase extends TestCase { @@ -41,10 +42,10 @@ abstract class DBALFunctionalTestCase extends TestCase */ protected $_conn; - /** - * @var \Doctrine\DBAL\Logging\DebugStack - */ - protected $_sqlLoggerStack; +// /** +// * @var \Doctrine\DBAL\Logging\DebugStack +// */ +// protected $_sqlLoggerStack; protected function resetSharedConn() { @@ -58,7 +59,7 @@ public function setUp() : void { if ( ! isset(self::$_sharedConn)) { $params = array( - 'driverClass' => 'Crate\DBAL\Driver\PDOCrate\Driver', + 'driverClass' => Driver::class, 'host' => 'localhost', 'port' => 4200 ); @@ -66,48 +67,49 @@ public function setUp() : void } $this->_conn = self::$_sharedConn; - $this->_sqlLoggerStack = new DebugStack(); - $this->_conn->getConfiguration()->setSQLLogger($this->_sqlLoggerStack); - } - - protected function onNotSuccessfulTest(Throwable $e) : void - { - if ($e instanceof AssertionFailedError) { - throw $e; - } - - if(isset($this->_sqlLoggerStack->queries) && count($this->_sqlLoggerStack->queries)) { - $queries = ""; - $i = count($this->_sqlLoggerStack->queries); - foreach (array_reverse($this->_sqlLoggerStack->queries) AS $query) { - $params = array_map(function($p) { if (is_object($p)) return get_class($p); else return "'".print_r($p, true)."'"; }, $query['params'] ?: array()); - $queries .= ($i+1).". SQL: '".$query['sql']."' Params: ".implode(", ", $params).PHP_EOL; - $i--; - } - - $trace = $e->getTrace(); - $traceMsg = ""; - foreach($trace AS $part) { - if(isset($part['file'])) { - if(strpos($part['file'], "PHPUnit/") !== false) { - // Beginning with PHPUnit files we don't print the trace anymore. - break; - } - - $traceMsg .= $part['file'].":".$part['line'].PHP_EOL; - } - } +// $this->_sqlLoggerStack = new DebugStack(); - $message = "[".get_class($e)."] ".$e->getMessage().PHP_EOL.PHP_EOL."With queries:".PHP_EOL.$queries.PHP_EOL."Trace:".PHP_EOL.$traceMsg; - - throw new \Exception($message, (int)$e->getCode(), $e); - } - throw $e; +// $this->_conn->getConfiguration()->setMiddlewares(); } +// protected function onNotSuccessfulTest(Throwable $e) : void +// { +// if ($e instanceof AssertionFailedError) { +// throw $e; +// } +// +// if(isset($this->_sqlLoggerStack->queries) && count($this->_sqlLoggerStack->queries)) { +// $queries = ""; +// $i = count($this->_sqlLoggerStack->queries); +// foreach (array_reverse($this->_sqlLoggerStack->queries) AS $query) { +// $params = array_map(function($p) { if (is_object($p)) return get_class($p); else return "'".print_r($p, true)."'"; }, $query['params'] ?: array()); +// $queries .= ($i+1).". SQL: '".$query['sql']."' Params: ".implode(", ", $params).PHP_EOL; +// $i--; +// } +// +// $trace = $e->getTrace(); +// $traceMsg = ""; +// foreach($trace AS $part) { +// if(isset($part['file'])) { +// if(strpos($part['file'], "PHPUnit/") !== false) { +// // Beginning with PHPUnit files we don't print the trace anymore. +// break; +// } +// +// $traceMsg .= $part['file'].":".$part['line'].PHP_EOL; +// } +// } +// +// $message = "[".get_class($e)."] ".$e->getMessage().PHP_EOL.PHP_EOL."With queries:".PHP_EOL.$queries.PHP_EOL."Trace:".PHP_EOL.$traceMsg; +// +// throw new \Exception($message, (int)$e->getCode(), $e); +// } +// throw $e; +// } + public function execute($stmt) { - return $this->_conn->query($stmt); + return $this->_conn->executeQuery($stmt); } public function refresh($table_name) diff --git a/test/Crate/Test/DBAL/Functional/BindingTest.php b/test/Crate/Test/DBAL/Functional/BindingTest.php index 819b151..c4768d8 100644 --- a/test/Crate/Test/DBAL/Functional/BindingTest.php +++ b/test/Crate/Test/DBAL/Functional/BindingTest.php @@ -22,9 +22,9 @@ namespace Crate\Test\DBAL\Functional; use Crate\Test\DBAL\DBALFunctionalTestCase; -use Doctrine\DBAL\DBALException; +use Doctrine\DBAL\Result; -class BindingTestCase extends DBALFunctionalTestCase +class BindingTest extends DBALFunctionalTestCase { public function testBindPositionalParam() @@ -32,27 +32,27 @@ public function testBindPositionalParam() $name = 'crate'; $stmt = $this->prepareStatement('SELECT * FROM sys.cluster WHERE name = ?'); - $stmt->bindParam(1, $name); - $stmt->execute(); + $stmt->bindValue(1, $name); + $stmt->executeStatement(); $noName = 'i0ejfNlzSFCloGYtSzddTw'; $stmt = $this->prepareStatement('SELECT * FROM sys.cluster WHERE name = ? OR master_node = ?'); - $stmt->bindParam(1, $name); - $stmt->bindParam(2, $noName); - $this->assertTrue($stmt->execute()); + $stmt->bindValue(1, $name); + $stmt->bindValue(2, $noName); + $this->assertInstanceOf(Result::class, $stmt->executeQuery()); } public function testBindPositionalValue() { $stmt = $this->prepareStatement('SELECT * FROM sys.cluster WHERE name = ?'); $stmt->bindValue(1, 'crate'); - $stmt->execute(); + $stmt->executeStatement(); $stmt = $this->prepareStatement('SELECT * FROM sys.cluster WHERE name = ? OR master_node = ?'); $stmt->bindValue(1, 'crate'); $stmt->bindValue(2, 'i0ejfNlzSFCloGYtSzddTw'); - $this->assertTrue($stmt->execute()); + $this->assertInstanceOf(Result::class, $stmt->executeQuery()); } public function testBindNamedParam() @@ -60,32 +60,32 @@ public function testBindNamedParam() $name = 'crate'; $stmt = $this->prepareStatement('SELECT * FROM sys.cluster WHERE name = :name'); - $stmt->bindParam('name', $name); - $stmt->execute(); + $stmt->bindValue('name', $name); + $stmt->executeStatement(); $noName = 'i0ejfNlzSFCloGYtSzddTw'; $stmt = $this->prepareStatement('SELECT * FROM sys.cluster WHERE name = :name OR master_node = :master_node'); - $stmt->bindParam('name', $name); - $stmt->bindParam('master_node', $noName); - $this->assertTrue($stmt->execute()); + $stmt->bindValue('name', $name); + $stmt->bindValue('master_node', $noName); + $this->assertInstanceOf(Result::class, $stmt->executeQuery()); } public function testBindNamedValue() { $stmt = $this->prepareStatement('SELECT * FROM sys.cluster WHERE name = :name'); $stmt->bindValue('name', 'crate'); - $stmt->execute(); + $stmt->executeStatement(); $stmt = $this->prepareStatement('SELECT * FROM sys.cluster WHERE name = :name OR master_node = :master_node'); $stmt->bindValue('name', 'crate'); $stmt->bindValue('master_node', 'i0ejfNlzSFCloGYtSzddTw'); - $this->assertTrue($stmt->execute()); + $this->assertInstanceOf(Result::class, $stmt->executeQuery()); } public function testBindTimestamp() { - if ($this->_conn->getSchemaManager()->tablesExist("foo")) { + if ($this->_conn->createSchemaManager()->tablesExist(["foo"])) { $this->execute("DROP TABLE foo"); } @@ -99,15 +99,15 @@ public function testBindTimestamp() $stmt = $this->prepareStatement('SELECT * FROM foo WHERE ts > ?'); $stmt->bindValue(1, $date, 'datetimetz'); - $stmt->execute(); - $row = $stmt->fetchAll(); + $result = $stmt->executeQuery(); + $row = $result->fetchAllAssociative(); $this->assertEquals($row[0]['id'], 3); $this->assertEquals($row[0]['ts'], 1413901593000); $stmt = $this->prepareStatement('SELECT * FROM foo WHERE ts < ?'); $stmt->bindValue(1, $date, 'datetime'); - $stmt->execute(); - $row = $stmt->fetchAll(); + $result = $stmt->executeQuery(); + $row = $result->fetchAllAssociative(); $this->assertEquals($row[0]['id'], 1); $this->assertEquals($row[0]['ts'], 1413901591000); diff --git a/test/Crate/Test/DBAL/Functional/ConnectionTest.php b/test/Crate/Test/DBAL/Functional/ConnectionTest.php index 3aa3d5f..de4dcb6 100644 --- a/test/Crate/Test/DBAL/Functional/ConnectionTest.php +++ b/test/Crate/Test/DBAL/Functional/ConnectionTest.php @@ -21,10 +21,14 @@ */ namespace Crate\Test\DBAL\Functional; +use Crate\PDO\PDOCrateDB; use Crate\Test\DBAL\DBALFunctionalTestCase; -use Crate\PDO\PDO; +use Doctrine\DBAL\Connection; +use Crate\DBAL\Driver\PDOCrate\Driver; +use Doctrine\DBAL\Statement; +use Crate\PDO\PDOStatement; -class ConnectionTestCase extends DBALFunctionalTestCase +class ConnectionTest extends DBALFunctionalTestCase { public function setUp() : void { @@ -49,40 +53,36 @@ public function testBasicAuthConnection() 'password' => $auth[1], ); $conn = \Doctrine\DBAL\DriverManager::getConnection($params); - $this->assertEquals($auth[0], $conn->getUsername()); - $this->assertEquals($auth[1], $conn->getPassword()); - $auth_attr = $conn->getWrappedConnection()->getAttribute(PDO::CRATE_ATTR_HTTP_BASIC_AUTH); - $this->assertEquals($auth_attr, $auth); + $this->assertEquals($auth[0], $conn->getParams()['user']); + $this->assertEquals($auth[1], $conn->getParams()['password']); + $auth_attr = $conn->getNativeConnection()->getAttribute(PDOCrateDB::CRATE_ATTR_HTTP_BASIC_AUTH); + $this->assertEquals($auth, $auth_attr); } public function testGetConnection() { - $this->assertInstanceOf('Doctrine\DBAL\Connection', $this->_conn); - $this->assertInstanceOf('Crate\DBAL\Driver\PDOCrate\PDOConnection', $this->_conn->getWrappedConnection()); + $this->assertInstanceOf(Connection::class, $this->_conn); } public function testGetDriver() { - $this->assertInstanceOf('Crate\DBAL\Driver\PDOCrate\Driver', $this->_conn->getDriver()); + $this->assertInstanceOf(Driver::class, $this->_conn->getDriver()); } public function testStatement() { $sql = 'SELECT * FROM sys.cluster'; $stmt = $this->_conn->prepare($sql); - $this->assertInstanceOf('Doctrine\DBAL\Statement', $stmt); - $this->assertInstanceOf('Crate\PDO\PDOStatement', $stmt->getWrappedStatement()); - + $this->assertInstanceOf(Statement::class, $stmt); + $this->assertInstanceOf(\Doctrine\DBAL\Driver\Statement::class, $stmt->getWrappedStatement()); } public function testConnect() { - $this->assertTrue($this->_conn->connect()); - - $stmt = $this->_conn->query('select * from sys.cluster'); + $stmt = $this->_conn->executeQuery('select * from sys.cluster'); $this->assertEquals(1, $stmt->rowCount()); - $row = $stmt->fetch(); + $row = $stmt->fetchAssociative(); $this->assertEquals('crate', $row['name']); } diff --git a/test/Crate/Test/DBAL/Functional/DataAccessTest.php b/test/Crate/Test/DBAL/Functional/DataAccessTest.php index 4a3cfbe..546311c 100644 --- a/test/Crate/Test/DBAL/Functional/DataAccessTest.php +++ b/test/Crate/Test/DBAL/Functional/DataAccessTest.php @@ -24,15 +24,16 @@ use Crate\DBAL\Types\MapType; use Crate\Test\DBAL\DBALFunctionalTestCase; -use Doctrine\DBAL\DBALException; +use Doctrine\DBAL\Exception; use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Schema\Column; use Doctrine\DBAL\Types\Type; use Doctrine\DBAL\Connection; +use Doctrine\DBAL\Types\Types; use PDO; -class DataAccessTestCase extends DBALFunctionalTestCase +class DataAccessTest extends DBALFunctionalTestCase { static private $generated = false; @@ -43,7 +44,7 @@ public function setUp() : void if (self::$generated === false) { self::$generated = true; /* @var $sm \Doctrine\DBAL\Schema\AbstractSchemaManager */ - $sm = $this->_conn->getSchemaManager(); + $sm = $this->_conn->createSchemaManager(); $table = new \Doctrine\DBAL\Schema\Table("fetch_table"); $table->addColumn('test_int', 'integer'); $table->addColumn('test_string', 'string'); @@ -90,9 +91,9 @@ public function testPrepareWithBindValue() $stmt->bindValue(1, 1, PDO::PARAM_INT); $stmt->bindValue(2, 'foo', PDO::PARAM_STR); - $stmt->execute(); + $result = $stmt->executeQuery(); - $row = $stmt->fetch(\PDO::FETCH_ASSOC); + $row = $result->fetchAssociative(); $row = array_change_key_case($row, \CASE_LOWER); $this->assertEquals(array('test_int' => 1, 'test_string' => 'foo'), $row); } @@ -106,11 +107,11 @@ public function testPrepareWithBindParam() $stmt = $this->_conn->prepare($sql); $this->assertInstanceOf('Doctrine\DBAL\Statement', $stmt); - $stmt->bindParam(1, $paramInt, PDO::PARAM_INT); - $stmt->bindParam(2, $paramStr, PDO::PARAM_STR); - $stmt->execute(); + $stmt->bindValue(1, $paramInt, PDO::PARAM_INT); + $stmt->bindValue(2, $paramStr, PDO::PARAM_STR); + $result = $stmt->executeQuery(); - $row = $stmt->fetch(\PDO::FETCH_ASSOC); + $row = $result->fetchAssociative(); $row = array_change_key_case($row, \CASE_LOWER); $this->assertEquals(array('test_int' => 1, 'test_string' => 'foo'), $row); } @@ -124,11 +125,11 @@ public function testPrepareWithFetchAll() $stmt = $this->_conn->prepare($sql); $this->assertInstanceOf('Doctrine\DBAL\Statement', $stmt); - $stmt->bindParam(1, $paramInt, PDO::PARAM_INT); - $stmt->bindParam(2, $paramStr, PDO::PARAM_STR); - $stmt->execute(); + $stmt->bindValue(1, $paramInt, PDO::PARAM_INT); + $stmt->bindValue(2, $paramStr, PDO::PARAM_STR); + $result = $stmt->executeQuery(); - $rows = $stmt->fetchAll(\PDO::FETCH_ASSOC); + $rows = $result->fetchAllAssociative(); $rows[0] = array_change_key_case($rows[0], \CASE_LOWER); $this->assertEquals(array( 'test_int' => 1, @@ -158,11 +159,11 @@ public function testPrepareWithFetchAllBoth() $stmt = $this->_conn->prepare($sql); $this->assertInstanceOf('Doctrine\DBAL\Statement', $stmt); - $stmt->bindParam(1, $paramInt, PDO::PARAM_INT); - $stmt->bindParam(2, $paramStr, PDO::PARAM_STR); - $stmt->execute(); + $stmt->bindValue(1, $paramInt, PDO::PARAM_INT); + $stmt->bindValue(2, $paramStr, PDO::PARAM_STR); + $result = $stmt->executeQuery(); - $rows = $stmt->fetchAll(\PDO::FETCH_BOTH); + $rows = $result->fetchAll(PDO::FETCH_BOTH); $rows[0] = array_change_key_case($rows[0], \CASE_LOWER); $this->assertEquals(array('test_int' => 1, 'test_string' => 'foo', 0 => 1, 1 => 'foo'), $rows[0]); } @@ -176,11 +177,11 @@ public function testPrepareWithFetchColumn() $stmt = $this->_conn->prepare($sql); $this->assertInstanceOf('Doctrine\DBAL\Statement', $stmt); - $stmt->bindParam(1, $paramInt, PDO::PARAM_INT); - $stmt->bindParam(2, $paramStr, PDO::PARAM_STR); - $stmt->execute(); + $stmt->bindValue(1, $paramInt, PDO::PARAM_INT); + $stmt->bindValue(2, $paramStr, PDO::PARAM_STR); + $result = $stmt->executeQuery(); - $column = $stmt->fetchColumn(); + $column = $result->fetchOne(); $this->assertEquals(1, $column); } @@ -193,13 +194,12 @@ public function testPrepareWithIterator() $stmt = $this->_conn->prepare($sql); $this->assertInstanceOf('Doctrine\DBAL\Statement', $stmt); - $stmt->bindParam(1, $paramInt, PDO::PARAM_INT); - $stmt->bindParam(2, $paramStr, PDO::PARAM_STR); - $stmt->execute(); + $stmt->bindValue(1, $paramInt, PDO::PARAM_INT); + $stmt->bindValue(2, $paramStr, PDO::PARAM_STR); + $result = $stmt->executeQuery(); $rows = array(); - $stmt->setFetchMode(\PDO::FETCH_ASSOC); - foreach ($stmt as $row) { + while ($row = $result->fetchAssociative()) { $rows[] = array_change_key_case($row, \CASE_LOWER); } @@ -226,9 +226,9 @@ public function testPrepareWithExecuteParams() $sql = "SELECT test_int, test_string FROM fetch_table WHERE test_int = ? AND test_string = ?"; $stmt = $this->_conn->prepare($sql); $this->assertInstanceOf('Doctrine\DBAL\Statement', $stmt); - $stmt->execute(array($paramInt, $paramStr)); + $result = $stmt->executeQuery(array($paramInt, $paramStr)); - $row = $stmt->fetch(\PDO::FETCH_ASSOC); + $row = $result->fetchAssociative(); $this->assertTrue($row !== false); $row = array_change_key_case($row, \CASE_LOWER); $this->assertEquals(array('test_int' => 1, 'test_string' => 'foo'), $row); @@ -237,7 +237,7 @@ public function testPrepareWithExecuteParams() public function testFetchAll() { $sql = "SELECT test_int, test_string FROM fetch_table WHERE test_int = ? AND test_string = ?"; - $data = $this->_conn->fetchAll($sql, array(1, 'foo')); + $data = $this->_conn->fetchAllAssociative($sql, array(1, 'foo')); $this->assertEquals(1, count($data)); @@ -249,6 +249,7 @@ public function testFetchAll() $this->assertEquals('foo', $row['test_string']); } + // @todo maybe this is deprecated? There is no way to do this in dbal currently. public function testFetchBoth() { $sql = "SELECT test_int, test_string FROM fetch_table WHERE test_int = ? AND test_string = ?"; @@ -267,7 +268,7 @@ public function testFetchBoth() public function testFetchRow() { $sql = "SELECT test_int, test_string FROM fetch_table WHERE test_int = ? AND test_string = ?"; - $row = $this->_conn->fetchAssoc($sql, array(1, 'foo')); + $row = $this->_conn->fetchAssociative($sql, array(1, 'foo')); $this->assertTrue($row !== false); @@ -280,7 +281,7 @@ public function testFetchRow() public function testFetchArray() { $sql = "SELECT test_int, test_string FROM fetch_table WHERE test_int = ? AND test_string = ?"; - $row = $this->_conn->fetchArray($sql, array(1, 'foo')); + $row = $this->_conn->fetchNumeric($sql, array(1, 'foo')); $this->assertEquals(1, $row[0]); $this->assertEquals('foo', $row[1]); @@ -289,7 +290,7 @@ public function testFetchArray() public function testFetchColumn() { $sql = "SELECT test_int, test_string FROM fetch_table WHERE test_int = ? AND test_string = ?"; - $testInt = $this->_conn->fetchColumn($sql, array(1, 'foo'), 0); + $testInt = $this->_conn->fetchOne($sql, array(1, 'foo')); $this->assertEquals(1, $testInt); @@ -307,10 +308,10 @@ public function testExecuteQueryBindDateTimeType() $sql = 'SELECT count(*) AS c FROM fetch_table WHERE test_datetime = ?'; $stmt = $this->_conn->executeQuery($sql, array(1 => new \DateTime('2010-01-01 10:10:10')), - array(1 => Type::DATETIME) + array(1 => Types::DATETIME_MUTABLE) ); - $this->assertEquals(1, $stmt->fetchColumn()); + $this->assertEquals(1, $stmt->fetchOne()); } /** @@ -321,9 +322,9 @@ public function testExecuteUpdateBindDateTimeType() $datetime = new \DateTime('2010-02-02 20:20:20'); $sql = 'INSERT INTO fetch_table (test_int, test_string, test_datetime) VALUES (?, ?, ?)'; - $affectedRows = $this->_conn->executeUpdate($sql, + $affectedRows = $this->_conn->executeStatement($sql, array(1 => 50, 2 => 'foo', 3 => $datetime), - array(1 => PDO::PARAM_INT, 2 => PDO::PARAM_STR, 3 => Type::DATETIME) + array(1 => PDO::PARAM_INT, 2 => PDO::PARAM_STR, 3 => Types::DATETIME_MUTABLE) ); $this->assertEquals(1, $affectedRows); $this->refresh('fetch_table'); @@ -331,8 +332,8 @@ public function testExecuteUpdateBindDateTimeType() $this->assertEquals(1, $this->_conn->executeQuery( 'SELECT count(*) AS c FROM fetch_table WHERE test_datetime = ?', array(1 => $datetime), - array(1 => Type::DATETIME) - )->fetchColumn()); + array(1 => Types::DATETIME_MUTABLE) + )->fetchOne()); } /** @@ -342,10 +343,10 @@ public function testPrepareQueryBindValueDateTimeType() { $sql = 'SELECT count(*) AS c FROM fetch_table WHERE test_datetime = ?'; $stmt = $this->_conn->prepare($sql); - $stmt->bindValue(1, new \DateTime('2010-01-01 10:10:10'), Type::DATETIME); - $stmt->execute(); + $stmt->bindValue(1, new \DateTime('2010-01-01 10:10:10'), Types::DATETIME_MUTABLE); + $result = $stmt->executeQuery(); - $this->assertEquals(1, $stmt->fetchColumn()); + $this->assertEquals(1, $result->fetchOne()); } /** @@ -361,14 +362,14 @@ public function testNativeArrayListSupport() $stmt = $this->_conn->executeQuery('SELECT test_int FROM fetch_table WHERE test_int IN (?) ORDER BY test_int', array(array(100, 101, 102, 103, 104)), array(Connection::PARAM_INT_ARRAY)); - $data = $stmt->fetchAll(PDO::FETCH_NUM); + $data = $stmt->fetchAllNumeric(); $this->assertEquals(5, count($data)); $this->assertEquals(array(array(100), array(101), array(102), array(103), array(104)), $data); $stmt = $this->_conn->executeQuery('SELECT test_int FROM fetch_table WHERE test_string IN (?) ORDER BY test_int', array(array('foo100', 'foo101', 'foo102', 'foo103', 'foo104')), array(Connection::PARAM_STR_ARRAY)); - $data = $stmt->fetchAll(PDO::FETCH_NUM); + $data = $stmt->fetchAllNumeric(); $this->assertEquals(5, count($data)); $this->assertEquals(array(array(100), array(101), array(102), array(103), array(104)), $data); } @@ -402,10 +403,10 @@ public function testDateArithmetics() public function testQuoteSQLInjection() { - $this->expectException(DBALException::class); + $this->expectException(Exception::class); $sql = "SELECT * FROM fetch_table WHERE test_string = bar' OR '1'='1"; - $this->_conn->fetchAll($sql); + $this->_conn->fetchAllAssociative($sql); } /** @@ -439,7 +440,7 @@ public function testBitComparisonExpressionSupport() $sql[] = 'FROM fetch_table'; $stmt = $this->_conn->executeQuery(implode(PHP_EOL, $sql)); - $data = $stmt->fetchAll(PDO::FETCH_ASSOC); + $data = $stmt->fetchAllAssociative(); $this->assertEquals(4, count($data)); @@ -464,105 +465,30 @@ public function testBitComparisonExpressionSupport() public function testSetDefaultFetchMode() { - $stmt = $this->_conn->query("SELECT * FROM fetch_table"); - $stmt->setFetchMode(\PDO::FETCH_NUM); + $stmt = $this->_conn->executeQuery("SELECT * FROM fetch_table"); - $row = array_keys($stmt->fetch()); + $row = array_keys($stmt->fetchNumeric()); $this->assertEquals(0, count( array_filter($row, function($v) { return ! is_numeric($v); })), "should be no non-numerical elements in the result."); } - /** - * @group DBAL-196 - */ - public function testFetchAllSupportFetchClass() - { - $this->markTestSkipped("PDO::FETCH_CLASS not supported by crate PDO"); - - $this->setupFixture(); - - $sql = "SELECT test_int, test_string, test_datetime FROM fetch_table"; - $stmt = $this->_conn->prepare($sql); - $stmt->execute(); - - $results = $stmt->fetchAll( - \PDO::FETCH_CLASS, - __NAMESPACE__.'\\MyFetchClass' - ); - - $this->assertEquals(1, count($results)); - $this->assertInstanceOf(__NAMESPACE__.'\\MyFetchClass', $results[0]); - - $this->assertEquals(1, $results[0]->test_int); - $this->assertEquals('foo', $results[0]->test_string); - $this->assertStringStartsWith('2010-01-01T10:10:10', $results[0]->test_datetime); - } - /** * @group DBAL-241 */ public function testFetchAllStyleColumn() { $sql = "DELETE FROM fetch_table"; - $this->_conn->executeUpdate($sql); + $this->_conn->executeStatement($sql); $this->_conn->insert('fetch_table', array('test_int' => 1, 'test_string' => 'foo')); $this->_conn->insert('fetch_table', array('test_int' => 10, 'test_string' => 'foo')); $this->refresh("fetch_table"); $sql = "SELECT test_int FROM fetch_table ORDER BY test_int ASC"; - $rows = $this->_conn->query($sql)->fetchAll(\PDO::FETCH_COLUMN); + $rows = $this->_conn->executeQuery($sql)->fetchAll(PDO::FETCH_COLUMN); $this->assertEquals(array(1, 10), $rows); } - /** - * @group DBAL-214 - */ - public function testSetFetchModeClassFetchAll() - { - $this->markTestSkipped("PDO::FETCH_CLASS not supported crate PDO"); - $this->setupFixture(); - - $sql = "SELECT * FROM fetch_table"; - $stmt = $this->_conn->query($sql); - $stmt->setFetchMode(\PDO::FETCH_CLASS, __NAMESPACE__ . '\\MyFetchClass', array()); - - $results = $stmt->fetchAll(); - - $this->assertEquals(1, count($results)); - $this->assertInstanceOf(__NAMESPACE__.'\\MyFetchClass', $results[0]); - - $this->assertEquals(1, $results[0]->test_int); - $this->assertEquals('foo', $results[0]->test_string); - $this->assertStringStartsWith('2010-01-01T10:10:10', $results[0]->test_datetime); - } - - /** - * @group DBAL-214 - */ - public function testSetFetchModeClassFetch() - { - $this->markTestSkipped("PDO::FETCH_CLASS not supported by crate PDO"); - - $this->setupFixture(); - - $sql = "SELECT * FROM fetch_table"; - $stmt = $this->_conn->query($sql); - $stmt->setFetchMode(\PDO::FETCH_CLASS, __NAMESPACE__ . '\\MyFetchClass', array()); - - $results = array(); - while ($row = $stmt->fetch()) { - $results[] = $row; - } - - $this->assertEquals(1, count($results)); - $this->assertInstanceOf(__NAMESPACE__.'\\MyFetchClass', $results[0]); - - $this->assertEquals(1, $results[0]->test_int); - $this->assertEquals('foo', $results[0]->test_string); - $this->assertStringStartsWith('2010-01-01T10:10:10', $results[0]->test_datetime); - } - /** * @group DBAL-257 */ @@ -570,8 +496,8 @@ public function testEmptyFetchColumnReturnsFalse() { $this->_conn->executeQuery('DELETE FROM fetch_table')->execute(); $this->refresh("fetch_table"); - $this->assertFalse($this->_conn->fetchColumn('SELECT test_int FROM fetch_table')); - $this->assertFalse($this->_conn->query('SELECT test_int FROM fetch_table')->fetchColumn()); + $this->assertFalse($this->_conn->fetchOne('SELECT test_int FROM fetch_table')); + $this->assertFalse($this->_conn->executeQuery('SELECT test_int FROM fetch_table')->fetchOne()); } /** @@ -581,9 +507,8 @@ public function testSetFetchModeOnDbalStatement() { $sql = "SELECT test_int, test_string FROM fetch_table WHERE test_int = ? AND test_string = ?"; $stmt = $this->_conn->executeQuery($sql, array(1, "foo")); - $stmt->setFetchMode(\PDO::FETCH_NUM); - while ($row = $stmt->fetch()) { + while ($row = $stmt->fetchNumeric()) { $this->assertTrue(isset($row[0])); $this->assertTrue(isset($row[1])); } diff --git a/test/Crate/Test/DBAL/Functional/ModifyLimitQueryTest.php b/test/Crate/Test/DBAL/Functional/ModifyLimitQueryTest.php index a0eb173..7f326e5 100644 --- a/test/Crate/Test/DBAL/Functional/ModifyLimitQueryTest.php +++ b/test/Crate/Test/DBAL/Functional/ModifyLimitQueryTest.php @@ -23,7 +23,7 @@ namespace Crate\Test\DBAL\Functional; use Crate\Test\DBAL\DBALFunctionalTestCase; -use Doctrine\DBAL\DBALException; +use Doctrine\DBAL\Exception; class ModifyLimitQueryTest extends DBALFunctionalTestCase @@ -61,7 +61,7 @@ public function tearDown() : void $sm->dropTable('modify_limit_table'); $sm->dropTable('modify_limit_table2'); self::$tableCreated = false; - } catch (DBALException $e) {} + } catch (Exception $e) {} } } @@ -117,7 +117,7 @@ public function assertLimitResult($expectedResults, $sql, $limit, $offset) { $p = $this->_conn->getDatabasePlatform(); $data = array(); - foreach ($this->_conn->fetchAll($p->modifyLimitQuery($sql, $limit, $offset)) AS $row) { + foreach ($this->_conn->fetchAllAssociative($p->modifyLimitQuery($sql, $limit, $offset)) AS $row) { $row = array_change_key_case($row, CASE_LOWER); $data[] = $row['test_int']; } diff --git a/test/Crate/Test/DBAL/Functional/NamedParametersTest.php b/test/Crate/Test/DBAL/Functional/NamedParametersTest.php index a2c4de6..d71205f 100644 --- a/test/Crate/Test/DBAL/Functional/NamedParametersTest.php +++ b/test/Crate/Test/DBAL/Functional/NamedParametersTest.php @@ -167,7 +167,7 @@ public function tearDown() : void public function testTicket($query,$params,$types,$expected) { $stmt = $this->_conn->executeQuery($query, $params, $types); - $result = $stmt->fetchAll(\PDO::FETCH_ASSOC); + $result = $stmt->fetchAllAssociative(); foreach ($result as $k => $v) { $result[$k] = array_change_key_case($v, CASE_LOWER); diff --git a/test/Crate/Test/DBAL/Functional/Schema/SchemaManagerTest.php b/test/Crate/Test/DBAL/Functional/Schema/SchemaManagerTest.php index 00988d9..9c316d7 100644 --- a/test/Crate/Test/DBAL/Functional/Schema/SchemaManagerTest.php +++ b/test/Crate/Test/DBAL/Functional/Schema/SchemaManagerTest.php @@ -28,6 +28,7 @@ use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Types\IntegerType; use Doctrine\DBAL\Types\Type; +use Doctrine\DBAL\Types\Types; class SchemaManagerTest extends DBALFunctionalTestCase { @@ -75,12 +76,12 @@ public function testListTables() public function createListTableColumns() { $table = new Table('list_table_columns'); - $table->addColumn('text', Type::STRING); + $table->addColumn('text', Types::STRING); $table->addColumn('ts', TimestampType::NAME); - $table->addColumn('num_float_double', Type::FLOAT); - $table->addColumn('num_short', Type::SMALLINT); - $table->addColumn('num_int', Type::INTEGER); - $table->addColumn('num_long', Type::BIGINT); + $table->addColumn('num_float_double', Types::FLOAT); + $table->addColumn('num_short', Types::SMALLINT); + $table->addColumn('num_int', Types::INTEGER); + $table->addColumn('num_long', Types::BIGINT); $table->addColumn('id', 'integer', array('notnull' => true)); $table->setPrimaryKey(array('id')); @@ -101,7 +102,7 @@ public function createListTableColumns() // ARRAY schema definition via platform options $arrOpts = array( - 'type' => Type::FLOAT, + 'type' => Types::FLOAT, ); $table->addColumn('arr_float', 'array', array('platformOptions'=>$arrOpts)); @@ -119,7 +120,8 @@ public function testListTableColumns() { $table = $this->createListTableColumns(); - $this->_sm->dropAndCreateTable($table); + $this->_sm->dropTable($table); + $this->_sm->createTable($table); $columns = $this->_sm->listTableColumns('list_table_columns'); $columnsKeys = array_keys($columns); @@ -209,7 +211,7 @@ protected function createTestTable($name = 'test_table', $data = array()) protected function getTestTable($name, $options=array()) { - $table = new Table($name, array(), array(), array(), false, $options); + $table = new Table($name, array(), array(), array(), [], $options); $table->setSchemaConfig($this->_sm->createSchemaConfig()); $table->addColumn('id', 'integer', array('notnull' => true)); $table->setPrimaryKey(array('id')); @@ -220,7 +222,7 @@ protected function getTestTable($name, $options=array()) protected function getTestCompositeTable($name) { - $table = new Table($name, array(), array(), array(), false, array()); + $table = new Table($name, array(), array(), array(), [], array()); $table->setSchemaConfig($this->_sm->createSchemaConfig()); $table->addColumn('id', 'integer', array('notnull' => true)); $table->addColumn('other_id', 'integer', array('notnull' => true)); diff --git a/test/Crate/Test/DBAL/Functional/TableOptionsTest.php b/test/Crate/Test/DBAL/Functional/TableOptionsTest.php index 9f545b7..ec29189 100644 --- a/test/Crate/Test/DBAL/Functional/TableOptionsTest.php +++ b/test/Crate/Test/DBAL/Functional/TableOptionsTest.php @@ -22,10 +22,8 @@ namespace Crate\Test\DBAL\Functional; - -use Crate\DBAL\Platforms\CratePlatform; +use Crate\DBAL\Types\TimestampType; use Crate\Test\DBAL\DBALFunctionalTestCase; -use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Schema\Table; use InvalidArgumentException; @@ -56,7 +54,7 @@ public function testAdditionalTableOptions() $options['table_options']['number_of_replicas'] = '0-2'; $options['table_options']['write.wait_for_active_shards'] = 'ALL'; - $table = new Table('t1', [], [], [], 0, $options); + $table = new Table('t1', [], [], [], [], $options); $table->addColumn('id', 'integer'); $table->addColumn('parted', 'integer'); $table->addColumn('date', 'timestamp'); @@ -72,6 +70,8 @@ public function testAdditionalTableOptions() public function testGetAdditionalTableOptions() { + $platform = $this->_conn->getDatabasePlatform(); + $options = []; $options['sharding_routing_column'] = 'id'; $options['sharding_num_shards'] = 6; @@ -80,10 +80,10 @@ public function testGetAdditionalTableOptions() $options['table_options']['number_of_replicas'] = '0-2'; $options['table_options']['write.wait_for_active_shards'] = 'ALL'; - $table = new Table('table_option_test', [], [], [], 0, $options); + $table = new Table('table_option_test', [], [], [], [], $options); $table->addColumn('id', 'integer'); $table->addColumn('parted', 'integer'); - $table->addColumn('date', 'timestamp'); + $table->addColumn('date', TimestampType::NAME); $sm = $this->_conn->getSchemaManager(); $sm->createTable($table); @@ -106,7 +106,7 @@ public function testPartitionColumnsNotArray() $options = []; $options['partition_columns'] = 'parted'; - $table = new Table('t1', [], [], [], 0, $options); + $table = new Table('t1', [], [], [], [], $options); $table->addColumn('parted', 'integer'); $this->expectException(InvalidArgumentException::class); diff --git a/test/Crate/Test/DBAL/Functional/TypeConversionTest.php b/test/Crate/Test/DBAL/Functional/TypeConversionTest.php index 7ae5f6e..7291a92 100644 --- a/test/Crate/Test/DBAL/Functional/TypeConversionTest.php +++ b/test/Crate/Test/DBAL/Functional/TypeConversionTest.php @@ -24,13 +24,13 @@ use Crate\DBAL\Platforms\CratePlatform; use Crate\DBAL\Types\TimestampType; -use Crate\Test\DBAL\DBALFunctionalTestCase; use Crate\DBAL\Types\ArrayType; use Crate\DBAL\Types\MapType; use Doctrine\DBAL\Types\Type; +use Doctrine\DBAL\Types\Types; use PHPUnit\Framework\TestCase; -class TypeConversionTestCase extends TestCase { +class TypeConversionTest extends TestCase { private $platform; @@ -44,7 +44,7 @@ public function testTimestampType() $input = new \DateTime("2014-10-21 15:23:38"); // datetimetz - $type = Type::getType(Type::DATETIMETZ); + $type = Type::getType(Types::DATETIMETZ_MUTABLE); $expected = $input->format('Y-m-d\TH:i:sO'); $output = $type->convertToDatabaseValue($input, $this->platform); $this->assertEquals($output, $expected); @@ -54,7 +54,7 @@ public function testTimestampType() $this->assertEquals($inputRestored, $input); // datetime - $type = Type::getType(Type::DATETIME); + $type = Type::getType(Types::DATETIME_MUTABLE); $expected = $input->format('Y-m-d\TH:i:s'); $output = $type->convertToDatabaseValue($input, $this->platform); $this->assertEquals($output, $expected); @@ -64,7 +64,7 @@ public function testTimestampType() $this->assertEquals($inputRestored, $input); // date - $type = Type::getType(Type::DATE); + $type = Type::getType(Types::DATE_MUTABLE); $expected = $input->format('Y-m-d\TH:i:s'); $output = $type->convertToDatabaseValue($input, $this->platform); $this->assertEquals($output, $expected); @@ -74,7 +74,7 @@ public function testTimestampType() $this->assertEquals($inputRestored, $input); // time - $type = Type::getType(Type::TIME); + $type = Type::getType(Types::TIME_MUTABLE); $expected = $input->format('Y-m-d\TH:i:s'); $output = $type->convertToDatabaseValue($input, $this->platform); $this->assertEquals($output, $expected); @@ -96,10 +96,10 @@ public function testTimestampType() public function testTimestampTypeNull() { - $types = array(Type::getType(Type::DATETIMETZ), - Type::getType(Type::DATETIME), - Type::getType(Type::DATE), - Type::getType(Type::TIME), + $types = array(Type::getType(Types::DATETIMETZ_MUTABLE), + Type::getType(Types::DATETIME_MUTABLE), + Type::getType(Types::DATE_MUTABLE), + Type::getType(Types::TIME_MUTABLE), Type::getType(TimestampType::NAME) ); foreach ($types as $type) { diff --git a/test/Crate/Test/DBAL/Functional/Types/MapTypeTest.php b/test/Crate/Test/DBAL/Functional/Types/MapTypeTest.php index 83a5f71..66a3eeb 100644 --- a/test/Crate/Test/DBAL/Functional/Types/MapTypeTest.php +++ b/test/Crate/Test/DBAL/Functional/Types/MapTypeTest.php @@ -29,6 +29,7 @@ use Doctrine\DBAL\Schema\Column; use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Types\Type; +use Doctrine\DBAL\Types\Types; class MapTypeTest extends DBALFunctionalTestCase { @@ -39,8 +40,8 @@ public function testStrictMapTableCreationWithSchemaManager() { $objDefinition = array( 'type' => MapType::STRICT, 'fields' => array( - new Column('id', Type::getType(Type::INTEGER), array()), - new Column('name', Type::getType(Type::STRING), array()), + new Column('id', Type::getType(Types::INTEGER), array()), + new Column('name', Type::getType(Types::STRING), array()), ), ); $table->addColumn( @@ -53,4 +54,4 @@ public function testStrictMapTableCreationWithSchemaManager() { $this->assertEquals(array('CREATE TABLE items (object_column OBJECT ( strict ) AS ( id INTEGER, name TEXT ))'), $sql); } -} \ No newline at end of file +} diff --git a/test/Crate/Test/DBAL/Functional/WriteTest.php b/test/Crate/Test/DBAL/Functional/WriteTest.php index 635a4ff..461cea7 100644 --- a/test/Crate/Test/DBAL/Functional/WriteTest.php +++ b/test/Crate/Test/DBAL/Functional/WriteTest.php @@ -25,7 +25,9 @@ use Crate\DBAL\Types\MapType; use Crate\Test\DBAL\DBALFunctionalTestCase; use Doctrine\DBAL\Schema\Column; +use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Types\Type; +use Doctrine\DBAL\Types\Types; use PDO; class WriteTest extends DBALFunctionalTestCase @@ -39,20 +41,23 @@ public function setUp() : void if (self::$generated === false) { self::$generated = true; /* @var $sm \Doctrine\DBAL\Schema\AbstractSchemaManager */ + $sm = $this->_conn->createSchemaManager(); + $platform = $this->_conn->getDatabasePlatform(); $table = new \Doctrine\DBAL\Schema\Table("write_table"); - $table->addColumn('test_int', Type::INTEGER); - $table->addColumn('test_string', Type::STRING); - $table->addColumn('test_float', Type::FLOAT); - $table->addColumn('test_array', Type::TARRAY, array('columnDefinition'=>'ARRAY(STRING)')); + $table->setSchemaConfig($sm->createSchemaConfig()); + $table->addColumn('test_int', Types::INTEGER); + $table->addColumn('test_string', Types::STRING); + $table->addColumn('test_float', Types::FLOAT); + $table->addColumn('test_array', Types::ARRAY, array('columnDefinition'=>'ARRAY(STRING)')); $table->addColumn("test_map", MapType::NAME); - $table->addColumn("test_bool", Type::BOOLEAN); + $table->addColumn("test_bool", Types::BOOLEAN); $platformOptions = array( 'type' => MapType::STRICT, 'fields' => array( - new Column('id', Type::getType(Type::INTEGER), array()), - new Column('name', Type::getType(Type::STRING), array()), - new Column('value', Type::getType(Type::FLOAT), array()), + new Column('id', Type::getType(Types::INTEGER), array()), + new Column('name', Type::getType(Types::STRING), array()), + new Column('value', Type::getType(Types::FLOAT), array()), ), ); $table->addColumn('test_obj', MapType::NAME, array('platformOptions'=>$platformOptions)); @@ -77,19 +82,20 @@ public function tearDown() : void public function testExecuteUpdateFirstTypeIsNull() { $sql = "INSERT INTO write_table (test_string, test_int) VALUES (?, ?)"; - $this->_conn->executeUpdate($sql, array("text", 1111), array(null, PDO::PARAM_INT)); + $this->_conn->executeStatement($sql, array("text", 1111), array(null, PDO::PARAM_INT)); $this->refresh('write_table'); $sql = "SELECT test_obj, test_string, test_int FROM write_table WHERE test_string = ? AND test_int = ?"; - $this->assertEquals($this->_conn->fetchColumn($sql, array("text", 1111)), null); - $this->assertEquals($this->_conn->fetchColumn($sql, array("text", 1111), 1), "text"); - $this->assertEquals($this->_conn->fetchColumn($sql, array("text", 1111), 2), 1111); + $this->assertEquals($this->_conn->fetchOne($sql, array("text", 1111)), null); + // @Todo Currently not possible to get a colum by the offset + // $this->assertEquals($this->_conn->fetchOne($sql, array("text", 1111), 1), "text"); + // $this->assertEquals($this->_conn->fetchOne($sql, array("text", 1111), 2), 1111); } public function testExecuteUpdate() { $sql = "INSERT INTO write_table (test_int) VALUES ( " . $this->_conn->quote(1, PDO::PARAM_INT) . ")"; - $affected = $this->_conn->executeUpdate($sql); + $affected = $this->_conn->executeStatement($sql); $this->assertEquals(1, $affected, "executeUpdate() should return the number of affected rows!"); } @@ -97,7 +103,7 @@ public function testExecuteUpdate() public function testExecuteUpdateWithTypes() { $sql = "INSERT INTO write_table (test_int, test_string) VALUES (?, ?)"; - $affected = $this->_conn->executeUpdate($sql, array(1, 'foo'), array(\PDO::PARAM_INT, \PDO::PARAM_STR)); + $affected = $this->_conn->executeStatement($sql, array(1, 'foo'), array(\PDO::PARAM_INT, \PDO::PARAM_STR)); $this->assertEquals(1, $affected, "executeUpdate() should return the number of affected rows!"); } @@ -109,9 +115,9 @@ public function testPrepareRowCountReturnsAffectedRows() $stmt->bindValue(1, 1); $stmt->bindValue(2, "foo"); - $stmt->execute(); + $result = $stmt->executeQuery(); - $this->assertEquals(1, $stmt->rowCount()); + $this->assertEquals(1, $result->rowCount()); } public function testPrepareWithPdoTypes() @@ -121,9 +127,9 @@ public function testPrepareWithPdoTypes() $stmt->bindValue(1, 1, \PDO::PARAM_INT); $stmt->bindValue(2, "foo", \PDO::PARAM_STR); - $stmt->execute(); + $result = $stmt->executeQuery(); - $this->assertEquals(1, $stmt->rowCount()); + $this->assertEquals(1, $result->rowCount()); } public function testPrepareWithDbalTypes() @@ -135,9 +141,9 @@ public function testPrepareWithDbalTypes() $stmt->bindValue(2, "foo", Type::getType('string')); $stmt->bindValue(3, 3.141592, Type::getType('float')); $stmt->bindValue(4, array('id'=>1, 'name'=>'christian', 'value'=>1.234), Type::getType('map')); - $stmt->execute(); + $result = $stmt->executeQuery(); - $this->assertEquals(1, $stmt->rowCount()); + $this->assertEquals(1, $result->rowCount()); } public function testPrepareWithDbalTypeNames() @@ -150,9 +156,9 @@ public function testPrepareWithDbalTypeNames() $stmt->bindValue(3, 3.141592, 'float'); $stmt->bindValue(4, array('id'=>1, 'name'=>'christian', 'value'=>1.234), 'map'); $stmt->bindValue(5, true, 'boolean'); - $stmt->execute(); + $result = $stmt->executeQuery(); - $this->assertEquals(1, $stmt->rowCount()); + $this->assertEquals(1, $result->rowCount()); } public function insertRows() @@ -186,11 +192,11 @@ public function testDelete() $this->assertEquals(1, $this->_conn->delete('write_table', array('test_int' => 2))); $this->refresh('write_table'); - $this->assertEquals(1, count($this->_conn->fetchAll('SELECT * FROM write_table'))); + $this->assertEquals(1, count($this->_conn->fetchAllAssociative('SELECT * FROM write_table'))); $this->assertEquals(1, $this->_conn->delete('write_table', array('test_int' => 1))); $this->refresh('write_table'); - $this->assertEquals(0, count($this->_conn->fetchAll('SELECT * FROM write_table'))); + $this->assertEquals(0, count($this->_conn->fetchAllAssociative('SELECT * FROM write_table'))); } public function testUpdate() diff --git a/test/Crate/Test/DBAL/Platforms/CratePlatformTest.php b/test/Crate/Test/DBAL/Platforms/CratePlatformTest.php index f34f9c5..582414c 100644 --- a/test/Crate/Test/DBAL/Platforms/CratePlatformTest.php +++ b/test/Crate/Test/DBAL/Platforms/CratePlatformTest.php @@ -28,14 +28,16 @@ use Crate\DBAL\Types\ArrayType; use Crate\DBAL\Types\MapType; use Doctrine\Common\EventManager; -use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Events; +use Doctrine\DBAL\Exception; use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Schema\Column; use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Schema\TableDiff; use Doctrine\DBAL\Types\Type; -use Doctrine\Tests\DBAL\Platforms\AbstractPlatformTestCase; +use Doctrine\DBAL\Types\Types; +use Doctrine\DBAL\Tests\Platforms\AbstractPlatformTestCase; +use Doctrine\DBAL\Tests\Platforms\GetAlterTableSqlDispatchEventListener; class CratePlatformTest extends AbstractPlatformTestCase { @@ -54,6 +56,7 @@ public function getGenerateTableSql() : string public function getGenerateTableWithMultiColumnUniqueIndexSql() : array { + return []; } public function getGenerateTableWithMultiColumnIndexSql() @@ -138,7 +141,9 @@ public function testQuotedColumnInForeignKeyPropagation() : void $this->markTestSkipped('Platform does not support ADD FOREIGN KEY.'); } - protected function getQuotedColumnInForeignKeySQL() : array {} + protected function getQuotedColumnInForeignKeySQL() : array { + return []; + } protected function getQuotesReservedKeywordInUniqueConstraintDeclarationSQL() : string { @@ -158,7 +163,9 @@ public function testQuotesAlterTableRenameColumn() : void $this->markTestSkipped('Platform does not support ALTER TABLE.'); } - protected function getQuotedAlterTableRenameColumnSQL() : array {} + protected function getQuotedAlterTableRenameColumnSQL() : array { + return []; + } /** * @group DBAL-835 @@ -168,7 +175,10 @@ public function testQuotesAlterTableChangeColumnLength() : void $this->markTestSkipped('Platform does not support ALTER TABLE.'); } - protected function getQuotedAlterTableChangeColumnLengthSQL() : array {} + protected function getQuotedAlterTableChangeColumnLengthSQL() : array + { + return []; + } /** * @group DBAL-807 @@ -195,7 +205,10 @@ public function testGeneratesAlterTableRenameColumnSQL() : void $this->markTestSkipped('Platform does not support ALTER TABLE.'); } - public function getAlterTableRenameColumnSQL() : array {} + public function getAlterTableRenameColumnSQL() : array + { + return []; + } /** * @group DBAL-1016 @@ -205,7 +218,10 @@ public function testQuotesTableIdentifiersInAlterTableSQL() : void $this->markTestSkipped('Platform does not support ALTER TABLE.'); } - protected function getQuotesTableIdentifiersInAlterTableSQL() : array {} + protected function getQuotesTableIdentifiersInAlterTableSQL() : array + { + return []; + } /** * @group DBAL-1062 @@ -215,7 +231,10 @@ public function testGeneratesAlterTableRenameIndexUsedByForeignKeySQL() : void $this->markTestSkipped('Platform does not support ALTER TABLE.'); } - protected function getGeneratesAlterTableRenameIndexUsedByForeignKeySQL() : array {} + protected function getGeneratesAlterTableRenameIndexUsedByForeignKeySQL() : array + { + return []; + } /** * @group DBAL-1090 @@ -225,7 +244,10 @@ public function testAlterStringToFixedString() : void $this->markTestSkipped('Platform does not support ALTER TABLE.'); } - protected function getAlterStringToFixedStringSQL() : array {} + protected function getAlterStringToFixedStringSQL() : array + { + return []; + } public function testGenerateSubstrExpression() { @@ -235,7 +257,7 @@ public function testGenerateSubstrExpression() public function testGenerateNowExpression() { - $this->expectException(DBALException::class); + $this->expectException(Exception::class); $this->expectExceptionMessage('Operation \'Crate\DBAL\Platforms\CratePlatform::getNowExpression\' is not supported by platform.'); $this->platform->getNowExpression(); } @@ -247,7 +269,7 @@ public function testGenerateRegexExpression() public function testGenerateDateDiffExpression() { - $this->expectException(DBALException::class); + $this->expectException(Exception::class); $this->expectExceptionMessage('Operation \'Crate\DBAL\Platforms\CratePlatform::getDateDiffExpression\' is not supported by platform.'); $this->platform->getDateDiffExpression('2014-10-10 10:10:10', '2014-10-20 20:20:20'); @@ -255,7 +277,7 @@ public function testGenerateDateDiffExpression() public function testCreateDatabases() { - $this->expectException(DBALException::class); + $this->expectException(Exception::class); $this->expectExceptionMessage('Operation \'Crate\DBAL\Platforms\CratePlatform::getCreateDatabaseSQL\' is not supported by platform.'); $this->platform->getCreateDatabaseSQL('foo'); @@ -263,7 +285,7 @@ public function testCreateDatabases() public function testListDatabases() { - $this->expectException(DBALException::class); + $this->expectException(Exception::class); $this->expectExceptionMessage('Operation \'Crate\DBAL\Platforms\CratePlatform::getListDatabasesSQL\' is not supported by platform.'); $this->platform->getListDatabasesSQL(); @@ -271,7 +293,7 @@ public function testListDatabases() public function testDropDatabases() { - $this->expectException(DBALException::class); + $this->expectException(Exception::class); $this->expectExceptionMessage('Operation \'Crate\DBAL\Platforms\CratePlatform::getDropDatabaseSQL\' is not supported by platform.'); $this->platform->getDropDatabaseSQL('foo'); @@ -279,7 +301,7 @@ public function testDropDatabases() public function testGenerateBlobTypeGeneration() { - $this->expectException(DBALException::class); + $this->expectException(Exception::class); $this->expectExceptionMessage('Operation \'Crate\DBAL\Platforms\CratePlatform::getBlobTypeDeclarationSQL\' is not supported by platform.'); $this->platform->getBlobTypeDeclarationSQL(array()); @@ -287,14 +309,14 @@ public function testGenerateBlobTypeGeneration() public function testTruncateTableSQL() { - $this->expectException(DBALException::class); + $this->expectException(Exception::class); $this->platform->getTruncateTableSQL('foo'); } public function testReadLockSQL() { - $this->expectException(DBALException::class); + $this->expectException(Exception::class); $this->platform->getReadLockSQL(); } @@ -318,7 +340,7 @@ public function testSQLResultCasting() public function testGenerateTableSqlWithoutColumns() { - $this->expectException(DBALException::class); + $this->expectException(Exception::class); $this->expectExceptionMessage('No columns specified for table foo'); @@ -346,7 +368,7 @@ public function testGenerateTableSql() public function testUnsupportedUniqueIndexConstraint() { - $this->expectException(DBALException::class); + $this->expectException(Exception::class); $this->expectExceptionMessage("Unique constraints are not supported. Use `primary key` instead"); $table = new Table("foo"); @@ -357,7 +379,7 @@ public function testUnsupportedUniqueIndexConstraint() public function testUniqueConstraintInCustomSchemaOptions() { - $this->expectException(DBALException::class); + $this->expectException(Exception::class); $this->expectExceptionMessage("Unique constraints are not supported. Use `primary key` instead"); $table = new Table("foo"); @@ -380,11 +402,15 @@ public function testGeneratesTableAlterationSql() : void public function testGetAlterTableSqlDispatchEvent() : void { $events = array( - 'onSchemaAlterTableAddColumn' + 'onSchemaAlterTableAddColumn', + 'onSchemaAlterTableChangeColumn', + 'onSchemaAlterTableRemoveColumn', + 'onSchemaAlterTableRenameColumn', + 'onSchemaAlterTable' ); - $listenerMock = $this->getMockBuilder('GetAlterTableSqlDispatchEvenListener') - ->setMethods($events) + $listenerMock = $this->getMockBuilder(GetAlterTableSqlDispatchEventListener::class) + ->onlyMethods($events) ->getMock(); $listenerMock ->expects($this->once()) @@ -411,7 +437,7 @@ public function testGenerateTableWithMultiColumnUniqueIndex() : void $table->addColumn('bar', 'string', array('notnull' => false, 'length' => 255)); $table->addUniqueIndex(array("foo", "bar")); - $this->expectException(DBALException::class); + $this->expectException(Exception::class); $this->expectExceptionMessage('Operation \'Unique constraints are not supported. Use `primary key` instead\' is not supported by platform.'); $this->platform->getCreateTableSQL($table); @@ -455,8 +481,8 @@ public function testGenerateObjectSQLDeclaration() array('platformOptions'=>array( 'type'=>MapType::STRICT, 'fields'=>array( - new Column('num', Type::getType(Type::INTEGER)), - new Column('text', Type::getType(Type::STRING)), + new Column('num', Type::getType(Types::INTEGER)), + new Column('text', Type::getType(Types::STRING)), new Column('arr', Type::getType(ArrayType::NAME)), new Column('obj', Type::getType(MapType::NAME)), ), @@ -471,7 +497,7 @@ public function testGenerateArraySQLDeclaration() $this->assertEquals($this->getSQLDeclaration($column), 'arr ARRAY ( TEXT )'); $column = new Column('arr', Type::getType(ArrayType::NAME), - array('platformOptions'=> array('type'=>Type::INTEGER))); + array('platformOptions'=> array('type'=> Types::INTEGER))); $this->assertEquals($this->getSQLDeclaration($column), 'arr ARRAY ( INTEGER )'); } @@ -483,9 +509,7 @@ public function testPlatformSupport() { $this->assertFalse($this->platform->supportsIndexes()); $this->assertFalse($this->platform->supportsCommentOnStatement()); $this->assertFalse($this->platform->supportsForeignKeyConstraints()); - $this->assertFalse($this->platform->supportsForeignKeyOnUpdate()); $this->assertFalse($this->platform->supportsViews()); - $this->assertFalse($this->platform->prefersSequences()); } /** @@ -499,7 +523,7 @@ protected function getQuotesReservedKeywordInTruncateTableSQL() : string /** * @return array}> */ - public function asciiStringSqlDeclarationDataProvider() : array + public static function asciiStringSqlDeclarationDataProvider() : array { return [ ['TEXT', ['length' => 12]],