Skip to content

Setup

If you run your tests using PHPUnit and thus use one process, make sure you have a database named smarthealth_test and a smarthealth user that has access to it.

If you run tests in parallel, ensure your database user has the necessary permissions to manage all databases.

PostgreSQL in DBngin

If you run the PHP test suite locally against PostgreSQL in DBngin, make sure the PostgreSQL instance has enough shared memory reserved for relation locks.

The default DBngin PostgreSQL settings can be too low for this project when running composer run-script test:php in parallel, which may cause errors like SQLSTATE[53200]: Out of memory: 7 ERROR: out of shared memory.

Recommended local settings:

  • max_locks_per_transaction = 256
  • shared_buffers = 256MB

You can apply them with:

bash
PGPASSWORD=smarthealth psql -h 127.0.0.1 -p 5432 -U smarthealth -d postgres -c "ALTER SYSTEM SET max_locks_per_transaction = '256';"
PGPASSWORD=smarthealth psql -h 127.0.0.1 -p 5432 -U smarthealth -d postgres -c "ALTER SYSTEM SET shared_buffers = '256MB';"
"/opt/homebrew/opt/postgresql@18/bin/pg_ctl" -D "/Users/$USER/Library/Application Support/com.tinyapp.DBngin/Engines/postgresql/<instance-id>" restart -m fast -w

After the restart, verify the active values:

bash
PGPASSWORD=smarthealth psql -h 127.0.0.1 -p 5432 -U smarthealth -d postgres -Atqc "show max_locks_per_transaction; show shared_buffers;"

Route permission tests

The UntestedRoutesRoutePermissionTest in tests/Routes asserts that there are no routes left untested. To be able to know which routes are tested, we need to generate this list of routes before running PHPUnit tests, and outside of that command too. The reason for this is that with Paratest, it's impossible to access one test in another or use Reflection on it.

To work around that, the composer run-script test:php command also runs php artisan test:routes:generate which generates this list in storage/tests/testedPermissionRoutes.php. If you want to run that test (or all tests), be sure to use the Composer script for this or run the command first. If you make changes to a route permission test or add a new one, also run the generate command before running UntestedRoutesRoutePermissionTest.