Improve test coverage.

This commit is contained in:
James Cole
2019-07-31 16:53:09 +02:00
parent 5524941c90
commit 9b574ce7ad
155 changed files with 1890 additions and 2263 deletions

View File

@@ -105,60 +105,11 @@ trait AccountServiceTrait
}
}
// /**
// * @param User $user
// * @param string $name
// *
// * @return Account
// * @throws \FireflyIII\Exceptions\FireflyException
// */
// public function storeOpposingAccount(User $user, string $name): Account
// {
// $opposingAccountName = (string)trans('firefly.initial_balance_account', ['name' => $name]);
// Log::debug('Going to create an opening balance opposing account.');
// /** @var AccountFactory $factory */
// $factory = app(AccountFactory::class);
// $factory->setUser($user);
//
// return $factory->findOrCreate($opposingAccountName, AccountType::INITIAL_BALANCE);
// }
// /**
// * @param Account $account
// * @param array $data
// *
// * @return bool
// * @throws \FireflyIII\Exceptions\FireflyException
// */
// public function updateOB(Account $account, array $data): bool
// {
// Log::debug(sprintf('updateIB() for account #%d', $account->id));
//
// $openingBalanceGroup = $this->getOBGroup($account);
//
// // no opening balance journal? create it:
// if (null === $openingBalanceGroup) {
// Log::debug('No opening balance journal yet, create group.');
// $this->storeOBGroup($account, $data);
//
// return true;
// }
//
// // opening balance data? update it!
// if (null !== $openingBalanceGroup->id) {
// Log::debug('Opening balance group found, update group.');
// $this->updateOBGroup($account, $openingBalanceGroup, $data);
//
// return true;
// }
//
// return true; // @codeCoverageIgnore
// }
/**
* @param Account $account
* @param string $note
*
* @codeCoverageIgnore
* @return bool
*/
public function updateNote(Account $account, string $note): bool
@@ -186,117 +137,6 @@ trait AccountServiceTrait
return true;
}
// /**
// * Find existing opening balance.
// *
// * @param Account $account
// *
// * @return TransactionJournal|null
// */
// public function getIBJournal(Account $account): ?TransactionJournal
// {
// $journal = TransactionJournal::leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
// ->where('transactions.account_id', $account->id)
// ->transactionTypes([TransactionType::OPENING_BALANCE])
// ->first(['transaction_journals.*']);
// if (null === $journal) {
// Log::debug('Could not find a opening balance journal, return NULL.');
//
// return null;
// }
// Log::debug(sprintf('Found opening balance: journal #%d.', $journal->id));
//
// return $journal;
// }
// /**
// * @param Account $account
// * @param array $data
// *
// * @return TransactionJournal|null
// * @throws \FireflyIII\Exceptions\FireflyException
// * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
// */
// public function storeIBJournal(Account $account, array $data): ?TransactionJournal
// {
// $amount = (string)$data['openingBalance'];
// Log::debug(sprintf('Submitted amount is %s', $amount));
//
// if (0 === bccomp($amount, '0')) {
// return null;
// }
//
// // store journal, without transactions:
// $name = $data['name'];
// $currencyId = $data['currency_id'];
// $journalData = [
// 'type' => TransactionType::OPENING_BALANCE,
// 'user' => $account->user->id,
// 'transaction_currency_id' => $currencyId,
// 'description' => (string)trans('firefly.initial_balance_description', ['account' => $account->name]),
// 'completed' => true,
// 'date' => $data['openingBalanceDate'],
// 'bill_id' => null,
// 'bill_name' => null,
// 'piggy_bank_id' => null,
// 'piggy_bank_name' => null,
// 'tags' => null,
// 'notes' => null,
// 'transactions' => [],
//
// ];
// /** @var TransactionJournalFactory $factory */
// $factory = app(TransactionJournalFactory::class);
// $factory->setUser($account->user);
// $journal = $factory->create($journalData);
// $opposing = $this->storeOpposingAccount($account->user, $name);
// Log::notice(sprintf('Created new opening balance journal: #%d', $journal->id));
//
// $firstAccount = $account;
// $secondAccount = $opposing;
// $firstAmount = $amount;
// $secondAmount = bcmul($amount, '-1');
// Log::notice(sprintf('First amount is %s, second amount is %s', $firstAmount, $secondAmount));
//
// if (bccomp($amount, '0') === -1) {
// Log::debug(sprintf('%s is a negative number.', $amount));
// $firstAccount = $opposing;
// $secondAccount = $account;
// $firstAmount = bcmul($amount, '-1');
// $secondAmount = $amount;
// Log::notice(sprintf('First amount is %s, second amount is %s', $firstAmount, $secondAmount));
// }
// /** @var TransactionFactory $factory */
// $factory = app(TransactionFactory::class);
// $factory->setUser($account->user);
// $factory->create(
// [
// 'account' => $firstAccount,
// 'transaction_journal' => $journal,
// 'amount' => $firstAmount,
// 'currency_id' => $currencyId,
// 'description' => null,
// 'identifier' => 0,
// 'foreign_amount' => null,
// 'reconciled' => false,
// ]
// );
// $factory->create(
// [
// 'account' => $secondAccount,
// 'transaction_journal' => $journal,
// 'amount' => $secondAmount,
// 'currency_id' => $currencyId,
// 'description' => null,
// 'identifier' => 0,
// 'foreign_amount' => null,
// 'reconciled' => false,
// ]
// );
//
// return $journal;
// }
/**
* Verify if array contains valid data to possibly store or update the opening balance.
*
@@ -340,52 +180,6 @@ trait AccountServiceTrait
return $currency;
}
// /**
// * @param Account $account
// * @param TransactionJournal $journal
// * @param array $data
// *
// * @return bool
// * @SuppressWarnings(PHPMD.CyclomaticComplexity)
// */
// protected function updateIBJournal(Account $account, TransactionJournal $journal, array $data): bool
// {
// $date = $data['openingBalanceDate'];
// $amount = (string)$data['openingBalance'];
// $negativeAmount = bcmul($amount, '-1');
// $currencyId = (int)$data['currency_id'];
// Log::debug(sprintf('Submitted amount for opening balance to update is "%s"', $amount));
// if (0 === bccomp($amount, '0')) {
// Log::notice(sprintf('Amount "%s" is zero, delete opening balance.', $amount));
// /** @var JournalDestroyService $service */
// $service = app(JournalDestroyService::class);
// $service->destroy($journal);
//
// return true;
// }
// $journal->date = $date;
// $journal->transaction_currency_id = $currencyId;
// $journal->save();
// /** @var Transaction $transaction */
// foreach ($journal->transactions()->get() as $transaction) {
// if ((int)$account->id === (int)$transaction->account_id) {
// Log::debug(sprintf('Will (eq) change transaction #%d amount from "%s" to "%s"', $transaction->id, $transaction->amount, $amount));
// $transaction->amount = $amount;
// $transaction->transaction_currency_id = $currencyId;
// $transaction->save();
// }
// if (!((int)$account->id === (int)$transaction->account_id)) {
// Log::debug(sprintf('Will (neq) change transaction #%d amount from "%s" to "%s"', $transaction->id, $transaction->amount, $negativeAmount));
// $transaction->amount = $negativeAmount;
// $transaction->transaction_currency_id = $currencyId;
// $transaction->save();
// }
// }
// Log::debug('Updated opening balance journal.');
//
// return true;
// }
/**
* Delete TransactionGroup with opening balance in it.
*
@@ -486,7 +280,9 @@ trait AccountServiceTrait
*
* @param Account $account
* @param array $data
*
* @return TransactionGroup|null
* @codeCoverageIgnore
*/
protected function updateOBGroup(Account $account, array $data): ?TransactionGroup
{