public function testTransform()
 {
     $srcHandler = $this->initHandler($this->sourceDocument, 0);
     $destHandler = $this->initHandler($this->destDocument, 1);
     $this->recordTransformer->init();
     $recordFrom = $this->getMock('Migration\\Resource\\Record', [], [], '', false);
     $recordFrom->expects($this->any())->method('getFields')->will($this->returnValue(['field1', 'field2']));
     $recordTo = $this->getMock('Migration\\Resource\\Record', [], [], '', false);
     $recordTo->expects($this->any())->method('getFields')->will($this->returnValue(['field3']));
     $field2Handler = $this->getMock('Migration\\Handler\\SetValue', ['handle'], [], '', false);
     $field2Handler->expects($this->once())->method('handle');
     $srcHandler->expects($this->any())->method('getHandlers')->willReturn(['field2' => $field2Handler]);
     $destHandler->expects($this->any())->method('getHandlers')->willReturn([]);
     $this->recordTransformer->transform($recordFrom, $recordTo);
 }
 /**
  * @return void
  */
 public function testTransform()
 {
     $srcHandler = $this->initHandler($this->sourceDocument, 0);
     $destHandler = $this->initHandler($this->destDocument, 1);
     $this->recordTransformer->init();
     $this->sourceDocument->expects($this->any())->method('getName')->willReturn('source_document_name');
     $recordFrom = $this->getMock('Migration\\ResourceModel\\Record', [], [], '', false);
     $recordFrom->expects($this->any())->method('getFields')->will($this->returnValue(['field1', 'field2']));
     $recordFrom->expects($this->any())->method('getData')->will($this->returnValue(['field1' => 1, 'field2' => 2]));
     $recordTo = $this->getMock('Migration\\ResourceModel\\Record', [], [], '', false);
     $recordTo->expects($this->any())->method('getFields')->will($this->returnValue(['field2']));
     $recordTo->expects($this->any())->method('setData')->with(['field2' => 2]);
     $field2Handler = $this->getMock('Migration\\Handler\\SetValue', ['handle'], [], '', false);
     $field2Handler->expects($this->once())->method('handle');
     $srcHandler->expects($this->any())->method('getHandlers')->willReturn(['field2' => $field2Handler]);
     $destHandler->expects($this->any())->method('getHandlers')->willReturn([]);
     $this->mapReader->expects($this->any())->method('getFieldMap')->with('source_document_name', 'field1')->willReturnArgument(1);
     $this->recordTransformer->transform($recordFrom, $recordTo);
 }
Пример #3
0
 /**
  * @param array $data
  * @param Resource\Document $sourceDocument
  * @param Resource\Document $destDocument
  * @param \Migration\RecordTransformer $recordTransformer
  * @param Resource\Record\Collection $destinationRecords
  * @return void
  */
 protected function transformData($data, $sourceDocument, $destDocument, $recordTransformer, $destinationRecords)
 {
     if ($recordTransformer) {
         $record = $this->recordFactory->create(['document' => $sourceDocument, 'data' => $data]);
         $destRecord = $this->recordFactory->create(['document' => $destDocument]);
         $recordTransformer->transform($record, $destRecord);
     } else {
         $destRecord = $this->recordFactory->create(['document' => $destDocument, 'data' => $data]);
     }
     $destinationRecords->addRecord($destRecord);
 }