doctrine / data-fixtures

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

Problem with proxy in fixtures #344

Closed khrizt closed 4 years ago

khrizt commented 4 years ago

Hi,

I'm starting to use this library to feed fixtures to my tests and I found myself with a problem. I need to create a fixture of a user that has a company, I've tried using the getReference method with 2 fixture files and then I tried this:

<?php

use Doctrine\Common\DataFixtures\FixtureInterface;
use Doctrine\Persistence\ObjectManager;

final class UserFixture implements FixtureInterface
{
    public User $user
    public Company $company;

    public function __construct()
    {
        $this->company = Company::create('Company name');
        $this->user = User::create('email');
    }

    public function load(ObjectManager $manager)
    {
        $manager->persist($this->company);
        $manager->persist($this->employee);
        $manager->flush();
    }
}

But both times when I do a find in my code I always get the proxy instead of the entity itself, usually it would not be a problem but in this case I'm using ReflectionClass to get the list of properties and I only get the list doctrine Proxy's properties.

Is there some way to avoid that? Maybe creating fixture some other way, or clearing the cache somehow?

Thanks in advance, I'm kinda lost right now.

khrizt commented 4 years ago

Sorry, I already solved that looking for parent class of proxy.