Exemple #1
0
 /**
  * @covers \Magento\Framework\Module\Setup\Migration::appendClassAliasReplace
  */
 public function testAppendClassAliasReplace()
 {
     $moduleListMock = $this->getMock('Magento\\Framework\\Module\\ModuleListInterface');
     $moduleListMock->expects($this->once())->method('getOne')->will($this->returnValue([]));
     $filesystemMock = $this->getMock('Magento\\Framework\\Filesystem', [], [], '', false);
     $modulesDirMock = $this->getMock('Magento\\Framework\\Filesystem\\Directory\\Read', [], [], '', false);
     $filesystemMock->expects($this->any())->method('getDirectoryRead')->will($this->returnValue($modulesDirMock));
     $contextMock = $this->getMock('Magento\\Framework\\Module\\Setup\\Context', [], [], '', false);
     $contextMock->expects($this->any())->method('getFilesystem')->will($this->returnValue($filesystemMock));
     $contextMock->expects($this->once())->method('getEventManager')->will($this->returnValue($this->getMock('Magento\\Framework\\Event\\ManagerInterface', [], [], '', false)));
     $contextMock->expects($this->once())->method('getResourceModel')->will($this->returnValue($this->getMock('Magento\\Framework\\App\\Resource', [], [], '', false)));
     $contextMock->expects($this->once())->method('getLogger')->will($this->returnValue($this->getMock('Psr\\Log\\LoggerInterface')));
     $contextMock->expects($this->once())->method('getModulesReader')->will($this->returnValue($this->getMock('Magento\\Framework\\Module\\Dir\\Reader', [], [], '', false)));
     $contextMock->expects($this->once())->method('getModuleList')->will($this->returnValue($moduleListMock));
     $migrationData = $this->getMock('Magento\\Framework\\Module\\Setup\\MigrationData', [], [], '', false);
     $setupModel = new \Magento\Framework\Module\Setup\Migration($contextMock, 'core_setup', 'Magento_Core', $migrationData, 'app/etc/aliases_to_classes_map.json');
     $setupModel->appendClassAliasReplace('tableName', 'fieldName', 'entityType', 'fieldContentType', ['pk_field1', 'pk_field2'], 'additionalWhere');
     $expectedRulesList = ['tableName' => ['fieldName' => ['entity_type' => 'entityType', 'content_type' => 'fieldContentType', 'pk_fields' => ['pk_field1', 'pk_field2'], 'additional_where' => 'additionalWhere']]];
     $this->assertAttributeEquals($expectedRulesList, '_replaceRules', $setupModel);
 }
 /**
  * @covers \Magento\Framework\Module\Setup\Migration::appendClassAliasReplace
  */
 public function testAppendClassAliasReplace()
 {
     $setupMock = $this->getMockForAbstractClass('\\Magento\\Framework\\Setup\\ModuleDataSetupInterface');
     $filesystemMock = $this->getMock('Magento\\Framework\\Filesystem', [], [], '', false);
     $migrationData = $this->getMock('Magento\\Framework\\Module\\Setup\\MigrationData', [], [], '', false);
     $setupModel = new \Magento\Framework\Module\Setup\Migration($setupMock, $filesystemMock, $migrationData, 'app/etc/aliases_to_classes_map.json');
     $setupModel->appendClassAliasReplace('tableName', 'fieldName', 'entityType', 'fieldContentType', ['pk_field1', 'pk_field2'], 'additionalWhere');
     $expectedRulesList = ['tableName' => ['fieldName' => ['entity_type' => 'entityType', 'content_type' => 'fieldContentType', 'pk_fields' => ['pk_field1', 'pk_field2'], 'additional_where' => 'additionalWhere']]];
     $this->assertAttributeEquals($expectedRulesList, '_replaceRules', $setupModel);
     // Check that replace for the same field is not set twice
     $setupModel->appendClassAliasReplace('tableName', 'fieldName', 'newEntityType', 'newFieldContentType', ['new_pk_field1', 'new_pk_field2'], 'newAdditionalWhere');
     $this->assertAttributeEquals($expectedRulesList, '_replaceRules', $setupModel);
 }