예제 #1
0
 public function testHandle()
 {
     /** @var Record|\PHPUnit_Framework_MockObject_MockObject $recordToHandle */
     $recordToHandle = $this->getMockBuilder('Migration\\Resource\\Record')->setMethods(['getValue', 'setValue', 'getFields'])->disableOriginalConstructor()->getMock();
     /** @var Record $oppositeRecord|\PHPUnit_Framework_MockObject_MockObject */
     $oppositeRecord = $this->getMockBuilder('Migration\\Resource\\Record')->disableOriginalConstructor()->getMock();
     $fieldName = 'fieldname';
     $recordToHandle->expects($this->once())->method('getFields')->will($this->returnValue([$fieldName]));
     $recordToHandle->expects($this->once())->method('getValue')->with($fieldName)->will($this->returnValue('SELECT * FROM `source_some_document` LEFT JOIN `source_other_document`'));
     $recordToHandle->expects($this->once())->method('setValue')->with($fieldName, 'SELECT * FROM `pfx_dest_some_document` LEFT JOIN `pfx_dest_other_document`');
     $this->map->expects($this->any())->method('getDocumentMap')->willReturnMap([['source_some_document', MapInterface::TYPE_SOURCE, 'dest_some_document'], ['source_other_document', MapInterface::TYPE_SOURCE, 'dest_other_document'], ['source_ignored_document', MapInterface::TYPE_SOURCE, false]]);
     $this->source->expects($this->once())->method('getDocumentList')->will($this->returnValue(['source_some_document', 'source_other_document', 'source_ignored_document']));
     $this->source->expects($this->any())->method('addDocumentPrefix')->will($this->returnArgument(0));
     $this->handler->setField($fieldName);
     $this->handler->handle($recordToHandle, $oppositeRecord);
 }
 /**
  * @return void
  */
 public function testHandle()
 {
     $fieldNameRuleId = 'rule_id';
     $fieldNameForNormalization = 'website_ids';
     $idsForNormalization = '1,2,3';
     $normalizedData = [[$fieldNameRuleId => 1, $this->normalizationField => 1], [$fieldNameRuleId => 1, $this->normalizationField => 2], [$fieldNameRuleId => 1, $this->normalizationField => 3]];
     /** @var Record|\PHPUnit_Framework_MockObject_MockObject $recordToHandle */
     $recordToHandle = $this->getMockBuilder('Migration\\ResourceModel\\Record')->setMethods(['getValue', 'getFields'])->disableOriginalConstructor()->getMock();
     /** @var Record $oppositeRecord|\PHPUnit_Framework_MockObject_MockObject */
     $oppositeRecord = $this->getMockBuilder('Migration\\ResourceModel\\Record')->disableOriginalConstructor()->getMock();
     $recordToHandle->expects($this->once())->method('getFields')->willReturn([$fieldNameRuleId, $fieldNameForNormalization]);
     $recordToHandle->expects($this->any())->method('getValue')->willReturnMap([[$fieldNameRuleId, 1], [$fieldNameForNormalization, $idsForNormalization]]);
     $this->destination->expects($this->once())->method('clearDocument')->with($this->normalizationDocument)->willReturnSelf();
     $this->destination->expects($this->once())->method('saveRecords')->with($this->normalizationDocument, $normalizedData)->willReturnSelf();
     $this->handler->setField($fieldNameForNormalization);
     $this->handler->handle($recordToHandle, $oppositeRecord);
 }