public function test_getNewPeriodDataForPv_date()
 {
     /** === Test Data === */
     $mResult = new \Praxigento\BonusBase\Service\Period\Response\GetForPvBasedCalc();
     $mCalcTypeId = 4;
     $mPeriodType = \Praxigento\Core\Tool\IPeriod::TYPE_DAY;
     /** === Setup Mocks === */
     // $firstDate = $this->_repoService->getFirstDateForPvTransactions();
     $mFirstDate = 'timestamp';
     $this->mRepoService->shouldReceive('getFirstDateForPvTransactions')->once()->andReturn($mFirstDate);
     // $periodMonth = $this->_toolPeriod->getPeriodCurrent($firstDate, $periodType);
     $mPeriodMonth = 'month';
     $this->mToolPeriod->shouldReceive('getPeriodCurrent')->once()->with($mFirstDate, $mPeriodType)->andReturn($mPeriodMonth);
     // $dsBegin = $this->_toolPeriod->getPeriodFirstDate($periodMonth);
     $mDsBegin = 'datestamp begin';
     $this->mToolPeriod->shouldReceive('getPeriodFirstDate')->once()->with($mPeriodMonth)->andReturn($mDsBegin);
     // $dsEnd = $this->_toolPeriod->getPeriodLastDate($periodMonth);
     $mDsEnd = 'datestamp end';
     $this->mToolPeriod->shouldReceive('getPeriodLastDate')->once()->with($mPeriodMonth)->andReturn($mDsEnd);
     // $periodId = $this->_repoPeriod->create($period);
     $mPeriodId = 32;
     $this->mRepoPeriod->shouldReceive('create')->once()->andReturn($mPeriodId);
     // $dateStarted = $this->_toolDate->getUtcNowForDb();
     $mDateStarted = 'started';
     $this->mToolDate->shouldReceive('getUtcNowForDb')->once()->andReturn($mDateStarted);
     // $calcId = $this->_repoCalc->create($calc);
     $mCalcId = 64;
     $this->mRepoCalc->shouldReceive('create')->once()->andReturn($mCalcId);
     /** === Call and asserts  === */
     $res = $this->obj->getNewPeriodDataForPv($mResult, $mPeriodType, $mCalcTypeId);
     $this->assertEquals($mPeriodId, $res->getPeriodData()->getId());
     $this->assertEquals($mCalcId, $res->getCalcData()->getId());
 }
Пример #2
0
 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;
 }