Nimut / testing-framework

TYPO3 testing framework that provides base classes and configuration for PHPUnit tests
GNU General Public License v2.0
52 stars 25 forks source link

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

Open tomasnorre opened 2 years ago

tomasnorre commented 2 years ago

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 commented 2 years ago

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 https://github.com/Nimut/testing-framework/issues/136) and add an information about your TYPO3 and testing-framework versions.

tomasnorre commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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.