I am struggling to understand how autoloading works when running integration tests in Nextcloud 20 and get the error Your test case is not allowed to access the database.
The “stable” documentation (same as NC 19?) still mentions the bootstrap.php which I also use, but the Nextcloud 20 documentation has no mention of it. How do integration tests work now?
Problem
In my app I implemented IBootstrap
already and deleted app.php. When i run my integration tests I get:
$ vendor/phpunit/phpunit/phpunit -c phpunit.xml.dist
PHPUnit 9.4.0 by Sebastian Bergmann and contributors.…FFFFF.FFFFFFFFFFF…F 44 / 44 (100%)
Time: 00:00.349, Memory: 24.00 MB
There were 17 failures:
- OCA\UserBackendSqlRaw\Tests\Integration\UserBackendTest::testExistingUserIsRecognizedByUsername
Your test case is not allowed to access the database./var/www/nextcloud/tests/lib/TestCase.php:131
/var/www/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php:155
/var/www/nextcloud/3rdparty/pimple/pimple/src/Pimple/Container.php:118
/var/www/nextcloud/lib/private/AppFramework/Utility/SimpleContainer.php:122
/var/www/nextcloud/lib/private/ServerContainer.php:156
/var/www/nextcloud/lib/private/Server.php:1703
/var/www/nextcloud/lib/private/AllConfig.php:95
/var/www/nextcloud/lib/private/AllConfig.php:416
/var/www/nextcloud/lib/private/AllConfig.php:319
/var/www/nextcloud/lib/private/User/User.php:104
/var/www/nextcloud/lib/private/User/Manager.php:176
/var/www/nextcloud/lib/private/User/Manager.php:153
/var/www/nextcloud/lib/private/User/Manager.php:190
/var/www/nextcloud/apps/user_backend_sql_raw/tests/Integration/UserBackendTest.php:102
…
Questions
- Do I even need the autoload directives in composer.json or should Nextcloud’s tests/bootstrap.php take care of this?
- Did something change in Nextcloud 20 regarding bootstrap.php’s capabilities?
- Is there more documentation or an app that would be a good example on how to do this in Nextcloud 20?
- I checked out nextcloud/server at tag v20.0.0 and then my app as a submodule in apps. There is also a proper config.php. Is this a wrong setup to develop apps?
The IRC channel seems dead, no message for the past three days. Hoping that any of the devs can help me out here.
Files
phpunit.xml.dist
<phpunit bootstrap="../../tests/bootstrap.php" colors="true">
<testsuites>
<testsuite name="unit">
<directory>./tests/Unit</directory>
</testsuite>
<testsuite name="integration">
<directory>./tests/Integration</directory>
</testsuite>
</testsuites>
</phpunit>
The path to bootrap.php is correct AFAICS, since phpunit.xml.dist is in the main app folder.
composer.json
...
"autoload": {
"psr-4": {
"OCA\\UserBackendSqlRaw\\" : "lib/"
}
},
"autoload-dev": {
"psr-4": {
"OCA\\UserBackendSqlRaw\\Tests\\" : "tests/"
}
},
...