Fix test coverage.

This commit is contained in:
James Cole
2019-08-17 12:08:09 +02:00
parent 1d4434698e
commit b53cbbe469
16 changed files with 83 additions and 213 deletions

View File

@@ -27,6 +27,7 @@ use FireflyIII\Models\Account;
use FireflyIII\Models\Budget;
use FireflyIII\Models\Category;
use FireflyIII\Models\TransactionType;
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use Illuminate\Support\Collection;
use Log;
@@ -97,11 +98,24 @@ class PopupReport implements PopupReportInterface
*/
public function byBudget(Budget $budget, array $attributes): array
{
// filter by currency, if set.
$currencyId = $attributes['currencyId'] ?? null;
$currency = null;
if (null !== $currencyId) {
/** @var CurrencyRepositoryInterface $repos */
$repos = app(CurrencyRepositoryInterface::class);
$currency = $repos->find((int)$currencyId);
}
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
$collector->setAccounts($attributes['accounts'])->setRange($attributes['startDate'], $attributes['endDate']);
if (null !== $currency) {
$collector->setCurrency($currency);
}
if (null === $budget->id) {
$collector->setTypes([TransactionType::WITHDRAWAL])->withoutBudget();
}
@@ -122,12 +136,25 @@ class PopupReport implements PopupReportInterface
*/
public function byCategory(Category $category, array $attributes): array
{
// filter by currency, if set.
$currencyId = $attributes['currencyId'] ?? null;
$currency = null;
if (null !== $currencyId) {
/** @var CurrencyRepositoryInterface $repos */
$repos = app(CurrencyRepositoryInterface::class);
$currency = $repos->find((int)$currencyId);
}
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
$collector->setAccounts($attributes['accounts'])->setTypes([TransactionType::WITHDRAWAL, TransactionType::TRANSFER])
$collector->setAccounts($attributes['accounts'])
->setTypes([TransactionType::WITHDRAWAL, TransactionType::TRANSFER, TransactionType::DEPOSIT])
->setRange($attributes['startDate'], $attributes['endDate'])->withAccountInformation()
->setCategory($category);
if (null !== $currency) {
$collector->setCurrency($currency);
}
return $collector->getExtractedJournals();
}
@@ -142,6 +169,15 @@ class PopupReport implements PopupReportInterface
*/
public function byExpenses(Account $account, array $attributes): array
{
// filter by currency, if set.
$currencyId = $attributes['currencyId'] ?? null;
$currency = null;
if (null !== $currencyId) {
/** @var CurrencyRepositoryInterface $repos */
$repos = app(CurrencyRepositoryInterface::class);
$currency = $repos->find((int)$currencyId);
}
/** @var JournalRepositoryInterface $repository */
$repository = app(JournalRepositoryInterface::class);
$repository->setUser($account->user);
@@ -149,20 +185,15 @@ class PopupReport implements PopupReportInterface
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
$collector->setAccounts(new Collection([$account]))->setRange($attributes['startDate'], $attributes['endDate'])
$collector->setAccounts(new Collection([$account]))
->setRange($attributes['startDate'], $attributes['endDate'])
->setTypes([TransactionType::WITHDRAWAL, TransactionType::TRANSFER]);
$journals = $collector->getExtractedJournals();
$report = $attributes['accounts']->pluck('id')->toArray(); // accounts used in this report
$filtered = [];
// TODO not sure if filter is necessary.
/** @var array $journal */
foreach ($journals as $journal) {
if (in_array($journal['source_account_id'], $report, true)) {
$filtered[] = $journal;
}
if (null !== $currency) {
$collector->setCurrency($currency);
}
return $filtered;
return $collector->getExtractedJournals();
}
/**