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

Fix deprecation on load fixtures command #280

Merged
merged 1 commit into from May 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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);
yceruto marked this conversation as resolved.
Show resolved Hide resolved

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello,

The Symfony Command constructor argument is waiting for a string and not an object. https://github.com/symfony/symfony/blob/4.4/src/Symfony/Component/Console/Command/Command.php#L69

On previous SF versions (without PHP 7 type), it breaks here (https://github.com/symfony/symfony/blob/3.4/src/Symfony/Component/Console/Command/Command.php#L660), which is calls by the setName.

Running bin/console --env=test for example returns

In Command.php line 659:
                                                                        
  Warning: preg_match() expects parameter 2 to be string, object given

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use 3.2.2 which fixes this. Thanks!


$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