renatomarinho/laravel-wave-test
Composer 安装命令:
composer require renatomarinho/laravel-wave-test
包简介
Automatically generates tests for Laravel applications
README 文档
README
Laravel Wave Test is a tool designed to streamline the process of creating and running tests in Laravel projects. This package provides two main commands: generate:tests to automatically generate test files based on your application's routes, and execute:tests to run all tests within the Feature directory and its subdirectories.
Note: This package is intended to accelerate the initial creation of tests. The generated
*Test.phpfiles may require manual adjustments to properly fit the specific requirements of your project.
Installation
-
Install the package via Composer:
composer require renatomarinho/laravel-wave-test
-
Verify the ServiceProvider Registration: The package includes a
ServiceProviderthat will be registered automatically in Laravel 5.5+ (thanks to Package Auto-Discovery).If you're using an older version of Laravel or auto-discovery is disabled, add the following provider to the
providersarray in theconfig/app.phpfile:RenatoMarinho\LaravelWaveTest\TestGeneratorServiceProvider::class,
-
Publish Optional Configurations (if needed):
php artisan vendor:publish --provider="RenatoMarinho\LaravelWaveTest\TestGeneratorServiceProvider"
Available Commands
1. php artisan generate:tests
This command scans all registered routes in your Laravel project and generates corresponding test files in the tests/Feature directory. Each route will be converted into a test file, organized into folders based on the route name.
Features:
- Organizes tests into folders based on the first segment of the route name.
- Converts route names like
example.updateintoExampleUpdateTest.php. - Automatically mocks route parameters using Faker.
Example Generated Structure:
tests/
└── Feature/
├── Example/
│ ├── IndexTest.php
│ ├── StoreTest.php
│ ├── ShowTest.php
│ ├── UpdateTest.php
│ └── DestroyTest.php
└── AnotherFolder/
└── AnotherTest.php
Usage:
php artisan generate:tests
2. php artisan execute:tests
This command lists all folders inside tests/Feature and runs tests in those folders using PHPUnit. It simplifies the process of executing all tests organized in subfolders.
Usage:
php artisan execute:tests
Example Output:
Executing tests in the Feature directory...
Running tests for folder: Example
PHPUnit 11.5.7 by Sebastian Bergmann and contributors.
..
Time: 00:01.234, Memory: 20.00 MB
OK (2 tests, 2 assertions)
Tests passed for folder: Example
All tests executed successfully!
How to Use
-
Generate Automatic Tests: Run the following command to generate test files based on your application's routes:
php artisan generate:tests
Tip: Ensure your routes are named appropriately (e.g.,
example.index,example.store) to ensure proper test generation. -
Adjust the Generated Tests: After generation, review the created
*Test.phpfiles and make necessary adjustments to align them with your project's specific requirements. For example:- Change HTTP request methods (
get,post,delete, etc.) as needed. - Customize mocked values to match the data expected by your controllers.
- Change HTTP request methods (
-
Run All Tests: Use the following command to execute all tests within the
Featuredirectory and its subdirectories:php artisan execute:tests
Limitations
- The generated tests serve as a starting point and may need adjustments to function correctly within the context of your project.
- Currently, the package does not support generating complex integration tests or tests involving multiple scenarios.
- The mocking logic uses default values from Faker. You may need to customize these values to meet your application's validation requirements.
Roadmap
- Add Artificial Intelligence (AI) Integration: We plan to incorporate AI to improve the quality of generated tests, making them more robust and aligned with best practices.
- Support for Integration Tests: Expand the package to generate integration tests in addition to functional tests.
- Enhanced Parameter Mocking: Implement advanced logic to detect parameter types and generate more accurate mock values.
- Support for Other Laravel Features: Add support for testing events, queues, jobs, and other Laravel features.
Contribution
Contributions are welcome! If you encounter bugs or have suggestions for improvements, please open an issue or submit a pull request to the official repository.
License
This package is distributed under the Apache 2.0. Feel free to use, modify, and distribute it according to the terms of the license.
We hope this package helps you save time and effort while ensuring your Laravel application remains well-tested. Happy coding! 🚀
renatomarinho/laravel-wave-test 适用场景与选型建议
renatomarinho/laravel-wave-test 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 112 次下载、GitHub Stars 达 1, 最近一次更新时间为 2025 年 02 月 12 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 renatomarinho/laravel-wave-test 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 renatomarinho/laravel-wave-test 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 112
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 12
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Apache-2.0
- 更新时间: 2025-02-12