mirror of
https://github.com/doctrine/DoctrineFixturesBundle.git
synced 2026-03-23 22:32:17 +01:00
Merge remote-tracking branch 'origin/4.1.x' into 4.2.x
This commit is contained in:
2
.github/workflows/coding-standards.yml
vendored
2
.github/workflows/coding-standards.yml
vendored
@@ -12,4 +12,4 @@ on:
|
||||
jobs:
|
||||
coding-standards:
|
||||
name: "Coding Standards"
|
||||
uses: "doctrine/.github/.github/workflows/coding-standards.yml@7.2.2"
|
||||
uses: "doctrine/.github/.github/workflows/coding-standards.yml@8.0.0"
|
||||
|
||||
2
.github/workflows/composer-lint.yml
vendored
2
.github/workflows/composer-lint.yml
vendored
@@ -17,4 +17,4 @@ on:
|
||||
jobs:
|
||||
composer-lint:
|
||||
name: "Composer Lint"
|
||||
uses: "doctrine/.github/.github/workflows/composer-lint.yml@7.2.2"
|
||||
uses: "doctrine/.github/.github/workflows/composer-lint.yml@8.0.0"
|
||||
|
||||
6
.github/workflows/continuous-integration.yml
vendored
6
.github/workflows/continuous-integration.yml
vendored
@@ -38,7 +38,7 @@ jobs:
|
||||
|
||||
steps:
|
||||
- name: "Checkout"
|
||||
uses: "actions/checkout@v4"
|
||||
uses: "actions/checkout@v5"
|
||||
with:
|
||||
fetch-depth: 2
|
||||
|
||||
@@ -80,12 +80,12 @@ jobs:
|
||||
|
||||
steps:
|
||||
- name: "Checkout"
|
||||
uses: "actions/checkout@v4"
|
||||
uses: "actions/checkout@v5"
|
||||
with:
|
||||
fetch-depth: 2
|
||||
|
||||
- name: "Download coverage files"
|
||||
uses: "actions/download-artifact@v4"
|
||||
uses: "actions/download-artifact@v5"
|
||||
with:
|
||||
path: "reports"
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ on:
|
||||
jobs:
|
||||
release:
|
||||
name: "Git tag, release & create merge-up PR"
|
||||
uses: "doctrine/.github/.github/workflows/release-on-milestone-closed.yml@7.2.2"
|
||||
uses: "doctrine/.github/.github/workflows/release-on-milestone-closed.yml@8.0.0"
|
||||
secrets:
|
||||
GIT_AUTHOR_EMAIL: ${{ secrets.GIT_AUTHOR_EMAIL }}
|
||||
GIT_AUTHOR_NAME: ${{ secrets.GIT_AUTHOR_NAME }}
|
||||
|
||||
2
.github/workflows/static-analysis.yml
vendored
2
.github/workflows/static-analysis.yml
vendored
@@ -11,4 +11,4 @@ on:
|
||||
|
||||
jobs:
|
||||
static-analysis:
|
||||
uses: "doctrine/.github/.github/workflows/phpstan.yml@7.2.2"
|
||||
uses: "doctrine/.github/.github/workflows/phpstan.yml@8.0.0"
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
"symfony/http-kernel": "^6.4 || ^7.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"doctrine/coding-standard": "13.0.0",
|
||||
"doctrine/coding-standard": "14.0.0",
|
||||
"phpstan/phpstan": "2.1.11",
|
||||
"phpunit/phpunit": "^10.5.38 || 11.4.14"
|
||||
},
|
||||
|
||||
25
config/services.php
Normal file
25
config/services.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
|
||||
|
||||
use Doctrine\Bundle\FixturesBundle\Command\LoadDataFixturesDoctrineCommand;
|
||||
use Doctrine\Bundle\FixturesBundle\Loader\SymfonyFixturesLoader;
|
||||
use Doctrine\Bundle\FixturesBundle\Purger\ORMPurgerFactory;
|
||||
|
||||
return static function (ContainerConfigurator $container): void {
|
||||
$container->services()
|
||||
->set('doctrine.fixtures_load_command', LoadDataFixturesDoctrineCommand::class)
|
||||
->args([
|
||||
service('doctrine.fixtures.provider'),
|
||||
service('doctrine'),
|
||||
])
|
||||
->tag('console.command', ['command' => 'doctrine:fixtures:load'])
|
||||
|
||||
->alias('doctrine.fixtures.provider', 'doctrine.fixtures.loader')
|
||||
->set('doctrine.fixtures.loader', SymfonyFixturesLoader::class)
|
||||
|
||||
->set('doctrine.fixtures.purger.orm_purger_factory', ORMPurgerFactory::class)
|
||||
->tag('doctrine.fixtures.purger_factory', ['alias' => 'default']);
|
||||
};
|
||||
@@ -1,21 +0,0 @@
|
||||
<?xml version="1.0" ?>
|
||||
<container xmlns="http://symfony.com/schema/dic/services"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
|
||||
<services>
|
||||
|
||||
<!-- commands -->
|
||||
<service id="doctrine.fixtures_load_command" class="Doctrine\Bundle\FixturesBundle\Command\LoadDataFixturesDoctrineCommand">
|
||||
<argument type="service" id="doctrine.fixtures.provider" />
|
||||
<argument type="service" id="doctrine" />
|
||||
<tag name="console.command" command="doctrine:fixtures:load" />
|
||||
</service>
|
||||
|
||||
<service id="doctrine.fixtures.provider" alias="doctrine.fixtures.loader" />
|
||||
<service id="doctrine.fixtures.loader" class="Doctrine\Bundle\FixturesBundle\Loader\SymfonyFixturesLoader" />
|
||||
|
||||
<service id="doctrine.fixtures.purger.orm_purger_factory" class="Doctrine\Bundle\FixturesBundle\Purger\ORMPurgerFactory">
|
||||
<tag name="doctrine.fixtures.purger_factory" alias="default"/>
|
||||
</service>
|
||||
</services>
|
||||
</container>
|
||||
@@ -69,7 +69,7 @@ Once your fixtures have been written, load them by executing this command:
|
||||
.. caution::
|
||||
|
||||
By default the ``load`` command **purges the database**, removing all data
|
||||
from every table. To append your fixtures' data add the ``--append`` option.
|
||||
from every table. To append your fixtures' data, add the ``--append`` option.
|
||||
|
||||
This command looks for all services tagged with ``doctrine.fixture.orm``. If you're
|
||||
using the `default service configuration`_, any class that implements ``ORMFixtureInterface``
|
||||
@@ -85,7 +85,7 @@ To see other options for the command, run:
|
||||
Accessing Services from the Fixtures
|
||||
------------------------------------
|
||||
|
||||
In some cases you may need to access your application's services inside a fixtures
|
||||
In some cases, you may need to access your application's services inside a fixtures
|
||||
class. No problem! Your fixtures class is a service, so you can use normal dependency
|
||||
injection::
|
||||
|
||||
@@ -177,8 +177,8 @@ exact same object via its name.
|
||||
}
|
||||
|
||||
The only caveat of using references is that fixtures need to be loaded in a
|
||||
certain order (in this example, if the ``Group`` fixtures are load before the
|
||||
``User`` fixtures, you'll see an error). By default Doctrine loads the fixture
|
||||
certain order (in this example, if the ``Group`` fixtures are loaded before the
|
||||
``User`` fixtures, you'll see an error). By default, Doctrine loads the fixture
|
||||
files in alphabetical order, but you can control their order as explained in the
|
||||
next section.
|
||||
|
||||
@@ -299,11 +299,19 @@ You can also customize purging behavior significantly more and implement a custo
|
||||
// src/Purger/CustomPurger.php
|
||||
namespace App\Purger;
|
||||
|
||||
use Doctrine\Common\DataFixtures\Purger\PurgerInterface;
|
||||
use Doctrine\Common\DataFixtures\Purger\ORMPurger;
|
||||
use Doctrine\Common\DataFixtures\Purger\ORMPurgerInterface;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
|
||||
// ...
|
||||
class CustomPurger implements PurgerInterface
|
||||
class CustomPurger implements ORMPurgerInterface
|
||||
{
|
||||
private EntityManagerInterface $entityManager;
|
||||
|
||||
public function setEntityManager(EntityManagerInterface $em): void
|
||||
{
|
||||
$this->entityManager = $em;
|
||||
}
|
||||
|
||||
public function purge(): void
|
||||
{
|
||||
// ...
|
||||
@@ -319,7 +327,7 @@ You can also customize purging behavior significantly more and implement a custo
|
||||
{
|
||||
public function createForEntityManager(?string $emName, EntityManagerInterface $em, array $excluded = [], bool $purgeWithTruncate = false) : PurgerInterface
|
||||
{
|
||||
return new CustomPurger($em);
|
||||
return new CustomPurger();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ use Doctrine\Bundle\FixturesBundle\ORMFixtureInterface;
|
||||
use Symfony\Component\Config\FileLocator;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Extension\Extension;
|
||||
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
|
||||
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
|
||||
|
||||
use function dirname;
|
||||
|
||||
@@ -21,9 +21,9 @@ final class DoctrineFixturesExtension extends Extension
|
||||
*/
|
||||
public function load(array $configs, ContainerBuilder $container): void
|
||||
{
|
||||
$loader = new XmlFileLoader($container, new FileLocator(dirname(__DIR__) . '/../config'));
|
||||
$loader = new PhpFileLoader($container, new FileLocator(dirname(__DIR__) . '/../config'));
|
||||
|
||||
$loader->load('services.xml');
|
||||
$loader->load('services.php');
|
||||
|
||||
$container->registerForAutoconfiguration(ORMFixtureInterface::class)
|
||||
->addTag(FixturesCompilerPass::FIXTURE_TAG);
|
||||
|
||||
Reference in New Issue
Block a user