Skip to content

Commit 7e9a68a

Browse files
committed
Merge branch '5.x' into 5.next
2 parents 0b25abf + b106365 commit 7e9a68a

5 files changed

Lines changed: 45 additions & 37 deletions

File tree

en/development/testing.rst

Lines changed: 41 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ An example table would be::
510510
],
511511
],
512512
],
513-
// More tables.
513+
// More tables
514514
];
515515

516516
The options available to ``columns``, ``indexes`` and ``constraints`` match the
@@ -536,36 +536,6 @@ To load a SQL dump file you can use the following::
536536
At the beginning of each test run ``SchemaLoader`` will drop all tables in the
537537
connection 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-
569539
Creating 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+
747757
Fixture Factories
748758
-----------------
749759

en/orm/entities.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,7 @@ field that should be exposed::
566566

567567
class User extends Entity
568568
{
569-
protected $_virtual = ['full_name'];
569+
protected array $_virtual = ['full_name'];
570570
}
571571

572572
This list can be modified at runtime using the ``setVirtual()`` method::

fr/orm/entities.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ doivent être exposés::
594594

595595
class User extends Entity
596596
{
597-
protected $_virtual = ['full_name'];
597+
protected array $_virtual = ['full_name'];
598598
}
599599

600600
Cette liste peut être modifiée à la volée en utilisant la méthode

ja/orm/entities.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ CakePHP では以下のように簡単にできます。 ::
499499

500500
class User extends Entity
501501
{
502-
protected $_virtual = ['full_name'];
502+
protected array $_virtual = ['full_name'];
503503
}
504504

505505
実行時に ``setVirtual()`` を使うことでこのリストを変更できます。 ::

pt/orm/entities.rst

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -496,9 +496,7 @@ virtuais que devem ser expostas::
496496

497497
class User extends Entity
498498
{
499-
500-
protected $_virtual = ['full_name'];
501-
499+
protected array $_virtual = ['full_name'];
502500
}
503501

504502
Esta lista pode ser modificada em tempo de execução usando o método

0 commit comments

Comments
 (0)