From 62307d43b2456f6fbf946e3067ac22ddf97476cd Mon Sep 17 00:00:00 2001 From: Mark Story Date: Wed, 23 Sep 2026 23:16:41 -0400 Subject: [PATCH] Add docs for fixture/deletestrategy refs cakephp/cakephp#19613 --- docs/en/appendices/5-5-migration-guide.md | 7 ++++++- docs/en/development/testing.md | 17 +++++++++++++---- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/docs/en/appendices/5-5-migration-guide.md b/docs/en/appendices/5-5-migration-guide.md index 7390e29ba5..dcd5c3ecdc 100644 --- a/docs/en/appendices/5-5-migration-guide.md +++ b/docs/en/appendices/5-5-migration-guide.md @@ -26,4 +26,9 @@ Coming soon ## New Features -Coming soon +### TestSuite + +- `Cake\TestSuite\Fixture\DeleteStrategy` was added. This fixture strategy + cleans fixtures with `DELETE` instead of `TRUNCATE` which can be more + performant on MySQL, with the trade off of auto increment values not being + reset between tests. diff --git a/docs/en/development/testing.md b/docs/en/development/testing.md index d51bc5e4e1..d5a3a7ec10 100644 --- a/docs/en/development/testing.md +++ b/docs/en/development/testing.md @@ -743,10 +743,16 @@ public function getFixtures(): array By default, CakePHP resets fixture state at the end of each test by truncating all the tables in the database. This operation can become expensive as your -application grows. By using `TransactionStrategy` each test method will be run -inside a transaction that is rolled back at the end of the test. This can yield -improved performance but requires your tests not heavily rely on static fixture -data, as auto-increment values are not reset before each test. +application grows. CakePHP also provides two other fixture management strategies: + +- `TransactionStrategy` - each test method will be run inside a transaction that + is rolled back at the end of the test. This can yield improved performance but + requires your tests not heavily rely on static fixture data, as auto-increment + values are not reset before each test. +- `DeleteStrategy` - after each test, foreign keys are disabled and records are + removed with `DELETE` queries. This can yield improved performance but + requires your tests not heavily rely on static fixture data, as auto-increment + values are not reset before each test. The fixture state management strategy can be defined within the test case: @@ -778,6 +784,9 @@ To switch out the general default strategy, use Configure key `TestSuite.fixture The recommended strategy for medium and large applications is the `TransactionStrategy`, as using rollbacks to undo changes from tests is simpler to maintain, and reduces the chances of cross-contamination and side-effects between tests. +::: info DeleteStategy was added in version 5.5.0 +::: + ### Fixture Factories As your application grows, so does the number and the size of your test