Bootstrapping Nextcloud for phpunit

In the notestutorial app there is code for unit and integration testing included. Tests can be run conveniently through gmake test.

Unfortunately, I get an error message saying:

PHP Warning:  require_once(/usr/local/www/devcloud/apps/notestutorial/tests/../../../tests/bootstrap.php): failed to open stream: No such file or directory in /usr/local/www/devcloud/apps/notestutorial/tests/bootstrap.php on line 3

From the the dev docs and the core dev docs I understand that in order for phpunit to find any of the classes under test the NC environment needs to be bootstrapped.

I could not find the explicit --bootstrap directive but the tests/bootstrap.php file seems to be have that purpose. It contains only one line which appears to point nowhere reasonnable:

require_once __DIR__ . '/../../../tests/bootstrap.php';

It seemed the file pointed to itself (and missed) so I commented out the statement. Current error is that the NC classes cannot be found:

[user@host /usr/local/www/devcloud/apps/notestutorial]$ gmake test
./vendor/phpunit/phpunit/phpunit -c phpunit.xml
PHP Fatal error:  Uncaught Error: Class 'OCA\NotesTutorial\Tests\Unit\Controller\NoteControllerTest' not found in /usr/local/www/devcloud/apps/notestutorial/tests/Unit/Controller/NoteApiControllerTest.php:7
Stack trace:
#0 /usr/local/www/devcloud/apps/notestutorial/vendor/phpunit/phpunit/src/Util/FileLoader.php(66): include_once()
#1 /usr/local/www/devcloud/apps/notestutorial/vendor/phpunit/phpunit/src/Util/FileLoader.php(54): PHPUnit\Util\FileLoader::load('/usr/local/www/...')
#2 /usr/local/www/devcloud/apps/notestutorial/vendor/phpunit/phpunit/src/Framework/TestSuite.php(383): PHPUnit\Util\FileLoader::checkAndLoad('/usr/local/www/...')
#3 /usr/local/www/devcloud/apps/notestutorial/vendor/phpunit/phpunit/src/Framework/TestSuite.php(481): PHPUnit\Framework\TestSuite->addTestFile('/usr/local/www/...')
#4 /usr/local/www/devcloud/apps/notestutorial/vendor/phpunit/phpunit/src/Util/Configuration.php(1031): PHPUnit\Framework\TestSuite->addTestFiles(Array)
#5 /usr/local/www/devcloud/apps/notestutorial/vendor/phpunit/phpunit/src/Util/ in /usr/local/www/devcloud/apps/notestutorial/tests/Unit/Controller/NoteApiControllerTest.php on line 7

What must I do to make the NC classes available to phpunit?

It seems there once was a OC_root/tests directory which is no longer there. The boilerplate bootstrap.php file is therefore not helpful.

Partial fix: bootstrap.php needs this line:

require_once __DIR__.'/../../../lib/base.php';

The following lines may also help if your app has a JS frontend:

require_once __DIR__.'/../vendor/autoload.php';
\OC_App::loadApp('notestutorial'); // or whatever your app under test is

Any comments welcome.

Now, this is a bit awkward and I am sorry for asking the community in this case. There is a OC_root/tests directory, only it was not part of the distribution I used. Should have checked out with git.

With the directory in place and the link from <myapp>/tests/bootstrap.php restored everything works.