Help us improve
Share bugs, ideas, or general feedback.
From magento2-commerce
Writes PHPUnit tests for PHP code: unit tests, mocking, data providers, test doubles, assertions, and TDD practices. Use for testing PHP apps including Magento.
npx claudepluginhub orcaqubits/agentic-commerce-skills-plugins --plugin magento2-commerceHow this skill is triggered — by the user, by Claude, or both
Slash command
/magento2-commerce:php-testingThis skill is limited to the following tools:
The summary Claude sees in its skill listing — used to decide when to auto-load this skill
**Fetch live docs**: Web-search `site:docs.phpunit.de phpunit 10` (or current version) for the latest PHPUnit documentation. Check `https://phpunit.de/` for current version.
PHPUnit testing framework conventions and practices. Invoke whenever task involves any interaction with PHPUnit — writing tests, configuring PHPUnit, data providers, mocking, assertions, debugging test failures, or coverage.
Writes PHPUnit tests for PHP projects: unit tests, assertions, mocks, stubs, data providers, exception testing, TDD workflows. Supports WooCommerce via WC_Unit_Test_Case.
Generates isolated PHPUnit unit tests for PHP 8.4 classes using AAA pattern, descriptive naming, and attributes. Supports Value Objects, Entities, Services.
Share bugs, ideas, or general feedback.
Fetch live docs: Web-search site:docs.phpunit.de phpunit 10 (or current version) for the latest PHPUnit documentation. Check https://phpunit.de/ for current version.
PHPUnit\Framework\TestCasetest or annotated #[Test]setUp() — runs before each testtearDown() — runs after each testsetUpBeforeClass() / tearDownAfterClass() — per-class lifecycleCommon assertions:
assertEquals($expected, $actual) — loose comparisonassertSame($expected, $actual) — strict comparison (type + value)assertTrue($value) / assertFalse($value)assertNull($value) / assertNotNull($value)assertInstanceOf($class, $object)assertCount($count, $array)assertArrayHasKey($key, $array)assertStringContainsString($needle, $haystack)expectException($class) — exception testingSupply multiple test cases to a single test method:
#[DataProvider('providerName')] attribute (PHPUnit 10+)Verify behavior — assert that methods were called with expected arguments:
$this->createMock(SomeClass::class)$mock->expects($this->once())->method('save')->with($entity)$mock->expects($this->never())->method('delete')Provide canned responses — no behavior verification:
$stub->method('getById')->willReturn($entity)$stub->method('getList')->willReturn($searchResults)willReturn($value) — always returns this valuewillReturnMap($map) — returns based on argument mappingwillReturnCallback($callable) — dynamic returnwillThrowException($exception) — throws on callwillReturnSelf() — returns the mock (for fluent APIs)willReturnOnConsecutiveCalls($val1, $val2, $val3) — different return per call.
Note:
willReturnOnConsecutiveCalls()is deprecated in PHPUnit 10.3+. UsewillReturn()with$this->onConsecutiveCalls()orwillReturnCallback()with a counter instead.
$this->expectException(NoSuchEntityException::class);
$this->expectExceptionMessage('Entity not found');
$repository->getById(999);
Don't test private methods directly — test through public methods. If a private method is complex enough to test independently, it should probably be extracted to its own class.
Create the class under test with mocked dependencies:
--coverage-html <dir> — generate HTML coverage report--coverage-text — terminal outputphpunit.xml or phpunit.xml.dist:
testGetByIdThrowsWhenNotFound()setUp() for common test setupFetch PHPUnit docs for exact assertion methods, mock API, and configuration options for your PHPUnit version before writing tests.