Skillshub php-testing
Unit and integration testing standards for PHP applications. Use when writing PHPUnit unit tests or integration tests for PHP applications. (triggers: tests/**/*.php, phpunit.xml, phpunit, pest, mock, assert, tdd)
install
source · Clone the upstream repo
git clone https://github.com/ComeOnOliver/skillshub
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/ComeOnOliver/skillshub "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/HoangNguyen0403/agent-skills-standard/php-testing" ~/.claude/skills/comeonoliver-skillshub-php-testing && rm -rf "$T"
manifest:
skills/HoangNguyen0403/agent-skills-standard/php-testing/SKILL.mdsource content
PHP Testing
Priority: P1 (HIGH)
Structure
tests/ ├── Unit/ ├── Integration/ └── Feature/
Implementation Guidelines
- Standards: Use
(9/10+) orPHPUnit
. Organize intoPest
,Unit/
, andIntegration/
. Class names should extendFeature/
(e.g.,TestCase
).class OrderServiceTest extends TestCase - TDD Workflow: Follow Red-Green-Refactor. Red: write failing test first for
, then Green: implement minimal logic to pass, then Refactor.createOrder() - Mocking: Use
for dependencies. Define behavior withcreateMock(PaymentService::class)
andexpects($this->once())
withmethod('charge')
. DO NOT mock simple Data Objects.with(100)->willReturn(true) - Fluent Assertions:
(assertSame checks type + value
) — use===
overassertSame('Test', $result->title)
to avoid type coercion surprises. Also useassertEquals
andassertCount()
.assertMatchesRegularExpression() - Data Providers: Use
(PHPUnit 10+) with a#[DataProvider('statusProvider')]
orpublic static function statusProvider(): array
(Pest).dataset - Isolation: Ensure tests are Independent and Repeatable. DB tests must use
orTransactions
.SQLite :memory: - Pest syntax: Use
andit('creates an order', function() { ... })
for cleaner, more readable tests.expect($result->title)->toBe('Test') - Coverage: Aim for
line coverage. Use80%+
to whitelist specific directories.phpunit.xml - Automation: Run tests on every PR using GitHub Actions or GitLab CI.
Anti-Patterns
- No testing private methods: Test through public interfaces only.
- No over-mocking internals: Mock only external boundaries.
- No real network/DB in unit tests: Use in-memory databases or mocks.
- No coverage-metric chasing: Prioritize meaningful assertions.