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); }
public function setUp() { $connection = WealthbotMySqlSqliteConnection::getInstance(); $sql = "SELECT * FROM " . BaseRepository::TABLE_SYSTEM_ACCOUNT . " ORDER BY id ASC LIMIT 1"; $result = $connection->query($sql); $this->account = new Account(); $this->account->loadFromArray($result[0]); $this->repository = new DistributionRepository(); $this->businessCalendar = new BusinessCalendar(); }
public function testGetAccountsByRebalancerActionData() { $rebalancerActionRepo = new RebalancerActionRepository(); $rebalancerActions = $rebalancerActionRepo->findAll(); /** @var RebalancerAction $rebalancerAction */ $rebalancerAction = $rebalancerActions->first(); $sql = "SELECT u.*, up.client_account_managed as account_managed from rebalancer_actions ra\n LEFT JOIN client_portfolio_values cpv ON cpv.id = ra.client_portfolio_value_id\n LEFT JOIN client_portfolio cp ON cp.id = cpv.client_portfolio_id\n LEFT JOIN users u ON u.id = cp.client_id\n LEFT JOIN user_profiles up ON up.user_id = u.id\n WHERE ra.id = :rebalancerActionId\n "; $parameters = array('rebalancerActionId' => $rebalancerAction->getId()); $connection = WealthbotMySqlSqliteConnection::getInstance(); $pdo = $connection->getPdo(); $statement = $pdo->prepare($sql); $statement->execute($parameters); $result = $statement->fetch(\PDO::FETCH_ASSOC); $client = new Client(); $client->setId($result['id']); $accounts = $this->repository->findClientAccounts($client); $rebalancerAction->setClient($client); $client->setAccountManaged(Client::ACCOUNT_MANAGED_HOUSEHOLD); $collection = $this->repository->getAccountsByRebalancerAction($rebalancerAction); $this->assertCount(4, $collection); //------------------------------------------------------------------------- $rebalancerAction->setAccountId($accounts->first()->getId()); $client->setAccountManaged(Client::ACCOUNT_MANAGED_ACCOUNT); $collection = $this->repository->getAccountsByRebalancerAction($rebalancerAction); $account = $collection->first(); $this->assertCount(1, $collection); $this->assertEquals($rebalancerAction->getAccountId(), $account->getId()); $this->assertEquals($client->getId(), $account->getClient()->getId()); }