argument not modified when passed by reference to a mocked method in an overloaded class
Author: davidcoutadeurCreated Sep 20, 2024Updated Mar 20, 2026
LabelsBughelp wanted
Mockery Version
1.6.12
PHP Version
PHP 8.3
Issue Description
When using a Mockery::on closure for modifying the value of an argument passed by reference, the value is not modified in the original function.
Important notice: the context is a class mocked with ":overload"
$phpLDAPMock = Mockery::mock('overload:\Ltb\PhpLDAP');Here is the code that is not working:
$phpLDAPMock->shouldreceive('ldap_parse_result')
->with("ldap_connection", "ldap_search_result1", null, null, null, null,
\Mockery::on(function(&$control) use(&$returnedcontrol1, &$returnedcontrol2, &$control1, &$control2){
$cookie = $control[0]['value']['cookie'];
switch ($cookie) {
case $control1[0]['value']['cookie']:
$control = $returnedcontrol1;
// Here, $control contains the correct value,
// but back in the ldap_parse_result function, the value is unchanged
return true;
case $control2[0]['value']['cookie']:
$control = $returnedcontrol2;
return true;
default:
return false;
}
})
);Steps to Reproduce
No response
Expected Behavior
No response
Actual Behavior
No response
Exception or Error
No response
Additional Information
No response
Source: mockery/mockery