public function test_getDependedCalc_incomplete() { /** === Test Data === */ $RESULT = new \Praxigento\BonusBase\Service\Period\Response\GetForDependentCalc(); $BASE_PERIOD_ID = 2; $BASE_TYPE_CODE = 'base'; $BASE_DS_BEGIN = 'begin'; $BASE_DS_END = 'end'; $DEP_TYPE_CODE = 'depend'; $DEP_TYPE_ID = 4; /** === Setup Mocks === */ // $baseCalcData = $this->_repoService->getLastCalcForPeriodById($basePeriodId); $this->mRepoService->shouldReceive('getLastCalcForPeriodById')->once()->with($BASE_PERIOD_ID)->andReturn(null); /** === Call and asserts === */ $this->obj->getDependedCalc($RESULT, $BASE_PERIOD_ID, $BASE_TYPE_CODE, $BASE_DS_BEGIN, $BASE_DS_END, $DEP_TYPE_CODE, $DEP_TYPE_ID); }
public function getForDependentCalc(Request\GetForDependentCalc $request) { $result = new Response\GetForDependentCalc(); $baseCalcTypeCode = $request->getBaseCalcTypeCode(); $dependentCalcTypeCode = $request->getDependentCalcTypeCode(); $msg = "'Get latest period for Dependent Calculation' operation is started " . "(dependent={$dependentCalcTypeCode}, base={$baseCalcTypeCode})."; $this->_logger->info($msg); $def = $this->_manTrans->begin(); try { /* get IDs for calculations codes */ $baseCalcTypeId = $this->_repoTypeCalc->getIdByCode($baseCalcTypeCode); $dependentCalcTypeId = $this->_repoTypeCalc->getIdByCode($dependentCalcTypeCode); /* get the last base period data from repo */ $basePeriodData = $this->_repoService->getLastPeriodByCalcType($baseCalcTypeId); if (is_null($basePeriodData)) { $msg = "There is no period for '{$baseCalcTypeCode}' calculation yet (base). " . "Depended '{$dependentCalcTypeCode}' could not be calculated."; $this->_logger->warning($msg); } else { /* there is period for base calculation, place base data into response */ $result->setBasePeriodData($basePeriodData); $baseDsBegin = $basePeriodData->getDstampBegin(); $baseDsEnd = $basePeriodData->getDstampEnd(); /* then get data for depended period & calc */ $periodId = $basePeriodData->getId(); $result = $this->_subDepended->getDependedCalc($result, $periodId, $baseCalcTypeCode, $baseDsBegin, $baseDsEnd, $dependentCalcTypeCode, $dependentCalcTypeId); } $this->_manTrans->commit($def); /* mark succeed if depended data exists */ if ($result->getDependentPeriodData() && $result->getDependentCalcData()) { $result->markSucceed(); } } finally { $this->_manTrans->end($def); } $this->_logger->info("'Get latest period for Dependent Calculation' operation is completed."); return $result; }