- What is DUnit used for in PHP testing?
- DUnit is a PHPUnit extension focused on database unit testing. It helps load fixtures, isolate tests with transactions, and make assertions about database state. It is a test-only dependency, not a Laravel application runtime package.
- Is DUnit compatible with Laravel?
- Not natively. DUnit integrates through PHPUnit base classes and database assertions, while modern Laravel tests center on Illuminate\Foundation\Testing\TestCase, RefreshDatabase, factories, seeders, and native database assertions. You should run a compatibility spike before using it in a Laravel suite.
- How do I install DUnit with Composer?
- Install it as a require-dev dependency and pin an exact version because it is test infrastructure. Do not expect Laravel package auto-discovery or Laravel-specific configuration. Validate the target PHP and PHPUnit APIs before adding it to CI.
- Does DUnit support Laravel 10 or Laravel 11?
- There is no indicated official Laravel integration for modern Laravel versions. Support depends on whether its PHPUnit and PHP constraints match your stack, and Laravel's test bootstrapping may conflict. Treat it as legacy-oriented unless you fund and own a compatibility fork.
- Can DUnit replace Laravel RefreshDatabase or factories?
- No. Laravel's RefreshDatabase or transaction strategy, factories, seeders, and assertDatabaseHas or assertDatabaseMissing are the preferred native tools. DUnit-style table comparisons may still be useful as a reference or in a bounded legacy suite.
- What are the production concerns with DUnit?
- DUnit is test-only, so it should not affect production runtime. The main risks are CI supply-chain and lifecycle issues: Docker availability, registry access, image pinning, php-nightly tags, and PHPUnit API compatibility. Pin stable images and keep it out of production dependencies.
- Does DUnit run tests across multiple PHP versions or Docker images?
- DUnit's v2.1.0 Docker runner can orchestrate test environments, but the php-nightly image is PHP 7 beta and not a modern Laravel target. Use stable, pinned images rather than mutable tags or nightly builds. Confirm Docker and registry behavior in your CI topology.
- What are alternatives to DUnit for Laravel database tests?
- Use Laravel-native assertDatabaseHas, assertDatabaseMissing, schema assertions, RefreshDatabase, factories, and seeders. Pest or PHPUnit can run those tests without a DUnit base class. DUnit is best treated as a legacy reference rather than a new strategic dependency.
- Is DUnit actively maintained?
- v2.1.0 shows some maintenance by fixing Ctrl+C handling and $COLUMNS, adding dunit --pull, and shrinking default images. However, lifecycle risk remains high for modern Laravel because of PHPUnit class and API compatibility, PHP constraints, and base-class conflicts. Confirm who owns compatibility and security patching before adoption.
- How should we migrate from DUnit to Laravel-native tests?
- First preserve existing DUnit behavior with a compatibility fork or shim if the legacy suite must keep running. Then progressively replace brittle table comparisons with Laravel assertions, schema checks, factories, and seeders. Run a one-day compatibility spike before coupling core test infrastructure to DUnit.