| Install | |
|---|---|
composer require gsferro/generate-tests-easy |
|
| Latest Version: | v1.0.0 |
| PHP: | ^8.0|^8.1|^8.2|^8.3|^8.4 |
A Laravel package for automatically generating comprehensive Pest tests for your application based on code analysis.
Generate Tests Easy is a powerful tool that analyzes your Laravel application's models, controllers, and database structure to automatically generate comprehensive test suites using Pest PHP. It can detect relationships, scopes, validation rules, and other features to create relevant tests that ensure your application works as expected.
| Package | Version |
|---|---|
| PHP | ^8.0|^8.1|^8.2|^8.3|^8.4 |
| Laravel | ^8.0|^9.0|^10.0|^11.0|^12.0 |
| Pest PHP | ^1.22|^2.8.1|^3.0 |
| Pest Plugin Laravel | ^1.4|^2.0|^3.2 |
| Pest Plugin Arch | ^2.0|^v3.0 |
| PHPUnit | ^9.5.10|^10.1|^11.0|^12.0 |
| Symfony Finder | ^5.0|^6.0|^7.0 |
composer require gsferro/generate-tests-easy --dev
To generate tests for all models and controllers in your application:
php artisan generate-tests:all
# Generate tests for a specific model
php artisan generate-tests:model User
# Generate tests for a specific controller
php artisan generate-tests:controller UserController
# Generate tests for models based on database tables
php artisan generate-tests:database
# Generate tests for Filament resources
php artisan generate-tests:filament PatientResource
# Generate tests for all Filament resources
php artisan generate-tests:filament --all
All commands support the following options:
--force: Overwrite existing tests--verbose: Show detailed information during generationWhen working with Filament resources, the package recognizes the standard Filament resource structure:
PatientResource.php
PatientResource/
├── Pages/
│ ├── CreatePatient.php
│ ├── EditPatient.php
│ ├── ListPatients.php
│ └── ViewPatient.php
The package will generate appropriate tests for each component of the resource:
Each test is tailored to the specific functionality of the component, ensuring comprehensive test coverage. For example, ViewPatient tests will verify that:
Publish the configuration file:
php artisan vendor:publish --tag=generate-tests-easy-config
return [
// Path where tests will be generated
'test_path' => 'tests',
// Whether to install Pest if not already installed
'install_pest' => true,
// Whether to configure Pest Arch presets
'configure_arch_presets' => true,
// Test coverage target percentage
'coverage_target' => 80,
// Custom stubs path (if you want to customize the test templates)
'stubs_path' => null,
];
You can extend the package by:
Contributions are welcome! Please feel free to submit a Pull Request.
This package is open-sourced software licensed under the MIT license.
This package comes with its own test suite to ensure functionality works as expected. To run the tests:
# Run all tests
composer test
# Run tests with coverage report
composer test:coverage
# Run only unit tests
composer test:unit
# Run only feature tests
composer test:feature
# Run architecture tests
composer test:arch
These commands are defined in the composer.json file and use Pest PHP for testing. The test suite includes unit tests, feature tests, and architecture tests to ensure the package works correctly.