fzaninotto / Faker

Faker is a PHP library that generates fake data for you
MIT License
26.8k stars 3.57k forks source link

Improvement maybe: Fill any object you want. #2041

Open didslm opened 3 years ago

didslm commented 3 years ago

Summary

I already did something in my project where it uses faker to fill objects and tries to guess the format if not it goes by the input type (int|string|bool) it works even with custom object. There is already something inside for Doctrine entities but I couldn't find it for objects with some setters. Btw this works only if the object has setters.

Self-enclosed code snippet for reproduction

To use it you just provide the object and it will fill it. Example

$faker->fillObject($someObject, FILL_OPTIONAL_PARAMETERS);