No slash command · from php-foundation
PHPUnit and Pest testing patterns for PHP projects: test structure, naming, data providers, test doubles, fixtures, and coverage targets. Stack-agnostic.
Ships in php-foundation. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Patterns for PHPUnit and Pest that apply to any PHP codebase. Detect which runner the project uses before writing tests: pestphp/pest in require-dev → Pest; otherwise PHPUnit. Both run on top of PHPUnit assertions.
grep -q pestphp/pest composer.json && echo pest || echo phpunit
vendor/bin/phpunit # PHPUnit
vendor/bin/pest # Pest
vendor/bin/phpunit --coverage-text # coverage (needs Xdebug or PCOV)
Prefer a composer test script if one exists.
PHPUnit (class-based):
<?php
declare(strict_types=1);
namespace App\Tests\Unit;
use App\Domain\Money;
use App\Domain\Currency;
use PHPUnit\Framework\TestCase;
final class MoneyTest extends TestCase
{
public function test_it_adds_two_amounts_of_the_same_currency(): void
{
// Arrange
$a = new Money(100, Currency::USD);
$b = new Money(250, Currency::USD);
// Act
$sum = $a->add($b);
// Assert
self::assertSame(350, $sum->amount);
}
public function test_it_rejects_a_currency_mismatch(): void
{
$this->expectException(\InvalidArgumentException::class);
(new Money(100, Currency::USD))->add(new Money(100, Currency::EUR));
}
}
Pest (function-based, same engine):
<?php
declare(strict_types=1);
use App\Domain\Money;
use App\Domain\Currency;
it('adds two amounts of the same currency', function () {
$sum = (new Money(100, Currency::USD))->add(new Money(250, Currency::USD));
expect($sum->amount)->toBe(350);
});
it('rejects a currency mismatch', function () {
expect(fn () => (new Money(100, Currency::USD))->add(new Money(100, Currency::EUR)))
->toThrow(InvalidArgumentException::class);
});
tests/, namespace App\Tests\... (mapped via autoload-dev).src/Domain/Money.php → tests/Unit/Domain/MoneyTest.php.tests/Unit (pure, no I/O) from tests/Integration / tests/Feature (DB, HTTP, filesystem).test_it_<behaviour>() or #[Test] attribute. Pest: it('<behaviour>'). Describe behaviour, not implementation.Drive many cases through one body instead of duplicating tests.
// PHPUnit
public static function discountCases(): array
{
return [
'no discount below 100' => [50, 0.0],
'5% at 100' => [100, 0.05],
'15% at 1000' => [1000, 0.15],
];
}
#[DataProvider('discountCases')]
public function test_discount_tiers(int $total, float $expected): void
{
self::assertSame($expected, discountFor($total));
}
// Pest
it('applies discount tiers', function (int $total, float $expected) {
expect(discountFor($total))->toBe($expected);
})->with([
[50, 0.0],
[100, 0.05],
[1000, 0.15],
]);
public function test_it_sends_a_receipt_after_charging(): void
{
$gateway = $this->createMock(PaymentGateway::class);
$gateway->expects(self::once())
->method('charge')
->with(self::equalTo(500))
->willReturn(new Receipt('rcpt_1'));
$mailer = $this->createMock(Mailer::class);
$mailer->expects(self::once())->method('send');
$service = new CheckoutService($gateway, $mailer);
$service->checkout($order);
}
Discipline:
protected function setUp(): void
{
parent::setUp();
$this->repository = new InMemoryUserRepository();
}
setUp() for common arrange steps; keep heavy fixtures out of unit tests.vendor/bin/phpunit --coverage-text (requires PCOV or Xdebug). Report the number; do not chase the last few percent on glue code.What SKILL.md sets; muted values are Claude Code's defaults
3 skills in this plugin
/composer-toolingComposer conventions for any PHP project: dependency management, version constraints, PSR-4 autoloading, scripts, platform requirements, and the composer.json vs composer.lock contract. Stack-agnostic — referenced by every PHP plugin in the marketplace.
Use this skill to:
- Read composer.json to detect the PHP version, framework, and key packages before writing code.
- Add dependencies with correct version constraints and the right require vs require-dev placement.
- Configure PSR-4 autoloading and regenerate the autoloader after adding namespaces.
- Use composer scripts and platform config consistently.
Do NOT use this skill for:
- PHP language idioms — see php-foundation:php-conventions.
- Testing setup and runners — see php-foundation:php-testing.
- Framework-specific package guidance (Laravel/Symfony bundles) — those live in framework plugin skills.
/php-conventionsModern PHP idioms for any PHP project (PHP 8.1+): readonly properties, enums, match expressions, constructor property promotion, typed properties, named arguments, nullsafe operator, first-class callable syntax, strict_types, PSR-12 style, and null discipline. Apply when the project is a PHP 8.1+ project. Stack-agnostic — referenced by every PHP plugin in the marketplace.
Use this skill to:
- Write strongly-typed, immutable-by-default value objects with readonly properties and enums.
- Replace switch ladders and magic constants with match expressions and backed enums.
- Cut constructor boilerplate with property promotion and express optionality with typed nullable returns.
- Keep code PSR-12 compliant with declare(strict_types=1) in every file.
Do NOT use this skill for:
- Framework-specific idioms (Eloquent, Doctrine, Symfony services, Laravel facades — those live in framework plugin skills).
- Composer / autoloading / dependency management — see php-foundation:composer-tooling.
- Testing patterns — see php-foundation:php-testing.
npx claudepluginhub aratkruglik/claude-sdlc --plugin php-foundationOther plugins' skills for the same job