erikgall/eloquent-phpunit
Eloquent PHPUnit adds convenient PHPUnit integration for Eloquent models, reducing boilerplate around test setup and database assertions. It helps you verify model behavior and persistence cleanly, making Laravel or standalone Eloquent test suites faster to write and easier to maintain.
composer require --dev <vendor>/<package>. It is intended for test suites, not production runtime.hasOne test method is the first thing to check if you have one-to-one relationships that were previously untested.User has one Profile, assert it with the new method:public function test_user_has_one_profile(): void
{
$this->assertHasOne(User::class, 'profile');
}
php artisan test --filter=UserTest or ./vendor/bin/phpunit --filter=UserTest) before expanding to the full suite.$user = User::factory()->hasProfile()->create();
$this->assertHasOne(User::class, 'profile');
$this->assertTrue($user->profile->is($user->profile()->first()));
/**
* @dataProvider relationshipProvider
*/
public function test_model_relationships(string $model, string $relationship): void
{
$this->assertHasOne($model, $relationship);
}
hasOne support, add or update tests for models where the inverse relationship was already covered but the one-to-one side was missing. This is especially useful for User → Profile, Order → Invoice, and similar domain models.RefreshDatabase or DatabaseMigrations and ensure both sides of the relationship are available.hasOne method. Relationship helpers often accept either a relationship name or a related model class, and the argument order matters.dd($model->relationship()->toSql());
This quickly reveals missing foreign keys, incorrect model classes, or wrong relationship names.
hasOne test support. No breaking changes are implied by the release note, but update your test coverage if you previously skipped one-to-one relationships because the helper was unavailable.How can I help you explore Laravel packages today?