agentsclimarketplace

Php testing

Skill fusengine/agents/plugins/php-expert/skills/php-testing

Use when writing or configuring tests on a framework-agnostic PHP project and choosing between PHPUnit and Pest. Covers PHPUnit 12 attributes, Pest 4, test doubles, fixtures, and coverage. Do NOT use for Laravel test helpers (RefreshDatabase, HTTP tests → laravel-expert laravel-testing) or quality tooling (PHPStan/Rector/Fixer → php-quality-tooling).From its SKILL.md

Install
npx -y skills add fusengine/agents --skill php-testing

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

SKILL.md

4.4 KB, 925 tokens by cl100k_base, as published. Nobody here has run it

PHP Testing

Two frameworks, one engine. Pest is a layer over PHPUnit — both need PHP 8.3+ and share the same runner and assertions underneath.

Agent Workflow (MANDATORY)

Before ANY implementation, use TeamCreate to spawn 3 agents:

  1. fuse-ai-pilot:explore-codebase - Detect existing framework (phpunit.xml vs Pest.php), test layout, PHP version
  2. fuse-ai-pilot:research-expert - Verify latest PHPUnit 12 / Pest 4 docs via Context7/Exa
  3. mcp__context7__query-docs - Check attribute names, test-double API, config schema

After implementation, run fuse-ai-pilot:sniper for validation.


Overview

FrameworkStyleStrength
PHPUnit 12Class-based, xUnitEnterprise baseline, explicit, widest tooling/CI support
Pest 4Closure-based, expressiveModern DX, browser + arch + mutation testing, less boilerplate

Pest 4 runs on PHPUnit's engine, so PHPUnit knowledge transfers directly. The choice is about ergonomics and team preference, not capability.


Critical Rules

  1. PHP 8.3+ required - Both PHPUnit 12 and Pest 4 drop older PHP
  2. Attributes only, no annotations - PHPUnit 12 removed docblock annotations (@test, @dataProvider)
  3. Data providers are public static - Non-static providers no longer work
  4. createStub() is not configurable - Configure expectations only on createMock()
  5. One framework per project - Pest or PHPUnit, not both driving the same suite
  6. Mock at boundaries - Network/DB/clock, never internal implementation detail

Decision Guide

Choosing a framework? (non-Laravel)
├── Enterprise / strict CI / mixed team → PHPUnit 12 (explicit, ubiquitous)
├── Modern DX, greenfield, small team → Pest 4 (concise, expressive)
├── Need browser / architecture / mutation testing out of the box → Pest 4
└── Migrating a large PHPUnit suite → stay PHPUnit, or drift-migrate to Pest

Honest note: PHPUnit is the enterprise/CI baseline; Pest has strong community momentum but that trend is not normative. Either is a correct, well-supported choice — pick per team, not per hype.

→ Full matrix in references/choosing-framework.md


Reference Guide

Concepts

TopicReferenceLoad when
Framework choicereferences/choosing-framework.mdDeciding PHPUnit vs Pest
PHPUnit 12references/phpunit-12.mdWriting PHPUnit tests
Pest 4references/pest-4.mdWriting Pest tests
Annotation migrationreferences/annotations-to-attributes.mdUpgrading pre-12 tests

Templates

TemplateUse Case
references/templates/phpunit-xml.mdphpunit.xml + first TestCase
references/templates/pest-setup.mdPest.php + first Pest tests
references/templates/test-doubles.mdStubs, mocks, fixtures, coverage

Quick Start

PHPUnit 12

use PHPUnit\Framework\TestCase;

final class GreeterTest extends TestCase
{
    public function testGreets(): void
    {
        $this->assertSame('Hi, Al', (new Greeter)->greet('Al'));
    }
}

Pest 4

it('greets', function () {
    expect((new Greeter)->greet('Al'))->toBe('Hi, Al');
});

Best Practices

DO

  • Name tests by behavior (testRejectsExpiredToken), assert one behavior each
  • Use #[DataProvider] with public static providers for table-driven tests
  • Gate CI on an explicit coverage threshold, not a report

DON'T

  • Keep @test / @dataProvider annotations (removed in PHPUnit 12)
  • Configure expectations on createStub() results
  • Mock the class under test — mock its collaborators

What ships with it: 8 files

16.2 KB alongside SKILL.md

Keep looking

Skills are one crate of 613,297. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.