[Core] Fix Helper::numerify#256
Merged
pimjansen merged 1 commit intoFakerPHP:mainfrom Jan 13, 2021
Merged
Conversation
|
Do we have an example on the diff output of botht he old and new method? |
Author
To reproduce this you can try Factory::create()->seed(1);
echo Helper::numerify('##########'); // "0000000050"
echo BaseProvider::numerify('##########'); // "7203244899" |
pimjansen
approved these changes
Jan 13, 2021
|
Thanks! |
Author
|
Thanks @pimjansen |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What is the reason for this PR?
There's a bug in
Helper::numerifycaused by a - compared toBase::numerify- changed use of mt_rand:Base::numerifyusesrandomNumber($size), where the argument$sizeis the number of digits whileHelper::numerifyusesmt_rand(0, $size), where$sizeis the highest possible value to be returned.Thus executing
Helper::numerify(str_repeat('#', 10))always returns strings like0000000050:Author's checklist
Summary of changes
This PR fixes the issue and adds a test to verify functionality. The test is based on a very high probability that
Helper::numerify(str_repeat('#', 10))should return large numbers.Since
mt_rand(0, 10 ** $size - 1)is not as easy to read asstatic::randomNumber($size)(at least for me), I'd be in favor of replacing the change done with this PR once the number extension is implemented, but this is out of scope for this bugfix PR.Review checklist