Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Dbunit Laravel Package

phpunit/dbunit

PHPUnit extension for database interaction testing. Provides DbUnit helpers for setting up database fixtures and asserting database state in tests. Install via Composer (dev) or PHAR. Note: this package is no longer maintained.

View on GitHub
Deep Wiki
Context7

phpunit/dbunit is a PHPUnit extension for database interaction testing, providing utilities to set up, populate, and assert database state as part of your test suite. It integrates with PHPUnit to make database-driven tests repeatable and easier to maintain.

Note: this extension is no longer maintained (see upstream notice), so consider alternatives if you need active support.

  • Install via Composer as a dev dependency (composer require --dev phpunit/dbunit)
  • PHAR distribution available for standalone usage
  • Database fixtures/datasets for predictable test setups
  • Assertions on database state to verify expected records after actions
  • PHPUnit integration via configuration (e.g., extensionsDirectory)
Frequently asked questions about Dbunit
Can phpunit/dbunit work with Laravel’s Eloquent ORM for model testing?
Yes, phpunit/dbunit integrates with Eloquent by leveraging PDO-based database connections. You can use it to set up fixtures for models, assert record counts, or validate relationships in your test suite. It’s particularly useful for testing repository patterns or complex query logic where Laravel’s native tools may lack granular control.
How do I install phpunit/dbunit for Laravel projects?
Add it as a dev dependency via Composer: `composer require --dev phpunit/dbunit`. For PHPUnit integration, configure the `extensionsDirectory` in your `phpunit.xml` to point to the PHAR or installed extension. Ensure your Laravel testing environment uses PHPUnit 7.x or earlier, as this package lacks PHP 8.x support.
Is phpunit/dbunit compatible with Laravel’s DatabaseTransactions trait?
Yes, it complements Laravel’s `DatabaseTransactions` trait by providing dataset-based test setups. While `DatabaseTransactions` rolls back changes per test, phpunit/dbunit lets you preload fixtures (e.g., XML/YAML) for deterministic test scenarios. Use both for transactional tests with controlled initial states.
What database types does phpunit/dbunit support in Laravel?
It supports any PDO-compatible database (MySQL, PostgreSQL, SQLite) that Laravel uses. The package abstracts database interactions, so as long as your Laravel app connects via PDO, phpunit/dbunit will work. SQLite is often preferred for testing due to its lightweight, in-memory capabilities.
Why is phpunit/dbunit no longer maintained? Should I avoid it?
The package was archived in 2015 with no active updates. While it may still work for PHP 7.x/Laravel 8.x, risks include PHP 8.x incompatibilities or unpatched vulnerabilities. Use it only if you need advanced dataset features (e.g., XML/YAML fixtures) and are willing to accept maintenance risks or fork the project.
How do I create and load database fixtures with phpunit/dbunit?
Fixtures are defined in XML, YAML, or CSV files. Use DbUnit’s `DatabaseTestCase` or `DatabaseDataSet` to load datasets before tests. For example, create a `users.xml` file with test data, then load it in your test setup method. Laravel’s factories can generate data, but phpunit/dbunit offers more control for complex relationships or static test data.
Can I use phpunit/dbunit with Laravel’s RefreshDatabase trait?
No, these serve different purposes. `RefreshDatabase` resets the database between tests using migrations, while phpunit/dbunit loads predefined datasets. You could combine them by using `RefreshDatabase` for schema setup and phpunit/dbunit for fixture data, but they aren’t designed to work together directly.
Are there performance concerns with phpunit/dbunit in CI/CD pipelines?
Yes, loading large datasets (e.g., XML/YAML) can slow down tests. For CI/CD, optimize by using minimal fixtures, caching datasets, or running database-heavy tests in parallel. Compare performance against Laravel’s `DatabaseTransactions` or factory-based approaches, which are generally faster for simple setups.
What alternatives exist for database testing in Laravel?
For active maintenance, consider Laravel’s native tools like `RefreshDatabase`, `DatabaseMigrations`, or `DatabaseTransactions`. For fixture management, explore `thephpleague/fixture` or `fzaninotto/faker`. If you need mocking, `mockery` or Laravel’s `createMock()` can simulate database interactions without real connections.
How do I assert database state in phpunit/dbunit tests?
Use DbUnit’s assertion methods like `assertTableEquals()` or `assertDataset()` to compare expected vs. actual database states. For example, verify a user was created by asserting the `users` table matches your fixture. This is more precise than Laravel’s `assertDatabaseHas()` for complex scenarios with multiple related records.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport