- How do I install `codenco-dev/eloquent-model-tester` for Laravel?
- Run `composer require codenco-dev/eloquent-model-tester --dev` to install it as a development dependency. This avoids runtime overhead and keeps it isolated to your testing environment.
- Does this package work with Laravel 10 and newer?
- Yes, the package is designed to work with modern Laravel versions (8.x and above). Check the [GitHub repository](https://github.com/codenco-dev/eloquent-model-tester) for the latest compatibility notes.
- Can I use this package without model factories?
- No, factories are required for meaningful tests, especially for relationships. If you lack factories, generate them using `php artisan make:model ModelName -mf` or manually define them in `database/factories`.
- Will this package slow down my CI/CD pipeline?
- It may introduce minor overhead due to database introspection, but the impact is usually negligible. For large projects, consider running schema tests separately or in parallel with other test suites.
- How do I test model relationships with this package?
- Use methods like `assertHasRelation()` to verify relationships exist and are correctly configured. Ensure your factories include related models to avoid false negatives in tests.
- Can I integrate this with Pest instead of PHPUnit?
- Yes, the package works with both PHPUnit and Pest. Simply extend your Pest test classes with `HasModelTester` and use the provided assertions like `assertTableStructure()`.
- What if my test database schema differs from production?
- Schema tests may fail if migrations or seeders differ between environments. Use `RefreshDatabase` or `MigrateFreshDatabase` traits to reset the test database before tests, ensuring consistency.
- Does this package replace Laravel’s built-in Schema assertions?
- No, it complements them. While Laravel’s `assertDatabaseHas()` or `assertDatabaseMissing()` work for row-level checks, this package focuses on model structure, fillable/guarded attributes, and relationships.
- How do I handle custom database connections in tests?
- The package assumes the default Laravel database connection. For custom connections, manually configure the test environment or extend the package’s traits to support your setup.
- What’s the best way to start using this in an existing project?
- Begin with 1–2 critical models (e.g., `User`, `Order`) to validate its value. Use `php artisan make:test Models/ModelNameTest` and gradually expand coverage. Document your test conventions to align the team.