Best use case
phpunit is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
PHPUnit PHP testing framework. Use for PHP testing.
Teams using phpunit should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/phpunit/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How phpunit Compares
| Feature / Agent | phpunit | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
PHPUnit PHP testing framework. Use for PHP testing.
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
SKILL.md Source
# PHPUnit
PHPUnit is the standard unit testing framework for the PHP ecosystem. Examples include usage in Laravel, Symfony, and WordPress.
## When to Use
- **PHP Application**: The industry standard.
- **TDD**: Built-in support for mocking and code coverage.
## Quick Start
```php
<?php
use PHPUnit\Framework\TestCase;
final class StackTest extends TestCase
{
public function testPushAndPop(): void
{
$stack = [];
$this->assertEmpty($stack);
array_push($stack, 'foo');
$this->assertNotEmpty($stack);
$this->assertEquals('foo', array_pop($stack));
}
}
```
## Core Concepts
### Assertions
Methods like `$this->assertTrue()`, `$this->assertSame()`, `$this->expectException()`.
### Mock Objects
PHPUnit gives you control over the behavior of dependencies.
```php
$stub = $this->createMock(SomeClass::class);
$stub->method('doSomething')->willReturn('foo');
$this->assertEquals('foo', $stub->doSomething());
```
### Data Providers
Pass data to a test method (similar to parameterized tests).
```php
#[DataProvider('additionProvider')]
public function testAdd(int $a, int $b, int $expected): void { ... }
```
## Best Practices (2025)
**Do**:
- **Use Strict Assertions**: `$this->assertSame()` checks types (===), whereas `assertEquals` is loose (==). Strict is safer.
- **Use Namespaces**: Organize tests `Tests\Unit\UserTest` matching `App\Models\User`.
- **PHPUnit 11 features**: Use the new attributes `#[Test]` instead of `/** @test */` annotations if on PHP 8.2+.
**Don't**:
- **Don't test private methods**: Test the public API. If a private method is complex, extract it to a new class.
## References
- [PHPUnit Documentation](https://phpunit.de/documentation.html)Related Skills
template
Expert [skill-name] assistance covering [feature 1], [feature 2], and [feature 3]. Use when [working with X], [debugging Y], or [implementing Z].
zsh
Zsh shell with oh-my-zsh. Use for terminal shell.
zed
Zed high-performance collaborative editor. Use for fast editing.
xcode
Xcode Apple development IDE with simulators. Use for iOS/macOS development.
webstorm
WebStorm JavaScript IDE with debugging. Use for web development.
webpack
Webpack module bundler with loaders and plugins. Use for bundling.
warp
Warp modern terminal with AI. Use for terminal work.
vscode
Visual Studio Code editor with extensions and debugging. Use for code editing.
vite
Vite fast build tool with HMR. Use for modern frontend builds.
visual-studio
Visual Studio IDE for Windows with debugging and profiling. Use for .NET development.
vim
Vim text editor with motions, macros, and plugins. Use for terminal editing.
turbopack
Turbopack Rust-powered bundler. Use for fast builds.