Agent Skills › krayin/laravel-crm › pest-testing

pest-testing

GitHub

专为 Krayin CRM 设计的测试技能,基于 Pest PHP v3 和 Laravel 12。涵盖单元测试、功能测试的创建与调试,支持数据集、Mock 及自定义断言,并包含架构测试规范及最佳实践指南。

.github/skills/pest-testing/SKILL.md krayin/laravel-crm

触发场景

编写或更新 Krayin CRM 的单元测试和功能测试 调试测试失败用例 使用数据集、Mock 对象或自定义期望 用户提及 test, spec, TDD, expects, assertion, coverage

安装

npx skills add krayin/laravel-crm --skill pest-testing -g -y
更多选项

非标准路径

npx skills add https://github.com/krayin/laravel-crm/tree/2.2/.github/skills/pest-testing -g -y

不安装直接使用

npx skills use krayin/laravel-crm@pest-testing

指定 Agent (Claude Code)

npx skills add krayin/laravel-crm --skill pest-testing -a claude-code -g -y

安装 repo 全部 skill

npx skills add krayin/laravel-crm --all -g -y

预览 repo 内 skill

npx skills add krayin/laravel-crm --list

SKILL.md

Frontmatter
{
    "name": "pest-testing",
    "license": "MIT",
    "metadata": {
        "author": "webkul"
    },
    "description": "Use when writing or updating Krayin CRM tests (unit or feature), debugging test failures, using datasets, mocks or custom expectations, writing architecture tests, or when the user mentions test, spec, TDD, expects, assertion, or coverage. Uses the Pest PHP framework (v3) with Laravel 12."
}

Pest Testing in Krayin CRM

When to Apply

Activate this skill when:

  • Creating or updating tests (unit or feature)
  • Debugging test failures
  • Using datasets, mocks, or custom expectations
  • Writing architecture or convention tests
  • The user mentions test, spec, TDD, expects, assertion, coverage, or verifying behavior

Krayin Testing Structure

Test Locations

Krayin tests are stored in the root tests/ directory:

/tests
├── Feature/
├── Unit/
├── Pest.php
├── TestCase.php
└── CreatesApplication.php

Available Test Suites

Defined in phpunit.xml:

Test Suite Location Command
Unit tests/Unit php artisan test --testsuite="Unit"
Feature tests/Feature php artisan test --testsuite="Feature"

Pest.php Configuration

tests/Pest.php binds the base test case for feature tests:

uses(\Tests\TestCase::class)->in('Feature');

It also defines helper functions you can reuse, such as:

  • getDefaultAdmin()
  • actingAsSanctumAuthenticatedAdmin()
  • getFirstName($fullName)

Running Tests

Run All Tests

php artisan test --compact

Run a Specific Test Suite

php artisan test --testsuite="Feature"
php artisan test --testsuite="Unit"

Run a Specific Test File

php artisan test --compact tests/Feature/ExampleTest.php

Run with Filter

php artisan test --compact --filter=testName

Creating New Tests

Create Feature Test

php artisan make:test --pest ExampleFeatureTest

Create Unit Test

php artisan make:test --pest --unit ExampleUnitTest

Basic Test Structure

it('passes basic assertion', function () {
    expect(true)->toBeTrue();
});

it('returns successful response', function () {
    $response = $this->get('/');

    $response->assertSuccessful();
});

Assertions

Prefer specific response helpers:

Use Instead of
assertSuccessful() assertStatus(200)
assertNotFound() assertStatus(404)
assertForbidden() assertStatus(403)

Datasets

it('has valid emails', function (string $email) {
    expect($email)->toContain('@');
})->with([
    'james' => 'james@krayin.com',
    'john'  => 'john@krayin.com',
]);

Common Pitfalls

  • Forgetting to use assertSuccessful() and other specific helpers
  • Skipping --pest when creating tests
  • Ignoring helper utilities already available in tests/Pest.php

Testing Best Practices

  • Cover happy paths, failure paths, and edge cases
  • Keep tests isolated and focused
  • Use factories where available
  • Follow existing test patterns in the repository

版本历史

  • 1963f21 当前 2026-08-20 16:31

同 Skill 集合

.github/skills/krayin-authorization/SKILL.md
.github/skills/crm-package-development/SKILL.md

元信息

文件数
0
版本
999b596
Hash
ec6e652f
收录时间
2026-08-20 16:31

首页 - Wiki
Copyright © 2011-2026 iteam. Current version is 2.156.0. UTC+08:00, 2026-11-21 16:28
浙ICP备14020137号-1