A guide for unit and integration testing in PHP. Helps developers enforce quality standards across PHP projects.

Install

mkdir -p .claude/skills/php-testing && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/3258" && unzip -o skill.zip -d .claude/skills/php-testing && rm skill.zip

Installs to .claude/skills/php-testing

Activation

This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.

Write unit and integration tests for PHP applications with PHPUnit and Pest. Use when writing PHPUnit unit tests or integration tests for PHP applications.
155 chars✓ has a “when” trigger
Intermediate

Key capabilities

  • Write unit tests with PHPUnit or Pest
  • Implement integration tests
  • Create mocks for dependencies
  • Use data providers for test cases

How it works

It provides standards for structuring tests, isolating dependencies through mocking, and using data providers to ensure repeatable test execution.

Inputs & outputs

You give it
PHP class or service
You get back
Test suite results

When to use php-testing

  • Write unit tests for PHP classes
  • Set up integration test suites
  • Review PHP test coverage

About this skill

PHP Testing

Priority: P1 (HIGH)

Structure

See implementation examples for test directory layout.

Write Tests with PHPUnit and Pest

  • Standards: Use PHPUnit (9/10+) or Pest. Organize into Unit/, Integration/, and Feature/. Class names should extend TestCase.
  • TDD Workflow: Follow Red-Green-Refactor. Write failing test first, implement minimal logic, then refactor.

See implementation examples for PHPUnit service test with mock.

Apply Assertions and Data Providers

  • Fluent Assertions: Use assertSame (===) over assertEquals to avoid type coercion. Also use assertCount() and assertMatchesRegularExpression().
  • Data Providers: Use #[DataProvider('statusProvider')] (PHPUnit 10+) or dataset (Pest).

See implementation examples for Pest expressive syntax with datasets.

Isolate Test Dependencies

  • Mocking: Use createMock() for dependencies. NOT mock simple Data Objects.
  • Isolation: Ensure tests Independent and Repeatable. DB tests must use Transactions or SQLite :memory:.
  • Coverage: Aim for 80%+ line coverage. Use phpunit.xml to whitelist specific directories.
  • Automation: Run tests on every PR using GitHub Actions or GitLab CI.

Anti-Patterns

  • No testing private methods: Test through public interfaces only.
  • No over-mocking internals: Mock only external boundaries.
  • No real network/DB in unit tests: Use in-memory databases or mocks.
  • No coverage-metric chasing: Prioritize meaningful assertions.

References

Canonical response anchors

When this skill applies, preserve the following domain terminology or equivalent concrete examples in the answer when relevant:

  • Define a static method returning test cases as arrays,method
  • independent
  • type coercion

When not to use it

  • When testing private methods directly
  • When using real network or database connections in unit tests

Limitations

  • Requires tests to be independent and repeatable

How it compares

It enforces TDD workflows and isolation patterns that prevent common testing anti-patterns in PHP.

Compared to similar skills

php-testing side by side with the closest alternatives in the catalog.

SkillInstallsUpdatedSafetyDifficulty
php-testing (this skill)828dNo flagsIntermediate
laravel-13-facades03moNo flagsIntermediate
php-best-practices1528dNo flagsBeginner
laravel-pdf113moReviewBeginner

Try saying

Example prompts that trigger this skill in your AI assistant.

Search skills

Search the agent skills registry