-
Notifications
You must be signed in to change notification settings - Fork 11.2k
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
[9.x] Add additional uuid testing helpers #42619
Conversation
Please feel free to suggest / improve the naming. Went down the rabbit hole of "recycle" like words, but this felt the best at the end of the day for me. |
|
* Set the sequence that will be used to generate UUIDs. | ||
* | ||
* @param array $sequence | ||
* @param callable|null $whenMissing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any chance to change the callable
type hint to something static analysis better understands? The recent updates to the Collections doc blocks were a really nice QoL improvement and I'd love for more code to be annotated like that :)
/**
* @param null|callable(): UuidInterface $whenMissing
*/
Same for all the other methods that take a callback as a parameter.
Str::createUuidsNormally(); | ||
} | ||
|
||
public function testItCanSpecifyASquenceOfUuidsToUtilise() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo in Squence
|
||
$retrieved = Str::uuid(); | ||
$this->assertSame($zeroth, $retrieved); | ||
$this->assertSame((string) $zeroth, (string) $retrieved); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the second assertion necessary? We're already checking that they're the same instance.
I think I prefer |
If we dig this, I’ll submit another for |
* add uuid testing helpers * allow devs to handle empty sequences * cleanup in case * docblocks
This PR adds some testing helpers to the generation of UUIDs via the
Str
helper.Currently in order to control UUID creation, you need to do the following...
This locks the helper so that it only returns the one UUID throughout the whole process.
I find myself always having to re-learn how this works and that I have to capture a UUID first or needing to fake a specific UUID generation.
With this PR the following is now possible...
You may also pass a closure to only freeze creation for the duration of the closure...
Finally, it is also possible to provide a sequence of UUIDs to return.
You may specify the keys if there are only certain instances you wish to sequence....
If you would like to throw an exception when there is no more UUIDs in the array, you pass a closure to control what happens when finding an index that has no specified UUID...
This closure is also called when there is a missing key if you specify specific keys in the sequence...