/** * @return void */ public function setUp() { $this->config = $this->getMockBuilder('Migration\\Config')->disableOriginalConstructor()->setMethods(['getSource'])->getMock(); $this->config->expects($this->any())->method('getSource')->will($this->returnValue(['type' => DatabaseStage::SOURCE_TYPE])); $this->source = $this->getMockBuilder('Migration\\ResourceModel\\Source')->disableOriginalConstructor()->setMethods(['getDocument', 'getRecordsCount', 'getAdapter', 'addDocumentPrefix', 'getRecords'])->getMock(); $this->source->expects($this->any())->method('addDocumentPrefix')->willReturnCallback(function ($name) { return 'source_suffix_' . $name; }); $this->destination = $this->getMockBuilder('Migration\\ResourceModel\\Destination')->disableOriginalConstructor()->setMethods(['getDocument', 'getRecordsCount', 'getAdapter', 'addDocumentPrefix', 'saveRecords'])->getMock(); $this->destination->expects($this->any())->method('addDocumentPrefix')->willReturnCallback(function ($name) { return 'destination_suffix_' . $name; }); $this->progress = $this->getMockBuilder('Migration\\App\\ProgressBar\\LogLevelProcessor')->disableOriginalConstructor()->setMethods(['start', 'finish', 'advance'])->getMock(); $this->progress->expects($this->any())->method('start'); $this->progress->expects($this->any())->method('finish'); $this->progress->expects($this->any())->method('advance'); $this->recordFactory = $this->getMockBuilder('Migration\\ResourceModel\\RecordFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock(); $this->logger = $this->getMockBuilder('Migration\\Logger\\Logger')->disableOriginalConstructor()->setMethods(['create'])->getMock(); $this->map = $this->getMockBuilder('Migration\\Reader\\Map')->disableOriginalConstructor()->setMethods(['getDocumentMap', 'init', 'getDocumentList', 'getDestDocumentsToClear'])->getMock(); /** @var \Migration\Reader\MapFactory|\PHPUnit_Framework_MockObject_MockObject $mapFactory */ $mapFactory = $this->getMockBuilder('Migration\\Reader\\MapFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock(); $mapFactory->expects($this->any())->method('create')->with('customer_attr_map_file')->willReturn($this->map); $this->groups = $this->getMockBuilder('Migration\\Reader\\Groups')->disableOriginalConstructor()->getMock(); $this->groups->expects($this->any())->method('getGroup')->with('source_documents')->willReturn(['source_document_1' => 'entity_id']); /** @var \Migration\Reader\GroupsFactory|\PHPUnit_Framework_MockObject_MockObject $groupsFactory */ $groupsFactory = $this->getMockBuilder('Migration\\Reader\\GroupsFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock(); $groupsFactory->expects($this->any())->method('create')->with('customer_attr_document_groups_file')->willReturn($this->groups); $this->logger = $this->getMockBuilder('Migration\\Logger\\Logger')->disableOriginalConstructor()->setMethods(['debug'])->getMock(); $this->step = new Data($this->config, $this->source, $this->destination, $this->progress, $this->recordFactory, $mapFactory, $groupsFactory, $this->logger); }
public function testCreate() { $adapterClassName = '\\Migration\\Resource\\Adapter\\Mysql'; $data = ['config' => ['key' => 'value']]; $adapter = $this->getMock($adapterClassName, [], [], '', false); $this->config->expects($this->once())->method('getOption')->with('resource_adapter_class_name')->will($this->returnValue(null)); $this->objectManager->expects($this->once())->method('create')->with('\\Migration\\Resource\\Adapter\\Mysql', $data)->will($this->returnValue($adapter)); $this->assertInstanceOf($adapterClassName, $this->adapterFactory->create($data)); }
/** * @return void */ public function setUp() { $this->progress = $this->getMock('\\Migration\\App\\ProgressBar\\LogLevelProcessor', ['start', 'finish', 'advance'], [], '', false); $this->logger = $this->getMock('\\Migration\\Logger\\Logger', ['debug', 'error'], [], '', false); $this->config = $this->getMock('\\Migration\\Config', [], [], '', false); $this->config->expects($this->any())->method('getSource')->willReturn(['type' => 'database', 'version' => '1.14.1.0']); $this->source = $this->getMock('\\Migration\\ResourceModel\\Source', [], [], '', false); $this->destination = $this->getMock('\\Migration\\ResourceModel\\Destination', [], [], '', false); $this->recordCollectionFactory = $this->getMock('\\Migration\\ResourceModel\\Record\\CollectionFactory', ['create'], [], '', false); $this->recordFactory = $this->getMock('\\Migration\\ResourceModel\\RecordFactory', ['create'], [], '', false); }
/** * @return void */ public function testHandleSuccessWithoutBubble() { $extra = ['mode' => 'application mode']; $record = ['message' => $this->message, 'level' => $this->recordLevel, 'extra' => $extra]; $this->fileHandler->setLevel($this->handlerLevel); $this->fileHandler->setBubble(false); $file = 'file/path/file.log'; $this->file->expects($this->any())->method('filePutContents')->willReturn(1); $this->file->expects($this->any())->method('getRealPath')->willReturnMap([[$file, false], ['file/path', false], ['file', '/existing_path/file']]); $this->file->expects($this->once())->method('createDirectory')->willReturn(true); $this->config->expects($this->any())->method('getOption')->with('log_file')->willReturn($file); $result = $this->fileHandler->handle($record); $this->assertTrue($result); }
public function testDeleteDocumentBackup() { $docName = 'somename'; $this->adapter->expects($this->once())->method('deleteBackup')->with('pfx_' . $docName); $this->config->expects($this->once())->method('getOption')->with('dest_prefix')->will($this->returnValue('pfx_')); $this->resourceDestination->deleteDocumentBackup($docName); }
public function testGetRecords() { $resourceName = 'core_config_data'; $pageNumber = 2; $this->config->expects($this->at(0))->method('getOption')->with('bulk_size')->will($this->returnValue(100)); $this->config->expects($this->at(1))->method('getOption')->with('dest_prefix')->will($this->returnValue(100)); $this->adapter->expects($this->once())->method('loadPage'); $this->resourceDestination->getRecords($resourceName, $pageNumber); }
public function setUp() { $this->progressBar = $this->getMock('\\Migration\\App\\ProgressBar\\LogLevelProcessor', ['start', 'finish', 'advance'], [], '', false); $this->source = $this->getMock('Migration\\Resource\\Source', ['getDocument', 'getDocumentList', 'getRecords', 'getRecordsCount', 'getPageSize', 'setLastLoadedRecord'], [], '', false); $this->destination = $this->getMock('Migration\\Resource\\Destination', ['getDocument', 'getDocumentList', 'saveRecords', 'clearDocument'], [], '', false); $this->recordFactory = $this->getMock('Migration\\Resource\\RecordFactory', ['create'], [], '', false); $this->recordTransformerFactory = $this->getMock('Migration\\RecordTransformerFactory', ['create'], [], '', false); $this->map = $this->getMockBuilder('Migration\\Reader\\Map')->disableOriginalConstructor()->setMethods(['getDocumentMap', 'getHandlerConfig'])->getMock(); /** @var \Migration\Config|\PHPUnit_Framework_MockObject_MockObject $config */ $this->config = $this->getMockBuilder('Migration\\Config')->setMethods(['getOption'])->disableOriginalConstructor()->getMock(); $this->config->expects($this->any())->method('getOption')->willReturnMap([['direct_document_copy', 0], ['bulk_size', 100]]); /** @var \Migration\Reader\MapFactory|\PHPUnit_Framework_MockObject_MockObject $mapFactory */ $mapFactory = $this->getMock('\\Migration\\Reader\\MapFactory', [], [], '', false); $mapFactory->expects($this->any())->method('create')->with('map_file')->willReturn($this->map); $this->progress = $this->getMock('Migration\\App\\Progress', ['getProcessedEntities', 'addProcessedEntity'], [], '', false); $this->logger = $this->getMockBuilder('Migration\\Logger\\Logger')->disableOriginalConstructor()->setMethods(['debug'])->getMock(); $this->data = new Data($this->progressBar, $this->source, $this->destination, $this->recordFactory, $this->recordTransformerFactory, $mapFactory, $this->progress, $this->logger, $this->config); }
/** * @return void */ public function setUp() { $this->logger = $this->getMock('Migration\\Logger\\Logger', ['error'], [], '', false); $this->progress = $this->getMock('\\Migration\\App\\ProgressBar\\LogLevelProcessor', ['start', 'finish', 'advance'], [], '', false); $this->logger = $this->getMock('\\Migration\\Logger\\Logger', ['debug', 'error'], [], '', false); $this->config = $this->getMock('\\Migration\\Config', [], [], '', false); $this->config->expects($this->any())->method('getSource')->willReturn(['type' => 'database', 'version' => '1.9']); $this->source = $this->getMock('\\Migration\\ResourceModel\\Source', [], [], '', false); $select = $this->getMockBuilder('Magento\\Framework\\DB\\Select')->setMethods(['from', 'joinLeft'])->disableOriginalConstructor()->getMock(); $select->expects($this->any())->method('from')->willReturnSelf(); $select->expects($this->any())->method('joinLeft')->willReturnSelf(); $sourceAdapter = $this->getMockBuilder('Migration\\ResourceModel\\Adapter\\Mysql')->disableOriginalConstructor()->setMethods(['getSelect', 'loadDataFromSelect'])->getMock(); $sourceAdapter->expects($this->any())->method('getSelect')->willReturn($select); $this->source->expects($this->any())->method('getAdapter')->willReturn($sourceAdapter); $this->destination = $this->getMock('\\Migration\\ResourceModel\\Destination', [], [], '', false); $this->recordCollection = $this->getMock('\\Migration\\ResourceModel\\Record\\Collection', ['addRecord'], [], '', false); $this->recordFactory = $this->getMock('\\Migration\\ResourceModel\\RecordFactory', ['create'], [], '', false); }
/** * @param array $attributeData * @param array $expected * * @dataProvider dataProviderEncryptionData * @return void */ public function testHandle($attributeData, $expected) { $fieldName = 'value'; list($key, $dbValue, $initVector, $encryptedValue, $cypher, $mode) = array_values($attributeData); list($decryptedValue, $newValue) = array_values($expected); /** @var \Migration\ResourceModel\Record|\PHPUnit_Framework_MockObject_MockObject $recordToHandle */ $recordToHandle = $this->getMock('Migration\\ResourceModel\\Record', ['getValue', 'setValue', 'getFields'], [], '', false); $recordToHandle->expects($this->once())->method('getValue')->with($fieldName)->willReturn($dbValue); $recordToHandle->expects($this->once())->method('setValue')->with($fieldName, $newValue); $recordToHandle->expects($this->once())->method('getFields')->will($this->returnValue([$fieldName])); $oppositeRecord = $this->getMockBuilder('Migration\\ResourceModel\\Record')->disableOriginalConstructor()->getMock(); $crypt = $this->getMock('\\Magento\\Framework\\Encryption\\Crypt', ['decrypt'], [$key, $cypher, $mode, $initVector], '', true); $crypt->expects($this->once())->method('decrypt')->with(base64_decode((string) $encryptedValue))->willReturn($decryptedValue); $this->configReader->expects($this->once())->method('getOption')->with(self::CRYPT_KEY)->will($this->returnValue($key)); $this->cryptFactory->expects($this->once())->method('create')->with(['key' => $key, 'cipher' => $cypher, 'mode' => $mode, 'initVector' => $initVector])->will($this->returnValue($crypt)); $this->encryptor->expects($this->once())->method('encrypt')->with($decryptedValue)->willReturn($newValue); $handler = new \Migration\Handler\Settings\Encrypt($this->encryptor, $this->cryptFactory, $this->configReader); $handler->setField($fieldName); $handler->handle($recordToHandle, $oppositeRecord); }
public function testCreateDelta() { $this->adapter->expects($this->once())->method('createDelta')->with('spfx_document', 'spfx_m2_cl_document', 'key_field'); $this->config->expects($this->any())->method('getOption')->with(Source::CONFIG_DOCUMENT_PREFIX)->willReturn('spfx_'); $this->resourceSource->createDelta('document', 'key_field'); }
public function testGetDeletedRecords() { $this->adapter->expects($this->once())->method('loadDeletedRecords')->with('m2_cl_document', 'key_field', 0, 100); $this->config->expects($this->any())->method('getOption')->willReturnMap([['source_prefix', ''], ['bulk_size', 100]]); $this->resourceSource->getDeletedRecords('document', 'key_field'); }