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.
phpunit/phpunit) already supports. No major version conflicts expected.ext-pdo).DatabaseTransactions trait for transactional tests but offers additional dataset control (e.g., preloading fixtures).RefreshDatabase trait, DatabaseMigrations, and DatabaseTransactions may suffice for many use cases.thephpleague/fixture or fzaninotto/faker for data generation; mockery for mocking database interactions.Factories or Seeders provide?phpunit configuration (via phpunit.xml).--group) for faster feedback.RefreshDatabase).DB::table()->insert() with DbUnit datasets for a complex invoice workflow.composer.json (dev dependency) and configure PHPUnit:
<!-- phpunit.xml -->
<phpunit ...>
<extensions>
<extension class="DbUnit\Extension\PHPUnit\DbUnitExtension"/>
</extensions>
</phpunit>
tests/_data/users.xml) and reference them in tests:
public function testUserCreation() {
$this->setDataSet(new XmlDataSet('tests/_data/users.xml'));
// Test logic...
}
DB::assertions in favor of dataset validation.TestCase would require custom adapters.composer require --dev phpunit/phpunit:^7.0).phpunit/dbunit to composer.json and run composer install.phpunit.xml example above).DB::select() + custom scripts).users.xml):
<dataset>
<user id="1" name="John Doe" email="john@example.com"/>
</dataset>
setUp() database setup with setDataSet() calls.use DbUnit\Extension\PHPUnit\DbUnitTestCase;
class UserTest extends DbUnitTestCase {
protected function getDataSet() {
return $this->createFlatXmlDataSet('tests/_data/users.xml');
}
public function testUserExists() {
$user = User::find(1);
$this->assertEquals('John Doe', $user->name);
}
}
--debug to verify dataset loading.TestCase, Migrations, and Factories.AbstractXmlDataSet::DEBUG_OUTPUT.--process-isolation or adjust pdo settings.composer platform-check or polyfills (e.g., ramsey/collection for array methods).DbUnit assertions (e.g., assertDataSet()).How can I help you explore Laravel packages today?