Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass a PSR logger to LoadDataFixturesDoctrineCommand #454

Open
wants to merge 1 commit into
base: 3.6.x
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions src/Command/LoadDataFixturesDoctrineCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Doctrine\Common\DataFixtures\Executor\ORMExecutor;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\Persistence\ManagerRegistry;
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 @@ -134,9 +135,27 @@
$input->getOption('purge-with-truncate'),
);
$executor = new ORMExecutor($em, $purger);
$executor->setLogger(static function ($message) use ($ui): void {
$ui->text(sprintf(' <comment>></comment> <info>%s</info>', $message));
$executor->setLogger(new class ($ui) extends AbstractLogger {
private SymfonyStyle $ui;

public function __construct(SymfonyStyle $ui)
{
$this->ui = $ui;
}

/** {@inheritDoc} */
public function log($level, $message, array $context = []): void
{
$this->ui->text(sprintf(' <comment>></comment> <info>%s</info>', $message));

Check warning on line 149 in src/Command/LoadDataFixturesDoctrineCommand.php

View check run for this annotation

Codecov / codecov/patch

src/Command/LoadDataFixturesDoctrineCommand.php#L149

Added line #L149 was not covered by tests
}

/** @deprecated to be removed when dropping support for doctrine/data-fixtures <1.8 */
public function __invoke(string $message): void
{
$this->log(0, $message);

Check warning on line 155 in src/Command/LoadDataFixturesDoctrineCommand.php

View check run for this annotation

Codecov / codecov/patch

src/Command/LoadDataFixturesDoctrineCommand.php#L155

Added line #L155 was not covered by tests
}
});

$executor->execute($fixtures, $input->getOption('append'));

return 0;
Expand Down