public function testSaveStatus()
 {
     $jobRepo = new JobRepository();
     $clientRepo = new ClientRepository();
     $portfolioRepo = new PortfolioRepository();
     $job = $jobRepo->findFirst();
     $client = $clientRepo->findClientByEmail('*****@*****.**');
     $portfolio = $portfolioRepo->findPortfolioByClient($client);
     $rebalancerActions = $this->repository->findByPortfolioAndJob($portfolio, $job);
     /** @var RebalancerAction $rebalancerAction */
     $rebalancerAction = $rebalancerActions->first();
     $sql = "SELECT * FROM " . BaseRepository::TABLE_REBALANCER_ACTION . " ra where ra.id = :id";
     $connection = WealthbotMySqlSqliteConnection::getInstance();
     $pdo = $connection->getPdo();
     $statement = $pdo->prepare($sql);
     $statement->execute(array('id' => $rebalancerAction->getId()));
     $result = $statement->fetch(\PDO::FETCH_ASSOC);
     $this->assertNotEquals(Job::REBALANCE_TYPE_NO_ACTIONS, $result['status']);
     $tmpStatus = $result['status'];
     $rebalancerAction->setStatus(Job::REBALANCE_TYPE_NO_ACTIONS);
     $this->repository->saveStatus($rebalancerAction);
     $statement = $pdo->prepare($sql);
     $statement->execute(array('id' => $rebalancerAction->getId()));
     $result = $statement->fetch(\PDO::FETCH_ASSOC);
     $this->assertEquals(Job::REBALANCE_TYPE_NO_ACTIONS, $result['status']);
     $rebalancerAction->setStatus($tmpStatus);
     $this->repository->saveStatus($rebalancerAction);
 }
예제 #2
0
 public function testFindAllCurrentJob()
 {
     $jobs = $this->repository->findAllCurrentRebalancerJob();
     $this->assertCount(3, $jobs);
     $now = new \DateTime();
     /** @var Job $job */
     foreach ($jobs as $job) {
         $jobStartedAt = new \DateTime($job->getStartedAt());
         $this->assertNull($job->getFinishedAt());
         $this->assertLessThan($now->getTimestamp(), $jobStartedAt->getTimestamp());
         $this->assertEquals(Job::JOB_NAME_REBALANCER, $job->getName());
     }
 }
 public function testFindVSPForTradeData()
 {
     $riaRepo = new RiaRepository();
     $ria = $riaRepo->findOneBy(array('email' => '*****@*****.**'));
     $jobRepo = new JobRepository();
     $job = $jobRepo->findOneBy(array('user_id' => $ria->getId()));
     $accountRepo = new AccountRepository();
     $securityRepo = new SecurityRepository();
     $tradeData = new TradeData();
     $tradeData->setJobId($job->getId());
     $tradeData->setAccountId($accountRepo->findOneByAccountNumber('916985328')->getId());
     $tradeData->setSecurityId($securityRepo->findOneBySymbol('RWX')->getId());
     $vsps = $this->repository->findVSPForTradeData($tradeData);
     $vspsExpected = array(array('purchase' => 'VSP', 'purchase_date' => '02132013', 'quantity' => 36), array('purchase' => 'VSP', 'purchase_date' => '02162013', 'quantity' => 20));
     $this->assertEquals($vspsExpected, $vsps);
 }