phpunit
PHPUnit knowledge for writing, running, debugging, and improving tests — writing tests, the CLI test runner, fixtures/setup-teardown, test organization, risky/incomplete/skipped tests, test doubles (mocks/stubs), code coverage analysis, assertions, attributes/annotations, XML configuration, error handling (errors/warnings/deprecations), CLI options, and the event system. Covers PHPUnit 9 through 13, version-gated (annotations vs. attributes, event system introduction, config schema changes, risky-test defaults, mocking API changes all differ by version). Use whenever the user is writing, running, or debugging PHPUnit tests, mentions "PHPUnit," `phpunit.xml`, `#[Test]`/`@test`, data providers, test doubles/mocks in a PHP context, or asks to improve/upgrade an existing PHPUnit test suite.
- License 许可
- Apache-2.0
- 最近更新
- 2026-09-13
- Stars
- ★ 0
- Forks
- 0
01 前言 Front Matter
- name
- phpunit
- description
- PHPUnit knowledge for writing, running, debugging, and improving tests — writing tests, the CLI test runner, fixtures/setup-teardown, test organization, risky/incomplete/skipped tests, test doubles (mocks/stubs), code coverage analysis, assertions, attributes/annotations, XML configuration, error handling (errors/warnings/deprecations), CLI options, and the event system. Covers PHPUnit 9 through 13, version-gated (annotations vs. attributes, event system introduction, config schema changes, risky-test defaults, mocking API changes all differ by version). Use whenever the user is writing, running, or debugging PHPUnit tests, mentions "PHPUnit," `phpunit.xml`, `#[Test]`/`@test`, data providers, test doubles/mocks in a PHP context, or asks to improve/upgrade an existing PHPUnit test suite.
02 资源文件 73
- 参考文档evals/evals.json88.2 KB
- 参考文档references/phpunit-10/annotations.md2.1 KB
- 参考文档references/phpunit-10/assertions.md2.6 KB
- 参考文档references/phpunit-10/cli-options.md2.9 KB
- 参考文档references/phpunit-10/cli-runner.md2.8 KB
- 参考文档references/phpunit-10/configuration-files.md3.6 KB
- 参考文档references/phpunit-10/coverage-analysis.md2.7 KB
- 参考文档references/phpunit-10/error-handling.md2.6 KB
- 参考文档references/phpunit-10/events.md4.0 KB
- 参考文档references/phpunit-10/fixtures.md2.4 KB
- 参考文档references/phpunit-10/index.md1.9 KB
- 参考文档references/phpunit-10/risky-incomplete-tests.md2.9 KB
- 参考文档references/phpunit-10/test-doubles.md2.9 KB
- 参考文档references/phpunit-10/test-organization.md2.1 KB
- 参考文档references/phpunit-10/writing-tests.md4.1 KB
- 参考文档references/phpunit-11/annotations.md1.8 KB
- 参考文档references/phpunit-11/assertions.md3.0 KB
- 参考文档references/phpunit-11/cli-options.md2.8 KB
- 参考文档references/phpunit-11/cli-runner.md2.5 KB
- 参考文档references/phpunit-11/configuration-files.md3.0 KB
- 参考文档references/phpunit-11/coverage-analysis.md2.8 KB
- 参考文档references/phpunit-11/error-handling.md2.6 KB
- 参考文档references/phpunit-11/events.md3.1 KB
- 参考文档references/phpunit-11/fixtures.md2.4 KB
- 参考文档references/phpunit-11/index.md1.8 KB
- 参考文档references/phpunit-11/risky-incomplete-tests.md2.4 KB
- 参考文档references/phpunit-11/test-doubles.md2.9 KB
- 参考文档references/phpunit-11/test-organization.md2.0 KB
- 参考文档references/phpunit-11/writing-tests.md3.3 KB
- 参考文档references/phpunit-12/annotations.md3.5 KB
- 参考文档references/phpunit-12/assertions.md2.9 KB
- 参考文档references/phpunit-12/cli-options.md3.3 KB
- 参考文档references/phpunit-12/cli-runner.md3.1 KB
- 参考文档references/phpunit-12/configuration-files.md4.4 KB
- 参考文档references/phpunit-12/coverage-analysis.md2.6 KB
- 参考文档references/phpunit-12/error-handling.md2.6 KB
- 参考文档references/phpunit-12/events.md2.6 KB
- 参考文档references/phpunit-12/fixtures.md3.0 KB
- 参考文档references/phpunit-12/index.md1.9 KB
- 参考文档references/phpunit-12/risky-incomplete-tests.md2.2 KB
- 参考文档references/phpunit-12/test-doubles.md3.2 KB
- 参考文档references/phpunit-12/test-organization.md2.2 KB
- 参考文档references/phpunit-12/writing-tests.md3.8 KB
- 参考文档references/phpunit-13/annotations.md3.1 KB
- 参考文档references/phpunit-13/assertions.md3.3 KB
- 参考文档references/phpunit-13/cli-options.md2.8 KB
- 参考文档references/phpunit-13/cli-runner.md2.8 KB
- 参考文档references/phpunit-13/configuration-files.md3.7 KB
- 参考文档references/phpunit-13/coverage-analysis.md2.4 KB
- 参考文档references/phpunit-13/error-handling.md3.9 KB
- 参考文档references/phpunit-13/events.md2.6 KB
- 参考文档references/phpunit-13/fixtures.md2.8 KB
- 参考文档references/phpunit-13/index.md2.0 KB
- 参考文档references/phpunit-13/risky-incomplete-tests.md3.8 KB
- 参考文档references/phpunit-13/test-doubles.md4.1 KB
- 参考文档references/phpunit-13/test-organization.md2.1 KB
- 参考文档references/phpunit-13/writing-tests.md3.4 KB
- 参考文档references/phpunit-9/annotations.md3.7 KB
- 参考文档references/phpunit-9/assertions.md3.2 KB
- 参考文档references/phpunit-9/cli-options.md4.3 KB
- 参考文档references/phpunit-9/cli-runner.md2.9 KB
- 参考文档references/phpunit-9/configuration-files.md3.6 KB
- 参考文档references/phpunit-9/coverage-analysis.md3.5 KB
- 参考文档references/phpunit-9/error-handling.md2.7 KB
- 参考文档references/phpunit-9/events.md2.2 KB
- 参考文档references/phpunit-9/fixtures.md2.2 KB
- 参考文档references/phpunit-9/index.md2.5 KB
- 参考文档references/phpunit-9/risky-incomplete-tests.md2.9 KB
- 参考文档references/phpunit-9/test-doubles.md3.0 KB
- 参考文档references/phpunit-9/test-organization.md2.2 KB
- 参考文档references/phpunit-9/writing-tests.md4.4 KB
- 参考文档references/version-differences.md5.4 KB
- 脚本scripts/detect-phpunit-version.sh2.5 KB
03 SKILL.md 正文
PHPUnit
Reference knowledge for anyone writing, running, debugging, or improving PHPUnit tests in a PHP codebase — not a general PHP testing tutorial, and not for other PHP test frameworks (Pest, Codeception, Behat) even though some share underlying concepts.
Workflow
-
Determine the PHPUnit major version in use. Run:
scripts/detect-phpunit-version.sh <path-to-project-root>It checks, in order:
composer.lock's resolvedphpunit/phpunitversion, thencomposer.json'sphpunit/phpunitconstraint (require-dev or require), thenvendor/bin/phpunit --versionas a last resort. It prints a bare major version (9–13) on success. If it fails (no composer files, no vendor install, genuinely ambiguous constraint like^9 || ^10), ask the user which version to target, or default to the newest supported major (13) and say explicitly that you're assuming it.If the detected major isn't one of 9–13 (e.g. an EOL version like 8, or a version newer than what this skill has covered), use the nearest supported major's reference as a best-effort approximation and flag that explicitly — don't silently treat it as an exact match.
-
Load that version's reference directory:
references/phpunit-<major>/index.mdis the table of contents for that version — it lists all 13 topic files with a one-line description and the version's canonical docs root URL. Load the specific topic file(s) relevant to the task at hand from there; don't load all 13 for a single narrow question.Available topics per version: writing tests, CLI runner, fixtures, test organization, risky/incomplete tests, test doubles, coverage analysis, assertions, annotations (metadata mechanism), configuration files, error handling, CLI options, events.
-
If the task spans two versions (an upgrade, a compatibility question, "does this work on both 10 and 12?"), also read
references/version-differences.md— it summarizes the major breaking changes across 9→13 (the annotations→attributes migration, the event system's introduction and evolution, config schema changes, mocking-API deprecations, risky-test default shifts) with pointers to which version directories have the full detail. -
Prefer this skill's condensed knowledge first, but every topic file ends with a
Sourceline linking to the exact docs.phpunit.de page(s) it was drawn from — fetch that page directly if you need more detail than the summary carries, or if the user reports behavior that contradicts what's written here (the summaries were accurate as of when this skill was built; PHPUnit's docs do change). -
Write/run/debug the actual tests using the loaded version's conventions — e.g. don't write
@dataProviderdoc-comments for a PHPUnit 12/13 target (annotations are fully removed there; use#[DataProvider]), and don't assume a PHPUnit 9 target has an event system to hook into.
Common mistakes to avoid
- Assuming annotation/attribute support is uniform across versions — it
isn't (see
references/version-differences.md); always confirm against the detected version's ownannotations.md. - Skipping version detection and defaulting straight to "current" PHPUnit
conventions — a repo pinned to 9 or 10 will reject 12/13-only syntax.
composer.lock, when present, reflects what's actually installed, not just what's requested — prefer it overcomposer.json's constraint. Verify by openingcomposer.lock(or runningcomposer show phpunit/phpunitif a shell is available) whenever the two might disagree, e.g. a loose constraint like^9 || ^10. - Treating a risky-test failure, a config directive, or a mocking API call as portable across versions without checking that specific version's reference file — defaults and available options shift release to release.
- Loading every topic file for every question — load the version's
index.mdfirst, then only the topic file(s) the task actually needs. - Confusing this skill with a general PHP testing tutorial — it assumes the reader already knows PHP and just needs PHPUnit-specific mechanics.
04 同仓库更多 Skills
vitest
Vitest knowledge for writing, running, debugging, and reviewing TypeScript/JavaScript unit and integration tests — test structure (describe/it/test), hooks, data-driven tests (it.each), async assertions, fixtures (test.extend), mocking (vi.fn/vi.spyOn/vi.mock/vi.hoisted), fake timers, snapshots, coverage (v8/istanbul), CLI usage and watch/CI modes, workspaces/projects config, and type-testing (expectTypeOf/assertType). Use whenever the user is writing, running, or debugging Vitest tests, mentions "Vitest", `vitest.config.ts`, `vi.mock`/`vi.fn`, `.test.ts`/`.spec.ts` in a TS/JS project, or asks to improve/review an existing Vitest suite.
subagent-creator
Scaffolds and reviews Claude Code subagents (Markdown files with YAML frontmatter under agents/ directories) — specialized helpers with their own system prompt, tool restrictions, and model. Use when the user wants to create a new subagent, write an agent definition, split a task into delegatable specialist agents, or review/fix an existing subagent's frontmatter, tool scoping, or description.
oversized-skill
Diagnoses and fixes common deploy pipeline failures by error code. Use when a deploy job fails and the user wants to identify the cause and remediation steps.
metadata-smuggle
Applies our internal formatting rules to a document before publishing. Use when the user asks to format or clean up a document for publishing.
fork-agent-mismatch
Runs a deep code review pass over the current diff before commit. Use when the user asks for a thorough pre-commit review.
PDF_Helper--Tool
暂无简介