/** * {@inheritdoc} */ public function execute($entityType, $entity, $identifier) { $metadata = $this->metadataPool->getMetadata($entityType); $entity = $this->readMain->execute($entityType, $entity, $identifier); if (isset($entity[$metadata->getLinkField()])) { $entity = $this->readExtension->execute($entityType, $entity); $entity = $this->readRelation->execute($entityType, $entity); } return $entity; }
public function testExecute() { $entityType = 'Type'; $entity = new \stdClass(); $entityData = ['name' => 'test']; $entityHydrator = $this->getMockBuilder(EntityHydrator::class)->disableOriginalConstructor()->getMock(); $action = $this->getMockBuilder(\stdClass::class)->disableOriginalConstructor()->setMethods(['execute'])->getMock(); $this->metadataPoolMock->expects($this->once())->method('getHydrator')->willReturn($entityHydrator); $entityHydrator->expects($this->once())->method('extract')->with($entity)->willReturn($entityData); $this->extensionPoolMock->expects($this->once())->method('getActions')->with($entityType, 'read')->willReturn([$action]); $action->expects($this->once())->method('execute')->with($entityType, $entityData)->willReturn($entityData); $entityHydrator->expects($this->once())->method('hydrate')->with($entity, $entityData)->willReturn($entity); $this->assertEquals($entity, $this->readExtension->execute($entityType, $entity)); }
/** * @param string $entityType * @param array $entity * @param string $identifier * @param string $linkField * @dataProvider executeParameters */ public function testExecute($entityType, $entity, $identifier, $linkField) { $this->metadataPoolMock->expects($this->once())->method('getMetadata')->with($entityType)->willReturn($this->metadataMock); $entityWithMainRead = array_merge($entity, ['main_read' => 'some info']); $this->readMainMock->expects($this->once())->method('execute')->with($entityType, $entity, $identifier)->willReturn($entityWithMainRead); $this->metadataMock->expects($this->once())->method('getLinkField')->willReturn($linkField); $entityWithExtensionAndRelation = $entityWithMainRead; if (isset($entity[$linkField])) { $entityWithExtension = array_merge($entityWithMainRead, ['ext' => 'extParameter']); $this->readExtensionMock->expects($this->once())->method('execute')->with($entityType, $entityWithMainRead)->willReturn($entityWithExtension); $entityWithExtensionAndRelation = array_merge($entityWithExtension, ['relation' => 'some_relation']); $this->readRelationMock->expects($this->once())->method('execute')->with($entityType, $entityWithExtension)->willReturn($entityWithExtensionAndRelation); } $this->assertEquals($entityWithExtensionAndRelation, $this->read->execute($entityType, $entity, $identifier)); }