Skip to content
This repository has been archived by the owner on Jun 30, 2023. It is now read-only.

[Question] Plans for adding support for PostgreSQL? #137

Open
tomasnorre opened this issue Aug 13, 2021 · 7 comments
Open

[Question] Plans for adding support for PostgreSQL? #137

tomasnorre opened this issue Aug 13, 2021 · 7 comments

Comments

@tomasnorre
Copy link
Contributor

tomasnorre commented Aug 13, 2021

Hi.

Are there any plans for adding support for PostgreSQL.

When running my tests for the TYPO3 Crawler with typo3DatabaseDriver=pdo_pgsql I get the error: FATAL: database "typo3test_ft027f169" does not exist if I switch to the typo3/testing-framework the DB is created as expected.

Might be that I jumped to the wrong conclusion here, but looks to me that it's supported.

I have limited knowledge on PostgreSQL, but if I can help in any way getting this added, let me know.

@IchHabRecht
Copy link
Contributor

Hi @tomasnorre,

I'm not aware of any issues with PostgreSQL yet. Would you mind to check if there is an issue with Doctrine itself (see #136) and add an information about your TYPO3 and testing-framework versions.

@tomasnorre
Copy link
Contributor Author

tomasnorre commented Aug 13, 2021

Hi @IchHabRecht

Sure will see what I can figure out. As mentioned, can be that I jumped to the conclusion to fast. I'll update here when have more information.

TYPO3: 10.4.18
nimut/testing-framework: 5.2.1
doctrine/dbal: 2.13.2

@tomasnorre
Copy link
Contributor Author

I haven't found out the problem yet. If I add the database manually myself, my tests runs into this problem.

PDOException: SQLSTATE[42704]: Undefined object: 7 ERROR: unrecognized configuration parameter "sql_mode"

Commenting out the setDBinit line, they run through.
https://github.com/Nimut/testing-framework/blob/master/src/TestingFramework/TestSystem/AbstractTestSystem.php#L61

I'll keep looking into this.

Running my tests with the typo3/testing-framework they work, so I would not expect this to be a dbal/doctrine issue.

@tomasnorre
Copy link
Contributor Author

tomasnorre commented Aug 15, 2021

Just did a small "poc" for the nimut/testing-framework itself. It runs into the same problem with sql_mode as mentioned above when using PostgreSQL, but doesn't have a problem with the bootstrapping the DB as I do in the Crawler. So far so good, now I can check and compare how the tests are bootstrapped in the two cases.

Update: I don't find any differences in the tests run, besides that Nimut tests are through parallel. Both a using the FunctionalTests.xml that Nimut includes.

Reproducible with following commands:

$ php -v                                                                                                              
PHP 7.4.22 (cli) (built: Jul 30 2021 13:08:36) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.22, Copyright (c), by Zend Technologies
    with Xdebug v3.0.4, Copyright (c) 2002-2021, by Derick Rethans

$ docker run --tmpfs=/data -e PGDATA=/data -e POSTGRES_USER=root -e POSTGRES_PASSWORD=root -d -p 5432:5432 postgres:10

$ composer install

$ find '.Build/public/typo3conf/ext/testbase/Tests/Functional' -wholename '*Test.php' | parallel --gnu 'echo; echo "Running functional test suite {}"; typo3DatabaseDriver=pdo_pgsql .Build/bin/phpunit -c res/Configuration/FunctionalTests.xml {}';
1) Nimut\Testbase\Tests\Functional\TestSystem\TestSystemTest::databaseExceptionContainsErrorMessage
Failed asserting that exception of type "Doctrine\DBAL\Exception\DriverException" matches expected exception
RuntimeException". Message was: "An exception occurred while executing 'SET SESSION sql_mode = 
STRICT_ALL_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_VALUE_ON_ZERO,NO_ENGINE_SUBSTITUTION,NO_ZERO_DATE,NO_ZERO_IN_DATE,ONLY_FULL_GROUP_BY';':

SQLSTATE[42704]: Undefined object: 7 ERROR:  unrecognized configuration parameter "sql_mode"" at
testing-framework/.Build/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDO/Exception.php:18
testing-framework/.Build/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:58
testing-framework/.Build/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:1520
testing-framework/.Build/public/typo3/sysext/core/Classes/Database/Connection.php:107
testing-framework/.Build/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:1938
testing-framework/.Build/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:1276
testing-framework/.Build/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:1028
testing-framework/.Build/vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php:120
testing-framework/.Build/vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php:1063
testing-framework/.Build/public/typo3/sysext/core/Classes/Database/Schema/ConnectionMigrator.php:218
testing-framework/.Build/public/typo3/sysext/core/Classes/Database/Schema/ConnectionMigrator.php:142
testing-framework/.Build/public/typo3/sysext/core/Classes/Database/Schema/SchemaMigrator.php:178
testing-framework/src/TestingFramework/TestSystem/AbstractTestSystem.php:526
testing-framework/src/TestingFramework/TestSystem/AbstractTestSystem.php:149
testing-framework/src/TestingFramework/TestCase/AbstractFunctionalTestCase.php:202
testing-framework/tests/Packages/testbase/Tests/Functional/TestSystem/TestSystemTest.php:64

@IchHabRecht
Copy link
Contributor

Hi @tomasnorre,

Please try to include following configuration into your function test case:

    protected $configurationToUseInTestInstance = [
        'SYS' => [
            'setDBinit' => '',
        ],
    ];

The initial DB configuration was commented in the typo3 testing-framework due to another bug.

@tomasnorre
Copy link
Contributor Author

tomasnorre commented Aug 16, 2021

Will try it out. That would probably solve my sql_mode problem, but will still have the create db problem.
Will stay on this topic.

Added:
If I have to do that for every functional tests, It's too my like it's not compatible with PostgreSQL. I would rather have a check in the nimut/testing-framework not setting this is the tests were running against PostgreSQL. We have the typo3DatabaseDriver, that is used for SQLite check too, so it should be possible to check against it somewhere else too.

@tomasnorre
Copy link
Contributor Author

If updating https://github.com/Nimut/testing-framework/blob/main/src/TestingFramework/TestSystem/AbstractTestSystem.php#L672 to

if ($databaseDriver === 'pdo_sqlite') {
  $originalConfigurationArray['DB']['Connections']['Default']['path'] = $this->systemPath . 'test.sqlite';
  $originalConfigurationArray['DB']['Connections']['Default']['initCommands'] = '';
}
+ if ($databaseDriver === 'pdo_pgsql') {
+  $originalConfigurationArray['SYS']['setDBinit'] = '';
+  $originalConfigurationArray['DB']['Connections']['Default']['initCommands'] = '';
+}

Then the Tests are running with PostgreSQL too.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants