-
-
Notifications
You must be signed in to change notification settings - Fork 85
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Auto populate ModelFactory::getDefaults() based on doctrine mapping #100
Comments
Hey @MGDSoft, glad you like the bundle! #15 I think would address "create fixtures for all entities with a single command" so I'd love some help on that. For the auto default values, this would be really neat. I'm trying to think on how it would work:
|
👀 is this feature in building? |
Not yet by me anyway - my schedule's pretty full currently. |
mhh i like this idea :/ some dummy/inspire code/test $classMetaData = $entityManager->getClassMetadata(Product::class);
$defaultsArray = [];
$fakerTypes = [
'integer' => faker()->randomNumber(),
'string' => faker()->sentence(),
'date' => faker()->dateTime(),
];
foreach ($classMetaData->fieldMappings as $property) {
// create with faker
if (!$property['nullable']) {
$defaultsArray[] = $fakerTypes[$property['type']];
}
}
foreach ($classMetaData->associationMappings as $classname => $values) {
// Check Factory exist and create or skip? class_exists($classname.'Factory')
} /**
* @ORM\Entity
* @ORM\Table(name="products")
*/
class Product
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue
*/
protected int $id;
/**
* @ORM\Column(type="string", nullable=true)
*/
protected string $name;
/**
* @ORM\Column(type="date")
*/
protected DateTime $someDate;
/**
* @ORM\Column(type="array")
*/
protected array $someArray = [];
/**
* @ManyToOne(targetEntity="Category")
* @JoinColumn(name="category_id", referencedColumnName="id")
*/
protected Category $category;
public function getId()
{
return $this->id;
}
public function getName()
{
return $this->name;
}
public function setName($name)
{
$this->name = $name;
} |
Thanks, yes, that's basically what I was thinking. Pretty easy for the scalar doctrine types. It gets more complicated for the non-nullable I think this should be an opt-in flag on the maker command (ie |
Its need take care of Asserts too. As examble a string $email with an Assert/Email must use faker()->email() instead of faker()->sentence(). And you think about it its need also to take care of the fieldNames.
for strings we can look for
i have to investigate on relationships and yes auto-creating for non exist sounds like a good solution. |
I think this Issue can be closed? |
Closed with #173. |
Hi @kbond thx for this bundle!
Two years ago I created a similiar bundle https://github.com/MGDSoft/FixturesGeneratorBundle.
This bundle can create auto defaultValues and create fixtures for all entities with a single command (with his dependencies), it would be great if that features was in this bundle too.
I can help with this if you are agree.
The text was updated successfully, but these errors were encountered: