Skip to content
This repository has been archived by the owner on Dec 11, 2020. It is now read-only.

Allow to add extra "Name" guessers in ORM entity populators #1591

Open
chingologram opened this issue Oct 1, 2018 · 1 comment
Open

Allow to add extra "Name" guessers in ORM entity populators #1591

chingologram opened this issue Oct 1, 2018 · 1 comment

Comments

@chingologram
Copy link

chingologram commented Oct 1, 2018

Hi. First of all, thanks for Faker.
I am trying to come up with a small set of tools to allow devs in my team to write tests.
This is a legacy application with lots of columns which not always match the expected naming which Faker associates to certain formatters.
Also, we have some columns which Faker of course can't guess how to populate (small varchar values with length < 5 that always take one of three or four alphanumerical values). Also, columns used as foreign keys that don't match exactly the name in the destination table (because they're not the only reference from that table).
Of course, on a per-case scenario I can override the value with custom formatters, but then we are repeating ourselves over and over to set default values on those columns which the populator can't guess.
I checked the code in the EntityPopulator classes of the ORM populators, and found that these are tightly coupled with Faker\Guesser\Name class.
I think keeping the default Name guesser is super useful, but it would be nice if there was an optional parameter that can be passed to EntityPopulator, which holds extra associations between field names and formatters.
For example, then one could do:
$customEntityPopulator = new EntityPopulator('MyEntity');
$customEntityPopulator->addNameGuesser(new CustomNameGuesser);
$populator->addEntity($customEntityPopulator);

Then, if our CustomNameGuesser instance can't resolve the formatter based on the column name, we continue normally to the normal name guessing mechanism (first trying Faker\Guesser\Name and then ColumnTypeGuesser). So possibly each nameguesser could pass a status to the subsequent one, with either the guessing function or false if it couldn't be resolved for that column, and the subsequent guessers pick up based on that.
Is this at all possible?

@chingologram chingologram changed the title Allow to override "Name" guesser in ORM entity populators Allow to add extra "Name" guessers in ORM entity populators Oct 1, 2018
@jakagacic
Copy link

This feature would be very useful 👍

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants