Download the PHP package hidayetov/auto-testify without Composer
On this page you can find all versions of the php package hidayetov/auto-testify. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download hidayetov/auto-testify
More information about hidayetov/auto-testify
Files in hidayetov/auto-testify
Package auto-testify
Short Description Automatic test generator for Laravel models
License MIT
Informations about the package auto-testify
AutoTestify
AutoTestify is a powerful Laravel package designed to automatically generate comprehensive test files for your Eloquent models. It simplifies the testing process by creating CRUD (Create, Read, Update, Delete) and uniqueness tests, saving you time and ensuring your models are thoroughly tested.
Features
- Automatic CRUD Tests: Generates tests for creating, retrieving, updating, and deleting model instances.
- Uniqueness Testing: Detects unique fields from the database schema or model configuration and generates corresponding tests.
- Database Flexibility: Works with or without a database connection:
- If migrated and
doctrine/dbalis installed, detects unique fields from the database. - Otherwise, uses the
$uniqueproperty defined in your model.
- If migrated and
- Resilient Design: Skips database-dependent tests gracefully if no connection is available.
- Customizable: Easily extendable for additional test cases or model-specific logic.
Requirements
- PHP: 8.1 or higher
- Laravel: 11.0 or higher
- Optional:
doctrine/dbal(for database schema detection)
Installation
Step 1: Install via Composer
Add the package to your Laravel project:
Step 2: (Optional) Enable Database Schema Detection
If you want AutoTestify to detect unique fields from your database schema, install doctrine/dbal:
Without this, the package will rely on the $unique property in your models.
Usage
Generating a Test File
Run the following Artisan command to generate a test file for a specific model:
For example, to generate tests for a User model:
This will create tests/Feature/UserTest.php with CRUD and uniqueness tests.
Example Model Configuration
Define $fillable and (optionally) $unique properties in your model:
Generated Tests
For the User model above, the generated UserTest.php might look like this:
Configuration
Model Setup
$fillable: Required to specify fields that can be mass-assigned.$unique: Optional; define unique fields if not relying on database schema detection.
Database Detection
Ensure your database is migrated (php artisan migrate) and doctrine/dbal is installed for automatic unique field detection.
Running Tests
After generating the test files, run your tests with:
Example Output
Troubleshooting
-
"No connection could be made" Error: Ensure your
.envfile is configured correctly and your database server is running.-
Example
.envfor MySQL: - Or use SQLite:
-
- Unique Tests Not Generated: Define
$uniquein your model or installdoctrine/dbaland migrate your database.
License
This package is open-sourced under the MIT License.
Author
- Hidayet Hidayetov - GitHub
- Special thanks to contributors and collaborators!
Happy testing with AutoTestify! 🚀