public function getForPvBasedCalc(Request\GetForPvBasedCalc $request) { $result = new Response\GetForPvBasedCalc(); $calcTypeCode = $request->getCalcTypeCode(); $periodType = $request->getPeriodType() ?? ToolPeriod::TYPE_MONTH; $msg = "'Get latest period for PV based calc' operation is started in bonus base module " . "(type code: {$calcTypeCode}; period: {$periodType})."; $this->_logger->info($msg); /* get calculation type ID by type code */ $calcTypeId = $this->_repoTypeCalc->getIdByCode($calcTypeCode); $def = $this->_manTrans->begin(); try { $reqLatest = new Request\GetLatest(); $reqLatest->setCalcTypeId($calcTypeId); $latestPeriod = $this->getLatest($reqLatest); $periodData = $latestPeriod->getPeriodData(); if (is_null($periodData)) { $result = $this->_subPvBased->getNewPeriodDataForPv($result, $periodType, $calcTypeId); } else { $result->setPeriodData($periodData); $periodId = $periodData->getId(); $this->_logger->info("There is registered period #{$periodId} for '{$calcTypeCode}' calculation."); $calcData = $latestPeriod->getCalcData(); $result = $this->_subPvBased->checkExistingPeriod($result, $calcTypeCode, $calcTypeId, $periodType, $periodData, $calcData); } /* mark succeed if period data exists */ if ($result->getPeriodData() && $result->getCalcData()) { $this->_manTrans->commit($def); $result->markSucceed(); } } finally { $this->_manTrans->end($def); } $this->_logger->info("'Get latest period for PV based calc' operation is completed in bonus base module."); return $result; }
public function test_checkExistingPeriod_noCalc() { /** === Test Data === */ $RESULT = new \Praxigento\BonusBase\Service\Period\Response\GetForPvBasedCalc(); $CALC_TYPE_CODE = 'code'; $CALC_TYPE_ID = 4; $PERIOD_TYPE = \Praxigento\Core\Tool\IPeriod::TYPE_DAY; $PERIOD = new \Praxigento\BonusBase\Data\Entity\Period(); $CALC = null; /** === Mock object itself === */ $this->obj = \Mockery::mock(PvBased::class . '[_checkStateForExistingPeriod]', $this->objArgs); /** === Setup Mocks === */ /** === Call and asserts === */ $res = $this->obj->checkExistingPeriod($RESULT, $CALC_TYPE_CODE, $CALC_TYPE_ID, $PERIOD_TYPE, $PERIOD, $CALC); $this->assertEquals(\Praxigento\BonusBase\Service\Period\Response\GetForPvBasedCalc::ERR_NO_CALC_FOR_EXISTING_PERIOD, $res->getErrorCode()); }