zenstruck / foundry

A model factory library for creating expressive, auto-completable, on-demand dev/test fixtures with Symfony and Doctrine.
https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html
MIT License
607 stars 62 forks source link

Doctrine embeddables with v2 #617

Closed norkunas closed 2 weeks ago

norkunas commented 2 weeks ago

Tried to upgrade to v2 and a problem arises that it tries to fetch embeddable ID from Doctrine ClassMetadataInfo. Here is a relevant trace:

Error: Call to a member function getValue() on null

/var/www/html/vendor/doctrine/orm/src/Mapping/ClassMetadataInfo.php:895
/var/www/html/vendor/zenstruck/foundry/src/Proxy.php:446
/var/www/html/vendor/zenstruck/foundry/src/Proxy.php:254
/var/www/html/vendor/zenstruck/foundry/src/Factory.php:519
/var/www/html/vendor/zenstruck/foundry/src/Factory.php:463
/var/www/html/vendor/zenstruck/foundry/src/Factory.php:129
/var/www/html/vendor/zenstruck/foundry/src/Persistence/PersistentProxyObjectFactory.php:77
/var/www/html/vendor/zenstruck/foundry/src/FactoryCollection.php:94
/var/www/html/vendor/zenstruck/foundry/src/Persistence/PersistentProxyObjectFactory.php:101
/var/www/html/tests/ATest.php:279

I use Factory::createSequence and pass down embeddables

nikophil commented 2 weeks ago

Hi @norkunas

This is kinda strange: in 2.0, src/Proxy.php does not exist anymore. But in 1.38.0, src/Proxy:446 points to an empty line https://github.com/zenstruck/foundry/blob/1.x/src/Proxy.php#L446

could you provide the exact version you're using please? Also, could you also provide the ORM version?

thanks!

norkunas commented 2 weeks ago

Ugh, sorry, thought that after done all things with upgrade guide I've updated to v2, but no, with v2 now mostly everything is fine, thanks :man_facepalming:

nikophil commented 2 weeks ago

great to read this!

but... you said "mostly"? :sweat_smile: don't hesitate to log other annoyance you can encounter!

norkunas commented 2 weeks ago

Just some tests that are failing, but will refactor a little bit to make them work..

What disturbs me that even after I've done everything what I can, I still get these deprecations:

  1x: The "Zenstruck\Foundry\ObjectFactory::create()" method is considered final. It may change without further notice as of its next major version. You should not extend it from "Zenstruck\Foundry\Persistence\PersistentObjectFactory".

  1x: The "Zenstruck\Foundry\Persistence\PersistentObjectFactory::find()" method is considered final. It may change without further notice as of its next major version. You should not extend it from "Zenstruck\Foundry\Persistence\PersistentProxyObjectFactory".

  1x: The "Zenstruck\Foundry\Persistence\PersistentObjectFactory::findOrCreate()" method is considered final. It may change without further notice as of its next major version. You should not extend it from "Zenstruck\Foundry\Persistence\PersistentProxyObjectFactory".

  1x: The "Zenstruck\Foundry\Persistence\PersistentObjectFactory::randomOrCreate()" method is considered final. It may change without further notice as of its next major version. You should not extend it from "Zenstruck\Foundry\Persistence\PersistentProxyObjectFactory".

  1x: The "Zenstruck\Foundry\Persistence\PersistentObjectFactory::randomSet()" method is considered final. It may change without further notice as of its next major version. You should not extend it from "Zenstruck\Foundry\Persistence\PersistentProxyObjectFactory".

  1x: The "Zenstruck\Foundry\Persistence\PersistentObjectFactory::randomRange()" method is considered final. It may change without further notice as of its next major version. You should not extend it from "Zenstruck\Foundry\Persistence\PersistentProxyObjectFactory".

  1x: The "Zenstruck\Foundry\Persistence\PersistentObjectFactory::findBy()" method is considered final. It may change without further notice as of its next major version. You should not extend it from "Zenstruck\Foundry\Persistence\PersistentProxyObjectFactory".

  1x: The "Zenstruck\Foundry\Persistence\PersistentObjectFactory::random()" method is considered final. It may change without further notice as of its next major version. You should not extend it from "Zenstruck\Foundry\Persistence\PersistentProxyObjectFactory".

  1x: The "Zenstruck\Foundry\Persistence\PersistentObjectFactory::first()" method is considered final. It may change without further notice as of its next major version. You should not extend it from "Zenstruck\Foundry\Persistence\PersistentProxyObjectFactory".

  1x: The "Zenstruck\Foundry\Persistence\PersistentObjectFactory::last()" method is considered final. It may change without further notice as of its next major version. You should not extend it from "Zenstruck\Foundry\Persistence\PersistentProxyObjectFactory".

  1x: The "Zenstruck\Foundry\Persistence\PersistentObjectFactory::all()" method is considered final. It may change without further notice as of its next major version. You should not extend it from "Zenstruck\Foundry\Persistence\PersistentProxyObjectFactory".

  1x: The "Zenstruck\Foundry\Persistence\PersistentObjectFactory::repository()" method is considered final. It may change without further notice as of its next major version. You should not extend it from "Zenstruck\Foundry\Persistence\PersistentProxyObjectFactory".

Why these deprecations are not solved in the library itself? :slightly_smiling_face:

nikophil commented 2 weeks ago

:open_mouth:

which tool triggers these warnings? phpunit / phpstan / phpunit symfony's bridge ?

those are internal problems: we have PersistentProxyObjectFactory which extends PersistentObjectFactory, and from a user perspective, we don't want PersistentObjectFactory to be overridden in user land, so we marked is as @final. But we need it to be extended by PersistentProxyObjectFactory. We do not expect those to bubble up in userland :thinking:

norkunas commented 2 weeks ago

In Symfony I just run SYMFONY_DEPRECATIONS_HELPER='ignoreFile=./tests/baseline-ignore' php bin/phpunit :) So I will add them to baseline, just want to make sure that it's okay to ignore them :)

We are using phpunit with symfony bridge

nikophil commented 2 weeks ago

ok, thanks for the information. Usually, I'm setting SYMFONY_DEPRECATIONS_HELPER="max[self]=0&max[direct]=0&quiet[]=indirect&quiet[]=other" so that I'm not annoyed by indirect and other deprecations

norkunas commented 2 weeks ago

:+1: but I like to be explicit and see a list of deprecations which we ignore :)