Skip to content

Conversation

@vlakoff
Copy link
Contributor

@vlakoff vlakoff commented Nov 16, 2025

Fixes #176.

The test previously seeded error locations with:

do {
    $errorLocation = mt_rand(0, $blockSize);
} while (0 !== $errorLocations[$errorLocation]);

This allowed $errorLocation to equal $blockSize, which is out of range for an array of length $blockSize (valid indices are 0 … $blockSize - 1).

  • With MT_RAND_PHP, the upper bound was not hit in practice.
  • With MT_RAND_MT19937, the upper bound is reached, causing an OutOfBoundsException.

Fix: Correct the upper bound to $blockSize - 1:

do {
    $errorLocation = mt_rand(0, $blockSize - 1);
} while (0 !== $errorLocations[$errorLocation]);

- Switched RNG to the default MT_RAND_MT19937 (removed deprecated MT_RAND_PHP).
- Fixed off-by-one in mt_rand(0, $blockSize) — the upper bound was not hit with the previous mode, but is reached with MT_RAND_MT19937, causing OutOfBoundsException. Changed to mt_rand(0, $blockSize - 1).
@vlakoff
Copy link
Contributor Author

vlakoff commented Nov 16, 2025

By the way, this code is useless and looks like some sort of leftover:

if ($actual !== $expected) {
$array->getNextSet($query);
}

@codecov
Copy link

codecov bot commented Nov 16, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 70.58%. Comparing base (bd2370d) to head (f64a4f4).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##               main     #208   +/-   ##
=========================================
  Coverage     70.58%   70.58%           
  Complexity      995      995           
=========================================
  Files            49       49           
  Lines          3182     3182           
=========================================
  Hits           2246     2246           
  Misses          936      936           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@DASPRiD
Copy link
Member

DASPRiD commented Nov 16, 2025

By the way, this code is useless and looks like some sort of leftover:

if ($actual !== $expected) {
$array->getNextSet($query);
}

You are right, looking at the source test, that line does not exist and can be removed.

@DASPRiD
Copy link
Member

DASPRiD commented Nov 16, 2025

LGTM, you can remove that useless test code in another PR :)

@DASPRiD DASPRiD changed the title fix(tests): remove deprecated MT_RAND_PHP and fix mt_rand() upper bound test: remove deprecated MT_RAND_PHP and fix mt_rand() upper bound Nov 16, 2025
@DASPRiD DASPRiD merged commit 50e742e into Bacon:main Nov 16, 2025
9 checks passed
vlakoff added a commit to vlakoff/BaconQrCode that referenced this pull request Nov 16, 2025
As discussed in PR Bacon#208, lines 114–116 in BitArrayTest.php are useless
and appear to be leftover code. They do not exist in the source test
logic and can safely be removed.
DASPRiD pushed a commit that referenced this pull request Nov 16, 2025
As discussed in PR #208, lines 114–116 in BitArrayTest.php are useless
and appear to be leftover code. They do not exist in the source test
logic and can safely be removed.
@vlakoff vlakoff deleted the fix/tests-mt_rand branch November 16, 2025 18:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use of deprecated constant MT_RAND_PHP in tests

2 participants