doctrine / DoctrineFixturesBundle

Symfony integration for the doctrine/data-fixtures library
MIT License
2.45k stars 202 forks source link

`EntityManager` injected instead of type-hinted `ObjectManager` #323

Closed ThomasLandauer closed 4 years ago

ThomasLandauer commented 4 years ago

I'm getting this error from phpstan:

Parameter #1 $manager (Doctrine\Persistence\ObjectManager) of method App\DataFixtures\TestFixtures::load() is not compatible with parameter #1 $manager (Doctrine\Persistence\ObjectManager) of method Doctrine\Common\DataFixtures\FixtureInterface::load().

Following https://symfony.com/doc/current/bundles/DoctrineFixturesBundle/index.html this is what I have in the file:

namespace App\DataFixtures;

use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Common\Persistence\ObjectManager;

class TestFixtures extends Fixture
{
    public function load(ObjectManager $manager)
    {
        print_r(get_class($manager));
        die;
    }
}

And indeed, the output I'm getting is:

Doctrine\ORM\EntityManager

So EntityManager gets injected, whereas load() expects ObjectManager

xabbuh commented 4 years ago

The EntityManager class implements the EntityManagerInterface which extends the interface ObjectManager. I don't see why that should be an issue here.

greg0ire commented 4 years ago

You should probably use Doctrine\Persistence\ObjectManager here.

ThomasLandauer commented 4 years ago

@greg0ire cool - thanks - that fixed it for me!

Should I make a PR and change use Doctrine\Common\Persistence\ObjectManager; right away at https://symfony.com/doc/current/bundles/DoctrineFixturesBundle/index.html#writing-fixtures ?

greg0ire commented 4 years ago

Yes please!

ThomasLandauer commented 4 years ago

There you go :-) https://github.com/doctrine/DoctrineFixturesBundle/pull/324