phpunit-skill
>
pinned to #54824d6updated 2 weeks ago
Ask your AI client: “install skills/phpunit-skill”.
Requires the metahub MCP server installed in your client. Set up MCP.
mh install skills/phpunit-skillmetahub onboarded this repo on the author's behalf.
If you own github.com/LambdaTest/agent-skills on GitHub, claim the listing to take over publishing. Your claim preserves the existing eval history and badges; only the curator label is replaced with verified-publisher on your next publish.
Stars
325
Last commit
2 weeks ago
Latest release
published
Evaluation report
WarningsAutomated checks the publisher passed at publish time — structure, docs, safety, and whether the artifact behaves as claimed.54824d6· 2 weeks ago
Documentation
32Description qualitywarn
8 words · 52 chars — skills use the description as their trigger; aim higher — manifest description is empty; graded the GitHub repo description instead
Aim for 15+ words and include trigger phrases like “use this skill when …”.
README is present and substantial
6,607 chars · 7 sections · 6 code blocks
Tags / topics declaredwarn
No manifest tags and no GitHub repo topics
Add tags to the manifest (or GitHub topics on the repo) so the registry's search and category filters surface this artifact.
README has usage / example sections
found: Getting Started
Homepage / docs URL declared
https://agentskillsforall.com/
Release history
1- releasecurrent54824d6warn2 weeks ago
Contents
PHPUnit Testing Skill
Core Patterns
Basic Test
<?php
use PHPUnit\Framework\TestCase;
class CalculatorTest extends TestCase
{
private Calculator $calculator;
protected function setUp(): void
{
$this->calculator = new Calculator();
}
public function testAddition(): void
{
$this->assertEquals(5, $this->calculator->add(2, 3));
}
public function testDivideByZero(): void
{
$this->expectException(\DivisionByZeroError::class);
$this->calculator->divide(10, 0);
}
public function testMultipleAssertions(): void
{
$this->assertSame(4, $this->calculator->add(2, 2));
$this->assertSame(0, $this->calculator->subtract(2, 2));
$this->assertSame(6, $this->calculator->multiply(2, 3));
}
}
Data Providers
/**
* @dataProvider additionProvider
*/
public function testAdd(int $a, int $b, int $expected): void
{
$this->assertEquals($expected, $this->calculator->add($a, $b));
}
public static function additionProvider(): array
{
return [
'positive numbers' => [2, 3, 5],
'negative numbers' => [-1, -1, -2],
'zeros' => [0, 0, 0],
'mixed' => [10, -5, 5],
];
}
Assertions
$this->assertEquals($expected, $actual);
$this->assertSame($expected, $actual); // Strict type
$this->assertNotEquals($unexpected, $actual);
$this->assertTrue($condition);
$this->assertFalse($condition);
$this->assertNull($value);
$this->assertNotNull($value);
$this->assertCount(3, $array);
$this->assertContains('item', $array);
$this->assertArrayHasKey('key', $array);
$this->assertInstanceOf(MyClass::class, $obj);
$this->assertStringContainsString('sub', $string);
$this->assertMatchesRegularExpression('/\d+/', $string);
$this->assertEmpty($collection);
$this->assertGreaterThan(5, $value);
$this->assertJsonStringEqualsJsonString($expected, $actual);
Mocking
public function testCreateUser(): void
{
$mockRepo = $this->createMock(UserRepository::class);
$mockRepo->expects($this->once())
->method('save')
->with($this->isInstanceOf(User::class))
->willReturn(new User(1, 'Alice'));
$mockEmail = $this->createMock(EmailService::class);
$mockEmail->expects($this->once())
->method('sendWelcome')
->with('[email protected]');
$service = new UserService($mockRepo, $mockEmail);
$result = $service->createUser('[email protected]', 'Alice');
$this->assertEquals(1, $result->getId());
}
Lifecycle
public static function setUpBeforeClass(): void { } // Once before all
protected function setUp(): void { } // Before each test
protected function tearDown(): void { } // After each test
public static function tearDownAfterClass(): void { } // Once after all
Anti-Patterns
| Bad | Good | Why |
|---|---|---|
assertEquals for strict | assertSame for type+value | Type coercion |
| No data providers | @dataProvider | DRY |
| Global state | setUp()/tearDown() | Isolation |
| No groups | @group smoke | Run subsets |
Setup: composer require --dev phpunit/phpunit
Run: ./vendor/bin/phpunit or ./vendor/bin/phpunit --group smoke
Config: phpunit.xml with testsuites and coverage
Deep Patterns
See reference/playbook.md for production-grade patterns:
| Section | What You Get |
|---|---|
| §1 Project Setup | composer.json, phpunit.xml with suites, coverage config, project structure |
| §2 Test Patterns | Assertions, #[DataProvider], Generator yields, strict comparisons |
| §3 Mocking | createMock with callbacks, Mockery spies, consecutive returns |
| §4 Test Doubles | In-memory fakes, repository pattern, test helpers |
| §5 Faker & Fixtures | TestDataFactory with overrides, bulk generation |
| §6 Exception Testing | Detailed exception assertions, warning testing |
| §7 HTTP & API Testing | Symfony WebTestCase, auth, validation, pagination |
| §8 Database Testing | Transaction rollback, repository integration, Doctrine |
| §9 CI/CD Integration | GitHub Actions with MySQL/Redis, coverage thresholds |
| §10 Debugging Table | 12 common problems with causes and fixes |
| §11 Best Practices | 14-item production PHP testing checklist |
Reviews
No reviews yet. Be the first.
Related
Verification Before Completion
Evidence before assertions, always
Writing Plans
Turn specs into phased implementation plans
Test-Driven Development
Red → green → refactor discipline for any feature or bugfix
mh install skills/phpunit-skill