AliceDataFixtures: ObjectManagerPersister bad arguments

Hello

Following this issue : https://github.com/theofidry/AliceBundle/issues/6

I just updated theofidry/alice-data-fixtures to 1.5.1 and got this error by launching fixtures :

  Fidry\AliceDataFixtures\Bridge\Doctrine\Persister\ObjectManagerPersister::g  
  etMetadata(): Argument #2 ($object) must be of type object, array given, ca  
  lled in /app/vendor/theofidry/alice-data-fixtures/src/Bridge/Doctrine/Persi  
  ster/ObjectManagerPersister.php on line 158  

I updated hautelook/alice-bundle to 2.10 as well.

Thanks you

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 16 (8 by maintainers)

Commits related to this issue

Most upvoted comments

Hello

I’ve the same issue since i’ve updated theofidry/alice-data-fixtures to 1.5.1.

I my case, it’s appear because into my fixtures i’m using array:

App\Entity\User:
  user_2:
    roles: ['@role_*']

To testing and try to understand where is the problem, i’ve added this condition into the ObjectManagerPersister before the testing line with null, and all is fine now (i known it’s a bad idea to do this) :

elseif (is_array($fieldValueOrFieldValues)) {
    foreach ($fieldValueOrFieldValues as $fieldValue) {
        $this->getMetadata($targetEntityClassName, $fieldValue);
    }
}

There is another possibility to replace an array by a collection into fixtures (because collection is managed)? Or it’s necessary to update the library?

Thanks for your help.

Hi @theofidry,

I have tested and I can confirm #207 is solving the issue for me.

Thx @titiyoyo

I have the same issue. It worked just fine before this update.

Please consider reverting the change as I think this is a breaking change. Even if this was not intended to work with array instead of Collection, it did, and it was not clear that it should not work.

I think it’s the exact same error: a collection (for relationships) in Doctrine must be Collection instances AFAIK so having an array/iterable there is wrong in that regard

The only comment i’ve with your remarks, that’s before your last update of the library all is fine with this syntax, i think because we have now a strict types component enabled by default.

Thanks for your time.

I think it’s the exact same error: a collection (for relationships) in Doctrine must be Collection instances AFAIK so having an array/iterable there is wrong in that regard

On Mon 17 Jan 2022 at 15:49, Helo @.***> wrote:

I think I have a different context than fkizewski. However there’s probably a type related solution.

Domain\Model\ZmrList

/**     * @var iterable|array|Collection     */
private iterable $listColumns;

ORM\Maping\ZmrList.orm.yml

Domain\Model\ZmrList: type: entity oneToMany: listColumns: targetEntity: ListColumn mappedBy: zmrList

fixtures\zmrLists.yaml

Domain\Model\ZmrList: zmrList1: name: ‘BehatTestList1’ label: ‘Behat Test List 1’ type: ‘Entity’ form: @.***’ description: ‘A list for automated testing’

I have these informations… :

Doctrine\Persistence\Reflection\TypedNoDefaultReflectionProperty {#132 +name: “listColumns” +class: “Domain\Model\ZmrList” modifiers: “private” extra: { docComment: “”" /**\n * @var iterable|array|Collection\n */ “”" } } []“listColumns”

… by doing this in ObjectManagerPersister :

if ($fieldValueOrFieldValues instanceof Collection) { foreach ($fieldValueOrFieldValues->getValues() as $fieldValue) { $this->getMetadata($targetEntityClassName, $fieldValue); } } elseif (is_array($fieldValueOrFieldValues)) { dump($metadata->getReflectionProperty(‘listColumns’)); dump($metadata->getReflectionProperty(‘listColumns’)->getValue($object)); dd($fieldName); }

Do you have an idea on that @theofidry https://github.com/theofidry ?

Thanks you very much for your help

— Reply to this email directly, view it on GitHub https://github.com/theofidry/AliceDataFixtures/issues/202#issuecomment-1014622290, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABHPVANJUVZCHYJ5MP3YEM3UWQUAFANCNFSM5LFUAZSQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you were mentioned.Message ID: @.***>