Example #1
0
 public function testExecute()
 {
     $entityType = 'Type';
     $entity = new \stdClass();
     $action = $this->getMockBuilder(\stdClass::class)->disableOriginalConstructor()->setMethods(['execute'])->getMock();
     $this->relationActionPoolMock->expects($this->once())->method('getActions')->with($entityType, 'read')->willReturn([$action]);
     $action->expects($this->once())->method('execute')->with($entityType, $entity)->willReturn($entity);
     $this->assertEquals($entity, $this->readRelation->execute($entityType, $entity));
 }
Example #2
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;
 }
 /**
  * @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));
 }