foundry icon indicating copy to clipboard operation
foundry copied to clipboard

`make:factory` enhancements

Open nikophil opened this issue 3 years ago • 6 comments

  • [x] auto-detect phpstan and add specific @phpstan-method (not needed for psalm) https://github.com/zenstruck/foundry/pull/338
  • [x] availability to create factory for object not related to doctrine https://github.com/zenstruck/foundry/pull/343
  • [x] Use field limit length when specified #286 #294
  • [x] support default property for mongoDB #238 https://github.com/zenstruck/foundry/pull/340
  • [x] auto defaults for non-nullable 1-1/n-1 relationships #175 https://github.com/zenstruck/foundry/pull/221
  • [x] Foundry generates the factory with $faker->text() if its a string, i think $faker->sentence() oder $faker->word() would fit better. If doctrine type Text, I would recommend to use $faker->text()
  • [x] sort the default values alphanumeric
  • [x] indent the phpdoc properly (see below)
  • [x] Move the generated comments to @see annotations above the methods. (see below)
  • [x] Import non-nullable relationship factories (https://github.com/zenstruck/foundry/pull/351#discussion_r1029584697)
  • [x] auto-complete FQCN's bin/console make:entity User<tab> (auto-complete classes that start with User) https://github.com/zenstruck/foundry/pull/383
  • [x] handle enums default https://github.com/zenstruck/foundry/pull/393
  • [x] list embeddables in make:factory ~- [ ] add docs on --no-persistence behavior~ won'tdo
  • [x] handle when factory with same name already exists https://github.com/zenstruck/foundry/pull/402
  • [x] match directory/namespace structure https://github.com/zenstruck/foundry/issues/401 https://github.com/zenstruck/foundry/pull/411
  • [x] add a bundle's configuration for base namespace where to create factories

Some more complex features that would be very nice to add:

  • [x] based on auto defaults for non-nullable: if the factory is missing, we could also create the missing factory
  • [x] handle previous feature with --all ~- [ ] "update" factories~ this one is really tricky, and not sure people will actually use it....
  • [ ] add an option to make:entity: --with-factory

nikophil avatar Nov 14 '22 07:11 nikophil

Some additional suggestions by @OskarStark:

  1. Foundry generates the factory with $faker->text() if its a string, i think $faker->sentence() oder $faker->word() would fit better. If doctrine type Text, I would recommend to use $faker->text()

  2. Another proposal would be to sort the default values alphanumeric

  3. And we should indent the phpdoc properly

    CleanShot 2022-11-15 at 07 53 43@2x (php-cs-fixer adjusts these
  4. Move the generated comments to @see annotations above the methods. CleanShot 2022-11-15 at 07 55 55@2x

kbond avatar Nov 15 '22 10:11 kbond

Import non-nullable relationship factories

This is complete, correct?

kbond avatar Nov 25 '22 15:11 kbond

This is complete, correct?

I'd say it's almost complete, I'd like to display a message when a factory does not exists...

but that message will be removed when we'll implement if the factory is missing, we could also create the missing factory

nikophil avatar Nov 25 '22 15:11 nikophil

auto-detect phpstan and add specific @phpstan-method (not needed for psalm)

Are you sure this is not needed for Psalm?

The default @method annotations that make:factory generates are technically wrong (as of foundry 1.36). They do help IDEs with providing autocomplete, but they can't be used for statical analyses (or lead to false positives).

I could only use foundry with Psalm by either removing all the @method annotations, or adding psalm-specific ones.

janopae avatar Dec 12 '23 10:12 janopae

hi!

no, this was a false statement! Since then we've added the @psalm-method phpdocs https://github.com/zenstruck/foundry/blob/1.x/tests/Fixtures/Maker/expected/can_create_factory_for_entity_with_repository_with_data_set_psalm.php#L40-L53

Psalm/PHPStan detection is pretty weak here: it could fail if the default config file does not exists https://github.com/zenstruck/foundry/blob/1.x/src/Bundle/Maker/Factory/FactoryGenerator.php#L144-L151

nikophil avatar Dec 12 '23 11:12 nikophil

@nikophil Nice, thanks a lot! It seems like it was indeed my unusal Psalm setup that prevented the auto detection. :)

janopae avatar Dec 12 '23 11:12 janopae