Skip to content

Commit

Permalink
Merge branch '3.5.x' into 4.0.x
Browse files Browse the repository at this point in the history
* 3.5.x:
  Apply PHPCS' PHP 7.4 rules (#410)
  Drop support for DBAL 2 (#411)
  • Loading branch information
derrabus committed Nov 11, 2023
2 parents 22c1462 + 5de69ba commit 7e81bd1
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 50 deletions.
59 changes: 22 additions & 37 deletions Command/LoadDataFixturesDoctrineCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@
use Doctrine\Bundle\FixturesBundle\Purger\ORMPurgerFactory;
use Doctrine\Bundle\FixturesBundle\Purger\PurgerFactory;
use Doctrine\Common\DataFixtures\Executor\ORMExecutor;
use Doctrine\DBAL\Sharding\PoolingShardConnection;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\Persistence\ManagerRegistry;
use LogicException;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
Expand Down Expand Up @@ -63,30 +61,28 @@ protected function configure(): void
->addOption('em', null, InputOption::VALUE_REQUIRED, 'The entity manager to use for this command.')
->addOption('purger', null, InputOption::VALUE_REQUIRED, 'The purger to use for this command', 'default')
->addOption('purge-exclusions', null, InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED, 'List of database tables to ignore while purging')
->addOption('shard', null, InputOption::VALUE_REQUIRED, 'The shard connection to use for this command.')
->addOption('purge-with-truncate', null, InputOption::VALUE_NONE, 'Purge data by using a database-level TRUNCATE statement')
->setHelp(<<<'EOT'
The <info>%command.name%</info> command loads data fixtures from your application:
<info>php %command.full_name%</info>
Fixtures are services that are tagged with <comment>doctrine.fixture.orm</comment>.
If you want to append the fixtures instead of flushing the database first you can use the <comment>--append</comment> option:
<info>php %command.full_name%</info> <comment>--append</comment>
By default Doctrine Data Fixtures uses DELETE statements to drop the existing rows from the database.
If you want to use a TRUNCATE statement instead you can use the <comment>--purge-with-truncate</comment> flag:
<info>php %command.full_name%</info> <comment>--purge-with-truncate</comment>
To execute only fixtures that live in a certain group, use:
<info>php %command.full_name%</info> <comment>--group=group1</comment>

EOT
);
The <info>%command.name%</info> command loads data fixtures from your application:
<info>php %command.full_name%</info>
Fixtures are services that are tagged with <comment>doctrine.fixture.orm</comment>.
If you want to append the fixtures instead of flushing the database first you can use the <comment>--append</comment> option:
<info>php %command.full_name%</info> <comment>--append</comment>
By default Doctrine Data Fixtures uses DELETE statements to drop the existing rows from the database.
If you want to use a TRUNCATE statement instead you can use the <comment>--purge-with-truncate</comment> flag:
<info>php %command.full_name%</info> <comment>--purge-with-truncate</comment>
To execute only fixtures that live in a certain group, use:
<info>php %command.full_name%</info> <comment>--group=group1</comment>

EOT);
}

protected function execute(InputInterface $input, OutputInterface $output): int
Expand All @@ -102,17 +98,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int
}
}

if ($input->getOption('shard')) {
if (! $em->getConnection() instanceof PoolingShardConnection) {
throw new LogicException(sprintf(
'Connection of EntityManager "%s" must implement shards configuration.',
$input->getOption('em')
));
}

$em->getConnection()->connect($input->getOption('shard'));
}

$groups = $input->getOption('group');
$fixtures = $this->fixturesLoader->getFixtures($groups);
if (! $fixtures) {
Expand All @@ -132,7 +117,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
'Could not find purger factory with alias "%1$s", using default purger. Did you forget to register the %2$s implementation with tag "%3$s" and alias "%1$s"?',
$input->getOption('purger'),
PurgerFactory::class,
PurgerFactoryCompilerPass::PURGER_FACTORY_TAG
PurgerFactoryCompilerPass::PURGER_FACTORY_TAG,
));
$factory = new ORMPurgerFactory();
} else {
Expand All @@ -143,7 +128,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$input->getOption('em'),
$em,
$input->getOption('purge-exclusions'),
$input->getOption('purge-with-truncate')
$input->getOption('purge-with-truncate'),
);
$executor = new ORMExecutor($em, $purger);
$executor->setLogger(static function ($message) use ($ui): void {
Expand Down
2 changes: 1 addition & 1 deletion Loader/SymfonyFixturesLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ protected function createFixture($class): FixtureInterface
throw new LogicException(sprintf(
'The "%s" fixture class is trying to be loaded, but is not available. Make sure this class is defined as a service and tagged with "%s".',
$class,
FixturesCompilerPass::FIXTURE_TAG
FixturesCompilerPass::FIXTURE_TAG,
));
}

Expand Down
2 changes: 1 addition & 1 deletion Tests/Command/LoadDataFixturesDoctrineCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function testInstantiatingWithoutManagerRegistry(): void
'%s::__construct(): Argument #1 ($doctrine) must be of type %s, null given' :
'Argument 1 passed to %s::__construct() must be an instance of %s, null given',
DoctrineCommand::class,
ManagerRegistry::class
ManagerRegistry::class,
));

throw $e;
Expand Down
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
"symfony/phpunit-bridge": "^6.3.6",
"vimeo/psalm": "^4.30"
},
"conflict": {
"doctrine/dbal": "< 3"
},
"autoload": {
"psr-4": { "Doctrine\\Bundle\\FixturesBundle\\": "" }
},
Expand Down
2 changes: 1 addition & 1 deletion phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<arg name="cache" value=".phpcs-cache"/>
<arg name="colors"/>

<config name="php_version" value="70100"/>
<config name="php_version" value="70400"/>

<!-- Ignore warnings and show progress of the run -->
<arg value="nps"/>
Expand Down
10 changes: 0 additions & 10 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
parameters:
ignoreErrors:
-
message: "#^Call to method connect\\(\\) on an unknown class Doctrine\\\\DBAL\\\\Sharding\\\\PoolingShardConnection\\.$#"
count: 1
path: Command/LoadDataFixturesDoctrineCommand.php

-
message: "#^Class Doctrine\\\\DBAL\\\\Sharding\\\\PoolingShardConnection not found\\.$#"
count: 1
path: Command/LoadDataFixturesDoctrineCommand.php

-
message: "#^Constructor of class Doctrine\\\\Bundle\\\\FixturesBundle\\\\Tests\\\\Fixtures\\\\FooBundle\\\\DataFixtures\\\\RequiredConstructorArgsFixtures has an unused parameter \\$fooRequiredArg\\.$#"
count: 1
Expand Down

0 comments on commit 7e81bd1

Please sign in to comment.