skillfed

pest

Pest is a testing framework built on PHPUnit that replaces test classes with closures and assertion methods with a fluent expect() API. This skill covers test structure using test()/it()/describe(), the full expect() chain including modifiers and custom expectations, hooks for setup and teardown, datasets for parameterized testing, and advanced features like architecture rules and mutation testing.

Pest helps you write function-style tests with closures and expect() assertions instead of test classes and assertion methods.

AI-generated summary based on this skill's SKILL.md

18 0 MIT updated by xobotyi

Install

xobotyi/cc-foundry/pest · repository language: JavaScript

git clone https://github.com/xobotyi/cc-foundry
cp -r cc-foundry/plugins/php/skills/pest ~/.claude/skills/pest
npx skillfed install xobotyi/cc-foundry/pest

Frequently asked questions

AI-generated answers based on this skill's SKILL.md and metadata

How do I write pest tests using closures and the expect API?

Pest replaces PHPUnit class-based tests with function-style closures. Use test() or it() to define a test, then chain expect() with your assertion: test('adds numbers', function() { expect(1 + 1)->toBe(2); }). The expect() API provides fluent methods like toBe(), toEqual(), toContain(), and hundreds more, all chainable for readable assertions. Closures receive automatic dependency injection and access to $this for helper methods.

What are Pest datasets and how do data providers work?

Pest datasets enable parameterized testing without repeating test code. Use dataset() to define test cases, then reference them with ->with('datasetName'). Example: dataset('numbers', [1, 2, 3]) paired with test('is positive', fn($n) => expect($n)->toBeGreaterThan(0))->with('numbers'). Datasets replace PHPUnit's @dataProvider annotation and support inline arrays, external files, or database queries for flexible test data organization.

How do Pest hooks like beforeEach and afterEach work?

Pest hooks manage setup and teardown logic. Use beforeEach() to run code before each test—ideal for resetting state or creating fixtures. Use afterEach() for cleanup. Hooks can be scoped with describe() blocks: describe('auth', function() { beforeEach(fn() => login()); it('...'); }) ensures login runs only for tests in that block. Global hooks run for all tests; nested hooks inherit and stack.

What is Pest architecture testing and mutation testing?

Pest architecture testing enforces code structure rules without assertions. Use arch()->preset()->laravel() or custom rules like ->classes('App\Models')->shouldExtend(Model). Mutation testing verifies test quality by introducing code changes (mutations) and checking if tests catch them. Run pest --mutate to detect weak tests. Both features ensure code maintainability and test reliability beyond simple coverage metrics.

How do I run Pest CLI with filtering, coverage, and parallelization?

Pest CLI offers powerful execution control. Use --filter to run specific tests by name, --group to organize by tags, --coverage for code coverage reports, and --parallel to run tests concurrently. Example: pest --filter auth --coverage --parallel. Configure parallelization in pest.php with processes option. Combine flags for flexible test runs: pest --only, --skip, --profile for profiling slow tests.

How do I migrate from PHPUnit class-based tests to Pest?

Pest provides a migration path from PHPUnit. Replace class methods with test() closures: PHPUnit's public function testExample() becomes test('example', function() { ... }). Convert $this->assert*() calls to expect() chains. Use pest --convert to automatically transform existing PHPUnit tests. Hooks replace setUp/tearDown methods. Datasets replace @dataProvider. Most PHPUnit features map directly; Pest's syntax is more concise and readable.

SKILL.md

rendered from the published skill — quoted content, verbatim

Pest

Tests are functions, not classes. Write the expectation, not the ceremony — expect($x)->toBe($y), and let the description say what the code does.

Pest is a testing framework built on the PHPUnit engine: closures instead of test-case methods, an expect() expectation API instead of $this->assert*, and first-class architecture, mutation, type-coverage, and browser testing. $this inside a test closure is a PHPUnit TestCase, so the full PHPUnit assertion and test-double API stays available. All patterns target Pest 4 on PHP 8.5+ (it runs on the PHPUnit 12 engine; its own floor is PHP 8.3).

This skill governs Pest-specific decisions. It does not restate universal testing philosophy (test behavior not implementation, arrange-act-assert, isolation, mock at boundaries), the PHPUnit assertion/double API,

(truncated - see the full file via the links below)

Read as markdown · JSON record · Browse the source repository

File tree — 6 files
plugins/php/skills/pest/.dev/reference-inventory.json
plugins/php/skills/pest/SKILL.md
plugins/php/skills/pest/references/advanced-features.md
plugins/php/skills/pest/references/architecture.md
plugins/php/skills/pest/references/configuration.md
plugins/php/skills/pest/references/expectations.md

Related skills

Tags

function-based-testing fluent-assertions php-testing-framework behavioral-test-syntax test-data-providers structural-code-validation browser-automation-testing mutation-score-analysis test-filtering-focus phpunit-abstraction