SuperAPI AI 工具集

laravel-testing

测试与质量

查看项目

更新于 10-15 16:49

技能介绍

用途:为 Laravel 12+ 项目编写和运行测试,覆盖特性测试(tests/Feature)、单元测试、浏览器测试(Dusk)、数据库工厂与断言模式,涉及写测试或 tests/Feature/ 时建议启用。

主要能力: 1)特性测试:使用 RefreshDatabase 隔离数据库,通过 actingAs 模拟登录,使用 postJson 等发起请求,并用 assertCreated、assertUnauthorized、assertUnprocessable、assertJsonValidationErrors、assertJsonStructure、assertDatabaseHas 等断言响应与数据库状态。 2)单元测试:继承 PHPUnit\Framework\TestCase,对服务类(如 TaxCalculator)直接实例化并断言计算结果。 3)工厂:定义 definition(),通过 state 提供 completed()、cancelled() 等状态方法;支持 create()、count(5)、for()、has() 等关联写法。 4)断言:覆盖 HTTP 状态码、JSON 路径与结构、数据库存在/缺失/计数及软删除。 5)Mock:用 $this->mock() 配置 shouldReceive('charge')->once()->with(100.00)->andReturn(true)。 6)参考:references/phpunit.md 用于高级 PHPUnit 与数据提供器,references/dusk.md 用于浏览器测试与截图。

使用方式:常用命令包括 php artisan test、php artisan test tests/Feature/OrderTest.php、php artisan test --filter=test_user_can_create_order、php artisan test --parallel、php artisan test --coverage --min=80、php artisan test --stop-on-failure。

适用场景:Laravel 12+ 应用的接口、服务与浏览器端回归测试。

限制:资料未提供安装步骤、收费方式及与其他测试框架的兼容性说明,暂未提供。