Repository navigation
[11.x] Chore: Decouple Str::random() from Validator - #56852
taylorotwell merged 3 commits into
Conversation
3110ff3 to
86f2449
Compare
|
Instead of changing this behaviour, I wonder if we should follow the existing pattern of introducing a static |
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 theValidatorcan 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 theValidatorclass' 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 successfulfails making assertions against the matching random strings due to theValidator::$placeholderHashalready being set in a preceding test.As the
$placeholderHashis 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
flushStatemethod to theValidatorclass and calls it from theInteractsWithTestCaseLifecycpetrait, inline with similar behaviour elsewhere in the framework, per @timacdonald's suggestion.