class:
class TestMe
{
public function m1 (array &$a)
{
}
public function m2 (array &$a)
{
}
public function methodd()
{
$a = array();
$this->m1 ($a);
$this->m2 ($a);
return $a;
}
}
test:
class X extends PHPUnit_Framework_TestCase
{
public function testMethod()
{
$mock = $this->getMock('TestMe', array('m1','m2'));
$mock->expects($this->once())->method('m1')->with(array())->willReturnCallback(function (&$x) { $x['a'] = 1; });
$mock->expects($this->once())->method('m2')->with(array('a' => 1))->willReturnCallback(function (&$x) { $x['b'] = 2; });
$x = $mock->methodd();
$this->assertEquals (array('a' => 1, 'b' => 2), $x);
}
}
somehow it fails:
There was 1 failure:
1) X::testMethod Expectation failed for method name is equal to when invoked 1 time(s). Parameter 0 for invocation TestMe::m1(Array (...)) does not match expected value. Failed asserting that two arrays are equal. --- Expected +++ Actual @@ @@ Array ( + 'a' => 1 + 'b' => 2 )
FAILURES! Tests: 1, Assertions: 2, Failures: 1.
I dont know what it can be. In other words, I want to modify a "reference" parameter, and check it :)