Skip to content

Firefly III: a personal finances manager

Fix tests

James Cole30f454d38a86
diff --git a/app/Support/Http/Controllers/RenderPartialViews.php b/app/Support/Http/Controllers/RenderPartialViews.php
index 091236f9bf..20c12b79d5 100644
--- a/app/Support/Http/Controllers/RenderPartialViews.php
+++ b/app/Support/Http/Controllers/RenderPartialViews.php
@@ -193,6 +193,9 @@ trait RenderPartialViews
$categoryRepository = app(CategoryRepositoryInterface::class);
$category = $categoryRepository->findNull((int)$attributes['categoryId']);
$journals = $popupHelper->byCategory($category, $attributes);
+ if (null === $category) {
+ return 'This is an unknown category. Apologies.';
+ }
// @codeCoverageIgnoreStart
try {
$view = view('popup.report.category-entry', compact('journals', 'category'))->render();
diff --git a/tests/Feature/Controllers/BillControllerTest.php b/tests/Feature/Controllers/BillControllerTest.php
index a350194100..904ff11dc5 100644
--- a/tests/Feature/Controllers/BillControllerTest.php
+++ b/tests/Feature/Controllers/BillControllerTest.php
@@ -180,6 +180,7 @@ class BillControllerTest extends TestCase
'currency' => $this->getEuro(),
'currency_id' => $euro->id,
'currency_code' => $euro->code,
+ 'pay_dates' => [],
'currency_symbol' => $euro->symbol,
'currency_decimal_places' => $euro->decimal_places,
]
diff --git a/tests/Feature/Controllers/Chart/ReportControllerTest.php b/tests/Feature/Controllers/Chart/ReportControllerTest.php
index cadb24e0e6..33417e58ff 100644
--- a/tests/Feature/Controllers/Chart/ReportControllerTest.php
+++ b/tests/Feature/Controllers/Chart/ReportControllerTest.php
@@ -121,45 +121,10 @@ class ReportControllerTest extends TestCase
$expense = [
'accounts' => [
2 => ['sum' => '-100']]];
- $tasker->shouldReceive('getIncomeReport')->once()->andReturn($income);
- $tasker->shouldReceive('getExpenseReport')->once()->andReturn($expense);
$generator->shouldReceive('multiSet')->andReturn([]);
$this->be($this->user());
$response = $this->get(route('chart.report.operations', [1, '20120101', '20120131']));
$response->assertStatus(200);
}
-
- /**
- * @covers \FireflyIII\Http\Controllers\Chart\ReportController
- */
- public function testSum(): void
- {
- $generator = $this->mock(GeneratorInterface::class);
- $tasker = $this->mock(AccountTaskerInterface::class);
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
- $fiscalHelper = $this->mock(FiscalHelperInterface::class);
- $date = new Carbon;
-
- $this->mockDefaultSession();
- Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
-
- $fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
- $fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
-
- $income = [
- 'accounts' => [
- 1 => ['sum' => '100']]];
- $expense = [
- 'accounts' => [
- 2 => ['sum' => '-100']]];
- $tasker->shouldReceive('getIncomeReport')->andReturn($income)->times(1);
- $tasker->shouldReceive('getExpenseReport')->andReturn($expense)->times(1);
-
- $generator->shouldReceive('multiSet')->andReturn([]);
-
- $this->be($this->user());
- $response = $this->get(route('chart.report.sum', [1, '20120101', '20120131']));
- $response->assertStatus(200);
- }
}
diff --git a/tests/Feature/Controllers/Chart/TagReportControllerTest.php b/tests/Feature/Controllers/Chart/TagReportControllerTest.php
index b035b91c82..bbf17441da 100644
--- a/tests/Feature/Controllers/Chart/TagReportControllerTest.php
+++ b/tests/Feature/Controllers/Chart/TagReportControllerTest.php
@@ -29,10 +29,12 @@ use FireflyIII\Helpers\Fiscal\FiscalHelperInterface;
use FireflyIII\Models\Preference;
use FireflyIII\Models\TransactionType;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
+use FireflyIII\Repositories\Tag\OperationsRepositoryInterface;
use FireflyIII\Repositories\Tag\TagRepositoryInterface;
use Illuminate\Support\Collection;
use Log;
use Preferences;
+use Tests\Support\TestDataTrait;
use Tests\TestCase;
/**
@@ -43,6 +45,7 @@ use Tests\TestCase;
*/
class TagReportControllerTest extends TestCase
{
+ use TestDataTrait;
/**
*
*/
@@ -52,70 +55,21 @@ class TagReportControllerTest extends TestCase
Log::info(sprintf('Now in %s.', get_class($this)));
}
- /**
- * @covers \FireflyIII\Http\Controllers\Chart\TagReportController
- */
- public function testAccountExpense(): void
- {
- $generator = $this->mock(GeneratorInterface::class);
- $tagRepos = $this->mock(TagRepositoryInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $tag = $this->user()->tags()->first();
-
- $this->mockDefaultSession();
-
- $tagRepos->shouldReceive('setUser');
- $tagRepos->shouldReceive('get')->andReturn(new Collection([$tag]));
-
- $fiscalHelper = $this->mock(FiscalHelperInterface::class);
- $date = new Carbon;
- $fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
- $fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
-
- $generator->shouldReceive('pieChart')->andReturn([])->once();
-
- $this->be($this->user());
-
-
- $response = $this->get(route('chart.tag.account-expense', ['1', $tag->tag, '20120101', '20120131', 0]));
- $response->assertStatus(200);
- }
/**
* @covers \FireflyIII\Http\Controllers\Chart\TagReportController
*/
- public function testAccountIncome(): void
+ public function testBudgetExpense(): void
{
$generator = $this->mock(GeneratorInterface::class);
$tagRepos = $this->mock(TagRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
- $tag = $this->user()->tags()->first();
- $tagRepos->shouldReceive('setUser');
- $tagRepos->shouldReceive('get')->andReturn(new Collection([$tag]));
-
- $this->mockDefaultSession();
-
- $fiscalHelper = $this->mock(FiscalHelperInterface::class);
- $date = new Carbon;
- $fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
- $fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
+ $opsRepos = $this->mock(OperationsRepositoryInterface::class);
- $generator->shouldReceive('pieChart')->andReturn([])->once();
- $this->be($this->user());
+ $opsRepos->shouldReceive('listExpenses')->atLeast()->once()->andReturn($this->tagListExpenses());
- $response = $this->get(route('chart.tag.account-income', ['1', $tag->tag, '20120101', '20120131', 0]));
- $response->assertStatus(200);
- }
- /**
- * @covers \FireflyIII\Http\Controllers\Chart\TagReportController
- */
- public function testBudgetExpense(): void
- {
- $generator = $this->mock(GeneratorInterface::class);
- $tagRepos = $this->mock(TagRepositoryInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
$tag = $this->user()->tags()->first();
$tagRepos->shouldReceive('setUser');
$tagRepos->shouldReceive('get')->andReturn(new Collection([$tag]));
@@ -127,7 +81,7 @@ class TagReportControllerTest extends TestCase
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
- $generator->shouldReceive('pieChart')->andReturn([])->once();
+ $generator->shouldReceive('multiCurrencyPieChart')->andReturn([])->once();
$this->be($this->user());
$response = $this->get(route('chart.tag.budget-expense', ['1', $tag->tag, '20120101', '20120131', 0]));
@@ -142,10 +96,13 @@ class TagReportControllerTest extends TestCase
$generator = $this->mock(GeneratorInterface::class);
$tagRepos = $this->mock(TagRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
+ $opsRepos = $this->mock(OperationsRepositoryInterface::class);
$tag = $this->user()->tags()->first();
$tagRepos->shouldReceive('setUser');
$tagRepos->shouldReceive('get')->andReturn(new Collection([$tag]));
+ $opsRepos->shouldReceive('listExpenses')->atLeast()->once()->andReturn($this->tagListExpenses());
+
$this->mockDefaultSession();
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
@@ -153,7 +110,7 @@ class TagReportControllerTest extends TestCase
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
- $generator->shouldReceive('pieChart')->andReturn([])->once();
+ $generator->shouldReceive('multiCurrencyPieChart')->andReturn([])->once();
$this->be($this->user());
$response = $this->get(route('chart.tag.category-expense', ['1', $tag->tag, '20120101', '20120131', 0]));
@@ -172,6 +129,10 @@ class TagReportControllerTest extends TestCase
$collector = $this->mock(GroupCollectorInterface::class);
$tagRepos = $this->mock(TagRepositoryInterface::class);
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
+ $opsRepos = $this->mock(OperationsRepositoryInterface::class);
+
+ $opsRepos->shouldReceive('listExpenses')->atLeast()->once()->andReturn($this->tagListExpenses());
+ $opsRepos->shouldReceive('listIncome')->atLeast()->once()->andReturn($this->tagListIncome());
$withdrawal = $this->getRandomWithdrawalAsArray();
$tag = $this->user()->tags()->where('tag', 'Expensive')->first();
@@ -183,22 +144,14 @@ class TagReportControllerTest extends TestCase
$tagRepos->shouldReceive('setUser');
$tagRepos->shouldReceive('get')->andReturn(new Collection([$tag]));
- Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
Preferences::shouldReceive('get')->withArgs(['customFiscalYear', false])->andReturn($false);
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
- $collector->shouldReceive('setAccounts')->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('setRange')->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('setTypes')->withArgs([[TransactionType::WITHDRAWAL, TransactionType::TRANSFER]])->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('setTypes')->withArgs([[TransactionType::DEPOSIT, TransactionType::TRANSFER]])->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('setTags')->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('withAccountInformation')->andReturnSelf()->atLeast()->once();
- $collector->shouldReceive('getExtractedJournals')->andReturn([$withdrawal])->atLeast()->once();
$generator->shouldReceive('multiSet')->andReturn([])->once()->atLeast()->once();
$this->be($this->user());
- $response = $this->get(route('chart.tag.main', ['1', $tag->tag, '20120101', '20120131']));
+ $response = $this->get(route('chart.tag.main', ['1', $tag->id, '20120101', '20120131']));
$response->assertStatus(200);
}
@@ -210,7 +163,12 @@ class TagReportControllerTest extends TestCase
$this->mockDefaultSession();
$generator = $this->mock(GeneratorInterface::class);
$tagRepos = $this->mock(TagRepositoryInterface::class);
+ $opsRepos = $this->mock(OperationsRepositoryInterface::class);
+
+ $opsRepos->shouldReceive('listExpenses')->atLeast()->once()->andReturn($this->tagListExpenses());
+
$this->mock(AccountRepositoryInterface::class);
+
$tag = $this->user()->tags()->first();
$tagRepos->shouldReceive('setUser');
$tagRepos->shouldReceive('get')->andReturn(new Collection([$tag]));
@@ -220,7 +178,7 @@ class TagReportControllerTest extends TestCase
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
- $generator->shouldReceive('pieChart')->andReturn([])->once();
+ $generator->shouldReceive('multiCurrencyPieChart')->andReturn([])->once();
$this->be($this->user());
$response = $this->get(route('chart.tag.tag-expense', ['1', $tag->tag, '20120101', '20120131', 0]));
@@ -236,6 +194,10 @@ class TagReportControllerTest extends TestCase
$generator = $this->mock(GeneratorInterface::class);
$tagRepos = $this->mock(TagRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
+ $opsRepos = $this->mock(OperationsRepositoryInterface::class);
+
+ $opsRepos->shouldReceive('listIncome')->atLeast()->once()->andReturn($this->tagListIncome());
+
$tag = $this->user()->tags()->first();
$tagRepos->shouldReceive('setUser');
$tagRepos->shouldReceive('get')->andReturn(new Collection([$tag]));
@@ -245,7 +207,7 @@ class TagReportControllerTest extends TestCase
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
- $generator->shouldReceive('pieChart')->andReturn([])->once();
+ $generator->shouldReceive('multiCurrencyPieChart')->andReturn([])->once();
$this->be($this->user());
$response = $this->get(route('chart.tag.tag-income', ['1', $tag->tag, '20120101', '20120131', 0]));
diff --git a/tests/Feature/Controllers/Json/BoxControllerTest.php b/tests/Feature/Controllers/Json/BoxControllerTest.php
index ccdb01fa0c..7497c2ff41 100644
--- a/tests/Feature/Controllers/Json/BoxControllerTest.php
+++ b/tests/Feature/Controllers/Json/BoxControllerTest.php
@@ -29,7 +29,9 @@ use FireflyIII\Helpers\Report\NetWorthInterface;
use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
+use FireflyIII\Repositories\Budget\AvailableBudgetRepositoryInterface;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
+use FireflyIII\Repositories\Budget\OperationsRepositoryInterface;
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
use Illuminate\Support\Collection;
use Log;
@@ -67,14 +69,16 @@ class BoxControllerTest extends TestCase
];
$repository = $this->mock(BudgetRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
+ $opsRepository = $this->mock(OperationsRepositoryInterface::class);
+ $abRepository = $this->mock(AvailableBudgetRepositoryInterface::class);
Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
Amount::shouldReceive('formatAnything')->atLeast()->once()->andReturn('-100');
- $repository->shouldReceive('getAvailableBudget')->andReturn('1000');
+ $abRepository->shouldReceive('getAvailableBudget')->andReturn('1000');
$repository->shouldReceive('getActiveBudgets')->andReturn(new Collection);
- $repository->shouldReceive('collectBudgetInformation')->andReturn($return);
+ $opsRepository->shouldReceive('collectBudgetInformation')->andReturn($return);
$this->be($this->user());
$response = $this->get(route('json.box.available'));
@@ -95,14 +99,16 @@ class BoxControllerTest extends TestCase
];
$repository = $this->mock(BudgetRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
+ $opsRepository = $this->mock(OperationsRepositoryInterface::class);
+ $abRepository = $this->mock(AvailableBudgetRepositoryInterface::class);
Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
Amount::shouldReceive('formatAnything')->atLeast()->once()->andReturn('-100');
- $repository->shouldReceive('getAvailableBudget')->andReturn('1000');
+ $abRepository->shouldReceive('getAvailableBudget')->andReturn('1000');
$repository->shouldReceive('getActiveBudgets')->andReturn(new Collection);
- $repository->shouldReceive('collectBudgetInformation')->andReturn($return);
+ $opsRepository->shouldReceive('collectBudgetInformation')->andReturn($return);
$this->be($this->user());
$response = $this->get(route('json.box.available'));
diff --git a/tests/Feature/Controllers/Recurring/IndexControllerTest.php b/tests/Feature/Controllers/Recurring/IndexControllerTest.php
index cab0b2a1a2..1fcc031423 100644
--- a/tests/Feature/Controllers/Recurring/IndexControllerTest.php
+++ b/tests/Feature/Controllers/Recurring/IndexControllerTest.php
@@ -72,6 +72,8 @@ class IndexControllerTest extends TestCase
$pref->data = 50;
Preferences::shouldReceive('get')->withArgs(['listPageSize', 50])->atLeast()->once()->andReturn($pref);
+ $repository->shouldReceive('getOccurrencesInRange')->atLeast()->once()->andReturn([]);
+
$this->mockDefaultSession();
$transformer->shouldReceive('setParameters')->atLeast()->once();
@@ -126,6 +128,8 @@ class IndexControllerTest extends TestCase
$pref->data = 50;
Preferences::shouldReceive('get')->withArgs(['listPageSize', 50])->atLeast()->once()->andReturn($pref);
+ $repository->shouldReceive('getOccurrencesInRange')->atLeast()->once()->andReturn([]);
+
$this->mockDefaultSession();
$transformer->shouldReceive('setParameters')->atLeast()->once();
diff --git a/tests/Feature/Controllers/Report/BalanceControllerTest.php b/tests/Feature/Controllers/Report/BalanceControllerTest.php
index 358eb94bd1..71fcb55970 100644
--- a/tests/Feature/Controllers/Report/BalanceControllerTest.php
+++ b/tests/Feature/Controllers/Report/BalanceControllerTest.php
@@ -24,6 +24,8 @@ namespace Tests\Feature\Controllers\Report;
use Carbon\Carbon;
use FireflyIII\Helpers\Fiscal\FiscalHelperInterface;
+use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
+use Illuminate\Support\Collection;
use Log;
use Preferences;
use Tests\TestCase;
@@ -54,9 +56,12 @@ class BalanceControllerTest extends TestCase
{
$this->mockDefaultSession();
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
+ $repository = $this->mock(BudgetRepositoryInterface::class);
$date = new Carbon;
+ $budget = $this->getRandomBudget();
+
+ $repository->shouldReceive('getBudgets')->atLeast()->once()->andReturn(new Collection([$budget]));
- Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
diff --git a/tests/Feature/Controllers/Report/BudgetControllerTest.php b/tests/Feature/Controllers/Report/BudgetControllerTest.php
index a1f107581e..243c9a70c9 100644
--- a/tests/Feature/Controllers/Report/BudgetControllerTest.php
+++ b/tests/Feature/Controllers/Report/BudgetControllerTest.php
@@ -22,13 +22,17 @@ declare(strict_types=1);
namespace Tests\Feature\Controllers\Report;
-use Amount;
use Carbon\Carbon;
use FireflyIII\Helpers\Fiscal\FiscalHelperInterface;
+use FireflyIII\Repositories\Budget\BudgetLimitRepositoryInterface;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
+use FireflyIII\Repositories\Budget\NoBudgetRepositoryInterface;
+use FireflyIII\Repositories\Budget\OperationsRepositoryInterface;
use Illuminate\Support\Collection;
use Log;
+use Amount;
use Preferences;
+use Tests\Support\TestDataTrait;
use Tests\TestCase;
/**
@@ -40,6 +44,7 @@ use Tests\TestCase;
*/
class BudgetControllerTest extends TestCase
{
+ use TestDataTrait;
/**
*
*/
@@ -56,12 +61,24 @@ class BudgetControllerTest extends TestCase
public function testGeneral(): void
{
$this->mockDefaultSession();
- $return = [];
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
+ $opsRepos = $this->mock(OperationsRepositoryInterface::class);
+ $repository = $this->mock(BudgetRepositoryInterface::class);
+ $blRepos = $this->mock(BudgetLimitRepositoryInterface::class);
+ $nbRepos = $this->mock(NoBudgetRepositoryInterface::class);
+ $budget = $this->getRandomBudget();
+ $limit = $this->getRandomBudgetLimit();
+
+ $repository->shouldReceive('getBudgets')->atLeast()->once()->andReturn(new Collection([$budget]));
+ $blRepos->shouldReceive('getBudgetLimits')->atLeast()->once()->andReturn(new Collection([$limit]));
+
+ $opsRepos->shouldReceive('sumExpenses')->atLeast()->once()->andReturn([]);
+ $nbRepos->shouldReceive('sumExpenses')->atLeast()->once()->andReturn([]);
+
$date = new Carbon;
- Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
- //Amount::shouldReceive('formatAnything')->atLeast()->once()->andReturn('x');
+ //Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
+ Amount::shouldReceive('formatAnything')->atLeast()->once()->andReturn('x');
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
@@ -80,8 +97,14 @@ class BudgetControllerTest extends TestCase
$second = ['entries' => ['1', '1']];
$repository = $this->mock(BudgetRepositoryInterface::class);
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
+ $repository = $this->mock(BudgetRepositoryInterface::class);
+ $blRepos = $this->mock(BudgetLimitRepositoryInterface::class);
+ $nbRepos = $this->mock(NoBudgetRepositoryInterface::class);
+ $opsRepos = $this->mock(OperationsRepositoryInterface::class);
$date = new Carbon;
+ $opsRepos->shouldReceive('listExpenses')->atLeast()->once()->andReturn($this->budgetListExpenses());
+
Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
//Amount::shouldReceive('formatAnything')->atLeast()->once()->andReturn('x');
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
diff --git a/tests/Feature/Controllers/ReportControllerTest.php b/tests/Feature/Controllers/ReportControllerTest.php
index f49f4f9e2e..7b71c900f6 100644
--- a/tests/Feature/Controllers/ReportControllerTest.php
+++ b/tests/Feature/Controllers/ReportControllerTest.php
@@ -69,7 +69,7 @@ class ReportControllerTest extends TestCase
/**
* @covers \FireflyIII\Http\Controllers\ReportController
*/
- public function testAccountReport(): void
+ public function testDoubleReport(): void
{
$this->mockDefaultSession();
$this->mock(ReportHelperInterface::class);
@@ -92,7 +92,7 @@ class ReportControllerTest extends TestCase
$generator->shouldReceive('generate')->once()->andReturn('here-be-report');
$this->be($this->user());
- $response = $this->get(route('reports.report.account', [$account->id, $expense->id, '20160101', '20161231']));
+ $response = $this->get(route('reports.report.double', [$account->id, $expense->id, '20160101', '20161231']));
$response->assertStatus(200);
}
@@ -290,7 +290,7 @@ class ReportControllerTest extends TestCase
/**
* @covers \FireflyIII\Http\Controllers\ReportController
*/
- public function testOptionsAccount(): void
+ public function testOptionsDouble(): void
{
Log::debug(sprintf('Now in test %s', __METHOD__));
$this->mockDefaultSession();
@@ -304,11 +304,11 @@ class ReportControllerTest extends TestCase
$collection = new Collection([$account]);
- $repository->shouldReceive('getActiveAccountsByType')->withArgs([[AccountType::EXPENSE]])->once()->andReturn($collection);
- $repository->shouldReceive('getActiveAccountsByType')->withArgs([[AccountType::REVENUE]])->once()->andReturn($collection);
+ $repository->shouldReceive('getActiveAccountsByType')->withArgs([[AccountType::EXPENSE, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE]])->once()->andReturn($collection);
+ $repository->shouldReceive('getActiveAccountsByType')->withArgs([[AccountType::REVENUE, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE]])->once()->andReturn($collection);
$this->be($this->user());
- $response = $this->get(route('reports.options', ['account']));
+ $response = $this->get(route('reports.options', ['double']));
$response->assertStatus(200);
}
@@ -376,7 +376,7 @@ class ReportControllerTest extends TestCase
* @covers \FireflyIII\Http\Controllers\ReportController
* @covers \FireflyIII\Http\Requests\ReportFormRequest
*/
- public function testPostIndexAccountError(): void
+ public function testPostIndexDoubleError(): void
{
Log::debug(sprintf('Now in test %s', __METHOD__));
$this->mockDefaultSession();
@@ -395,9 +395,9 @@ class ReportControllerTest extends TestCase
$data = [
'accounts' => ['1'],
- 'exp_rev' => ['4'],
+ 'double' => ['4'],
'daterange' => '2016-01-01 - 2016-01-31',
- 'report_type' => 'account',
+ 'report_type' => 'double',
];
$this->be($this->user());
@@ -411,7 +411,7 @@ class ReportControllerTest extends TestCase
* @covers \FireflyIII\Http\Controllers\ReportController
* @covers \FireflyIII\Http\Requests\ReportFormRequest
*/
- public function testPostIndexAccountOK(): void
+ public function testPostIndexDoubleOK(): void
{
Log::debug(sprintf('Now in test %s', __METHOD__));
$this->mockDefaultSession();
@@ -425,15 +425,15 @@ class ReportControllerTest extends TestCase
$data = [
'accounts' => ['1'],
- 'exp_rev' => ['4'],
+ 'double' => ['4'],
'daterange' => '2016-01-01 - 2016-01-31',
- 'report_type' => 'account',
+ 'report_type' => 'double',
];
$this->be($this->user());
$response = $this->post(route('reports.index.post'), $data);
$response->assertStatus(302);
- $response->assertRedirect(route('reports.report.account', ['1', '1', '20160101', '20160131']));
+ $response->assertRedirect(route('reports.report.double', ['1', '1', '20160101', '20160131']));
}
/**
diff --git a/tests/Support/TestDataTrait.php b/tests/Support/TestDataTrait.php
index f92102549b..833a03d505 100644
--- a/tests/Support/TestDataTrait.php
+++ b/tests/Support/TestDataTrait.php
@@ -85,6 +85,108 @@ trait TestDataTrait
return $data;
}
+ /**
+ * Method that returns default data for when the tag OperationsRepos
+ * "listExpenses" method is called.
+ *
+ * @return array
+ */
+ protected function tagListExpenses(): array
+ {
+ $eur = TransactionCurrency::where('code', 'EUR')->first();
+ $usd = TransactionCurrency::where('code', 'USD')->first();
+ $tag1 = $this->user()->tags()->inRandomOrder()->first();
+ $tag2 = $this->user()->tags()->inRandomOrder()->where('id', '!=', $tag1->id)->first();
+ $data = [];
+ $amount = 400;
+ $date = null;
+ try {
+ $amount = random_int(100, 2500);
+ $date = new Carbon;
+ } catch (Exception $e) {
+ $e->getMessage();
+ }
+ $amount = bcmul((string)round($amount / 100, 2), '-1');
+
+ foreach ([$eur, $usd] as $currency) {
+ $data[$currency->id] = [
+ 'currency_id' => $currency->id,
+ 'currency_name' => $currency->name,
+ 'currency_symbol' => $currency->symbol,
+ 'currency_code' => $currency->code,
+ 'currency_decimal_places' => $currency->decimal_places,
+ 'categories' => [],
+ ];
+ foreach ([$tag1, $tag2] as $tag) {
+ $data[$currency->id]['tags'][$tag->id] = [
+ 'id' => $tag->id,
+ 'name' => $tag->tag,
+ 'transaction_journals' => [],
+ ];
+ // add two random amounts:
+ for ($i = 0; $i < 2; $i++) {
+ $data[$currency->id]['categories'][$tag->id]['transaction_journals'][$i] = [
+ 'amount' => $amount,
+ 'date' => $date,
+ ];
+ }
+ }
+ }
+
+ return $data;
+ }
+
+ /**
+ * Method that returns default data for when the tag OperationsRepos
+ * "listIncome" method is called.
+ *
+ * @return array
+ */
+ protected function tagListIncome(): array
+ {
+ $eur = TransactionCurrency::where('code', 'EUR')->first();
+ $usd = TransactionCurrency::where('code', 'USD')->first();
+ $tag1 = $this->user()->tags()->inRandomOrder()->first();
+ $tag2 = $this->user()->tags()->inRandomOrder()->where('id', '!=', $tag1->id)->first();
+ $data = [];
+ $amount = 400;
+ $date = null;
+ try {
+ $amount = random_int(100, 2500);
+ $date = new Carbon;
+ } catch (Exception $e) {
+ $e->getMessage();
+ }
+ $amount = (string)round($amount / 100, 2);
+
+ foreach ([$eur, $usd] as $currency) {
+ $data[$currency->id] = [
+ 'currency_id' => $currency->id,
+ 'currency_name' => $currency->name,
+ 'currency_symbol' => $currency->symbol,
+ 'currency_code' => $currency->code,
+ 'currency_decimal_places' => $currency->decimal_places,
+ 'categories' => [],
+ ];
+ foreach ([$tag1, $tag2] as $tag) {
+ $data[$currency->id]['tags'][$tag->id] = [
+ 'id' => $tag->id,
+ 'name' => $tag->tag,
+ 'transaction_journals' => [],
+ ];
+ // add two random amounts:
+ for ($i = 0; $i < 2; $i++) {
+ $data[$currency->id]['categories'][$tag->id]['transaction_journals'][$i] = [
+ 'amount' => $amount,
+ 'date' => $date,
+ ];
+ }
+ }
+ }
+
+ return $data;
+ }
+
/**
* Method that returns default data for when the category OperationsRepos
* "listExpenses" method is called.
diff --git a/tests/Unit/Generator/Report/Audit/MonthReportGeneratorTest.php b/tests/Unit/Generator/Report/Audit/MonthReportGeneratorTest.php
index 6be88ba75f..3812956f3a 100644
--- a/tests/Unit/Generator/Report/Audit/MonthReportGeneratorTest.php
+++ b/tests/Unit/Generator/Report/Audit/MonthReportGeneratorTest.php
@@ -32,7 +32,6 @@ use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
use Illuminate\Support\Collection;
use Log;
-use Mockery;
use Steam;
use Tests\TestCase;
@@ -76,6 +75,7 @@ class MonthReportGeneratorTest extends TestCase
'source_id' => $asset->id,
'source_name' => $asset->name,
'transaction_journal_id' => 1,
+ 'destination_account_id' => 8,
],
[
'description' => 'Hello2',
@@ -86,6 +86,7 @@ class MonthReportGeneratorTest extends TestCase
'source_id' => $asset->id,
'source_name' => $asset->name,
'transaction_journal_id' => 1,
+ 'destination_account_id' => 8,
],
];
@@ -105,13 +106,15 @@ class MonthReportGeneratorTest extends TestCase
// mock calls
Steam::shouldReceive('balance')->times(2)->andReturn('100');
$accountRepos->shouldReceive('setUser')->once();
- //$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1')->once();
$accountRepos->shouldReceive('getAccountCurrency')->atLeast()->once()->andReturn($euro);
// mock collector:
$collector->shouldReceive('setAccounts')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('setRange')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withAccountInformation')->atLeast()->once()->andReturnSelf();
+ $collector->shouldReceive('withBudgetInformation')->atLeast()->once()->andReturnSelf();
+ $collector->shouldReceive('withCategoryInformation')->atLeast()->once()->andReturnSelf();
+ $collector->shouldReceive('withBillInformation')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('getExtractedJournals')->atLeast()->once()->andReturn($return);
//$currencyRepos->shouldReceive('findNull')->withArgs([1])->andReturn($euro)->once();
diff --git a/tests/Unit/Transformers/AvailableBudgetTransformerTest.php b/tests/Unit/Transformers/AvailableBudgetTransformerTest.php
index 6eda0821ba..f69c6782b1 100644
--- a/tests/Unit/Transformers/AvailableBudgetTransformerTest.php
+++ b/tests/Unit/Transformers/AvailableBudgetTransformerTest.php
@@ -26,6 +26,8 @@ namespace Tests\Unit\Transformers;
use Carbon\Carbon;
use FireflyIII\Models\AvailableBudget;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
+use FireflyIII\Repositories\Budget\NoBudgetRepositoryInterface;
+use FireflyIII\Repositories\Budget\OperationsRepositoryInterface;
use FireflyIII\Transformers\AvailableBudgetTransformer;
use Illuminate\Support\Collection;
use Log;
@@ -56,7 +58,9 @@ class AvailableBudgetTransformerTest extends TestCase
*/
public function testBasic(): void
{
- $repository = $this->mock(BudgetRepositoryInterface::class);
+ $repository = $this->mock(BudgetRepositoryInterface::class);
+ $opsRepository = $this->mock(OperationsRepositoryInterface::class);
+ $nbRepos = $this->mock(NoBudgetRepositoryInterface::class);
$repository->shouldReceive('setUser')->atLeast()->once();
/** @var AvailableBudget $availableBudget */
@@ -93,12 +97,14 @@ class AvailableBudgetTransformerTest extends TestCase
];
- $budget = $this->getRandomBudget();
- $repository = $this->mock(BudgetRepositoryInterface::class);
+ $budget = $this->getRandomBudget();
+ $repository = $this->mock(BudgetRepositoryInterface::class);
+ $opsRepository = $this->mock(OperationsRepositoryInterface::class);
+ $nbRepos = $this->mock(NoBudgetRepositoryInterface::class);
$repository->shouldReceive('setUser')->atLeast()->once();
$repository->shouldReceive('getActiveBudgets')->atLeast()->once()->andReturn(new Collection([$budget]));
- $repository->shouldReceive('spentInPeriodMc')->atLeast()->once()->andReturn($data);
- $repository->shouldReceive('spentInPeriodWoBudgetMc')->atLeast()->once()->andReturn($data);
+ $opsRepository->shouldReceive('spentInPeriodMc')->atLeast()->once()->andReturn($data);
+ $nbRepos->shouldReceive('spentInPeriodWoBudgetMc')->atLeast()->once()->andReturn($data);
// spentInPeriodWoBudgetMc