コード例 #1
0
 public function test_qualifyByUserData()
 {
     $obm = \Magento\Framework\App\ObjectManager::getInstance();
     /**
      * Prepare request data.
      */
     /** @var  $callDownlineSnap \Praxigento\Downline\Service\ISnap */
     $callDownlineSnap = $obm->get('\\Praxigento\\Downline\\Service\\ISnap');
     $reqSnap = new \Praxigento\Downline\Service\Snap\Request\GetStateOnDate();
     $reqSnap->setDatestamp('20201231');
     $respSnap = $callDownlineSnap->getStateOnDate($reqSnap);
     $flatTree = $respSnap->getData();
     /** @var  $call \Praxigento\BonusBase\Service\Compress\Call */
     $call = $obm->get('Praxigento\\BonusBase\\Service\\Compress\\Call');
     $request = new Request\QualifyByUserData();
     $request->setCalcId(6);
     $request->setFlatTree($flatTree);
     $request->setQualifier(new CustomQualifyUser());
     $response = $call->qualifyByUserData($request);
     $this->assertTrue($response->isSucceed());
 }
コード例 #2
0
 public function test_qualifyByUserData()
 {
     /** === Test Data === */
     /**
      * Test data is not real customer tree, just for code coverage.
      */
     $calcId = 2;
     $tree = [];
     $skipExpand = false;
     $depth4 = 4;
     $cust4 = 4;
     $cust3 = 3;
     $cust2 = 2;
     $cust1 = 1;
     $treeExp = [$cust1 => [Snap::ATTR_PATH => 'path1'], $cust2 => [Snap::ATTR_PATH => 'path2'], $cust3 => [Snap::ATTR_PATH => 'path3'], $cust4 => [Snap::ATTR_PATH => 'path4']];
     /** === Setup Mocks === */
     $mQualifier = $this->_mock(\Praxigento\BonusBase\Tool\IQualifyUser::class);
     $this->mLogger->shouldReceive('info');
     // $treeExpanded = $this->_toolDownlineTree->expandMinimal($treeFlat, Snap::ATTR_PARENT_ID);
     $this->mToolDownlineTree->shouldReceive('expandMinimal')->once()->andReturn($treeExp);
     // $resp = $this->_callDownlineSnap->expandMinimal($req);
     $mRespExp = new DataObject();
     $this->mCallDownlineSnap->shouldReceive('expandMinimal')->andReturn($mRespExp);
     // return $resp->getSnapData();
     $mSanpData = [$cust1 => [Snap::ATTR_PATH => '/'], $cust2 => [Snap::ATTR_PATH => '/1/'], $cust3 => [Snap::ATTR_PATH => '/1/2/'], $cust4 => [Snap::ATTR_PATH => '/1/2/3/']];
     $mRespExp->setSnapData($mSanpData);
     // $mapById = $this->_mapById($treeExpanded);
     // $resp = $this->_callDownlineMap->byId($req);
     $mRespById = new DataObject([$cust1 => []]);
     $this->mCallDownlineMap->shouldReceive('byId')->andReturn($mRespById);
     // return $resp->getMapped();
     $mMapById = [$cust4 => [Customer::ATTR_HUMAN_REF => 'ref4'], $cust3 => [Customer::ATTR_HUMAN_REF => 'ref3'], $cust2 => [Customer::ATTR_HUMAN_REF => 'ref2'], $cust1 => [Customer::ATTR_HUMAN_REF => 'ref1']];
     $mRespById->setMapped($mMapById);
     // $mapDepth = $this->_mapByTreeDepthDesc($treeExpanded);
     // $resp = $this->_callDownlineMap->treeByDepth($req);
     $mRespByDepth = new DataObject();
     $this->mCallDownlineMap->shouldReceive('treeByDepth')->andReturn($mRespByDepth);
     // return $resp->getMapped();
     $mMapByDepth = [$depth4 => [$cust4, $cust3, $cust2]];
     $mRespByDepth->setMapped($mMapByDepth);
     // $mapTeams = $this->_mapByTeams($treeExpanded);
     // $resp = $this->_callDownlineMap->treeByTeams($req);
     $mRespByTeams = new DataObject();
     $this->mCallDownlineMap->shouldReceive('treeByTeams')->andReturn($mRespByTeams);
     // return $resp->getMapped();
     $mMapByTeams = [$cust3 => [$cust4], $cust2 => [$cust4]];
     $mRespByTeams->setMapped($mMapByTeams);
     // if($qualifier->isQualified($custData)) {
     $mQualifier->shouldReceive('isQualified')->once()->andReturn(true);
     $mQualifier->shouldReceive('isQualified')->once()->andReturn(false);
     $mQualifier->shouldReceive('isQualified')->once()->andReturn(true);
     $mQualifier->shouldReceive('isQualified')->once()->andReturn(false);
     $mQualifier->shouldReceive('isQualified')->once()->andReturn(false);
     // $parents = $this->_toolDownlineTree->getParentsFromPathReversed($path);
     $mParents = [$cust1];
     $this->mToolDownlineTree->shouldReceive('getParentsFromPathReversed')->andReturn($mParents);
     // $def = $this->_manTrans->begin();
     $mDef = $this->_mockTransactionDefinition();
     $this->mManTrans->shouldReceive('begin')->once()->andReturn($mDef);
     // $this->_repoBonusCompress->create($data);
     $this->mRepoBonusCompress->shouldReceive('create')->once();
     // $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\QualifyByUserData();
     $req->setCalcId($calcId);
     $req->setFlatTree($tree);
     $req->setQualifier($mQualifier);
     $req->setSkipTreeExpand($skipExpand);
     $resp = $this->call->qualifyByUserData($req);
     $this->assertTrue($resp->isSucceed());
 }