Test setup

Exowpee uses PHPUnit for testing. Configuration is in phpunit.xml. Run the commands below from the project root, with the Docker app and db services running. The full suite uses four processes and a separate test database for each process. Filtered runs use one parallel process, which still gets its own <DB_DATABASE>_test_1 database. The app container exports .env (env_file), so a plain serial artisan test would otherwise target the development database from .env. tests/TestCase.php refuses to run tests that use a Laravel database trait (RefreshDatabase, DatabaseTransactions, DatabaseMigrations, DatabaseTruncation) unless the target database name contains test; keep --parallel for filtered runs, or set DB_DATABASE to a dedicated test database. Tests that must commit for real (row locks seen from a second connection, migrations replayed in a temporary schema) cannot use RefreshDatabase’s transaction. They use Tests\Support\UsesTestDatabaseWithoutTransactions (included by IsolatedOrganizationSchema), which builds on DatabaseTruncation: they get the same per-process test database and guard, and write only into temporary schemas they drop. Tests without any database trait must not touch the database.

Running tests

The memory limit of each ParaTest worker comes from phpunit.xml (memory_limit), not from the -d flag of the parent command, which does not reach the workers. Raise it there if a full run dies with Allowed memory size ... exhausted.

Test structure

Writing a feature test

Feature tests make HTTP requests and assert on responses:

Writing a unit test

Unit tests test individual classes in isolation:

Factories

Model factories live in database/factories/:

Testing with database

Use RefreshDatabase trait to reset the database between tests:

Testing tips

  1. Always test authorization — Verify that unauthorized users get 403
  2. Test validation — Send invalid data and check for 422 errors
  3. Test multi-tenancy — Verify users can’t access other companies’ data
  4. Use factories — Don’t create test data manually
  5. Test side effects — Verify that stock changes, ledger entries, and events fire correctly