示例#1
0
 public function testAdd()
 {
     $newObj = new Base();
     $this->arrayCollection->add($newObj);
     $this->assertEquals($newObj, $this->arrayCollection->get(2));
     $newObj->setId(65);
     $this->arrayCollection->add($newObj);
     $this->assertEquals($newObj, $this->arrayCollection->get(65));
     $this->arrayCollection->add($newObj, 500);
     $this->assertEquals($newObj, $this->arrayCollection->get(500));
 }
 public function getTradeDataCollectionForJob(Job $job)
 {
     $sql = "SELECT\n                  rq.id as id,\n                  s.id as security_id,\n                  sca.id as account_id,\n                  sca.account_number as account_number,\n                  st.name as security_type,\n                  rq.status as action,\n                  p.quantity as position_quantity,\n                  s.symbol as symbol,\n                  SUM(rq.quantity) as quantity,\n                  SUM(rq.amount) as amount,\n                  IF(p.quantity = SUM(rq.quantity) OR (rq.status = '" . QueueItem::STATUS_SELL . "' AND rq.lot_id IS NULL), 'AS', 'S') as quantity_type\n                FROM " . $this->table . " rq\n                  LEFT JOIN " . self::TABLE_SECURITY . " s on s.id = rq.security_id\n                  LEFT JOIN " . self::TABLE_SYSTEM_ACCOUNT . " sca ON sca.id = rq.system_client_account_id\n                  LEFT JOIN " . self::TABLE_SECURITY_TYPE . " st ON st.id = s.security_type_id\n                  LEFT JOIN " . self::TABLE_LOT . " l ON l.id = rq.lot_id\n                  LEFT JOIN " . self::TABLE_POSITION . " p ON p.id = l.position_id\n                  LEFT JOIN " . self::TABLE_REBALANCER_ACTION . " ra On ra.id = rq.rebalancer_action_id\n                WHERE ra.job_id = :jobId\n                GROUP BY sca.id, s.id\n                ORDER BY rq.id";
     $paramaters = array('jobId' => $job->getId());
     $results = $this->db->query($sql, $paramaters);
     $tradeDataCollection = new ArrayCollection();
     foreach ($results as $result) {
         $tradeData = new TradeData();
         $tradeData->loadFromArray($result);
         if ($tradeData->getAction() === TradeData::ACTION_SELL) {
             $vsps = $this->findVSPForTradeData($tradeData);
             $tradeData->setVsps($vsps);
         }
         $tradeData->setJobId($job->getId());
         $tradeDataCollection->add($tradeData);
     }
     return $tradeDataCollection;
 }
 /**
  * @param array $data
  * @return ArrayCollection
  */
 private function getMockTradeDataCollection(array $data = array())
 {
     $tradeDataCollection = new ArrayCollection();
     foreach ($data as $item) {
         $tradeData = $this->getMockTradeData($item);
         $tradeDataCollection->add($tradeData);
     }
     return $tradeDataCollection;
 }
 public function testGetTradeDataCollectionForJob()
 {
     $riaRepo = new RiaRepository();
     $ria = $riaRepo->findOneBy(array('email' => '*****@*****.**'));
     $jobRepo = new JobRepository();
     $job = $jobRepo->findOneBy(array('user_id' => $ria->getId()));
     $tradeDataCollection = $this->repository->getTradeDataCollectionForJob($job);
     $this->assertCount(3, $tradeDataCollection);
     $securityRepo = new SecurityRepository();
     $accountRepo = new AccountRepository();
     $tradeDataExpectedArray = array(array('job_id' => $job->getId(), 'security_id' => $securityRepo->findOneBySymbol('RWX')->getId(), 'account_id' => $accountRepo->findOneByAccountNumber('916985328')->getId(), 'account_number' => '916985328', 'account_type' => TradeData::ACCOUNT_TYPE_CASH_ACCOUNT, 'security_type' => TradeData::SECURITY_TYPE_EQUITY, 'action' => TradeData::ACTION_SELL, 'quantity_type' => TradeData::QUANTITY_TYPE_ALL_SHARES, 'quantity' => '56', 'symbol' => 'RWX'), array('job_id' => $job->getId(), 'security_id' => $securityRepo->findOneBySymbol('VCIT')->getId(), 'account_id' => $accountRepo->findOneByAccountNumber('480888811')->getId(), 'account_number' => '480888811', 'account_type' => TradeData::ACCOUNT_TYPE_CASH_ACCOUNT, 'security_type' => TradeData::SECURITY_TYPE_EQUITY, 'action' => TradeData::ACTION_BUY, 'quantity_type' => TradeData::QUANTITY_TYPE_SHARES, 'quantity' => '12', 'symbol' => 'VCIT'), array('job_id' => $job->getId(), 'security_id' => $securityRepo->findOneBySymbol('BND')->getId(), 'account_id' => $accountRepo->findOneByAccountNumber('122223334')->getId(), 'account_number' => '122223334', 'account_type' => TradeData::ACCOUNT_TYPE_CASH_ACCOUNT, 'security_type' => TradeData::SECURITY_TYPE_EQUITY, 'action' => TradeData::ACTION_BUY, 'quantity_type' => TradeData::QUANTITY_TYPE_SHARES, 'quantity' => '1', 'symbol' => 'BND'), array('job_id' => '59', 'security_id' => $securityRepo->findOneBySymbol('VGIT')->getId(), 'account_id' => $accountRepo->findOneByAccountNumber('916985328')->getId(), 'account_number' => '916985328', 'account_type' => TradeData::ACCOUNT_TYPE_CASH_ACCOUNT, 'security_type' => TradeData::SECURITY_TYPE_EQUITY, 'action' => TradeData::ACTION_SELL, 'quantity_type' => TradeData::QUANTITY_TYPE_ALL_SHARES, 'quantity' => '10', 'symbol' => 'VGIT'));
     $tradeDataCollectionExpected = new ArrayCollection();
     foreach ($tradeDataExpectedArray as $key => $tradeDataExpected) {
         $tradeData = new TradeData();
         $tradeData->loadFromArray($tradeDataExpected);
         $tradeDataCollectionExpected->add($tradeData, $key);
     }
     foreach ($tradeDataCollection as $tradeData) {
         $tradeData->setId(null);
         $tradeDataExpected = $tradeDataCollectionExpected->current();
         $this->assertEquals($tradeData, $tradeDataExpected);
         $tradeDataCollectionExpected->next();
     }
 }