PHPUnit under PHPBrew results in SQLSTATE[HY000] [2002] No such file or directory

I have a successful NextCloud install (cloned from the git repo). I’m getting an error when I run PHPUnit.

System setup:

OS: Ubuntu 24.04 LTS

which php /home/user/.phpbrew/php/php-8.3.10/bin/php
which phpunit /home/user/.phpbrew/php/php-8.3.10/bin/phpunit
Nextcloud install /home/user/projects/github/nextcloud/server

I installed PHPUnit manually from the website and placed it in the directory mentioned above.

When I try to run

$ phpunit --bootstrap ./tests/bootstrap.php apps/settings/tests/Settings/Admin/ServerTest.php

I get this error (relevant portion):

Warning: Module "mysqli" is already loaded in Unknown on line 0

Warning: Module "mysqlnd" is already loaded in Unknown on line 0
PHPUnit 10.5.29 by Sebastian Bergmann and contributors.

Error in bootstrap script: Doctrine\DBAL\Exception:
Failed to connect to the database: An exception occurred in the driver: SQLSTATE[HY000] [2002] No such file or directory
#0 /home/user/projects/github/nextcloud/server/3rdparty/doctrine/dbal/src/Connection.php(453): OC\DB\Connection->connect()
#1 /home/user/projects/github/nextcloud/server/3rdparty/doctrine/dbal/src/Connection.php(411): Doctrine\DBAL\Connection->getDatabasePlatformVersion()
#2 /home/user/projects/github/nextcloud/server/3rdparty/doctrine/dbal/src/Connection.php(318): Doctrine\DBAL\Connection->detectDatabasePlatform()
#3 /home/user/projects/github/nextcloud/server/3rdparty/doctrine/dbal/src/Connection.php(1320): Doctrine\DBAL\Connection->getDatabasePlatform()
#4 /home/user/projects/github/nextcloud/server/lib/private/DB/Connection.php(120): Doctrine\DBAL\Connection->setNestTransactionsWithSavepoints(true)
...

(NOTE: I get those warnings because I’m including extension=mysqlnd and extension=mysqli lines in my phpbrew’s php.ini)

I checked and phpbrew has pdo_mysql installed:

$ phpbrew ext
...
 [*] pdo          8.3.10
 [*] pdo_mysql    8.3.10
...

Do I have the system configuration correct? is PHPBrew causing the issue?

Thanks!

I suspect you have not installed the NC server, did you? I guess this warning comes from the fact that the config file was not found.

Christian

I did install the NC server. I actually did debugging, and it was picking up the config values.

I did find a work-around good enough for my purposes. I switched to sqlite3 and used the manual occ installation method.

I find it odd that NC worked fine for MySQL if I visited from the web but failed when I ran unit tests.

In any case, I’m pressing onward!

Thanks for the reply!

1 Like