用途:Pest 是构建在 PHPUnit 引擎之上的 PHP 测试框架,本技能用于处理与 Pest 相关的测试编写与评审,模式面向 Pest 4(PHPUnit 12 引擎,运行于 PHP 8.5+,自身最低要求 PHP 8.3)。本技能只管 Pest 特有决策,通用测试理念、PHPUnit 断言与替身 API、覆盖属性、phpunit.xml 细节归属于 phpunit 技能。
主要能力:test()/it()/describe() 函数式测试结构;expect() 期望 API(含 not/and/each/sequence、自定义期望);beforeEach/afterEach/beforeAll/afterAll 钩子;数据集(含命名、共享、惰性、绑定数据集与 ->with()/->repeat());异常断言 ->throws()/->throwsNoExceptions()/->fails();过滤、跳过、聚焦、分组、依赖与 ->flaky() 重试;Mockery 或 PHPUnit 测试替身做 Mock;高阶测试;arch() 架构测试与 php/security/laravel/strict 预设;变异测试、类型覆盖、浏览器测试、快照测试、压力测试等可选模式。
使用方式:composer require pestphp/pest --dev --with-all-dependencies(需先移除 phpunit/phpunit);--init 生成 tests/Unit、tests/Feature、tests/TestCase.php 与 tests/Pest.php,测试文件以 *Test.php 结尾。运行:./vendor/bin/pest,可用 --filter、--group、--parallel、--coverage --min=90、--dirty、--bail、--retry 等参数。
限制:Pest 自身无 Mock 库,需用 Mockery 或 PHPUnit 替身;变异/覆盖需 Xdebug 或 PCOV;浏览器测试需 pest-plugin-browser 与 Playwright;压力测试需 pest-plugin-stressless 与 k6;类型覆盖需 pest-plugin-type-coverage。不要在同一套件混用 Pest 与 PHPUnit 类式范式;现有代码风格若与约定冲突应遵循代码库并提示一次。