If you don’t use SQLite in production, you shouldn’t use it in testing or CI/CD either.
This is one of the reasons why I switched from using the SQLite + :memory:
combo for my Laravel + Pest testing:
Notice how I intentionally wrote the wrong field name in the search query. Surprisingly, my tests still pass. It should throw an \Illuminate\Database\QueryException
as it would in a browser.
According to the SQLite documentation:
If a keyword in double quotes (ex: “key” or “glob”) is used in a context where it cannot be resolved to an identifier but where a string literal is allowed, then the token is understood to be a string literal instead of an identifier.
So what we need to do is to use real database for testing, specifically MariaDB in my case. You’ll need to modify your phpunit.xml
first.
Adjust this configuration according to your needs. If left blank, Laravel will fallback to defaults, such as DB_USERNAME
being forge
.
Next, modify your GitHub action. Add your preferred database image into services
, next to container
:
Again, adjust the env
settings to match your phpunit.xml
.
That’s it, now your github action will run tests against a real database instead SQLite.