定制 gsferro/generate-tests-easy 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

gsferro/generate-tests-easy

Composer 安装命令:

composer require --dev gsferro/generate-tests-easy

包简介

Automated test generation for Laravel applications using Pest

README 文档

README

Generate Tests Easy Logo
Latest Version Total Downloads License

A Laravel package for automatically generating comprehensive Pest tests for your application based on code analysis.

Description

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.

Features

  • Automatically generates Pest tests for models, controllers, and other components
  • Analyzes database structure to create appropriate tests
  • Detects and tests model relationships, scopes, and validation rules
  • Supports API controllers with specialized API test generation
  • Installs and configures Pest if not already present
  • Configures Pest Arch presets for PHP, security, and Laravel
  • Supports Livewire components (if detected in your project)
  • Supports Filament resources and panels (if detected in your project)
  • Works with both new and existing projects

Requirements

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

Installation

composer require gsferro/generate-tests-easy --dev

Usage

Basic Usage

To generate tests for all models and controllers in your application:

php artisan generate-tests:all

Generate Tests for Specific Components

# 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

Options

All commands support the following options:

  • --force: Overwrite existing tests
  • --verbose: Show detailed information during generation

Types of Tests Generated

Filament Resource Structure

When 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:

  • A test for the main resource class (PatientResource)
  • Tests for each page class (ListPatients, CreatePatient, EditPatient, ViewPatient)

Each test is tailored to the specific functionality of the component, ensuring comprehensive test coverage. For example, ViewPatient tests will verify that:

  • The page can be rendered successfully
  • The page displays the correct record data
  • Relationships are properly displayed
  • The edit button works correctly

Model Tests

  • Basic Model Tests: Tests model attributes, inheritance, and traits
  • Relationship Tests: Tests each relationship defined in the model
  • Scope Tests: Tests each scope method defined in the model
  • Validation Tests: Tests validation rules defined in the model
  • Factory Tests: Tests model factory if available

Controller Tests

  • Unit Tests: Tests controller methods, routes, and configuration
  • Feature Tests: Tests HTTP requests to controller endpoints
  • API Tests: Tests API endpoints for API controllers

Livewire Tests (if Livewire is installed)

  • Component Tests: Tests Livewire component rendering and functionality
  • Event Tests: Tests Livewire events and listeners

Filament Tests (if Filament is installed)

  • Resource Tests: Tests Filament resource configuration, model association, and navigation
  • List Page Tests: Tests the resource list page, table columns, search, and sorting functionality
  • Create Page Tests: Tests the resource create page, form fields, validation, and record creation
  • Edit Page Tests: Tests the resource edit page, form fields, validation, and record updates
  • Form Tests: Tests form components, validation rules, and data submission
  • Table Tests: Tests table columns, filters, actions, and bulk actions
  • Panel Tests: Tests Filament panel configuration and access

Configuration

Publish the configuration file:

php artisan vendor:publish --tag=generate-tests-easy-config

Configuration Options

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,
];

Extending

You can extend the package by:

  1. Publishing and customizing the test stubs
  2. Creating custom analyzers for specific components
  3. Adding custom test generators

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This package is open-sourced software licensed under the MIT license.

Running Package Tests

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.

gsferro/generate-tests-easy 适用场景与选型建议

gsferro/generate-tests-easy 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 16 次下载、GitHub Stars 达 2, 最近一次更新时间为 2025 年 05 月 17 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「testing」 「laravel」 「generate」 「easy」 「pest」 「automated tests」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 gsferro/generate-tests-easy 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 gsferro/generate-tests-easy 我们能提供哪些服务?
定制开发 / 二次开发

基于 gsferro/generate-tests-easy 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 16
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 8
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-05-17