コード例 #1
0
 /**
  * @param array $data
  * @param Document $document
  */
 public function __construct(array $data = [], Document $document = null)
 {
     $this->data = $data;
     if ($document !== null) {
         $this->setStructure($document->getStructure());
     }
 }
コード例 #2
0
 /**
  * @param Resource\Document|\PHPUnit_Framework_MockObject_MockObject $document
  * @param int $callNumber
  * @return \Migration\Handler\Manager|\PHPUnit_Framework_MockObject_MockObject
  */
 protected function initHandler($document, $callNumber = 1)
 {
     $handlerManager = $this->getMock('Migration\\Handler\\Manager', ['initHandler', 'getHandlers'], [], '', false);
     $this->handlerManagerFactory->expects($this->at($callNumber))->method('create')->will($this->returnValue($handlerManager));
     $structure = $this->getMock('Migration\\Resource\\Structure', ['getFields'], [], '', false);
     $document->expects($this->once())->method('getStructure')->will($this->returnValue($structure));
     $fields = ['field1' => '', 'field2' => '', 'field3' => ''];
     $structure->expects($this->once())->method('getFields')->will($this->returnValue($fields));
     $handlerManager->expects($this->any())->method('initHandler');
     return $handlerManager;
 }
コード例 #3
0
 /**
  * @param Record $from
  * @param Record $to
  * @return void
  */
 protected function copy(Record $from, Record $to)
 {
     foreach ($from->getFields() as $field) {
         if (!$this->mapReader->isFieldIgnored($this->sourceDocument->getName(), $field, MapInterface::TYPE_SOURCE)) {
             $fieldMap = $this->mapReader->getFieldMap($this->sourceDocument->getName(), $field, MapInterface::TYPE_SOURCE);
             $to->setValue($fieldMap, $from->getValue($field));
         }
     }
 }
コード例 #4
0
 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\\Resource\\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\\Resource\\Record', [], [], '', false);
     $recordTo->expects($this->any())->method('getFields')->will($this->returnValue(['field2']));
     $recordTo->expects($this->once())->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);
 }
コード例 #5
0
ファイル: RatingsTest.php プロジェクト: okite11/frames21
 public function testIntegrityFieldFail()
 {
     $this->ratings = new Ratings($this->destination, $this->logger, $this->progress, 'integrity');
     $this->progress->expects($this->once())->method('start')->with(1);
     $this->progress->expects($this->once())->method('advance');
     $this->progress->expects($this->never())->method('finish');
     $this->destination->expects($this->once())->method('getDocumentList')->willReturn(['rating', 'rating_store']);
     $this->structure->expects($this->once())->method('getFields')->willReturn(['field' => []]);
     $this->document->expects($this->once())->method('getStructure')->willReturn($this->structure);
     $this->destination->expects($this->once())->method('getDocument')->with('rating')->willReturn($this->document);
     $this->logger->expects($this->once())->method('error')->with('Integrity check failed due to "is_active" field does not exist in "rating" document of ' . 'the destination resource');
     $this->assertFalse($this->ratings->perform());
 }
コード例 #6
0
 /**
  * @param Record $from
  * @param Record $to
  * @return void
  */
 protected function copy(Record $from, Record $to)
 {
     $sourceDocumentName = $this->sourceDocument->getName();
     $data = $from->getData();
     $sourceFields = $from->getFields();
     $destinationFields = $to->getFields();
     $diff = array_diff($sourceFields, $destinationFields);
     foreach ($diff as $field) {
         if (!$this->mapReader->isFieldIgnored($sourceDocumentName, $field, MapInterface::TYPE_SOURCE)) {
             $fieldMap = $this->mapReader->getFieldMap($sourceDocumentName, $field, MapInterface::TYPE_SOURCE);
             $data[$fieldMap] = $from->getValue($field);
         }
         unset($data[$field]);
     }
     $to->setData($data);
 }
コード例 #7
0
ファイル: IntegrityTest.php プロジェクト: okite11/frames21
 /**
  * @param bool|false $dataTypeMismatch
  */
 protected function setupFieldsValidation($dataTypeMismatch = false)
 {
     $dataTypeSource = $dataTypeMismatch ? 'varchar' : 'int';
     $fieldsSource = ['field1' => ['DATA_TYPE' => $dataTypeSource]];
     $structureSource = $this->getMockBuilder('\\Migration\\Resource\\Structure')->disableOriginalConstructor()->setMethods([])->getMock();
     $structureSource->expects($this->any())->method('getFields')->will($this->returnValue($fieldsSource));
     $this->documentSource = $this->getMockBuilder('\\Migration\\Resource\\Document')->disableOriginalConstructor()->getMock();
     $this->documentSource->expects($this->any())->method('getStructure')->will($this->returnValue($structureSource));
     $dataTypeDestination = 'int';
     $fieldsDestination = ['field1' => ['DATA_TYPE' => $dataTypeDestination]];
     $structureDestination = $this->getMockBuilder('\\Migration\\Resource\\Structure')->disableOriginalConstructor()->setMethods([])->getMock();
     $structureDestination->expects($this->any())->method('getFields')->will($this->returnValue($fieldsDestination));
     $this->documentDestination = $this->getMockBuilder('\\Migration\\Resource\\Document')->disableOriginalConstructor()->getMock();
     $this->documentDestination->expects($this->any())->method('getStructure')->will($this->returnValue($structureDestination));
     $this->source->expects($this->any())->method('getDocument')->will($this->returnValue($this->documentSource));
     $this->destination->expects($this->any())->method('getDocument')->will($this->returnValue($this->documentDestination));
 }
コード例 #8
0
 /**
  * @param Document $document
  * @param Record\Collection $recordsToSave
  * @return void
  */
 protected function saveRecords(Document $document, Record\Collection $recordsToSave)
 {
     $this->destination->clearDocument($document->getName());
     $this->destination->saveRecords($document->getName(), $recordsToSave);
 }
コード例 #9
0
ファイル: DocumentTest.php プロジェクト: okite11/frames21
 public function testGetStructure()
 {
     $this->assertSame($this->structure, $this->document->getStructure());
 }
コード例 #10
0
 /**
  * @param Resource\Document $sourceDocument
  * @param Resource\Document $destinationDocument
  * @param string $type
  * @return void
  */
 protected function verifyFields($sourceDocument, $destinationDocument, $type)
 {
     $sourceFields = array_keys($sourceDocument->getStructure()->getFields());
     $destFields = $destinationDocument->getStructure()->getFields();
     foreach ($sourceFields as $field) {
         $mappedField = $this->map->getFieldMap($sourceDocument->getName(), $field, $type);
         if ($mappedField && !isset($destFields[$mappedField])) {
             $this->missingDocumentFields[$type][$sourceDocument->getName()][] = $mappedField;
         }
     }
 }
コード例 #11
0
 /**
  * @param Resource\Document $sourceDocument
  * @param Resource\Document $destinationDocument
  * @param string $type
  * @return void
  */
 protected function verifyFields($sourceDocument, $destinationDocument, $type)
 {
     $sourceFields = $sourceDocument->getStructure()->getFields();
     $destFields = $destinationDocument->getStructure()->getFields();
     foreach ($sourceFields as $sourceField => $sourceFieldMetaData) {
         $mappedField = $this->map->getFieldMap($sourceDocument->getName(), $sourceField, $type);
         if ($mappedField) {
             if (!isset($destFields[$mappedField])) {
                 $this->missingDocumentFields[$type][$sourceDocument->getName()][] = $mappedField;
             } else {
                 if ($sourceFieldMetaData['DATA_TYPE'] != $destFields[$mappedField]['DATA_TYPE'] && !$this->map->isFieldDataTypeIgnored($sourceDocument->getName(), $sourceField, $type)) {
                     $this->mismatchDocumentFieldDataTypes[$type][$sourceDocument->getName()][] = $sourceField;
                 }
             }
         }
     }
 }
コード例 #12
0
 /**
  * @param Document $document
  * @param string $type
  * @return bool
  */
 protected function hasHandlers(Document $document, $type)
 {
     $result = false;
     foreach (array_keys($document->getStructure()->getFields()) as $fieldName) {
         $handlerConfig = $this->map->getHandlerConfig($document->getName(), $fieldName, $type);
         if (!empty($handlerConfig)) {
             $result = true;
             break;
         }
     }
     return $result;
 }
コード例 #13
0
 /**
  * @param Resource\Document $sourceDocument
  * @param Resource\Document $destDocument
  * @return bool
  */
 protected function haveEqualStructure(Resource\Document $sourceDocument, Resource\Document $destDocument)
 {
     $diff = array_diff_key($sourceDocument->getStructure()->getFields(), $destDocument->getStructure()->getFields());
     return empty($diff);
 }