PHPSpec:通过引用返回的函数

Rom*_*D69 3 php phpspec doctrine-orm

我在项目中将 Doctrine 2.5 更新为 2.6,但 phpspec 已损坏。

该函数getEntityChangeSet()现在通过引用返回。phpspec 似乎不支持。

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

响应是 returning by reference not supported

底层函数(doctrine/doctrine2)是

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

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

    return $this->entityChangeSets[$oid];
}
Run Code Online (Sandbox Code Playgroud)

您知道是否可以绕过这个或更改测试以使其工作?

sf_*_*anb 5

@Pamilme在 Twitter 上给出了答案

您必须使用 Mockery 来模拟 UnitOfWork。可以在这里找到一个例子:

    /** @var UnitOfWork|MockInterface $unitOfWork */
    $unitOfWork = Mockery::mock(UnitOfWork::class);
    $unitOfWork->shouldReceive('getEntityChangeSet')->withArgs([$productAttribute->getWrappedObject()])->andReturn([
        'configuration' => [
            ['choices' => [
                '8ec40814-adef-4194-af91-5559b5f19236' => 'Banana',
                '1739bc61-9e42-4c80-8b9a-f97f0579cccb' => 'Pineapple',
            ]],
            ['choices' => [
                '8ec40814-adef-4194-af91-5559b5f19236' => 'Banana',
            ]],
        ],
    ]);
    $entityManager->getUnitOfWork()->willReturn($unitOfWork);
Run Code Online (Sandbox Code Playgroud)