Ejemplo n.º 1
0
 /**
  * {@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'];
     $id = 1;
     $entityHydrator = $this->getMockBuilder(EntityHydrator::class)->disableOriginalConstructor()->getMock();
     $this->metadataPoolMock->expects($this->once())->method('getHydrator')->willReturn($entityHydrator);
     $entityHydrator->expects($this->once())->method('hydrate')->with($entity, $entityData)->willReturn($entity);
     $this->readEntityRowMock->expects($this->once())->method('execute')->with($entityType, $id)->willReturn($entityData);
     $this->assertEquals($entity, $this->readMain->execute($entityType, $entity, $id));
 }
Ejemplo n.º 3
0
 /**
  * @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));
 }