Help getting test database connected

I’m having some difficulty understanding the steps I need to carry out to get the unit tests to pass.

Most important error message seems to be:

Caused by
PDOException: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'librenms_phpunit_78hunjuybybh.locations' doesn't exist

Here’s my .env:

APP_KEY=base64:NlDfjqcdFPYelpUNSS7OkaMzSLiSso79XEZqp8tWPzk=

DB_HOST=localhost
DB_DATABASE=librenms
DB_USERNAME=librenms
DB_PASSWORD=librenms

#APP_URL=
NODE_ID=61f6015fccdff
VAPID_PUBLIC_KEY=BOEUw6H255hFlY6yIlYhSGa54zTg8xAa5kxSL6Ee36-5t5WVEMOEoxKrA0IEVMf_sdL2tu0puDZMirEFp9_xc2w
VAPID_PRIVATE_KEY=fNMdfmwUvcaQ3XRkELqfgiqIdU-3xQxk8qQ1LmVNGMc

APP_ENV=local
APP_DEBUG=true

DB_TEST_DATABASE="librenms_phpunit_78hunjuybybh"
DB_TEST_USERNAME="librenms"
DB_TEST_PASSWORD="librenms"

I’ve created this database, but it’s empty.

[librenms@librenms ~]$ mysql -u librenms -plibrenms
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 8477
Server version: 10.3.28-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> show databases;
+-------------------------------+
| Database                      |
+-------------------------------+
| information_schema            |
| librenms                      |
| librenms_phpunit_78hunjuybybh |
+-------------------------------+
3 rows in set (0.001 sec)

MariaDB [(none)]> connect librenms_phpunit_78hunjuybybh;
Connection id:    8478
Current database: librenms_phpunit_78hunjuybybh

MariaDB [librenms_phpunit_78hunjuybybh]> show tables;
Empty set (0.001 sec)

MariaDB [librenms_phpunit_78hunjuybybh]> Bye
[librenms@librenms ~]$


Here’s what I get when I run a test:

[librenms@librenms ~]$ ./lnms dev:check
<snip>

There were 7 errors:

1) LibreNMS\Tests\Unit\LocationTest::testCanSetLocation
Illuminate\Database\QueryException: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'librenms_phpunit_78hunjuybybh.locations' doesn't exist (SQL: select * from `locations` where (`location` = Where) limit 1)

<snip>

Caused by
Doctrine\DBAL\Driver\PDO\Exception: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'librenms_phpunit_78hunjuybybh.locations' doesn't exist

<snip>

Caused by
PDOException: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'librenms_phpunit_78hunjuybybh.locations' doesn't exist

<snip>

2) LibreNMS\Tests\Unit\LocationTest::testCanSetEncodedLocation
Illuminate\Database\QueryException: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'librenms_phpunit_78hunjuybybh.locations' doesn't exist (SQL: select * from `locations` where (`location` = 982 Larkin Club Hoppeville, AL 05359-3922 [35.807397,31.249408]) limit 1)

<snip>
Caused by
PDOException: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'librenms_phpunit_78hunjuybybh.locations' doesn't exist

<snip>

3) LibreNMS\Tests\Unit\LocationTest::testCanHandleGivenCoordinates
Illuminate\Database\QueryException: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'librenms_phpunit_78hunjuybybh.locations' doesn't exist (SQL: select * from `locations` where (`location` = Sed veritatis doloremque eaque ipsum.) limit 1)

<snip>

Caused by
Doctrine\DBAL\Driver\PDO\Exception: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'librenms_phpunit_78hunjuybybh.locations' doesn't exist

<snip>

Caused by
PDOException: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'librenms_phpunit_78hunjuybybh.locations' doesn't exist

<snip>

4) LibreNMS\Tests\Unit\LocationTest::testCanNotSetFixedCoordinates
Illuminate\Database\QueryException: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'librenms_phpunit_78hunjuybybh.locations' doesn't exist (SQL: select * from `locations` where (`location` = 2610 Sigmund Stravenue Generalland, MN 79997-8857) limit 1)

<snip>

Caused by
Doctrine\DBAL\Driver\PDO\Exception: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'librenms_phpunit_78hunjuybybh.locations' doesn't exist

<snip>

Caused by
PDOException: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'librenms_phpunit_78hunjuybybh.locations' doesn't exist

<snip>

5) LibreNMS\Tests\Unit\LocationTest::testCanSetDnsCoordinate
Illuminate\Database\QueryException: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'librenms_phpunit_78hunjuybybh.locations' doesn't exist (SQL: select * from `locations` where (`location` = 386 Ryleigh Overpass Antoniotown, IL 99117) limit 1)

<snip>

Caused by
Doctrine\DBAL\Driver\PDO\Exception: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'librenms_phpunit_78hunjuybybh.locations' doesn't exist

<snip>

Caused by
PDOException: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'librenms_phpunit_78hunjuybybh.locations' doesn't exist

<snip>

6) LibreNMS\Tests\Unit\LocationTest::testCanSetByApi
Illuminate\Database\QueryException: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'librenms_phpunit_78hunjuybybh.locations' doesn't exist (SQL: select * from `locations` where (`location` = No API) limit 1)

<snip>

Caused by
Doctrine\DBAL\Driver\PDO\Exception: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'librenms_phpunit_78hunjuybybh.locations' doesn't exist

<snip>

Caused by
PDOException: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'librenms_phpunit_78hunjuybybh.locations' doesn't exist

<snip>

7) LibreNMS\Tests\Unit\LocationTest::testCorrectPrecedence
Illuminate\Database\QueryException: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'librenms_phpunit_78hunjuybybh.locations' doesn't exist (SQL: select * from `locations` where (`location` = 4226 Hettinger Track Apt. 814 Collinport, MI 45028-7148 [-42, 42]) limit 1)

/opt/librenms/vendor/laravel/framework/src/Illuminate/Database/Connection.php:712
/opt/librenms/vendor/laravel/framework/src/Illuminate/Database/Connection.php:672
/opt/librenms/vendor/laravel/framework/src/Illuminate/Database/Connection.php:376
/opt/librenms/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php:2385
/opt/librenms/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php:2373
/opt/librenms/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php:2907
/opt/librenms/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php:2374
/opt/librenms/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php:625
/opt/librenms/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php:609
/opt/librenms/vendor/laravel/framework/src/Illuminate/Database/Concerns/BuildsQueries.php:294
/opt/librenms/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php:490
/opt/librenms/vendor/laravel/framework/src/Illuminate/Support/Traits/ForwardsCalls.php:23
/opt/librenms/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:2132
/opt/librenms/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:2144
/opt/librenms/app/Models/Device.php:412
/opt/librenms/tests/Unit/LocationTest.php:206
phpvfscomposer:///opt/librenms/vendor/phpunit/phpunit/phpunit:97

Caused by
Doctrine\DBAL\Driver\PDO\Exception: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'librenms_phpunit_78hunjuybybh.locations' doesn't exist

/opt/librenms/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDO/Exception.php:18
/opt/librenms/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:87
/opt/librenms/vendor/laravel/framework/src/Illuminate/Database/Connection.php:368
/opt/librenms/vendor/laravel/framework/src/Illuminate/Database/Connection.php:705
/opt/librenms/vendor/laravel/framework/src/Illuminate/Database/Connection.php:672
/opt/librenms/vendor/laravel/framework/src/Illuminate/Database/Connection.php:376
/opt/librenms/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php:2385
/opt/librenms/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php:2373
/opt/librenms/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php:2907
/opt/librenms/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php:2374
/opt/librenms/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php:625
/opt/librenms/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php:609
/opt/librenms/vendor/laravel/framework/src/Illuminate/Database/Concerns/BuildsQueries.php:294
/opt/librenms/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php:490
/opt/librenms/vendor/laravel/framework/src/Illuminate/Support/Traits/ForwardsCalls.php:23
/opt/librenms/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:2132
/opt/librenms/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:2144
/opt/librenms/app/Models/Device.php:412
/opt/librenms/tests/Unit/LocationTest.php:206
phpvfscomposer:///opt/librenms/vendor/phpunit/phpunit/phpunit:97

Caused by
PDOException: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'librenms_phpunit_78hunjuybybh.locations' doesn't exist

/opt/librenms/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:82
/opt/librenms/vendor/laravel/framework/src/Illuminate/Database/Connection.php:368
/opt/librenms/vendor/laravel/framework/src/Illuminate/Database/Connection.php:705
/opt/librenms/vendor/laravel/framework/src/Illuminate/Database/Connection.php:672
/opt/librenms/vendor/laravel/framework/src/Illuminate/Database/Connection.php:376
/opt/librenms/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php:2385
/opt/librenms/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php:2373
/opt/librenms/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php:2907
/opt/librenms/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php:2374
/opt/librenms/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php:625
/opt/librenms/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php:609
/opt/librenms/vendor/laravel/framework/src/Illuminate/Database/Concerns/BuildsQueries.php:294
/opt/librenms/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php:490
/opt/librenms/vendor/laravel/framework/src/Illuminate/Support/Traits/ForwardsCalls.php:23
/opt/librenms/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:2132
/opt/librenms/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:2144
/opt/librenms/app/Models/Device.php:412
/opt/librenms/tests/Unit/LocationTest.php:206
phpvfscomposer:///opt/librenms/vendor/phpunit/phpunit/phpunit:97

ERRORS!
Tests: 2596, Assertions: 6335, Errors: 7, Skipped: 207.
failed (254.04s)


[librenms@librenms ~]$

Not sure if this is the recommended approach but it “seems to work”.

[librenms@librenms ~]$ mysqldump -p librenms > librenms.sql
Enter password:
[librenms@librenms ~]$ mysql -p librenms_phpunit_78hunjuybybh < librenms.sql
Enter password:
[librenms@librenms ~]$ rm  librenms.sql