/**
  *
  * @param $entityAlias string Alias of the entity ('prxgt_acc_type_asset').
  * @param $demEntity array Associative array with entity definition (DEM subtree).
  */
 public function createEntity($entityAlias, $demEntity)
 {
     $tblName = $this->_resource->getTableName($entityAlias);
     $this->_logger->info("Create new table: {$tblName}.");
     /* init new object to create table in DB */
     $tbl = $this->_conn->newTable($tblName);
     if (isset($demEntity[DemCfg::COMMENT])) {
         $tbl->setComment($demEntity[DemCfg::COMMENT]);
     }
     $indexes = isset($demEntity[DemCfg::INDEX]) ? $demEntity[DemCfg::INDEX] : null;
     $relations = isset($demEntity[DemCfg::RELATION]) ? $demEntity[DemCfg::RELATION] : null;
     /* parse attributes */
     foreach ($demEntity[DemCfg::ATTRIBUTE] as $key => $attr) {
         $attrName = $attr[DemCfg::ALIAS];
         $attrType = $this->_parser->entityGetAttrType($attr[DemCfg::TYPE]);
         $attrSize = $this->_parser->entityGetAttrSize($attr[DemCfg::TYPE]);
         $attrOpts = $this->_parser->entityGetAttrOptions($attr, $indexes);
         $attrComment = isset($attr[DemCfg::COMMENT]) ? $attr[DemCfg::COMMENT] : null;
         $tbl->addColumn($attrName, $attrType, $attrSize, $attrOpts, $attrComment);
     }
     /* parse indexes */
     if ($indexes) {
         foreach ($indexes as $key => $ndx) {
             /* PRIMARY indexes are processed as columns options */
             if ($ndx[DemCfg::TYPE] == DemType::INDEX_PRIMARY) {
                 continue;
             }
             /* process not PRIMARY indexes */
             $ndxFields = $this->_parser->entityGetIndexFields($ndx);
             $ndxType = $this->_parser->entityGetIndexType($ndx);
             $ndxOpts = $this->_parser->entityGetIndexOptions($ndx);
             $ndxName = $this->_conn->getIndexName($entityAlias, $ndxFields, $ndxType);
             $this->_logger->info("Create new index: {$ndxName}.");
             $tbl->addIndex($ndxName, $ndxFields, $ndxOpts);
         }
     }
     /* create new table */
     $this->_conn->createTable($tbl);
     /* parse relations */
     if ($relations) {
         foreach ($relations as $one) {
             /* one only column FK is supported by Magento FW */
             $ownColumn = reset($one[DemCfg::OWN][DemCfg::ALIASES]);
             $refTableAlias = $one[DemCfg::REFERENCE][DemCfg::ENTITY][DemCfg::COMPLETE_ALIAS];
             $refTable = $this->_resource->getTableName($refTableAlias);
             $refColumn = reset($one[DemCfg::REFERENCE][DemCfg::ALIASES]);
             $onDelete = $this->_parser->referenceGetAction($one[DemCfg::ACTION][DemCfg::DELETE]);
             /* there is no onUpdate in M2, $purge is used instead. Set default value 'false' for purge. */
             //$onUpdate = $this->_parser->referenceGetAction($one[DemCfg::ACTION][DemCfg::UPDATE]);
             $onUpdate = false;
             $fkName = $this->_conn->getForeignKeyName($tblName, $ownColumn, $refTable, $refColumn);
             $this->_logger->info("Create new relation '{$fkName}' from '{$tblName}:{$ownColumn}' to '{$refTable}:{$refColumn}'.");
             try {
                 $this->_conn->addForeignKey($fkName, $tblName, $ownColumn, $refTable, $refColumn, $onDelete, $onUpdate);
             } catch (\Exception $e) {
                 $msg = "Cannot create FK '{$fkName}'. Error: " . $e->getMessage();
                 $this->_logger->error($msg);
             }
         }
     }
 }
 public function test_referenceGetAction_all()
 {
     /** === Test Data === */
     /** === Mocks === */
     /** === Test itself === */
     $obj = new Parser();
     $resp = $obj->referenceGetAction(null);
     $this->assertEquals(MageType::REF_ACTION_NO_ACTION, $resp);
     $resp = $obj->referenceGetAction(DemType::REF_ACTION_RESTRICT);
     $this->assertEquals(MageType::REF_ACTION_RESTRICT, $resp);
     $resp = $obj->referenceGetAction(DemType::REF_ACTION_CASCADE);
     $this->assertEquals(MageType::REF_ACTION_CASCADE, $resp);
 }