AgentStack
Browse Sign in
Browse Why AgentStack Sell Docs
Sign in
SKILL verified MPL-2.0 Self-run

Testing Strategy

skill-garrettw-php-arch-skills-testing-strategy · by garrettw

Use this skill when writing tests for a PHP application. Provides layer-specific guidance to choose the right testing style (unit, integration, feature) for domain objects, mappers, repositories, handlers, and controllers.

No reviews yet
0 installs
9 views
0.0% view→install

Install

$ agentstack add skill-garrettw-php-arch-skills-testing-strategy

✓ scanned · ✓ verified, works with Claude Code, Cursor, and more.

Security review

✓ Passed

No issues found. Passed automated security review. · v0.1.0 How review works →

  • Prompt-injection patterns
  • Secret / credential exfiltration
  • Dangerous shell & filesystem operations
  • Untrusted network calls
  • Known-malicious package signatures

What it can access

  • Network access No
  • Filesystem access No
  • Shell / process execution No
  • Environment & secrets No
  • Dynamic code execution No

From automated source analysis of v0.1.0. “Used” means the capability is present in the source — more access means more to trust, not that it’s unsafe.

View the full security report →

Verified badge

Passed review? Show it. Paste this badge into your README, it links to the public security report.

AgentStack Verified badge Links to your public security report.
[![AgentStack Verified](https://agentstack.voostack.com/badges/verified.svg)](https://agentstack.voostack.com/security/report/skill-garrettw-php-arch-skills-testing-strategy)

Reliability & compatibility

Security review passed
0 installs to date
no reviews yet
23d ago

Declared compatibility

Claude CodeClaude Desktop

Compatibility is declared by the source manifest. End-to-end runtime verification is coming, see below.

Preview Execution monitoring

We're building live execution health for every listing: tool-call success rate, median latency, uptime, and last-checked timestamps, measured, not self-reported. It isn't live yet, so we don't show numbers we can't stand behind.

How agent discovery & health will work →
Are you the author of Testing Strategy? Claim this listing to set pricing, connect Stripe payouts, and keep 70% of every sale.
Sign up to claim

About

Backend Testing Strategy by Architecture Layer

System Overview

Different architectural layers have different responsibilities, and tests should be structured to verify those specific responsibilities without over-specifying internal implementation details. This skill provides rules for matching the right testing style (unit, integration, feature) to the correct layer.

Numbered Workflows

1. Testing the Domain Layer

If testing pure domain logic (entities, value objects, policies):

  1. Use pure PHP unit tests. Do not boot the framework or database.
  2. Setup state. Instantiate the object directly using new (the "Given").
  3. Execute behavior. Call the domain method (the "When").
  4. Assert outcomes. Verify the new state, the returned result, or the events recorded (the "Then").

2. Testing Mappers and Repositories

If testing persistence boundaries:

  1. For Mappers: Use unit tests or fast integration tests. Focus on data conversion edge cases (null values, default fallbacks, enum string conversions).
  2. For Repositories: Use integration tests hitting a real (test) database. Do not mock the ORM inside a repository test. Write a fixture to the real database, call the repository, and assert the returned domain objects are correct.

3. Testing Application Handlers

If testing use case orchestration:

  1. Choose the testing style. Use integration tests hitting a real test database, OR unit tests with fakes/mocks for infrastructure. (Integration tests often provide higher confidence with less brittle setup).
  2. Assert coordination. Verify the handler successfully loads data, calls the domain, saves state, and publishes events.

4. Testing Controllers and Adapters

If testing framework edges and infrastructure adapters:

  1. For Controllers: Write Feature/Integration tests. Assert on HTTP status codes, JSON response shapes, and validation error formats.
  2. For Infrastructure Adapters: Write integration tests hitting a sandbox API (if available) or unit tests mocking the vendor's HTTP client. Verify that vendor exceptions are caught and translated into domain exceptions.
  3. For Architecture Boundaries: Add automated architecture tests to enforce the dependency rule (e.g., using Pest, Deptrac, PHP Arkitect, or a custom script). Verify that the domain core has zero imports from infrastructure, HTTP, or database libraries.

Using Tests to Analyze an Existing Codebase

Tests are also the fastest way to characterize and probe a legacy codebase before planning changes:

  • Run architecture tests first. A Deptrac/PHP Arkitect rule that the domain core imports nothing from infrastructure is a one-command smell detector — it maps exactly which layers are leaking before you read a line of business logic.
  • Write characterization tests before refactoring. Lock current behavior with a high-level integration test (per the architecture-migration playbook) so you can prove a Strangler-Fig slice hasn't changed anything. This is the safe on-ramp to any change.
  • Prefer real test databases over mock chains. For handlers and repositories, an integration test against a real (test) DB gives higher confidence with less brittle setup — and doubles as documentation of what the code actually does today.

Boundaries

Always Do

  • Always use the [Test Patterns by Layer](references/test-patterns-by-layer.md) to structure your tests correctly.
  • Always create small, specific fixtures for the test scenario rather than relying on massive global state.
  • Always make the test setup (the "Given") explicitly visible in the test method.

Ask First

  • Ask before introducing complex mock chains in a handler test if a real test database would be simpler and more robust.

Never Do

  • Never over-specify tests. Do not assert on private methods or the exact sequence of internal calls if the external contract is met.
  • Never mock the database inside a repository test.

Source & license

This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.

Install and usage instructions live in the source repository linked above.

Reviews

No reviews yet, be the first.

Versions

  • v0.1.0 Imported from the upstream source.