'PHPSpec: function returning by reference

I updated Doctrine 2.5 to 2.6 in my project and phpspec is broken.

The function getEntityChangeSet() is now returned by reference. It seems not to be supported by phpspec.

$unitOfWork
    ->getEntityChangeSet($site)
    ->willReturn(['_dataParent' => [0 => 2, 1 => 3]]);

The response is returning by reference not supported

the underlying function (doctrine/doctrine2) is

public function & getEntityChangeSet($entity)
{
    $oid  = spl_object_hash($entity);
    $data = [];

    if (!isset($this->entityChangeSets[$oid])) {
        return $data;
    }

    return $this->entityChangeSets[$oid];
}

Do you know if it's possible to bypass this or change test for make it work?



Solution 1:[1]

if you extends TestCase on your test class, you can also do something like:

$uow = $this->createMock(UnitOfWork::class);
$uow->method('getEntityChangeSet')->willReturn(['_dataParent' => [0 => 2, 1 => 3]);

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 lemospy