Skip to content

Commit

Permalink
Fix deprecation on load fixtures command
Browse files Browse the repository at this point in the history
  • Loading branch information
yceruto committed May 29, 2019
1 parent 1919ad2 commit 31d101b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
14 changes: 12 additions & 2 deletions Command/LoadDataFixturesDoctrineCommand.php
Expand Up @@ -15,8 +15,10 @@
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use const E_USER_DEPRECATED;
use function implode;
use function sprintf;
use function trigger_error;

/**
* Load data fixtures from bundles.
Expand All @@ -26,9 +28,17 @@ class LoadDataFixturesDoctrineCommand extends DoctrineCommand
/** @var SymfonyFixturesLoader */
private $fixturesLoader;

public function __construct(SymfonyFixturesLoader $fixturesLoader)
public function __construct(SymfonyFixturesLoader $fixturesLoader, ?ManagerRegistry $doctrine = null)
{
parent::__construct();
if ($doctrine === null) {
@trigger_error(sprintf(
'The "%s" constructor expects a "%s" instance as second argument, not passing it will throw a \TypeError in DoctrineFixturesBundle 4.0.',
static::class,
ManagerRegistry::class
), E_USER_DEPRECATED);
}

parent::__construct($doctrine);

$this->fixturesLoader = $fixturesLoader;
}
Expand Down
1 change: 1 addition & 0 deletions Resources/config/services.xml
Expand Up @@ -7,6 +7,7 @@
<!-- commands -->
<service id="doctrine.fixtures_load_command" class="Doctrine\Bundle\FixturesBundle\Command\LoadDataFixturesDoctrineCommand">
<argument type="service" id="doctrine.fixtures.loader" />
<argument type="service" id="doctrine" />
<tag name="console.command" command="doctrine:fixtures:load" />
</service>

Expand Down
2 changes: 2 additions & 0 deletions Tests/IntegrationTest.php
Expand Up @@ -12,6 +12,7 @@
use Doctrine\Bundle\FixturesBundle\Tests\Fixtures\FooBundle\DataFixtures\WithDependenciesFixtures;
use Doctrine\Bundle\FixturesBundle\Tests\Fixtures\FooBundle\FooBundle;
use Doctrine\Common\DataFixtures\Loader;
use Doctrine\Common\Persistence\ManagerRegistry;
use PHPUnit\Framework\TestCase;
use RuntimeException;
use Symfony\Bridge\Doctrine\DataFixtures\ContainerAwareLoader;
Expand Down Expand Up @@ -348,6 +349,7 @@ protected function configureRoutes(RouteCollectionBuilder $routes) : void
protected function configureContainer(ContainerBuilder $c, LoaderInterface $loader) : void
{
$c->setParameter('kernel.secret', 'foo');
$c->register('doctrine', ManagerRegistry::class);
$callback = $this->servicesCallback;
$callback($c);
}
Expand Down

0 comments on commit 31d101b

Please sign in to comment.