Esempio n. 1
0
 /**
  * @param string $entityType
  * @param object $entity
  * @return void
  */
 public function registerSnapshot($entityType, $entity)
 {
     $metadata = $this->metadataPool->getMetadata($entityType);
     $hydrator = $this->metadataPool->getHydrator($entityType);
     $entityData = $hydrator->extract($entity);
     $attributes = $this->attributeProvider->getAttributes($entityType);
     $this->snapshotData[$entityType][$entityData[$metadata->getIdentifierField()]] = array_intersect_key($entityData, $attributes);
 }
 public function testGetAttributes()
 {
     $entityType = 'Product';
     $entityTable = 'entity_table';
     $linkField = 'some_id';
     $identifierField = 'id';
     $metadata = $this->getMockBuilder(EntityMetadata::class)->disableOriginalConstructor()->getMock();
     $attributes = ['test' => 1];
     $this->metadataPoolMock->expects($this->atLeastOnce())->method('getMetadata')->willReturn($metadata);
     $connection = $this->getMockBuilder(AdapterInterface::class)->getMockForAbstractClass();
     $metadata->expects($this->once())->method('getEntityConnection')->willReturn($connection);
     $metadata->expects($this->once())->method('getEntityTable')->willReturn($entityTable);
     $metadata->expects($this->exactly(2))->method('getLinkField')->willReturn($linkField);
     $metadata->expects($this->once())->method('getIdentifierField')->willReturn($identifierField);
     $connection->expects($this->once())->method('describeTable')->with($entityTable)->willReturn([]);
     $this->objectManagerMock->expects($this->once())->method('get')->with(AttributeProviderInterface::class)->willReturn($this->concreteAttributeProviderMock);
     $this->concreteAttributeProviderMock->expects($this->once())->method('getAttributes')->with($entityType)->willReturn($attributes);
     $this->assertEquals($attributes, $this->attributeProvider->getAttributes($entityType));
 }