public function test_compressOi_isPeriod_Eu_exception() { /** === Test Data === */ $CALC_ID = 21; /** === Mocks === */ $mLogger = $this->_mockLogger(); $mConn = $this->_mockConnection(); $mDba = $this->_mockDbAdapter(null, $mConn); $mToolDate = $this->_mockFor('Praxigento\\Core\\Tool\\IDate'); $mToolPeriod = $this->_mockFor('Praxigento\\Core\\Tool\\IPeriod'); $mToolbox = $this->_mockToolbox(null, $mToolDate, null, $mToolPeriod); $mCallRepo = $this->_mockCallRepo(); $mCallAccount = $this->_mockFor('Praxigento\\Accounting\\Service\\IAccount'); $mCallBonusPersonalPeriod = $this->_mockFor('Praxigento\\Bonus\\Hybrid\\Lib\\Service\\IPeriod'); $mSubDb = $this->_mockFor('Praxigento\\Bonus\\Hybrid\\Lib\\Service\\Calc\\Sub\\Db'); $mSubCalc = $this->_mockFor('Praxigento\\Bonus\\Hybrid\\Lib\\Service\\Calc\\Sub\\Calc'); // $respGetPeriod = $this->_callPeriod->getForDependentCalc($reqGetPeriod); $mRespGetPeriod = new BonusPersonalPeriodGetForDependentCalcResponse(); $mCallBonusPersonalPeriod->expects($this->once())->method('getForDependentCalc')->willReturn($mRespGetPeriod); // if($respGetPeriod->isSucceed()) $mRespGetPeriod->markSucceed(); // $calcData = $respGetPeriod->getCalcData(); $mRespGetPeriod->setCalcData([Calculation::ATTR_ID => $CALC_ID]); // $this->_conn->beginTransaction(); $mConn->expects($this->once())->method('beginTransaction'); // $compressPtc = $this->_subDb->getCompressedPtcData($ptcCompressCalcId); $mSubDb->expects($this->once())->method('getCompressedPtcData')->willThrowException(new \Exception()); // $this->_conn->rollback(); $mConn->expects($this->once())->method('rollback'); /** * Prepare request and perform call. */ /** @var $call Call */ $call = new Call($mLogger, $mDba, $mToolbox, $mCallRepo, $mCallAccount, $mCallBonusPersonalPeriod, $mSubDb, $mSubCalc); $req = new Request\CompressOi(); $req->setScheme(Def::SCHEMA_EU); $resp = $call->compressOi($req); $this->assertFalse($resp->isSucceed()); }
public function compressOi(Request\CompressOi $request) { $result = new Response\CompressOi(); $scheme = $this->_getCalculationsScheme($request->getScheme()); $this->_logger->info("'OI Compression' calculation is started ({$scheme} scheme)."); if ($scheme == Def::SCHEMA_EU) { $calcType = Cfg::CODE_TYPE_CALC_COMPRESS_FOR_OI_EU; } else { $calcType = Cfg::CODE_TYPE_CALC_COMPRESS_FOR_OI_DEF; } $reqGetPeriod = new PeriodGetForDependentCalcRequest(); $reqGetPeriod->setBaseCalcTypeCode(Cfg::CODE_TYPE_CALC_VALUE_OV); $reqGetPeriod->setDependentCalcTypeCode($calcType); $respGetPeriod = $this->_callPeriod->getForDependentCalc($reqGetPeriod); if ($respGetPeriod->isSucceed()) { $def = $this->_manTrans->begin(); try { /* working vars */ $thisPeriodData = $respGetPeriod->getDependentPeriodData(); $thisPeriodId = $thisPeriodData[Period::ATTR_ID]; $thisCalcData = $respGetPeriod->getDependentCalcData(); $thisCalcId = $thisCalcData[Calculation::ATTR_ID]; $basePeriodData = $respGetPeriod->getBasePeriodData(); $baseDsBegin = $basePeriodData->getDstampBegin(); $baseDsEnd = $basePeriodData->getDstampEnd(); /* get the last PTC compression calc id for this period */ $ptcCompressCalcId = $this->_subDb->getLastCalculationIdForPeriod(Cfg::CODE_TYPE_CALC_COMPRESS_FOR_PTC, $baseDsBegin, $baseDsEnd); /* calculation itself */ $this->_logger->info("Processing period #{$thisPeriodId} ({$baseDsBegin}-{$baseDsEnd})"); /* get compressed data by calculation ID */ $compressPtc = $this->_subDb->getCompressedPtcData($ptcCompressCalcId); /* ranks configuration (ranks, schemes, qualification levels, etc.)*/ $cfgParams = $this->_subDb->getCfgParams(); /* calculate updates */ $updates = $this->_subCalc->compressOi($compressPtc, $cfgParams, $scheme); /* save updates and mark calculation complete */ $this->_subDb->saveCompressedOi($updates, $thisCalcId); $this->_subDb->markCalcComplete($thisCalcId); $this->_manTrans->commit($def); $result->markSucceed(); $result->setPeriodId($thisPeriodId); $result->setCalcId($thisCalcId); } finally { $this->_manTrans->end($def); } } $this->_logMemoryUsage(); $this->_logger->info("'OI Compression' calculation is completed."); return $result; }
public function test_compressOi_Eu() { $obm = \Magento\Framework\App\ObjectManager::getInstance(); /** @var $call \Praxigento\Bonus\Hybrid\Lib\Service\ICalc */ $call = $obm->get('Praxigento\\Bonus\\Hybrid\\Lib\\Service\\ICalc'); $request = new Request\CompressOi(); $request->setScheme(Def::SCHEMA_EU); $response = $call->compressOi($request); $this->assertTrue($response->isSucceed()); }