Page MenuHomePhabricator

Fix RandomImageGenerator as used in tests to work on PHP 8.1 without errors or warnings
Closed, ResolvedPublic

Description

Two Implicit conversion from float warnings:

00:02:55.325 1) AbuseFilterConsequencesTest::testFilterConsequences with data set "Test upload action" (array(5), array('upload', 'File:MyFile.svg'), array(array(5)))
00:02:55.325 Implicit conversion from float 40.840696 to int loses precision
00:02:55.332 
00:02:55.332 /workspace/src/tests/phpunit/includes/api/RandomImageGenerator.php:182
00:02:55.332 /workspace/src/tests/phpunit/includes/api/RandomImageGenerator.php:96
00:02:55.332 /workspace/src/extensions/AbuseFilter/tests/phpunit/AbuseFilterUploadTestTrait.php:48
00:02:55.332 /workspace/src/extensions/AbuseFilter/tests/phpunit/AbuseFilterConsequencesTest.php:578
00:02:55.332 /workspace/src/extensions/AbuseFilter/tests/phpunit/AbuseFilterConsequencesTest.php:822
00:02:55.332 /workspace/src/tests/phpunit/MediaWikiIntegrationTestCase.php:516
00:02:55.332 === Logs generated by test case
00:02:55.332 [objectcache] [debug] MainWANObjectCache using store {class} {"class":"EmptyBagOStuff"}
00:02:55.332 [localisation] [debug] LocalisationCache using store LCStoreNull []
00:02:55.332 [UserOptionsManager] [debug] Loading options from database {"user_id":2}
00:02:55.332 [GlobalTitleFail] [info] RequestContext::getTitle called with no title set. {"exception":{}}
00:02:55.332 [DeferredUpdates] [debug] DeferredUpdates::run: started MWCallableUpdate_MediaWiki\Extension\Notifications\Hooks::onUserSaveSettings #38868 []
00:02:55.333 [DeferredUpdates] [debug] DeferredUpdates::run: ended MWCallableUpdate_MediaWiki\Extension\Notifications\Hooks::onUserSaveSettings #38868, processing time: 0.00037789344787598 []
00:02:55.333 [DeferredUpdates] [debug] DeferredUpdates::run: started MWCallableUpdate_MediaWiki\User\UserGroupManager->addUserToGroup #38897 []
00:02:55.333 [DeferredUpdates] [debug] DeferredUpdates::run: ended MWCallableUpdate_MediaWiki\User\UserGroupManager->addUserToGroup #38897, processing time: 0.00066900253295898 []
00:02:55.333 [localisation] [debug] LocalisationCache using store LCStoreNull []
00:02:55.333 [objectcache] [debug] MainWANObjectCache using store {class} {"class":"EmptyBagOStuff"}
00:02:55.333 [wfDebug] [debug] wfRecursiveRemoveDir( /tmp/MW_PHPUnit_AbuseFilterConsequencesTest_VhSdhE ) {"private":false}
00:02:55.333 2) AbuseFilterConsequencesTest::testFilterConsequences with data set "Test upload action 2" (array(22), array('upload', 'File:MyFile.svg', 'Block me please!', 'Asking to be blocked'), array(array(22)))
00:02:55.333 Implicit conversion from float 196.3495 to int loses precision
00:02:55.333 
00:02:55.333 /workspace/src/tests/phpunit/includes/api/RandomImageGenerator.php:182
00:02:55.333 /workspace/src/tests/phpunit/includes/api/RandomImageGenerator.php:96
00:02:55.333 /workspace/src/extensions/AbuseFilter/tests/phpunit/AbuseFilterUploadTestTrait.php:48
00:02:55.333 /workspace/src/extensions/AbuseFilter/tests/phpunit/AbuseFilterConsequencesTest.php:578
00:02:55.333 /workspace/src/extensions/AbuseFilter/tests/phpunit/AbuseFilterConsequencesTest.php:822
00:02:55.333 /workspace/src/tests/phpunit/MediaWikiIntegrationTestCase.php:516
00:02:55.333 === Logs generated by test case
00:02:55.333 [objectcache] [debug] MainWANObjectCache using store {class} {"class":"EmptyBagOStuff"}
00:02:55.333 [localisation] [debug] LocalisationCache using store LCStoreNull []
00:02:55.333 [UserOptionsManager] [debug] Loading options from database {"user_id":2}
00:02:55.333 [GlobalTitleFail] [info] RequestContext::getTitle called with no title set. {"exception":{}}
00:02:55.333 [DeferredUpdates] [debug] DeferredUpdates::run: started MWCallableUpdate_MediaWiki\Extension\Notifications\Hooks::onUserSaveSettings #37135 []
00:02:55.333 [DeferredUpdates] [debug] DeferredUpdates::run: ended MWCallableUpdate_MediaWiki\Extension\Notifications\Hooks::onUserSaveSettings #37135, processing time: 0.00036907196044922 []
00:02:55.333 [DeferredUpdates] [debug] DeferredUpdates::run: started MWCallableUpdate_MediaWiki\User\UserGroupManager->addUserToGroup #37134 []
00:02:55.333 [DeferredUpdates] [debug] DeferredUpdates::run: ended MWCallableUpdate_MediaWiki\User\UserGroupManager->addUserToGroup #37134, processing time: 0.00060200691223145 []
00:02:55.333 [wfDebug] [debug] wfRecursiveRemoveDir( /tmp/MW_PHPUnit_AbuseFilterConsequencesTest_wfVBXT ) {"private":false}

Event Timeline

Looks like it's core's RandomImageGenerator that needs to be fixed. The offending line (182) is:

$angle = mt_rand( 0, ( 3.141592 / 2 ) * $radius ) / $radius;

mt_rand takes an integer as second parameter, and for this call, the second argument is most likely not an integer. Also, this code should use pi() or M_PI instead of manually approximating pi...

Looks like it's core's RandomImageGenerator that needs to be fixed. The offending line (182) is:

$angle = mt_rand( 0, ( 3.141592 / 2 ) * $radius ) / $radius;

mt_rand takes an integer as second parameter, and for this call, the second argument is most likely not an integer. Also, this code should use pi() or M_PI instead of manually approximating pi...

Aha, yeah. Also also, I was about to file a similar task for RCFilters's use of the same.

Jdforrester-WMF renamed this task from Fix AbuseFilter's test suite to work on PHP 8.1 without errors or warnings to Fix RandomImageGenerator as used in tests to work on PHP 8.1 without errors or warnings.Oct 13 2022, 2:01 PM
Jdforrester-WMF edited projects, added MediaWiki-Core-Tests; removed AbuseFilter.

Change 842458 had a related patch set uploaded (by Jforrester; author: Jforrester):

[mediawiki/core@master] RandomImageGenerator::getImageSpec: Don't pass a float to mt_rand(), for PHP 8.1

https://gerrit.wikimedia.org/r/842458

Change 842458 merged by jenkins-bot:

[mediawiki/core@master] RandomImageGenerator::getImageSpec: Don't pass a float to mt_rand(), for PHP 8.1

https://gerrit.wikimedia.org/r/842458

tstarling claimed this task.
tstarling subscribed.

Reproduced, confirmed the fix

Change 849076 had a related patch set uploaded (by Reedy; author: Jforrester):

[mediawiki/core@REL1_39] RandomImageGenerator::getImageSpec: Don't pass a float to mt_rand(), for PHP 8.1

https://gerrit.wikimedia.org/r/849076

Change 849076 merged by jenkins-bot:

[mediawiki/core@REL1_39] RandomImageGenerator::getImageSpec: Don't pass a float to mt_rand(), for PHP 8.1

https://gerrit.wikimedia.org/r/849076