Exemplo n.º 1
0
 public function __construct()
 {
     $opts = getopt(self::HELP . self::SERVER_URL . ':' . self::BALANCE . self::DAILY_BALANCE . self::EXPENSES . self::REMOVE_DUPLICATES . self::CLEAN_NAMES . '::' . self::BULK_DAILY_BALANCE . self::BULK_EXPENSES . self::FAILURE_THRESHOLD . ':' . self::ALL_DATA);
     if (array_key_exists(self::HELP, $opts) || count($opts) === 0) {
         $this->printUsage();
         exit;
     }
     $data = array();
     $dataUrl = self::DEFAULT_SERVER_URL;
     if (isset($opts[self::SERVER_URL]) && false !== $opts[self::SERVER_URL] && strlen($opts[self::SERVER_URL]) > 0) {
         $dataUrl = $opts[self::SERVER_URL];
     }
     $failureThreshold = 1;
     if (isset($opts[self::FAILURE_THRESHOLD]) && is_numeric($opts[self::FAILURE_THRESHOLD])) {
         $failureThreshold = $opts[self::FAILURE_THRESHOLD];
     }
     $data = $this->getData($dataUrl, $failureThreshold);
     $bulkLoad = isset($opts[self::BULK_DAILY_BALANCE]) || isset($opts[self::BULK_EXPENSES]);
     $transactionRecord = new TransactionRecord($data, $bulkLoad);
     if (isset($opts[self::REMOVE_DUPLICATES])) {
         $transactionRecord->removeDuplicateTransactions();
     }
     if (isset($opts[self::BULK_DAILY_BALANCE])) {
         error_log("THE BULK CALCULATED DAILY BALANCES: " . json_encode($transactionRecord->generateDailyCalculatedBalances()));
     }
     if (isset($opts[self::BULK_EXPENSES])) {
         error_log("THE BULK EXPENSES: " . json_encode($transactionRecord->generateExpenseList()));
     }
     if (isset($opts[self::BALANCE])) {
         error_log("THE BALANCE IS: " . $transactionRecord->getTotalBalance());
     }
     if (isset($opts[self::DAILY_BALANCE])) {
         error_log("THE DAILY BALANCE: " . json_encode($transactionRecord->getDailyBalances()));
     }
     if (isset($opts[self::EXPENSES])) {
         error_log("THE EXPENSES: " . json_encode($transactionRecord->getExpenses()));
     }
     if (isset($opts[self::CLEAN_NAMES])) {
         $regex = null;
         if (false !== $opts[self::CLEAN_NAMES] && strlen($opts[self::CLEAN_NAMES]) > 0) {
             $regex = $opts[self::CLEAN_NAMES];
         }
         error_log("THE CLEANED NAMES: " . json_encode($transactionRecord->cleanCompanyNames($regex)));
     }
     if (isset($opts[self::ALL_DATA])) {
         error_log("ALL DATA: " . $transactionRecord->getRawTransactionDataAsJSON());
     }
 }
 public function testRawData()
 {
     $rawData = array(array('page' => 1, 'totalCount' => 3, 'transactions' => array(array(Transaction::AMOUNT => 10.0, Transaction::COMPANY => 'Some xxxcompany', Transaction::DATE => '2015-01-01', Transaction::LEDGER => 'Some expense'), array(Transaction::AMOUNT => 10.0, Transaction::COMPANY => 'Some xxxcompany', Transaction::DATE => '2015-01-01', Transaction::LEDGER => 'Some expense'))), array('page' => 2, 'totalCount' => 3, 'transactions' => array(array(Transaction::AMOUNT => 10.0, Transaction::COMPANY => 'Some xxxcompany', Transaction::DATE => '2015-01-01', Transaction::LEDGER => 'Some expense'), 'garbage')));
     $transactionRecord = new TransactionRecord($rawData);
     $this->assertEquals(3, $transactionRecord->getExpectedTransactionCount());
     $this->assertEquals(3, $transactionRecord->getNumTransactions());
 }