|
1 | 1 | # PHPUnit Upgrade |
2 | 2 |
|
3 | | -CakePHP 5 supports PHPUnit 11 and 12. This guide covers migrating from older PHPUnit versions. |
| 3 | +This guide covers the PHPUnit version requirements and migration steps for CakePHP 5.x applications. |
| 4 | + |
| 5 | +## Current Requirements |
| 6 | + |
| 7 | +CakePHP 5.x requires **PHPUnit ^11.5.3 or ^12.1.3**. This means: |
| 8 | + |
| 9 | +- PHPUnit 11.5.3+ requires **PHP 8.2** or later |
| 10 | +- PHPUnit 12.1.3+ requires **PHP 8.3** or later |
| 11 | + |
| 12 | +> [!NOTE] |
| 13 | +> PHPUnit 10 is no longer supported in CakePHP 5.x. If you are still on PHPUnit 10, |
| 14 | +> you must upgrade to PHPUnit 11 or 12. |
4 | 15 |
|
5 | 16 | ## phpunit.xml Adjustments |
6 | 17 |
|
@@ -99,6 +110,8 @@ Common attribute replacements: |
99 | 110 | | `@covers` | `#[CoversClass(ClassName::class)]` | |
100 | 111 | | `@test` | `#[Test]` | |
101 | 112 |
|
| 113 | +Remember to import the attribute classes from `PHPUnit\Framework\Attributes`. |
| 114 | + |
102 | 115 | ### Test Doubles for Abstract Classes Deprecated |
103 | 116 |
|
104 | 117 | Methods for creating mock objects for abstract classes and traits are hard-deprecated. Testing traits in isolation from the classes that use them is discouraged. |
@@ -152,3 +165,13 @@ vendor/bin/rector process tests/ |
152 | 165 | ``` |
153 | 166 |
|
154 | 167 | Configure Rector with PHPUnit rulesets to handle data provider static conversion, annotation to attribute migration, and other changes automatically. |
| 168 | + |
| 169 | +## Upgrade Checklist |
| 170 | + |
| 171 | +Before upgrading PHPUnit versions, ensure: |
| 172 | + |
| 173 | +1. Your test suite runs without deprecation warnings on your current PHPUnit version |
| 174 | +2. All data providers are `public static` methods |
| 175 | +3. You are using attributes instead of annotations (required for PHPUnit 12) |
| 176 | +4. Mock expectations only use `createMock()`, not `createStub()` |
| 177 | +5. Run `vendor/bin/phpunit --migrate-configuration` after upgrading |
0 commit comments