SyntaxStudy
Sign Up
PHP Test Performance Tips
PHP Intermediate 3 min read

Test Performance Tips

Fast Tests

Slow tests erode the habit of running them. Key tricks: use in-memory SQLite, minimise RefreshDatabase usage, parallelise with Pest.

Example
// phpunit.xml — SQLite in-memory for speed
<env name="DB_CONNECTION" value="sqlite"/>
<env name="DB_DATABASE" value=":memory:"/>
// Pest parallel execution
./vendor/bin/pest --parallel
// Use DatabaseTransactions instead of RefreshDatabase for read-only tests
use DatabaseTransactions; // rolls back per test — no migration re-run
// Lazy factories for complex objects
$user = User::factory()->lazy(); // does not insert until ->create()
Pro Tip

An in-memory SQLite test suite can be 10x faster than MySQL — use it for unit tests.