Hi all I need to test a piece of code that call a function of another class that I can't edit now.
I need only to test It but the problem is that this function has a values passed by reference and a value returned, so I don't know how to mock It.
This is the function of column class:
public function functionWithValuePassedByReference(&$matches = null)
{
$regex = 'my regex';
return ($matches === null) ? preg_match($regex, $this->field) : preg_match($regex, $this->field, $matches);
}
This is the point where is called and where I need to mock:
$matches = [];
if ($column->functionWithValuePassedByReference($matches)) {
if (strtolower($matches['parameters']) == 'distinct') {
//my code
}
}
So I have tried
$this->columnMock = $this->createMock(Column::class);
$this->columnMock
->method('functionWithValuePassedByReference')
->willReturn(true);
If I do this return me error that index parameters doesn't exist obviously so I have tried this:
$this->columnMock = $this->createMock(Column::class);
$this->columnMock
->method('functionWithValuePassedByReference')
->with([])
->willReturn(true);
But same error, how can I mock that function?
Thanks