Skip to content

argument not modified when passed by reference to a mocked method in an overloaded class #1440

@davidcoutadeur

Description

@davidcoutadeur

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugAn error or unexpected behavior.help wantedContributions are welcome! Feel free to open a pull request to help resolve this issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions