/** * Tree: 1 => 2 => 3 => 4 */ public function test_calcParams() { /** === Test Data === */ $TREE = 'tree'; $CUST_1 = 1; $CUST_2 = 2; $CUST_3 = 3; $CUST_4 = 4; $Q_DATA = [$CUST_1 => 400, $CUST_2 => 300, $CUST_3 => 200, $CUST_4 => 100]; $MAX_LEVELS = 2; $PSAA_LEVEL = 120; $TREE_EXP = []; $MAP_BY_DEPTH = [3 => [$CUST_4], 2 => [$CUST_3], 1 => [$CUST_2], 0 => [$CUST_1]]; $MAP_BY_TEAMS = [$CUST_1 => [$CUST_2], $CUST_2 => [$CUST_3], $CUST_3 => [$CUST_4]]; $MAP_BY_ID = []; /** === Setup Mocks === */ // $treeExpanded = $this->_expandTree($tree); // $resp = $this->_callDownlineSnap->expandMinimal($req); $this->mCallDownlineSnap->shouldReceive('expandMinimal')->once()->andReturn(new DataObject(['SnapData' => $TREE_EXP])); // $mapByDepth = $this->_mapByTreeDepthDesc($treeExpanded); // $resp = $this->_callDownlineMap->treeByDepth($req); $this->mCallDownlineMap->shouldReceive('treeByDepth')->once()->andReturn(new DataObject(['Mapped' => $MAP_BY_DEPTH])); // $mapTeams = $this->_mapByTeams($tree); // $resp = $this->_callDownlineMap->treeByTeams($req); $this->mCallDownlineMap->shouldReceive('treeByTeams')->once()->andReturn(new DataObject(['Mapped' => $MAP_BY_TEAMS])); // $mapById = $this->_mapById($tree); // $resp = $this->_callDownlineMap->byId($req); $this->mCallDownlineMap->shouldReceive('byId')->once()->andReturn(new DataObject(['Mapped' => $MAP_BY_ID])); // $parents = $this->_toolDownlineTree->getParentsFromPathReversed($path); $this->mToolDownlineTree->shouldReceive('getParentsFromPathReversed')->once()->andReturn([$CUST_3, $CUST_2, $CUST_1]); $this->mToolDownlineTree->shouldReceive('getParentsFromPathReversed')->once()->andReturn([$CUST_2, $CUST_1]); $this->mToolDownlineTree->shouldReceive('getParentsFromPathReversed')->once()->andReturn([$CUST_1]); $this->mToolDownlineTree->shouldReceive('getParentsFromPathReversed')->once()->andReturn([]); /** === Call and asserts === */ $resp = $this->sub->calcParams($TREE, $Q_DATA, $MAX_LEVELS, $PSAA_LEVEL); $this->assertTrue(is_array($resp)); }
public function qualification(Request\Qualification $req) { $result = new Response\Qualification(); $datePerformed = $req->getDatePerformed(); $dateApplied = $req->getDateApplied(); $gvMaxLevels = $req->getGvMaxLevels(); $psaaLevel = $req->getPsaaLevel(); $this->_logger->info("'Qualification for Loyalty' calculation is started. Performed at: {$datePerformed}, applied at: {$dateApplied}."); $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); $updates = $this->_subQualification->calcParams($tree, $qualData, $gvMaxLevels, $psaaLevel); $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 Loyalty' calculation is complete."); return $result; }