Skip to content

Unify structure for ext/random's randomizer tests #9410

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

Merged
merged 3 commits into from
Aug 31, 2022

Conversation

TimWolla
Copy link
Member

@TimWolla TimWolla commented Aug 23, 2022

This is a work-in-progress follow-up for #9321:

This PR makes a sweeping change across all tests in ext/random/tests/03_randomizer to achieve a uniform appearance:

  • Use a descriptive test title.
  • Import all classes with use to reduce the visual noise within the test for repeated references to specific classes.
  • Do not use the backslash in front of function calls for consistency with tests elsewhere.
  • Do not use anonymous classes to give each engine a descriptive name.
  • Use echo $e->getMessage(), PHP_EOL; with a comma to dump error messages.
  • Use var_dump() to output randomizer values.
  • Use ->getInt(0, $i) for generic verification purposes, unless a specific method is tested.
  • Split tests to make them easier to grasp (e.g. one test per method instead of the big basic.phpt).
  • Test with varying parameters (dependent of $i), instead of testing multiple times with the same parameters to ensure the methods work correctly with different boundaries.
  • Reorganize the filesystem structure to make tests easier to find.
  • Create reusable userland engines for testing purposes.

TimWolla added a commit to TimWolla/php-src that referenced this pull request Aug 24, 2022
This fixes an incompatibility when wrapping native 32-bit engines with a userland
engine. The latter always used the 64-bit range function which then used two
32-bit numbers from the underlying engine to fill the 64-bit range, whereas the
native implementation used only one.

Now the selection of the range variant only depends on the requested range. A
32-bit range uses the 32-bit variant (even for 64-bit engines), whereas a
larger range uses the 64-bit variant.

This was found in php#9410 (comment)
TimWolla added a commit to TimWolla/php-src that referenced this pull request Aug 24, 2022
This fixes an incompatibility when wrapping native 32-bit engines with a userland
engine. The latter always used the 64-bit range function which then used two
32-bit numbers from the underlying engine to fill the 64-bit range, whereas the
native implementation used only one.

Now the selection of the range variant only depends on the requested range. A
32-bit range uses the 32-bit variant (even for 64-bit engines), whereas a
larger range uses the 64-bit variant.

This was found in php#9410 (comment)
@TimWolla TimWolla force-pushed the random-test-cleanup2 branch from aca8f15 to 8304060 Compare August 24, 2022 14:30
TimWolla added a commit that referenced this pull request Aug 25, 2022
)

This fixes an incompatibility when wrapping native 32-bit engines with a userland
engine. The latter always used the 64-bit range function which then used two
32-bit numbers from the underlying engine to fill the 64-bit range, whereas the
native implementation used only one.

Now the selection of the range variant only depends on the requested range. A
32-bit range uses the 32-bit variant (even for 64-bit engines), whereas a
larger range uses the 64-bit variant.

This was found in #9410 (comment)
@TimWolla TimWolla force-pushed the random-test-cleanup2 branch from 8304060 to f0765a0 Compare August 25, 2022 10:16
@TimWolla TimWolla force-pushed the random-test-cleanup2 branch from f0765a0 to 78dbe19 Compare August 25, 2022 11:23
@TimWolla TimWolla marked this pull request as ready for review August 25, 2022 12:51
@TimWolla TimWolla requested a review from zeriyoshi August 25, 2022 12:51
@TimWolla
Copy link
Member Author

@zeriyoshi This is now ready. I did a full sweeping change across all the randomizer tests to unify them and make them easier to understand and maintain (especially if new methods are added in the future). I recommend checking out the branch locally and not attempting to use the GitHub web interface to review.

@TimWolla
Copy link
Member Author

TimWolla commented Aug 29, 2022

@zeriyoshi Friendly ping. Are you able to look into this before the RC 1 tomorrow? If there's something you're unhappy with, then that's fine, just comment and I'll fix.

Copy link
Contributor

@zeriyoshi zeriyoshi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!
Apologies for the delay in review due to move. Thanks again!

@TimWolla TimWolla changed the base branch from master to PHP-8.2 August 31, 2022 07:08
@TimWolla
Copy link
Member Author

@saundefined @ramsey @adoy This PR cleans up and reorganizes the tests for the new-in-PHP-8.2 ext/random to make them easier to maintain in the long run and to make them more reliable. It does not introduce any functional changes whatsoever.

I would expect that this is fine to merge into PHP-8.2 as-is, because merging into master only will create a chaos for 8.2 → master merges, but I'd like to have your confirmation to be sure.

@adoy
Copy link
Member

adoy commented Aug 31, 2022

No problem for 8.2 you can go ahead with it. Thanks

@TimWolla
Copy link
Member Author

@adoy Thanks for the confirmation, I'll handle the merge tonight.

@TimWolla TimWolla merged commit f7d426c into php:PHP-8.2 Aug 31, 2022
TimWolla added a commit that referenced this pull request Aug 31, 2022
* PHP-8.2:
  Unify structure for ext/random's randomizer tests (#9410)
@TimWolla TimWolla deleted the random-test-cleanup2 branch August 31, 2022 17:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants