-
Notifications
You must be signed in to change notification settings - Fork 11.5k
[11.x] Chore: Decouple Str::random() from Validator #56852
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
[11.x] Chore: Decouple Str::random() from Validator #56852
Conversation
3110ff3
to
86f2449
Compare
Instead of changing this behaviour, I wonder if we should follow the existing pattern of introducing a static framework/src/Illuminate/Foundation/Testing/Concerns/InteractsWithTestCaseLifecycle.php Lines 169 to 190 in c1b1628
|
I prefer your approach, but that (selfishly) won't save me for 11.x as it doesn't exist until 12.x. I suppose it's debatable whether #54845 is a bug to be fixed within the bug fix window or not. It could be that the inline random is used and merged-forward to 12.x and the Moot point but the |
Do you meant the trait or something else? The trait has been there since 10x: https://github.com/laravel/framework/blob/10.x/src/Illuminate/Foundation/Testing/Concerns/InteractsWithTestCaseLifecycle.php#L157-L166 |
Oh, I am blind. I was looking in |
86f2449
to
178ce52
Compare
PR: laravel/framework#56852 Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
* [9.x] Supports flushing Validator state PR: laravel/framework#56852 Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com> * wip Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com> * wip --------- Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
The use of
Str::random()
within theValidator
can lead to non-deterministic test outcomes when using random string mocking such asStr::createRandomStringsUsing()
orStr::createRandomStringsUsingSequence()
.For example, with a test file that contains a set of tests as follows:
When accounting for the call to
Str::random()
within theValidator
class' constructor, the test will pass in isolation i.e. filtering to only runthe thing was successful
.If, however, the test file or the full test is run,
the thing was successful
fails making assertions against the matching random strings due to theValidator::$placeholderHash
already being set in a preceding test.As the
$placeholderHash
is a static property, the state persists through a single test process, which is why it impacts file, folder, and suite, but not a single test.This PR adds a
flushState
method to theValidator
class and calls it from theInteractsWithTestCaseLifecycpe
trait, inline with similar behaviour elsewhere in the framework, per @timacdonald's suggestion.