Phpunit
PHPUnit PHP testing framework. Use for PHP testing.From its SKILL.md
npx -y skills add G1Joshi/Agent-Skills --skill phpunitAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- 12 stars12 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
SKILL.md
1.8 KB, 415 tokens by cl100k_base, as published. Nobody here has run it
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
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.
$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).
#[DataProvider('additionProvider')]
public function testAdd(int $a, int $b, int $expected): void { ... }
Best Practices (2025)
Do:
- Use Strict Assertions:
$this->assertSame()checks types (===), whereasassertEqualsis loose (==). Strict is safer. - Use Namespaces: Organize tests
Tests\Unit\UserTestmatchingApp\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
What ships with it
Read from the repository
Just SKILL.md. No reference files, no scripts.