php-testo/testo/testo-write-tests
Claude Code and agent skill by php-testo/testo
- community
- ext:[{"type":"hook","description":"Pre/post lifecycle hooks"}]
Checking that the SKILL.md file is still in the repository.
Write or modify tests in a project that uses the Testo PHP testing framework. Use when adding a #[Test] class, writing assertions with the Assert facade, expecting exceptions with Expect, or adding lifecycle hooks (#[BeforeTest], #[AfterTest], #[BeforeClass], #[AfterClass]). Trigger when the user says "write a test", "add a test for X", "test this class", or edits a file under `tests/`.
Install
npx vskill@latest install php-testo/testo/testo-write-testsSemi-extensibleMentions customization, but needs skill-specific knowledge. Read the extensible skills standard
SKILL.md
The same SKILL.md was published earlier as php-testo/testo/testo-write-tests.
Writing tests with Testo
The attribute set, assertion facade, exception expectations, and lifecycle hooks are Testo's own. Write them the Testo way described below — don't transliterate idioms from other test frameworks.
Before you write code
This skill is the API surface for ordinary tests; sibling testo-* skills cover data providers, doubles, async, coverage and the rest. When a name here disagrees with the installed version, vendor/testo/ wins — verify against it before relying on memory.
If the project ships an AGENTS.md, honour it.
Canonical shape of a test class
Hard rules:
- Class-level
#[Test]when every public method is a test (preferred). Method-level#[Test]when only some are. final classby default.- No base class — Testo does not require one.
- Public methods returning
voidorneverunder a#[Test]class are auto-discovered as tests. - One
#[Covers(...)]at class level when all tests cover the same class; at method level when they differ. - Arrange / Act / Assert separated by a single blank line. Do not write
// Arrange,// Act,// Assertcomments. - File path mirrors the source:
src/Foo/Bar.php→tests/Unit/Foo/BarTest.php(or wherever the suite finder is rooted).
Assert facade (immediate checks)
Use the Testo\Assert facade for in-test checks. Order is actual, expected for same/equals.
Typed chains (use when you want a fluent series of checks on one value):
The string modifiers (ignoringCase(), ignoringLineEndings(), ignoringWhitespace(), ignoringBlankLines(), ignoringAnsi()) return a new chain and apply to every check after them; the chain they were called on stays strict, and there is no way to switch a mode off. They normalize the string and each check argument by the same rules, in a fixed order whatever the call order (ANSI, line endings, whitespace, blank lines, case). A substring, prefix or suffix that becomes empty after normalization, like contains(' ') under ignoringWhitespace(), throws InvalidArgumentException; same('') stays a valid check. On failure same() diffs the normalized strings. Since arguments are trimmed, contains(' foo ') no longer checks word boundaries: use matchesRegex('/\bfoo\b/'). Regex checks run on the string normalized by every modifier except ignoringCase() (use the i flag); the pattern itself is never changed.
The callable checks reflect what the callable points to: the closure, the function, the method of a [$obj, 'm'] / [Foo::class, 'm'] array or 'Foo::m' string, or __invoke(). isStatic() passes for a closure declared static, a static method and a plain function ('strlen', strlen(...)); an instance method, an invokable object and a closure not declared static fail it. hasReturnType() compares the declared type as written, ignoring member order, case, leading backslashes and whitespace, with ?T equal to T|null; it does not resolve subtypes or self, and a callable without a declared type fails.
Expecting exceptions
Use Testo\Expect declared before the Act phase. The test method's return type is never.
Other Expect modifiers: withMessageContaining(...), withMessageMatchingRegex(...) (withMessagePattern() is its deprecated alias; the testo-shift Rector set of testo/bridge-rector renames it), withPrevious(class, closure), memory-leak expectations. Do not use try/catch-based assertions for expected exceptions — Expect::exception is the correct API.
Marking a test as skipped or cancelled
Throw a status-bearing exception from the test body to short-circuit the run with a non-error verdict:
SkipTest→Status::Skipped. Use when the test isn't applicable in this environment (missing extension, disabled feature flag, unavailable optional dependency, etc.).CancelTest→Status::Cancelled. Use for cooperative cancellation (deadline expired, Fiber unwind). Not a generic "I don't want to run" — that'sSkipTest.
Constraints:
- Must escape the test method itself. The runner's inner try/catch maps the throw to a status; raising from an interceptor or a
#[BeforeTest]hook bubbles out of the pipeline and is treated asStatus::Abortedinstead, and raising from an#[AfterTest]hook only reaches thestderrchannel. To skip from a hook, leave the precondition check inside the test body. - These are not assertions — don't
try/catchthem inside the test, justthrow. - Subclasses work:
class MissingExtensionSkip extends SkipTest {}is still recognized. - Return type stays
void, orneverif the throw is unconditional.
Skipping a test with #[Skip]
To skip a test declaratively — without running any of its code — put Testo\Skip (from the testo/skip plugin) on the test method (inherited by an overriding method that does not repeat it), the class (skips every test of the case; inherited from parents and traits, a method-level reason wins), or a free function:
The test is reported as Status::Skipped and counted in the totals; its reason travels in the result's failure message {testId} is skipped via #[Skip] ==> {reason} (without ==> ... when the reason is empty). The JUnit, TeamCity and HTML reports show that message; the terminal prints the skipped line without it, and the compact --json report only counts the test in totals.skipped.
reason is optional and the attribute is not repeatable — but always pass a reason that points at an issue (#[Skip('flaky on CI, see ISSUE-123')]); a bare #[Skip] is how a skipped test rots unreviewed. The attribute needs no plugin registration: it wires its own interceptor, from a class, a method or a function alike.
Which skipping tool to reach for:
| Tool | Decided by | Visibility | Use when | |
|---|---|---|---|---|
#[Skip('...')] | code, ahead of time | always reported; reason in JUnit/TeamCity/HTML | the test is knowingly broken, tracked in an issue, and must be returned to | |
throw SkipTest | test body, at runtime | reported when the run gets there | test isn't applicable in this environment | |
#[Group] + --group=!x | runner invocation | invisible — filtered out of reports | a category you sometimes don't run |
Runtime contract of #[Skip]: the test is reported at the entry of its pipeline, so #[BeforeTest]/#[AfterTest], data providers, #[Retry]/#[Repeat], fibers and coverage never engage, and a data-driven test yields a single Skipped entry (the provider is not called). #[BeforeClass]/#[AfterClass] run when the case still has a test to run; when every test of the case is skipped they stay silent and the case class is never constructed (enabled neighbors construct it as usual). A run of only #[Skip]-marked tests is a success (exit 0). #[Skip] applies to plain tests only: on a #[Bench] or #[TestInline] target it is inert — the benchmark or inline case runs as usual. The testo/skip plugin (Testo\Skip\SkipPlugin) is part of the default suite plugins; it is what tells the lifecycle hooks about the skip ahead of the run.
Tests that intentionally perform no assertions
A test that finishes successfully without recording a single assertion is reported as Status::Risky — the framework assumes you forgot to assert. When a test legitimately verifies behaviour without the Assert facade (e.g. it only checks that a call does not throw), declare that intent with #[ExpectNoAssertions] to keep it Status::Passed:
Place it on a single test — a method or a function. It is not allowed on a class: "no test here asserts anything" is rarely a real contract, and a stray class-level marker would flip every genuinely-asserting test to Risky.
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewNot runA model review is scheduled for the next rescan.
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/testo-write-tests/SKILL.md
Popularity
- Repository stars
- 209
- Repository forks
- 14
- 7-day trend score
- 27
Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.
Extension points
hookPre/post lifecycle hooks
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/php-testo/testo/testo-write-tests)