sebastianbergmann/phpunit-mock-objects — Issue #81: Arguments that are passed by reference are not handled properly
Author: sebastianbergmann
Created: 2012-02-06 11:38:19+00:00
State: open

➜ ~ cat Test.php
getMockBuilder('Foo')
->disableOriginalConstructor()
->disableArgumentCloning()
->getMock();

$foo->expects($this->any())
->method('bar')
->will($this->returnCallback(array($this, 'callback')));

$a = $b = $c = 0;

$foo->bar($a, $b, $c);

$this->assertEquals(1, $b);
}

public function testCallback2() {
$foo = $this->getMockBuilder('Foo')
->disableOriginalConstructor()
->disableArgumentCloning()
->getMock();

$foo->expects($this->any())
->method('bar')
->will($this->returnCallback(
function ($a, &$b, $c) {
$b = 1;
}
));

$a = $b = $c = 0;

$foo->bar($a, $b, $c);

$this->assertEquals(1, $b);
}

public function callback($a, &$b, $c) {
$b = 1;
}
}

➜ ~ phpunit Test
PHPUnit @package_version@ by Sebastian Bergmann.

EE

Time: 0 seconds, Memory: 4.50Mb

There were 2 errors:

1) Test::testCallback
Parameter 2 to Test::callback() expected to be a reference, value given

/home/sb/Test.php:21

2) Test::testCallback2
Parameter 2 to Test::{closure}() expected to be a reference, value given

/home/sb/Test.php:42

FAILURES!
Tests: 2, Assertions: 0, Errors: 2.