Class DeleteStrategy
Fixture strategy that deletes all rows from the fixture tables at the end of test.
A drop-in alternative to {@link \Cake\TestSuite\Fixture\TruncateStrategy}: fixtures are
inserted before each test and the tables are emptied afterwards, without a wrapping
transaction, so afterCommit listeners behave as they do in the application.
TRUNCATE is a DDL statement, and on most database servers it does more work than
removing the rows - InnoDB for example drops and recreates the tablespace of every
table it is issued against. Deleting the handful of rows a fixture holds is usually
a lot cheaper, so test suites with many fixtures can spend noticeably less time in
teardown with this strategy.
The trade off is that DELETE does not reset auto increment counters. Fixtures
whose records omit their primary key, and which other fixtures or assertions then
refer to by id, need that counter to start from 1 in every test and have to keep
using TruncateStrategy.
Unlike TRUNCATE, DELETE is subject to foreign keys on every driver, so the rows
are removed with the constraints disabled and the order of the fixtures does not
matter.
Property Summary
Method Summary
-
__construct() public
Initialize strategy.
-
setupTest() public
Called before each test run in each TestCase.
-
teardownTest() public
Called after each test run in each TestCase.