laravel-verification

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Laravel Verification Loop

Laravel验证流程

Run before PRs, after major changes, and pre-deploy.
在提交PR前、重大变更完成后以及部署前运行。

When to Use

适用场景

  • Before opening a pull request for a Laravel project
  • After major refactors or dependency upgrades
  • Pre-deployment verification for staging or production
  • Running full lint -> test -> security -> deploy readiness pipeline
  • 为Laravel项目提交PR前
  • 重大重构或依赖升级完成后
  • 预发或生产环境的部署前验证
  • 运行完整的lint→测试→安全→部署就绪流水线

How It Works

运行逻辑

  • Run phases sequentially from environment checks through deployment readiness so each layer builds on the last.
  • Environment and Composer checks gate everything else; stop immediately if they fail.
  • Linting/static analysis should be clean before running full tests and coverage.
  • Security and migration reviews happen after tests so you verify behavior before data or release steps.
  • Build/deploy readiness and queue/scheduler checks are final gates; any failure blocks release.
  • 从环境检查到部署就绪的各个阶段按顺序执行,每一层验证都以上一步的通过为基础。
  • 环境和Composer检查是所有后续步骤的前置门槛,如果失败立即终止流程。
  • 在运行全量测试和覆盖率检查前,lint/静态分析的结果必须无报错。
  • 安全和迁移检查在测试完成后执行,这样你可以在处理数据或发布步骤前先验证代码行为符合预期。
  • 构建/部署就绪检查以及队列/调度器检查是最终关卡,任何失败都会阻塞发布流程。

Phase 1: Environment Checks

阶段1:环境检查

bash
php -v
composer --version
php artisan --version
  • Verify
    .env
    is present and required keys exist
  • Confirm
    APP_DEBUG=false
    for production environments
  • Confirm
    APP_ENV
    matches the target deployment (
    production
    ,
    staging
    )
If using Laravel Sail locally:
bash
./vendor/bin/sail php -v
./vendor/bin/sail artisan --version
bash
php -v
composer --version
php artisan --version
  • 验证
    .env
    文件存在且包含所有必填配置项
  • 生产环境需确认
    APP_DEBUG=false
  • 确认
    APP_ENV
    和目标部署环境(
    production
    staging
    )匹配
如果本地使用Laravel Sail:
bash
./vendor/bin/sail php -v
./vendor/bin/sail artisan --version

Phase 1.5: Composer and Autoload

阶段1.5:Composer和自动加载

bash
composer validate
composer dump-autoload -o
bash
composer validate
composer dump-autoload -o

Phase 2: Linting and Static Analysis

阶段2:Lint与静态分析

bash
vendor/bin/pint --test
vendor/bin/phpstan analyse
If your project uses Psalm instead of PHPStan:
bash
vendor/bin/psalm
bash
vendor/bin/pint --test
vendor/bin/phpstan analyse
如果你的项目使用Psalm而非PHPStan:
bash
vendor/bin/psalm

Phase 3: Tests and Coverage

阶段3:测试与覆盖率

bash
php artisan test
Coverage (CI):
bash
XDEBUG_MODE=coverage php artisan test --coverage
CI example (format -> static analysis -> tests):
bash
vendor/bin/pint --test
vendor/bin/phpstan analyse
XDEBUG_MODE=coverage php artisan test --coverage
bash
php artisan test
覆盖率检查(CI环境):
bash
XDEBUG_MODE=coverage php artisan test --coverage
CI示例(格式化检查→静态分析→测试):
bash
vendor/bin/pint --test
vendor/bin/phpstan analyse
XDEBUG_MODE=coverage php artisan test --coverage

Phase 4: Security and Dependency Checks

阶段4:安全与依赖检查

bash
composer audit
bash
composer audit

Phase 5: Database and Migrations

阶段5:数据库与迁移

bash
php artisan migrate --pretend
php artisan migrate:status
  • Review destructive migrations carefully
  • Ensure migration filenames follow
    Y_m_d_His_*
    (e.g.,
    2025_03_14_154210_create_orders_table.php
    ) and describe the change clearly
  • Ensure rollbacks are possible
  • Verify
    down()
    methods and avoid irreversible data loss without explicit backups
bash
php artisan migrate --pretend
php artisan migrate:status
  • 仔细审核破坏性迁移操作
  • 确保迁移文件命名遵循
    Y_m_d_His_*
    格式(例如
    2025_03_14_154210_create_orders_table.php
    ),且清晰描述变更内容
  • 确保迁移可回滚
  • 验证
    down()
    方法逻辑,在没有明确备份的情况下避免不可逆的数据丢失

Phase 6: Build and Deployment Readiness

阶段6:构建与部署就绪检查

bash
php artisan optimize:clear
php artisan config:cache
php artisan route:cache
php artisan view:cache
  • Ensure cache warmups succeed in production configuration
  • Verify queue workers and scheduler are configured
  • Confirm
    storage/
    and
    bootstrap/cache/
    are writable in the target environment
bash
php artisan optimize:clear
php artisan config:cache
php artisan route:cache
php artisan view:cache
  • 确保生产配置下缓存预热成功
  • 验证队列Worker和调度器已正确配置
  • 确认目标环境中
    storage/
    bootstrap/cache/
    目录具备可写权限

Phase 7: Queue and Scheduler Checks

阶段7:队列与调度器检查

bash
php artisan schedule:list
php artisan queue:failed
If Horizon is used:
bash
php artisan horizon:status
If
queue:monitor
is available, use it to check backlog without processing jobs:
bash
php artisan queue:monitor default --max=100
Active verification (staging only): dispatch a no-op job to a dedicated queue and run a single worker to process it (ensure a non-
sync
queue connection is configured).
bash
php artisan tinker --execute="dispatch((new App\\Jobs\\QueueHealthcheck())->onQueue('healthcheck'))"
php artisan queue:work --once --queue=healthcheck
Verify the job produced the expected side effect (log entry, healthcheck table row, or metric).
Only run this on non-production environments where processing a test job is safe.
bash
php artisan schedule:list
php artisan queue:failed
如果使用Horizon:
bash
php artisan horizon:status
如果
queue:monitor
命令可用,使用它检查队列积压情况,无需处理任务:
bash
php artisan queue:monitor default --max=100
主动验证(仅适用于预发环境):向专用队列分发一个空操作任务,运行单个Worker处理该任务(确保已配置非
sync
的队列连接)。
bash
php artisan tinker --execute="dispatch((new App\\Jobs\\QueueHealthcheck())->onQueue('healthcheck'))"
php artisan queue:work --once --queue=healthcheck
验证任务产生了预期的副作用(日志条目、健康检查表记录或指标数据)。
仅在运行测试任务安全的非生产环境中执行此操作。

Examples

示例

Minimal flow:
bash
php -v
composer --version
php artisan --version
composer validate
vendor/bin/pint --test
vendor/bin/phpstan analyse
php artisan test
composer audit
php artisan migrate --pretend
php artisan config:cache
php artisan queue:failed
CI-style pipeline:
bash
composer validate
composer dump-autoload -o
vendor/bin/pint --test
vendor/bin/phpstan analyse
XDEBUG_MODE=coverage php artisan test --coverage
composer audit
php artisan migrate --pretend
php artisan optimize:clear
php artisan config:cache
php artisan route:cache
php artisan view:cache
php artisan schedule:list
最简流程:
bash
php -v
composer --version
php artisan --version
composer validate
vendor/bin/pint --test
vendor/bin/phpstan analyse
php artisan test
composer audit
php artisan migrate --pretend
php artisan config:cache
php artisan queue:failed
CI风格流水线:
bash
composer validate
composer dump-autoload -o
vendor/bin/pint --test
vendor/bin/phpstan analyse
XDEBUG_MODE=coverage php artisan test --coverage
composer audit
php artisan migrate --pretend
php artisan optimize:clear
php artisan config:cache
php artisan route:cache
php artisan view:cache
php artisan schedule:list