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
Eloquent Model Tester

Eloquent Model Tester Laravel Package

codenco-dev/eloquent-model-tester

Laravel dev-only helper to test Eloquent models: verify table structure/columns, fillable vs guarded attributes, and model relationships. Works with PHPUnit and model factories, integrates easily in your model test classes.

View on GitHub
Deep Wiki
Context7

Test easier your Eloquent Models in your Laravel Project

Frequently asked questions about Eloquent Model Tester
How do I install codenco-dev/eloquent-model-tester in my Laravel project?
Run `composer require codenco-dev/eloquent-model-tester --dev` to install the package as a development dependency. Ensure your Laravel project uses PHPUnit or PestPHP for testing, as this package integrates with those frameworks.
Does this package work with Laravel 10+ and its latest features?
Yes, the package is designed to work with modern Laravel versions, including Laravel 10+. It supports features like model observers and integrates seamlessly with the latest testing conventions, though always verify compatibility with your specific Laravel version.
Can I test custom foreign keys in relationships (e.g., author_id instead of user_id)?
The package assumes Laravel’s default naming conventions for relationships (e.g., `user_id`). For custom foreign keys, you’ll need to manually override the assertion methods or extend the package to handle your specific naming patterns.
Will this package slow down my CI/CD pipeline due to database-dependent tests?
The package is lightweight (~100KB) and designed for CI/CD efficiency. Use Laravel’s `RefreshDatabase` trait to reset the database between tests, and consider parallelizing test execution to minimize runtime overhead.
How do I test model relationships like hasMany, belongsTo, or polymorphic relations?
Use fluent assertions like `assertHasHasManyRelation()`, `assertHasBelongsToRelation()`, or `assertHasMorphToRelation()`. Ensure you’ve set up factories for related models, as the package relies on them to populate test data for relationship validation.
Does this package support testing soft deletes or custom soft-delete columns?
Yes, it includes `assertHasSoftDeleteTimestampColumns()` to verify soft-delete functionality. By default, it checks for `deleted_at`, but you can customize the column name by overriding the assertion or extending the package.
Can I use this package without Laravel factories?
No, the package requires factories for testing relationships. If you haven’t set them up, generate them using `php artisan make:model ModelName -mf` or manually define factories in `database/factories`.
How do I test fillable and guarded attributes in my Eloquent models?
Use `assertCanOnlyFill()` to verify fillable attributes and `assertCanOnlyGuard()` for guarded attributes. Chain these methods with schema assertions for comprehensive validation, e.g., `$this->modelTestable(User::class)->assertHasColumns(['email'])->assertCanOnlyFill(['name', 'email'])`.
Is there a way to test model scopes or query constraints?
The package doesn’t directly test scopes or query constraints, as it focuses on structural validation. For scope testing, use Laravel’s native testing tools like `assertDatabaseHas()` or custom assertions in your test classes.
What alternatives exist for testing Eloquent models in Laravel?
Alternatives include Laravel’s built-in `Schema` facade (for manual column checks) or packages like `spatie/laravel-test-factories` for factory-based testing. However, `codenco-dev/eloquent-model-tester` uniquely combines schema, fillable/guarded, and relationship validation in a fluent, chainable API.
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.
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor