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

@@ -29,6 +29,7 @@ use FireflyIII\Models\AccountType;
use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Services\Internal\Support\AccountServiceTrait;
use FireflyIII\User;
use Log;
/**
@@ -43,6 +44,8 @@ class AccountUpdateService
/** @var AccountRepositoryInterface */
protected $accountRepository;
/** @var User */
private $user;
/**
* Constructor.
*/
@@ -67,6 +70,7 @@ class AccountUpdateService
public function update(Account $account, array $data): Account
{
$this->accountRepository->setUser($account->user);
$this->user = $account->user;
// update the account itself:
$account->name = $data['name'];
@@ -91,10 +95,13 @@ class AccountUpdateService
// has valid initial balance (IB) data?
$type = $account->accountType;
// if it can have a virtual balance, it can also have an opening balance.
if (in_array($type->type, $this->canHaveVirtual, true)) {
if ($this->validOBData($data)) {
$this->updateOBGroup($account, $data);
}
if (!$this->validOBData($data)) {
$this->deleteOBGroup($account);
}

View File

@@ -28,6 +28,7 @@ use Log;
/**
* Class CategoryUpdateService
* @codeCoverageIgnore
*/
class CategoryUpdateService
{

View File

@@ -28,6 +28,7 @@ use Log;
/**
* Class CurrencyUpdateService
* @codeCoverageIgnore
*/
class CurrencyUpdateService
{

View File

@@ -31,6 +31,7 @@ use Log;
/**
* Class GroupUpdateService
* TODO test.
*/
class GroupUpdateService
{

View File

@@ -48,6 +48,7 @@ use Log;
* Class to centralise code that updates a journal given the input by system.
*
* Class JournalUpdateService
* TODO test me
*/
class JournalUpdateService
{

View File

@@ -26,16 +26,16 @@ namespace FireflyIII\Services\Internal\Update;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Recurrence;
use FireflyIII\Services\Internal\Support\RecurringTransactionTrait;
use FireflyIII\Services\Internal\Support\TransactionServiceTrait;
use FireflyIII\Services\Internal\Support\TransactionTypeTrait;
use FireflyIII\User;
/**
* Class RecurrenceUpdateService
* @codeCoverageIgnore
*/
class RecurrenceUpdateService
{
use TransactionTypeTrait, TransactionServiceTrait, RecurringTransactionTrait;
use TransactionTypeTrait, RecurringTransactionTrait;
/** @var User */
private $user;
@@ -51,7 +51,6 @@ class RecurrenceUpdateService
*/
public function update(Recurrence $recurrence, array $data): Recurrence
{
// is expected by TransactionServiceTrait
$this->user = $recurrence->user;
$transactionType = $this->findTransactionType(ucfirst($data['recurrence']['type']));
// update basic fields first:

View File

@@ -1,179 +0,0 @@
<?php
/**
* TransactionUpdateService.php
* Copyright (c) 2018 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
*
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Services\Internal\Update;
use FireflyIII\Models\Transaction;
use FireflyIII\Services\Internal\Support\TransactionServiceTrait;
use FireflyIII\User;
use Log;
/**
* Class TransactionUpdateService
* TODO i think this is deprecated.
*/
class TransactionUpdateService
{
use TransactionServiceTrait;
/** @var User */
private $user;
/**
* Constructor.
*/
public function __construct()
{
if ('testing' === config('app.env')) {
Log::warning(sprintf('%s should not be instantiated in the TEST environment!', get_class($this)));
}
}
// /**
// * @param int $transactionId
// *
// * @return Transaction|null
// */
// public function reconcile(int $transactionId): ?Transaction
// {
// $transaction = Transaction::find($transactionId);
// if (null !== $transaction) {
// $transaction->reconciled = true;
// $transaction->save();
//
// return $transaction;
// }
//
// return null;
//
// }
/**
* @param User $user
*/
public function setUser(User $user): void
{
$this->user = $user;
}
// /**
// * @param Transaction $transaction
// * @param array $data
// *
// * @return Transaction
// * @throws \FireflyIII\Exceptions\FireflyException
// * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
// * @SuppressWarnings(PHPMD.CyclomaticComplexity)
// * @SuppressWarnings(PHPMD.NPathComplexity)
// *
// */
// public function update(Transaction $transaction, array $data): Transaction
// {
// $currency = $this->findCurrency($data['currency_id'], $data['currency_code']);
// $journal = $transaction->transactionJournal;
// $amount = (string)$data['amount'];
// $account = null;
// // update description:
// $transaction->description = $data['description'];
// $foreignAmount = null;
// if ((float)$transaction->amount < 0) {
// // this is the source transaction.
// $type = $this->accountType($journal, 'source');
// $account = $this->findAccount($type, $data['source_id'], $data['source_name']);
// $amount = app('steam')->negative($amount);
// $foreignAmount = app('steam')->negative((string)$data['foreign_amount']);
// }
//
// if ((float)$transaction->amount > 0) {
// // this is the destination transaction.
// $type = $this->accountType($journal, 'destination');
// $account = $this->findAccount($type, $data['destination_id'], $data['destination_name']);
// $amount = app('steam')->positive($amount);
// $foreignAmount = app('steam')->positive((string)$data['foreign_amount']);
// }
//
// // update the actual transaction:
// $transaction->description = $data['description'];
// $transaction->amount = $amount;
// $transaction->foreign_amount = null;
// $transaction->transaction_currency_id = null === $currency ? $transaction->transaction_currency_id : $currency->id;
// $transaction->account_id = $account->id;
// $transaction->reconciled = $data['reconciled'];
// $transaction->save();
//
// // set foreign currency
// $foreign = $this->findCurrency($data['foreign_currency_id'], $data['foreign_currency_code']);
// // set foreign amount:
// if (null !== $foreign && null !== $data['foreign_amount']) {
// $this->setForeignCurrency($transaction, $foreign);
// $this->setForeignAmount($transaction, $foreignAmount);
// }
// if (null === $foreign || null === $data['foreign_amount']) {
// $this->setForeignCurrency($transaction, null);
// $this->setForeignAmount($transaction, null);
// }
//
// // set budget:
// $budget = $this->findBudget($data['budget_id'], $data['budget_name']);
// $this->setBudget($transaction, $budget);
//
// // set category
// $category = $this->findCategory($data['category_id'], $data['category_name']);
// $this->setCategory($transaction, $category);
//
// return $transaction;
// }
//
// /**
// * Update budget for a journal.
// *
// * @param Transaction $transaction
// * @param int $budgetId
// *
// * @return Transaction
// */
// public function updateBudget(Transaction $transaction, int $budgetId): Transaction
// {
// $budget = $this->findBudget($budgetId, null);
// $this->setBudget($transaction, $budget);
//
// return $transaction;
//
// }
//
// /**
// * Update category for a journal.
// *
// * @param Transaction $transaction
// * @param string $category
// *
// * @return Transaction
// */
// public function updateCategory(Transaction $transaction, string $category): Transaction
// {
// $found = $this->findCategory(0, $category);
// $this->setCategory($transaction, $found);
//
// return $transaction;
// }
}