How to mock a function that a variable is passed by reference using PHPUnit?

My code looks something like this:

class A
{
    function foo(&$a, $b)
    {
        if ($a == 0) {
            return false;
        } else {
            $a = $b + 1;
            return true;
        }
    }
}

class B
{
    function foo1($a, $b)
    {
        $a = new A;
        $a->foo($a, $b);
        if ($a == 0) {
            return false;
        }
        echo $a;
        return true;
    }
}

I need to get the value $a.
How to mock a function foo()?

+5
source share
1 answer

PHPUnit clones the arguments before passing them to the bullying method. For primitive arguments, there is no need to work, but for objects, you can add a non-public method__clone to block this behavior.

+1
source

All Articles