-
Notifications
You must be signed in to change notification settings - Fork 20
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
Some thoughts/improvements #241
Comments
Default fieldsAgreed. That would be a very cool feature to decrease the amount of setup in the factory. Also, the already defined associations in the table class (if already found) could be used to generate the Factory namingI personally prefer the singular name because the plural name is always associated to the table instance or the whole table logic in total. Sure in the core we create entities via the table instance like Yes, there are table-like methods on the factory available |
I started the default fields stuff: #243 |
I am not sold on the singular part however
It also uses plural input (table, sure), and it creates a factory that can create multiple ones. See also the getRootTableRegistryName() part: class AccountingFactory extends CakephpBaseFactory
{
/**
* Defines the Table Registry used to generate entities with
*
* @return string
*/
protected function getRootTableRegistryName(): string
{
return 'Accountings';
} So instead of by default being in sync with table (which knows the entity by design), we need to go from Factory => Table => Entity instead. |
Factory defaults
When baking the factory, it by schema knows already required fields.
For now it is empty by default, even though maybe 3-4 fields are required:
It could actually already autocomplete those into the array:
It can even auto-guess the type or name if it matches to available faker methods somehow:
For unknown name matching, e.g. general string types, it could use the random generator per type by default. Or just leave the comment in as above to manually finish up.
It would easy enough to remove again but could be a quick start to have a valid and complete default data set per entity.
What do you think?
Factory naming
We have UsersFixture, UsersTable, .. which deal with the User entity
So the UserFactory should actually also be plural: UsersFactory
A consideration for a future version maybe? The bake script should easily be adjustable
and it seems quite BC.
The text was updated successfully, but these errors were encountered: