我在项目中更新了Doctrine 2.5到2.6并且phpspec被破坏了。
现在通过引用返回函数getEntityChangeSet()
。它似乎没有被phpspec支持。
$unitOfWork
->getEntityChangeSet($site)
->willReturn(['_dataParent' => [0 => 2, 1 => 3]]);
回应是
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];
}
你知道是否有可能绕过这个或改变测试以使其有效吗?
答案 0 :(得分:3)
答案已在Twitter上由@Pamilme
提供你必须使用Mockery模拟UnitOfWork。可以找到一个示例here:
/** @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);