parvej-mahmud/laravel-tdd-generator
Composer 安装命令:
composer require --dev parvej-mahmud/laravel-tdd-generator
包简介
Automatically generate comprehensive TDD files for Laravel modules including models, controllers, migrations, and routes
README 文档
README
A powerful Laravel package that automatically generates comprehensive Test-Driven Development (TDD) files for any given module or feature. This package creates well-structured test files for models, controllers, migrations, and routes with a single command.
Features
- 🚀 One Command, Complete TDD Suite: Generate all test files for a module with one command
- 🧪 Comprehensive Test Coverage: Creates tests for models, controllers, migrations, and routes
- 🎯 Smart Test Generation: Automatically detects common patterns and generates appropriate tests
- 🔧 Highly Customizable: Customizable stubs and configurations
- 📝 Best Practices: Follows Laravel testing best practices and conventions
- 🏗️ Multiple Test Types: Supports unit, feature, and integration tests
- 🔒 Security Aware: Includes authentication and authorization tests
Installation
Install the package via Composer:
composer require parvej-mahmud/laravel-tdd-generator --dev
Publish the configuration file:
php artisan vendor:publish --provider="ParvejMahmud\LaravelTddGenerator\TddGeneratorServiceProvider" --tag="config"
Optionally, publish the stub files for customization:
php artisan vendor:publish --provider="ParvejMahmud\LaravelTddGenerator\TddGeneratorServiceProvider" --tag="stubs"
Usage
Generate Complete TDD Suite
Generate all test files for a module:
php artisan make:tdd Post
This creates:
tests/Unit/PostTest.php- Model teststests/Feature/PostControllerTest.php- Controller teststests/Unit/PostsMigrationTest.php- Migration teststests/Feature/PostRouteTest.php- Route tests
Generate Specific Test Types
Generate only specific test types:
# Generate only model tests php artisan make:tdd Post --model # Generate only controller tests php artisan make:tdd Post --controller # Generate multiple specific types php artisan make:tdd Post --model --controller
Individual Commands
You can also use individual commands for more control:
# Generate model test only php artisan make:model-test Post # Generate controller test only php artisan make:controller-test PostController # Generate migration test only php artisan make:migration-test posts # Generate route test only php artisan make:route-test Post
Command Options
--model: Generate model tests--controller: Generate controller tests--migration: Generate migration tests--routes: Generate route tests--all: Generate all test types (default behavior)--force: Overwrite existing files
Generated Tests
Model Tests
The generated model tests include:
- ✅ CRUD operations (Create, Read, Update, Delete)
- ✅ Fillable attributes validation
- ✅ Required fields validation
- ✅ Relationships testing
- ✅ Timestamps verification
- ✅ Factory integration
Controller Tests
The generated controller tests include:
- ✅ All CRUD endpoints (index, show, store, update, destroy)
- ✅ Request validation testing
- ✅ Authentication and authorization
- ✅ Error handling (404, 422, etc.)
- ✅ Pagination testing
- ✅ Search functionality
Migration Tests
The generated migration tests include:
- ✅ Table creation verification
- ✅ Column existence and types
- ✅ Primary key validation
- ✅ Timestamps verification
- ✅ Constraints testing
- ✅ Data insertion capabilities
Route Tests
The generated route tests include:
- ✅ Route existence verification
- ✅ HTTP method validation
- ✅ URL generation testing
- ✅ Middleware verification
- ✅ Authentication requirements
- ✅ Error handling
Configuration
The package comes with a comprehensive configuration file. Here are the key options:
// config/tdd-generator.php return [ // Default test types to generate 'default_types' => [ 'model' => true, 'controller' => true, 'migration' => true, 'routes' => true, ], // Test namespaces 'namespaces' => [ 'unit' => 'Tests\\Unit', 'feature' => 'Tests\\Feature', ], // Authentication requirements 'auth_required' => [ 'store' => true, 'update' => true, 'destroy' => true, ], ];
Customizing Stubs
You can customize the generated test files by publishing and modifying the stub files:
php artisan vendor:publish --provider="ParvejMahmud\LaravelTddGenerator\TddGeneratorServiceProvider" --tag="stubs"
The stub files will be published to resources/stubs/tdd-generator/ where you can modify them to match your project's coding standards.
Examples
Basic Usage
# Generate complete TDD suite for a User module php artisan make:tdd User # Generate tests for an API resource php artisan make:tdd Product --controller --routes # Force overwrite existing files php artisan make:tdd Order --force
Advanced Usage
# Generate tests for a complex module with custom options php artisan make:tdd BlogPost --all # Generate only unit tests php artisan make:tdd Category --model --migration # Generate only feature tests php artisan make:tdd Comment --controller --routes
Best Practices
- Run Tests First: Always run the generated tests to ensure they pass with your current setup
- Customize as Needed: Modify the generated tests to match your specific business logic
- Use Factories: Ensure you have model factories set up for better test data generation
- Follow TDD: Use the generated tests as a starting point for your TDD workflow
- Keep Tests Updated: Update tests when you modify your models, controllers, or routes
Requirements
- PHP ^8.1
- Laravel ^10.0|^11.0
- PHPUnit ^10.0
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This package is open-sourced software licensed under the MIT license.
Support
If you encounter any issues or have questions, please open an issue on GitHub.
parvej-mahmud/laravel-tdd-generator 适用场景与选型建议
parvej-mahmud/laravel-tdd-generator 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 08 月 04 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「generator」 「testing」 「TDD」 「laravel」 「test-driven-development」 「artisan」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 parvej-mahmud/laravel-tdd-generator 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 parvej-mahmud/laravel-tdd-generator 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 parvej-mahmud/laravel-tdd-generator 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Helper that decorates any SUS with a phpspec lazy object wrapper
Memio's PrettyPrinter, used to generate PHP code from given Model
Provides access to magento2 object manager from behat and allows to change magento config settings temporarly
Testing Suite For Lumen like Laravel does.
The PHP SDK for Checkmango
Lumen fork of orchestra/testbench-core - Testing Helper for Lumen Development
统计信息
- 总下载量: 1
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 20
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-08-04