@@ -510,7 +510,7 @@ An example table would be::
510510 ],
511511 ],
512512 ],
513- // More tables.
513+ // More tables
514514 ];
515515
516516The options available to ``columns ``, ``indexes `` and ``constraints `` match the
@@ -536,36 +536,6 @@ To load a SQL dump file you can use the following::
536536At the beginning of each test run ``SchemaLoader `` will drop all tables in the
537537connection and rebuild tables based on the provided schema file.
538538
539- .. _fixture-state-management :
540-
541- Fixture State Managers
542- ----------------------
543-
544- By default CakePHP resets fixture state at the end of each test by truncating
545- all the tables in the database. This operation can become expensive as your
546- application grows. By using ``TransactionStrategy `` each test method will be run
547- inside a transaction that is rolled back at the end of the test. This can yield
548- improved performance but requires your tests not heavily rely on static fixture
549- data, as auto-increment values are not reset before each test.
550-
551- The fixture state management strategy can be defined within the test case::
552-
553- use Cake\TestSuite\TestCase;
554- use Cake\TestSuite\Fixture\FixtureStrategyInterface;
555- use Cake\TestSuite\Fixture\TransactionStrategy;
556-
557- class ArticlesTableTest extends TestCase
558- {
559- /**
560- * Create the fixtures strategy used for this test case.
561- * You can use a base class/trait to change multiple classes.
562- */
563- protected function getFixtureStrategy(): FixtureStrategyInterface
564- {
565- return new TransactionStrategy();
566- }
567- }
568-
569539Creating Fixtures
570540-----------------
571541
@@ -744,6 +714,46 @@ You can also directly include fixtures by FQCN::
744714 }
745715
746716
717+
718+ .. _fixture-state-management :
719+
720+ Fixture State Managers
721+ ----------------------
722+
723+ By default CakePHP resets fixture state at the end of each test by truncating
724+ all the tables in the database. This operation can become expensive as your
725+ application grows. By using ``TransactionStrategy `` each test method will be run
726+ inside a transaction that is rolled back at the end of the test. This can yield
727+ improved performance but requires your tests not heavily rely on static fixture
728+ data, as auto-increment values are not reset before each test.
729+
730+ The fixture state management strategy can be defined within the test case::
731+
732+ use Cake\TestSuite\TestCase;
733+ use Cake\TestSuite\Fixture\FixtureStrategyInterface;
734+ use Cake\TestSuite\Fixture\TransactionStrategy;
735+
736+ class ArticlesTableTest extends TestCase
737+ {
738+ /**
739+ * Create the fixtures strategy used for this test case.
740+ * You can use a base class/trait to change multiple classes.
741+ */
742+ protected function getFixtureStrategy(): FixtureStrategyInterface
743+ {
744+ return new TransactionStrategy();
745+ }
746+ }
747+
748+ To switch out the general default strategy, use Configure key ``TestSuite.fixtureStrategy `` in your ``app.php ``::
749+
750+ 'TestSuite' => [
751+ 'fixtureStrategy' => \Cake\TestSuite\Fixture\TransactionStrategy::class,
752+ ],
753+
754+
755+ 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.
756+
747757Fixture Factories
748758-----------------
749759
0 commit comments