Skip to content

Commit

Permalink
Use AbstractLogger instead of Closure in LoadDataFixturesDoctrineODMC…
Browse files Browse the repository at this point in the history
…ommand.
  • Loading branch information
mickverm committed Nov 29, 2024
1 parent 33a9d71 commit f908bd1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
},
"require-dev": {
"doctrine/coding-standard": "^11.0",
"doctrine/data-fixtures": "^1.7",
"doctrine/data-fixtures": "^1.7 || ^2.0",
"phpunit/phpunit": "^9.5.5",
"psalm/plugin-symfony": "^5.0",
"symfony/browser-kit": "^6.4 || ^7.0",
Expand Down
15 changes: 11 additions & 4 deletions src/Command/LoadDataFixturesDoctrineODMCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Doctrine\Bundle\MongoDBBundle\ManagerRegistry;
use Doctrine\Common\DataFixtures\Executor\MongoDBExecutor;
use Doctrine\Common\DataFixtures\Purger\MongoDBPurger;
use Psr\Log\AbstractLogger;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
Expand Down Expand Up @@ -37,7 +38,8 @@ protected function configure(): void
->addOption('group', null, InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED, 'Only load fixtures that belong to this group (use with --services)')
->addOption('append', null, InputOption::VALUE_NONE, 'Append the data fixtures instead of flushing the database first.')
->addOption('dm', null, InputOption::VALUE_REQUIRED, 'The document manager to use for this command.')
->setHelp(<<<'EOT'
->setHelp(
<<<'EOT'
The <info>doctrine:mongodb:fixtures:load</info> command loads data fixtures from your application:
<info>php %command.full_name%</info>
Expand All @@ -50,7 +52,7 @@ protected function configure(): void
<info>php %command.full_name%</info> <comment>--group=group1</comment>
EOT
);
);
}

protected function execute(InputInterface $input, OutputInterface $output): int
Expand Down Expand Up @@ -83,8 +85,13 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$purger = new MongoDBPurger($dm);
$executor = new MongoDBExecutor($dm, $purger);
$executor->setLogger(static function ($message) use ($output): void {
$output->writeln(sprintf(' <comment>></comment> <info>%s</info>', $message));
$executor->setLogger(new class($output) extends AbstractLogger {
public function __construct(private readonly OutputInterface $output) {}

public function log(mixed $level, string|\Stringable $message, array $context = []): void
{
$this->output->writeln(sprintf(' <comment>></comment> <info>%s</info>', $message));
}
});
$executor->execute($fixtures, $input->getOption('append'));

Expand Down

0 comments on commit f908bd1

Please sign in to comment.