Closed lukeraymonddowning closed 4 years ago
@bradroberts @AlanHolmes @andreich1980
Here is my work on defaults for issue #50
A lot of changes here so I would appreciate feedback and suggestions 👍
Read through the code. Everything seems fine. Created a test for that case.
This PR should also fix a problem described in #42 Do I have rights to commit to this PR (I'd like to add a test for that)? Or I should create my own new PR for that? @lukeraymonddowning ?
Do I have rights to commit to this PR (I'd like to add a test for that)? Or I should create my own new PR for that? @lukeraymonddowning ?
I think you should have rights here @andreich1980 👍
Code looks good to me 👍 (not had chance to test it)
Conflicting files tests/storage/composer.json @lukeraymonddowning you can leave only
"autoload"
and throw out"autoload-dev"
from thetests/storage/composer.json
My bad, I commited two versions via two my PRs.
And we have liftoff! Thanks all.
After using Poser for a while, you may wish to provide default relationships that should be applied every time we create a model. For example, in our examples, a
Customer
requires a relatedUser
model. To facilitate this, Poser understands adefault[RelationshipType][RelationshipMethodName]
syntax inside Poser Factories. To illustrate:Now, every time we call...
...a
User
calledJoe Bloggs
will be automatically assigned to the customer. However, if we call......the default will be ignored and instead a
User
called "John Doe" will be assigned to theCustomer
.For with/has relationship types, the case is much the same:
In this case, when we call
UserFactory::new()->create()
, it will be given anAddress
and 10Customer
s.If we would like to ignore your defaults for a given test, simply chain the
withoutDefaults
method to your Factory. call.This will create a
User
with noAddress
orCustomer
s. If you would only like to ignore certain defaults, you may pass them as properties to thewithoutDefaults
method.Now, our created
User
will have noCustomer
s but will have a defaultAddress
.