public function test_qualification() { $obm = \Magento\Framework\App\ObjectManager::getInstance(); /** @var $dba \Praxigento\Core\Lib\Context\IDbAdapter */ $dba = $obm->get(\Praxigento\Core\Lib\Context\IDbAdapter::class); $dba->getDefaultConnection()->beginTransaction(); /** @var $call \Praxigento\Bonus\GlobalSales\Lib\Service\ICalc */ $call = $obm->get(\Praxigento\Bonus\GlobalSales\Lib\Service\ICalc::class); $req = new Request\Qualification(); $req->setGvMaxLevels(2); $resp = $call->qualification($req); $this->assertTrue($resp->isSucceed()); $dba->getDefaultConnection()->rollback(); }
/** * @expectedException \Exception */ public function test_qualification_rollback() { /** === Test Data === */ $DATE_PERFORMED = 'performed'; $DATE_APPLIED = 'applied'; $GV_MAX_LEVELS = 3; /** === Setup Mocks === */ $this->mLogger->shouldReceive('info'); // $respGetPeriod = $this->_callBasePeriod->getForDependentCalc($reqGetPeriod); $mRespGetPeriod = new \Praxigento\BonusBase\Service\Period\Response\GetForDependentCalc(); $this->mCallBasePeriod->shouldReceive('getForDependentCalc')->once()->andReturn($mRespGetPeriod); // if($respGetPeriod->isSucceed()) { $mRespGetPeriod->markSucceed(); // $this->_getConn()->beginTransaction(); $this->mConn->shouldReceive('beginTransaction')->once(); // $tree = $this->_repoMod->getCompressedTree($calcIdBase); $this->mRepoMod->shouldReceive('getCompressedTree')->andThrow(new \Exception()); // $conn->rollback(); $this->mConn->shouldReceive('rollback')->once(); /** === Call and asserts === */ $req = new Request\Qualification(); $req->setDatePerformed($DATE_PERFORMED); $req->setDateApplied($DATE_APPLIED); $req->setGvMaxLevels($GV_MAX_LEVELS); $resp = $this->call->qualification($req); $this->assertFalse($resp->isSucceed()); }
public function qualification(Request\Qualification $req) { $result = new Response\Qualification(); $datePerformed = $req->getDatePerformed(); $dateApplied = $req->getDateApplied(); $gvMaxLevels = $req->getGvMaxLevels(); $msg = "'Qualification for Global Sales' calculation is started. " . "Performed at: {$datePerformed}, applied at: {$dateApplied}."; $this->_logger->info($msg); $reqGetPeriod = new PeriodGetForDependentCalcRequest(); $calcTypeBase = Cfg::CODE_TYPE_CALC_COMPRESSION; $calcType = Cfg::CODE_TYPE_CALC_QUALIFICATION; $reqGetPeriod->setBaseCalcTypeCode($calcTypeBase); $reqGetPeriod->setDependentCalcTypeCode($calcType); $respGetPeriod = $this->_callBasePeriod->getForDependentCalc($reqGetPeriod); if ($respGetPeriod->isSucceed()) { $def = $this->_manTrans->begin(); try { $periodDataDepend = $respGetPeriod->getDependentPeriodData(); $calcDataDepend = $respGetPeriod->getDependentCalcData(); $calcIdDepend = $calcDataDepend->getId(); $calcDataBase = $respGetPeriod->getBaseCalcData(); $dsBegin = $periodDataDepend->getDstampBegin(); $dsEnd = $periodDataDepend->getDstampEnd(); $calcIdBase = $calcDataBase->getId(); $tree = $this->_repoBonusCompress->getTreeByCalcId($calcIdBase); $qualData = $this->_repoMod->getQualificationData($dsBegin, $dsEnd); $cfgParams = $this->_repoMod->getConfigParams(); $updates = $this->_subQualification->calcParams($tree, $qualData, $cfgParams, $gvMaxLevels); $this->_repoMod->saveQualificationParams($updates); $this->_repoBonusService->markCalcComplete($calcIdDepend); $this->_manTrans->commit($def); $result->setPeriodId($periodDataDepend->getId()); $result->setCalcId($calcIdDepend); $result->markSucceed(); } finally { $this->_manTrans->end($def); } } $this->_logger->info("'Qualification for Global Sales' calculation is complete."); return $result; }