doctrine / data-fixtures

Doctrine2 ORM Data Fixtures Extensions
http://www.doctrine-project.org
MIT License
2.76k stars 224 forks source link

PHPStan error when using AbstractFixture getReference #430

Closed mickverm closed 1 year ago

mickverm commented 1 year ago

I'm currently using doctrine/data-fixtures 1.6.3 with phpstan/phpstan 1.10.0 on the highest level.

The following Fixture code:

namespace App\DataFixtures;

use App\Entity\User;
use App\Entity\UserGroup;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Persistence\ObjectManager;

class UserFixture extends Fixture
{
    public function load(ObjectManager $manager): void
    {
        $user = (new User())
            ->setLogin('user')
            ->addGroup($this->getReference(UserGroupFixture::GROUP_1, UserGroup::class))
            ->addGroup($this->getReference(UserGroupFixture::GROUP_2, UserGroup::class));

        $manager->persist($user);
        $manager->flush();
    }

    /**
     * @return array<class-string<FixtureInterface>>
     */
    public function getDependencies(): array
    {
        return [UserGroupFixture::class];
    }
}

Returns the following error:

Parameter #1 $group of method App\Entity\User::addGroup() expects App\Entity\UserGroup, object given.
mickverm commented 1 year ago

This appears to be fixed in 1.6.x-dev already, most likely by https://github.com/doctrine/data-fixtures/pull/427 Could a new 1.6.x version be released?

greg0ire commented 1 year ago

Sure! Done: https://github.com/doctrine/data-fixtures/releases/tag/1.6.4