Skip to content
Back to skills

Php Testing

ASecurity

Write unit and integration tests for PHP applications with PHPUnit and Pest. Use when writing PHPUnit unit tests or integration tests for PHP applications.

  • 24 stars
  • 0 votes
  • 2 copies
  • 17 views
  • Added September 4, 2026
testingphpsqlexpresstestinggitdatabase

Security analysis

A100/100

Pro scans all 2 files and shows the line behind each finding

Scanned September 4, 2026

npx -y skills add gabrielmoreira/agent-skills-mirror --skill php-testing --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Php Testing?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Php Testing
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/gabrielmoreira-php-testing/badge)](https://www.skillsdirectory.com/skills/gabrielmoreira-php-testing)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: php-testing
description: Write unit and integration tests for PHP applications with PHPUnit and Pest. Use when writing PHPUnit unit tests or integration tests for PHP applications.
metadata:
  triggers:
    files:
    - 'tests/**/*.php'
    - 'phpunit.xml'
    keywords:
    - phpunit
    - pest
    - mock
    - assert
    - tdd
---
# PHP Testing

## **Priority: P1 (HIGH)**

## Structure

See [implementation examples](references/implementation.md#directory-structure) 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](references/implementation.md#phpunit-service-test) 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](references/implementation.md#pest-dataset-example) 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

- [Testing Patterns & Mocks](references/implementation.md)

## 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

Files in this skill

  • SKILL.md2.4 KB
  • evals/evals.json3.5 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in testing →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.