-
-
Notifications
You must be signed in to change notification settings - Fork 224
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
386 additions
and
205 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,7 @@ jobs: | |
- "7.3" | ||
- "7.4" | ||
- "8.0" | ||
- "8.1" | ||
dependencies: | ||
- "highest" | ||
include: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
Transactions and purging | ||
======================== | ||
|
||
This package exposes an ``AbstractExecutor`` class and 3 concrete | ||
implementations for ``doctrine/orm``, ``doctrine/mongodb-odm`` and | ||
``doctrine/phpcr-odm``. | ||
|
||
The executors purge the database, then load the fixtures. The ORM | ||
implementation wraps these two steps in a database transaction, which | ||
provides a nice additional property: atomicity. | ||
Because of that transaction, the loading either succeeds or fails | ||
cleanly, meaning nothing is actually changed in the database if the | ||
loading fails. It delegates the purging to a separate class that can be | ||
configured to either use a ``TRUNCATE`` or a ``DELETE`` statement to | ||
empty tables. | ||
|
||
Not all RDBMS have the capability to allow ``TRUNCATE`` statements | ||
inside transactions though. Notably, MySQL will produce the infamous | ||
"There is no active transaction" message when we attempt to close a | ||
transaction that was already `implicitly closed`_. | ||
|
||
.. _implicitly closed: https://www.doctrine-project.org/projects/doctrine-migrations/en/stable/explanation/implicit-commits |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
Fixture ordering | ||
================ | ||
|
||
There are two interfaces you can implement in your fixtures to control | ||
in which order they are going to be loaded. | ||
|
||
* By implementing ``OrderedFixtureInterface``, you will be able to | ||
manually specify a priority for each fixture. | ||
* By implementing ``DependencyFixtureInterface``, you will be able to | ||
declare which class must be loaded after which classes (note the | ||
plural), and let the package figure out the order for you. | ||
|
||
.. note:: | ||
You may implement an interface in a fixture, and another interface | ||
in another fixture, and no even interface (besides | ||
``FixtureInterface``) in a third one. Implementing both in the same | ||
fixture is an error. | ||
|
||
Option 1: Controlling the order manually | ||
---------------------------------------- | ||
|
||
.. code-block:: php | ||
<?php | ||
namespace MyDataFixtures; | ||
use Doctrine\Common\DataFixtures\AbstractFixture; | ||
use Doctrine\Common\DataFixtures\OrderedFixtureInterface; | ||
use Doctrine\Persistence\ObjectManager; | ||
final class MyFixture extends AbstractFixture implements OrderedFixtureInterface | ||
{ | ||
public function load(ObjectManager $manager): void | ||
{ | ||
// … | ||
} | ||
public function getOrder(): int | ||
{ | ||
return 10; // smaller means sooner | ||
} | ||
} | ||
.. note:: | ||
While extending ``AbstractFixture`` is not required, it is likely | ||
you are going to need it since people usually need fixtures to be | ||
loading in a specific order because of references from one fixture | ||
to the other. | ||
|
||
Option 2: Declaring dependencies | ||
-------------------------------- | ||
|
||
If you have many models, and a project that evolves, there may be | ||
several correct orders. Using ``OrderedFixtureInterface`` may become | ||
impractical in case you need to insert a new fixture in a position where | ||
there is no gap in the order. Instead of always renumbering the | ||
fixtures, or being careful to leave big gaps, you can declare that your | ||
fixture must be loaded after some other fixtures, and let the package | ||
figure out what to do. | ||
|
||
.. code-block:: php | ||
<?php | ||
namespace MyDataFixtures; | ||
use Doctrine\Common\DataFixtures\AbstractFixture; | ||
use Doctrine\Common\DataFixtures\DependentFixtureInterface; | ||
use Doctrine\Persistence\ObjectManager; | ||
class MyFixture extends AbstractFixture implements DependentFixtureInterface | ||
{ | ||
public function load(ObjectManager $manager): void | ||
{ | ||
} | ||
/** | ||
* @return list<class-string<FixtureInterface>> | ||
*/ | ||
public function getDependencies(): array | ||
{ | ||
return [MyOtherFixture::class]; | ||
} | ||
} | ||
class MyOtherFixture extends AbstractFixture | ||
{ | ||
public function load(ObjectManager $manager): void | ||
{} | ||
} |
Oops, something went wrong.