-
-
Notifications
You must be signed in to change notification settings - Fork 329
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
Fixture lifecycle #388
Comments
Just my opinions:
|
If we decide to add
Tbh I don't feel strongly about this, if you feel this should stay in
Let's keep it as an idea then. I would prefer to finish the first alpha version of v3 before considering to add this.
👍 Thanks for taking the time to take a look at it @tshelburne |
I think we should keep BTW, one note - the library is changing so rapidly and has evolved so much that I can't really keep up with it - I've reduced my notifications to direct @ mentions only so that I'll see the meaningful parts instead of losing it in the bulk. Let me know if it seems to cause problems, but it seems the only reasonable way for me to keep up with it, TBH. |
I meant deprecating the usage of Nelmio\Entity\User:
user{1..10}:
__construct: # deprecate that for the factory statement below
create:
0 (unique): <username()>
__factory:
create:
0 (unique): <username()> But having Nelmio\Entity\User:
user{1..10}:
__construct:
- 0 (unique): <username()> |
Perfectly ok with me :) |
Regarding the Optional method calls problem:
Having it as a value complicates a bit things to be honest:
[1]: in the case of properties, Nelmio\Entity\User:
user1:
username: '80%? foo'
user2:
username (80%?): '50%? foo' The difference between the two is that there is 20% of chances that |
Hey will the optional methods ever get implemented? 🙏 |
I'm not really interested in actively implementing new features for alice. So no unless someone is willing to step up to contribute to it |
Too bad, but I get it. |
Calling for validation @tshelburne & @Seldaek as it's a big userland change. Short story long, it's a review of the current process and what I would like to change for v3. Main changes are support for multiple calls, external factories
/cc @soullivaneuh @ogizanagi
Points to review:
[ ] accessorsCurrently in v2
Instantiation process
If no
__constructor
option is given, the most appropriate constructor will be searched in the following order:It is possible to change that behaviour by specifying constructor arguments, which allows the user to:
false
)Population process
For each of the property described, the more suitable accessor to set the property is looked for in the following order:
Accessing properties
While generating values, some may be a reference to a fixture property, e.g.
owner: '@user1->username'
. This is done by looking at the first appropriate accessor (direct or getter)Limitations:
v3
After "population" step
To handle the limitation described in #313, a new step is added in the cycle:
This allows to add full support for calling methods. The old call method feature is deprecated in v2 and removed in v3. The syntax will be:
As in v3, the call
setLocation
will be done after the object has been fully populated (before was part of the "population" process).Unique values support for function calls
For both function calls and constructor, unique values should be able to be specified like so:
🚨 Problem: it becomes hard to distinguish when the key is an index for a flag and when it is a constructor method.
Proposal:
'0 (unique)'
and'create'
.__construct
for being used as a factory and introduce another factory option. See below for further description.Factory support
If accepted, this would deprecate the usage of
__construct
used as a factory which is a BC change in userland 🚨.Syntax:
Example:
It would benefit of the
unique
flag as well:Supporting static factories would be easy (it is an already supported feature with
__construct
):🔥 New feature: supporting non-static factories, i.e. an injected service:
Accessors
The
__set
option could be deprecated in favour of allowing the user to specify accessors for some properties:As shown in the example above,
__accessors
could help to specify read/write accessors on a property basis. If none is declared, the old behaviour is preserved, i.e. looking for the most suitable one.As a bonus, immutable mutators could be supported (would be consistent with the support of call methods done on immutable objects cf. #313 (comment)).
Note that there is a subtlety here:
$username
refers to the value generated for theusername
property, which may differ from object property if it's passing by a setter altering the input@self->username
will ignore the value generated for theusername
property and instead will look for an accessorOptional method calls
As expressed in #249, it would be a nice feature to have optional method calls:
i.e. there is a probability of
80%
that thesetLocation
method is called with the given parameters. But the sad thing is that it would be impossible to do with the array syntax:Proposal:
Configurators (i.e. external service calls)
Update:
See #629 (comment) and #629 (comment).
With the support of multiple method calls and factory with external services, it would make sense to support configurators as well
Obviously support for static calls could be provided. The only thing expected from a configurator method is to take the object as an input and return the configured object.
The text was updated successfully, but these errors were encountered: