← ClaudeAtlas

phpunit-9-modernlisted

PHPUnit 8.5 → 9.x modern test patterns. Use when writing or reviewing tests in a project on PHPUnit 8.5+ or 9.x, when migrating tests from PHPUnit 5/6/7 conventions, when adding type declarations to existing test methods, when picking between assertSame / assertEquals / assertIsXxx, when designing data providers, or when removing deprecated APIs (ProphecyTestCase, TestListener, @expectedException annotations). Counterpart to the phpunit-5.7 module (which targets the older API). Not for everyday assertion writing — load when reviewing test discipline, planning a PHPUnit upgrade, designing per-test fixtures, or picking between mock styles.
hmj1026/dhpk · ★ 1 · Testing & QA · score 74
Install: claude install-skill hmj1026/dhpk
# PHPUnit 8.5 / 9.x — modern API This skill covers the API consolidation that landed in PHPUnit 8.0 + 9.0. If you're upgrading from PHPUnit 5/6/7 conventions, also consult the `phpunit-5.7` module's skill for what's being left behind. > Version target: 8.5 (the LTS-style 8-line release) → 9.6 (final 9.x > minor). Both versions support PHP 7.3+. PHPUnit 10 requires PHP 8.1+ > and PHPUnit 11 requires 8.2+ — separate future modules. --- ## `void` return type on test methods (PHPUnit 8.0+) ```php final class OrderTest extends TestCase { protected function setUp(): void { parent::setUp(); $this->order = new Order(/* ... */); } public function testTotalIncludesTax(): void { self::assertSame(110, $this->order->totalWithTax()); } } ``` PHPUnit 8.0 added `void` return types to *all* template methods — `setUp()`, `tearDown()`, `setUpBeforeClass()`, `tearDownAfterClass()`. **A class extending TestCase without `void` on these methods produces a deprecation warning in 8.x and an error in 9.x.** Your own test methods don't strictly need `void`, but the convention since 8.0 is to add it (test methods don't return anything meaningful). ### Static lifecycle methods ```php public static function setUpBeforeClass(): void { /* ... */ } public static function tearDownAfterClass(): void { /* ... */ } ``` These were re-typed in PHPUnit 8 with explicit `static` + `void`. Inherited classes need to match the signature exactly. --- ## `expect