phpunit
Skill15 starsChanged 41 days agoMITView on GitHub
Expert PHPUnit testing assistance covering PHP assertions, data providers, and test doubles. Use when writing unit and functional tests for PHP, Laravel, Symfony, or WordPress.
2 other projects use a version of this.
Adopted by
Most recently taken up by
- hmj1026/dhpktheir own version, first seen Nov 6, 2026
- turkeryildirim/ai-skillstheir own version, first seen Nov 1, 2026
Other versions2 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 2
- turkeryildirim/ai-skills★ 4same name
- hmj1026/dhpk★ 2same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository350 other files it gives its agents.
- airflowSkill
- catboostSkill
- claudeSkill
- comfyuiSkill
- cursor-aiSkill
- dalleSkill
- daskSkill
- dbtSkill
- deepseekSkill
- fastaiSkill
- geminiSkill
- github-copilotSkill
- huggingfaceSkill
- jaxSkill
- jupyterSkill
- kerasSkill
- langchainSkill
- lightgbmSkill
- llamaindexSkill
- llamaSkill
- matplotlibSkill
- midjourneySkill
- mistralSkill
- mlflowSkill
- nltkSkill
- numpySkill
- ollamaSkill
- openai-gptSkill
- opencvSkill
- pandasSkill
- perplexitySkill
- plotlySkill
- polarsSkill
- pytorchSkill
- raySkill
- scikit-learnSkill
- seabornSkill
- spacySkill
- sparkSkill
- stable-diffusionSkill
- tensorflowSkill
- vaexSkill
- weights-biasesSkill
- whisperSkill
- xgboostSkill
- api-gatewaySkill
- clean-architectureSkill
- cqrsSkill
- domain-driven-designSkill
- event-drivenSkill
- event-sourcingSkill
- graphqlSkill
- grpcSkill
- hexagonalSkill
- microservicesSkill
- modular-monolithSkill
- monolithSkill
- rest-apiSkill
- sagaSkill
- serverlessSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
5 rules. About 0 are common, 1 is distinctive, and 4 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 116
Use PHPUnit Data Providers:
- Very specific: line 149
Use Static Data Providers: Ensure all data provider methods are declared as public static.
- Very specific: line 150
Run with --colors=always --testdox: Produce clean, human-readable test output in local terminals and CI.
- Very specific: line 155
Use @runInSeparateProcess unless strictly necessary: Process isolation adds severe performance overhead.
- Very specific: line 156
Use assertEquals on floats: Use assertEqualsWithDelta to avoid floating point precision failures.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
PHPUnit
PHPUnit is the standard unit testing framework for the PHP ecosystem. Examples include usage in Laravel, Symfony, and WordPress.
When to Use
- PHP Standard Testing Framework: The official, universal testing framework for Laravel, Symfony, and modern PHP applications.
- Unit and Integration Testing: Testing PHP domain models, services, controllers, and database interactions.
- Data Providers for Parameterized Tests: Running tests against multi-dimensional test datasets using
@dataProvider. - Mocking & Test Doubles: Generating mock objects and verifying invocation expectations natively without external libraries.
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
PHPUnit Test Case Structure
Extends TestCase and leverages modern PHP 8 attributes:
<?php
use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\Attributes\DataProvider;
final class CurrencyConverterTest extends TestCase
{
#[Test]
#[DataProvider('currencyProvider')]
public function it_converts_usd_to_eur(float $usd, float $expectedEur): void
{
$converter = new CurrencyConverter(exchangeRate: 0.92);
$this->assertEqualsWithDelta($expectedEur, $converter->toEur($usd), 0.01);
}
public static function currencyProvider(): array
{
return [
'zero value' => [0.0, 0.0],
'standard transaction' => [100.0, 92.0],
'fractional amount' => [10.50, 9.66],
];
}
}Native Mock Objects
Stubs methods and asserts on invocation parameters:
public function testPaymentServiceSendsNotification(): void
{
$mailerMock = $this->createMock(MailerInterface::class);
$mailerMock->expects($this->once())
->method('send')
->with($this->equalTo('user@example.com'));
$service = new PaymentService($mailerMock);
$service->processPayment('user@example.com', 50);
}Declarative phpunit.xml Configuration
Configures test suites, environment variables, and coverage enforcement:
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true"
cacheDirectory=".phpunit.cache">
<testsuites>
<testsuite name="Unit">
<directory>tests/Unit</directory>
</testsuite>
</testsuites>
<source>
<include><directory>src</directory></include>
</source>
</phpunit>Common Patterns
Data Providers for Clean Test Matrices
Problem: Writing multiple separate test methods to validate email formatting regex rules.
Solution: Use PHPUnit Data Providers:
use PHPUnit\Framework\TestCase;
class ValidatorTest extends TestCase
{
/**
* @dataProvider emailProvider
*/
public function testEmailValidation(string $email, bool $expected): void
{
$validator = new EmailValidator();
$this->assertSame($expected, $validator->isValid($email));
}
public static function emailProvider(): array
{
return [
['test@example.com', true],
['invalid-email', false],
['user@sub.domain.org', true],
['', false],
];
}
}Best Practices
Do:
- Adopt PHP 8 Attributes: Use
#[Test]and#[DataProvider]instead of legacy docblock annotations (@test). - Use Static Data Providers: Ensure all data provider methods are declared as
public static. - Run with
--colors=always --testdox: Produce clean, human-readable test output in local terminals and CI. - Enforce Strict Types in Tests: Add
declare(strict_types=1);at the top of all test files.
Don't:
- Use
@runInSeparateProcessunless strictly necessary: Process isolation adds severe performance overhead. - Use
assertEqualson floats: UseassertEqualsWithDeltato avoid floating point precision failures. - Catch exceptions manually: Use
$this->expectException(CustomException::class)to assert on thrown errors.
Troubleshooting
| Error | Cause | Solution |
Class 'PHPUnit\Framework\TestCase' not found | Composer autoload missing or PHPUnit not installed via Composer. | Run composer dump-autoload and execute via ./vendor/bin/phpunit. |
Failed asserting that false is true | Method assertion failed. | Add custom failure message: $this->assertTrue($val, 'Custom message'). |
Risky Test: This test did not perform any assertions | Test executed code without performing explicit $this->assert*. | Add assertion or mark with @doesNotPerformAssertions annotation. |
References
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

