public function test_addCalc() { /** === Test Data === */ $mCalcTypeId = 2; $mDsBegin = 'begin'; $mDsEnd = 'end'; /** === Setup Mocks === */ // $def = $this->_manTrans->begin(); $mDef = $this->_mockTransactionDefinition(); $this->mManTrans->shouldReceive('begin')->once()->andReturn($mDef); // $periodId = $this->_repoPeriod->create($periodData); $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($calcData); $mCalcId = 64; $this->mRepoCalc->shouldReceive('create')->once()->andReturn($mCalcId); // $this->_manTrans->commit($def); $this->mManTrans->shouldReceive('commit')->once()->with($mDef); // $this->_manTrans->end($def); $this->mManTrans->shouldReceive('end')->once()->with($mDef); /** === Call and asserts === */ $req = new Request\AddCalc(); $req->setCalcTypeId($mCalcTypeId); $req->setDateStampBegin($mDsBegin); $req->setDateStampEnd($mDsEnd); $res = $this->obj->addCalc($req); $this->assertTrue($res->isSucceed()); $this->assertInstanceOf(Response\AddCalc::class, $res); $this->assertInstanceOf(EPeriod::class, $res->getPeriod()); $this->assertInstanceOf(ECalculation::class, $res->getCalculation()); }
public function test_addCalc() { $def = $this->_manTrans->begin(); /** @var $call \Praxigento\BonusBase\Service\Period\Call */ $call = $this->_manObj->get(\Praxigento\BonusBase\Service\IPeriod::class); $req = new Request\AddCalc(); $req->setCalcTypeId(2); $req->setDateStampBegin('20160922'); $req->setDateStampEnd('20160925'); $res = $call->addCalc($req); $this->assertTrue($res->isSucceed()); $period = $res->getPeriod(); $this->assertInstanceOf(Period::class, $period); $calc = $res->getCalculation(); $this->assertInstanceOf(Calculation::class, $calc); // rollback $this->_manTrans->rollback($def); }
public function registerPeriod(Request\RegisterPeriod $request) { $result = new Response\RegisterPeriod(); $calcTypeId = $request->getCalcTypeId(); $calcTypeCode = $request->getCalcTypeCode(); $dsBegin = $request->getDateStampBegin(); $dsEnd = $request->getDateStampEnd(); $msgParams = is_null($calcTypeId) ? "type code '{$calcTypeCode}'" : "type ID #{$calcTypeId}"; $this->_logger->info("'Register Period' operation is started in bonus base module ({$msgParams}; {$dsBegin}-{$dsEnd})."); if (is_null($calcTypeId)) { /* get calculation type ID by type code */ $calcTypeId = $this->_repoTypeCalc->getIdByCode($calcTypeCode); $this->_logger->info("There is only calculation type code ({$calcTypeCode}) in request, calculation type id = {$calcTypeId}."); } $reqAddCalc = new Request\AddCalc(); $reqAddCalc->setCalcTypeId($calcTypeId); $reqAddCalc->setDateStampBegin($dsBegin); $reqAddCalc->setDateStampEnd($dsEnd); $data = $this->addCalc($reqAddCalc); $result->setPeriodData($data->getPeriod()); $result->setCalcData($data->getCalculation()); $result->markSucceed(); $this->_logger->info("'Register Period' operation is completed in bonus base module."); return $result; }