Skip to content

Firefly III: a personal finances manager

Improve test coverage.

James Cole003d07504ff4
diff --git a/app/Http/Controllers/Chart/AccountController.php b/app/Http/Controllers/Chart/AccountController.php
index 5335d0b8a5..80987ec48f 100644
--- a/app/Http/Controllers/Chart/AccountController.php
+++ b/app/Http/Controllers/Chart/AccountController.php
@@ -62,7 +62,7 @@ class AccountController extends Controller
/**
* AccountController constructor.
- * @codeCoverageIgnore
+ * @codeCoverageIgnore
*/
public function __construct()
{
diff --git a/app/Http/Controllers/Chart/BudgetController.php b/app/Http/Controllers/Chart/BudgetController.php
index ef36292918..3fe456e5ae 100644
--- a/app/Http/Controllers/Chart/BudgetController.php
+++ b/app/Http/Controllers/Chart/BudgetController.php
@@ -55,6 +55,7 @@ class BudgetController extends Controller
/**
* BudgetController constructor.
+ * @codeCoverageIgnore
*/
public function __construct()
{
@@ -297,7 +298,6 @@ class BudgetController extends Controller
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
-
$collector->setTypes([TransactionType::WITHDRAWAL])->setBudget($budget)->withAccountInformation();
if (null !== $budgetLimit) {
$collector->setRange($budgetLimit->start_date, $budgetLimit->end_date);
diff --git a/app/Http/Controllers/Chart/BudgetReportController.php b/app/Http/Controllers/Chart/BudgetReportController.php
index b2627ef8f1..2d0ee59b49 100644
--- a/app/Http/Controllers/Chart/BudgetReportController.php
+++ b/app/Http/Controllers/Chart/BudgetReportController.php
@@ -51,6 +51,7 @@ class BudgetReportController extends Controller
/**
* BudgetReportController constructor.
+ * @codeCoverageIgnore
*/
public function __construct()
{
diff --git a/app/Http/Controllers/Chart/CategoryController.php b/app/Http/Controllers/Chart/CategoryController.php
index b91e690b29..ef557369c2 100644
--- a/app/Http/Controllers/Chart/CategoryController.php
+++ b/app/Http/Controllers/Chart/CategoryController.php
@@ -50,6 +50,7 @@ class CategoryController extends Controller
/**
* CategoryController constructor.
+ * @codeCoverageIgnore
*/
public function __construct()
{
@@ -106,6 +107,7 @@ class CategoryController extends Controller
],
];
$step = $this->calculateStep($start, $end);
+ /** @var Carbon $current */
$current = clone $start;
Log::debug(sprintf('abc Step is %s', $step));
@@ -124,9 +126,12 @@ class CategoryController extends Controller
$current->addDay();
}
break;
+ // @codeCoverageIgnoreStart
+ // for some reason it doesn't pick up on these case entries.
case '1W':
case '1M':
case '1Y':
+ // @codeCoverageIgnoreEnd
while ($current <= $end) {
$currentEnd = app('navigation')->endOfPeriod($current, $step);
Log::debug(sprintf('abc Range is %s to %s', $current->format('Y-m-d'), $currentEnd->format('Y-m-d')));
@@ -391,7 +396,7 @@ class CategoryController extends Controller
$start = app('navigation')->startOfPeriod($date, $range);
$end = session()->get('end');
if ($end < $start) {
- [$end, $start] = [$start, $end];
+ [$end, $start] = [$start, $end]; // @codeCoverageIgnore
}
$data = $this->makePeriodChart($category, $start, $end);
diff --git a/app/Http/Controllers/Chart/CategoryReportController.php b/app/Http/Controllers/Chart/CategoryReportController.php
index ad880ae48b..6ad3b2d009 100644
--- a/app/Http/Controllers/Chart/CategoryReportController.php
+++ b/app/Http/Controllers/Chart/CategoryReportController.php
@@ -47,6 +47,7 @@ class CategoryReportController extends Controller
/**
* CategoryReportController constructor.
+ * @codeCoverageIgnore
*/
public function __construct()
{
@@ -285,7 +286,7 @@ class CategoryReportController extends Controller
$newSet = [];
foreach ($chartData as $key => $entry) {
if (0 === !array_sum($entry['entries'])) {
- $newSet[$key] = $chartData[$key];
+ $newSet[$key] = $chartData[$key]; // @codeCoverageIgnore
}
}
if (0 === count($newSet)) {
diff --git a/app/Http/Controllers/Chart/ExpenseReportController.php b/app/Http/Controllers/Chart/ExpenseReportController.php
index fd2110201e..e03c592552 100644
--- a/app/Http/Controllers/Chart/ExpenseReportController.php
+++ b/app/Http/Controllers/Chart/ExpenseReportController.php
@@ -49,6 +49,7 @@ class ExpenseReportController extends Controller
/**
* ExpenseReportController constructor.
+ * @codeCoverageIgnore
*/
public function __construct()
{
@@ -89,7 +90,7 @@ class ExpenseReportController extends Controller
$cache->addProperty($start);
$cache->addProperty($end);
if ($cache->has()) {
- // return response()->json($cache->get()); // @codeCoverageIgnore
+ return response()->json($cache->get()); // @codeCoverageIgnore
}
$format = app('navigation')->preferredCarbonLocalizedFormat($start, $end);
@@ -185,7 +186,7 @@ class ExpenseReportController extends Controller
$newSet = [];
foreach ($chartData as $key => $entry) {
if (0 === !array_sum($entry['entries'])) {
- $newSet[$key] = $chartData[$key];
+ $newSet[$key] = $chartData[$key]; // @codeCoverageIgnore
}
}
if (0 === count($newSet)) {
diff --git a/app/Http/Controllers/Chart/PiggyBankController.php b/app/Http/Controllers/Chart/PiggyBankController.php
index b67a057b4c..fb94165760 100644
--- a/app/Http/Controllers/Chart/PiggyBankController.php
+++ b/app/Http/Controllers/Chart/PiggyBankController.php
@@ -44,6 +44,7 @@ class PiggyBankController extends Controller
/**
* PiggyBankController constructor.
+ * @codeCoverageIgnore
*/
public function __construct()
{
diff --git a/app/Http/Controllers/Chart/ReportController.php b/app/Http/Controllers/Chart/ReportController.php
index fec7cd9219..07326a3f25 100644
--- a/app/Http/Controllers/Chart/ReportController.php
+++ b/app/Http/Controllers/Chart/ReportController.php
@@ -46,6 +46,7 @@ class ReportController extends Controller
/**
* ReportController constructor.
+ * @codeCoverageIgnore
*/
public function __construct()
{
diff --git a/app/Http/Controllers/Chart/TagReportController.php b/app/Http/Controllers/Chart/TagReportController.php
index 4a4a46e950..aacf46a64e 100644
--- a/app/Http/Controllers/Chart/TagReportController.php
+++ b/app/Http/Controllers/Chart/TagReportController.php
@@ -44,6 +44,7 @@ class TagReportController extends Controller
/**
* TagReportController constructor.
+ * @codeCoverageIgnore
*/
public function __construct()
{
@@ -279,7 +280,7 @@ class TagReportController extends Controller
$newSet = [];
foreach ($chartData as $key => $entry) {
if (0 === !array_sum($entry['entries'])) {
- $newSet[$key] = $chartData[$key];
+ $newSet[$key] = $chartData[$key]; // @codeCoverageIgnore
}
}
if (0 === count($newSet)) {
diff --git a/app/Support/Http/Controllers/AugumentData.php b/app/Support/Http/Controllers/AugumentData.php
index 53bb5d1025..dc5b7d912d 100644
--- a/app/Support/Http/Controllers/AugumentData.php
+++ b/app/Support/Http/Controllers/AugumentData.php
@@ -222,7 +222,7 @@ trait AugumentData
protected function filterBudgetLimits(Collection $budgetLimits, Budget $budget, Carbon $start, Carbon $end): Collection // filter data
{
$set = $budgetLimits->filter(
- function (BudgetLimit $budgetLimit) use ($budget, $start, $end) {
+ static function (BudgetLimit $budgetLimit) use ($budget, $start, $end) {
if ($budgetLimit->budget_id === $budget->id
&& $budgetLimit->start_date->lte($start) // start of budget limit is on or before start
&& $budgetLimit->end_date->gte($end) // end of budget limit is on or after end
diff --git a/app/Support/Http/Controllers/TransactionCalculation.php b/app/Support/Http/Controllers/TransactionCalculation.php
index 8fa5949477..d4642e7c2a 100644
--- a/app/Support/Http/Controllers/TransactionCalculation.php
+++ b/app/Support/Http/Controllers/TransactionCalculation.php
@@ -55,9 +55,7 @@ trait TransactionCalculation
->withAccountInformation()
->setTypes([TransactionType::WITHDRAWAL]);
- $result = $collector->getExtractedJournals();
-
- return $result;
+ return $collector->getExtractedJournals();
}
/**
diff --git a/phpunit.coverage.specific.xml b/phpunit.coverage.specific.xml
index 2bd193e356..2665e0bf58 100644
--- a/phpunit.coverage.specific.xml
+++ b/phpunit.coverage.specific.xml
@@ -49,6 +49,8 @@
<directory suffix="Test.php">./tests/Feature/Controllers/Admin</directory>
<directory suffix="Test.php">./tests/Feature/Controllers/Budget</directory>
<directory suffix="Test.php">./tests/Feature/Controllers/Category</directory>
+ <directory suffix="Test.php">./tests/Feature/Controllers/Chart</directory>
+ <directory suffix="Test.php">./tests/Feature/Controllers/Import</directory>
</testsuite>
diff --git a/phpunit.coverage.xml b/phpunit.coverage.xml
index 5bb3cd9969..2499add904 100644
--- a/phpunit.coverage.xml
+++ b/phpunit.coverage.xml
@@ -49,6 +49,8 @@
<directory suffix="Test.php">./tests/Feature/Controllers/Admin</directory>
<directory suffix="Test.php">./tests/Feature/Controllers/Budget</directory>
<directory suffix="Test.php">./tests/Feature/Controllers/Category</directory>
+ <directory suffix="Test.php">./tests/Feature/Controllers/Chart</directory>
+ <directory suffix="Test.php">./tests/Feature/Controllers/Import</directory>
</testsuite>
diff --git a/phpunit.xml b/phpunit.xml
index 3faf2448de..6ad538ee36 100644
--- a/phpunit.xml
+++ b/phpunit.xml
@@ -49,6 +49,8 @@
<directory suffix="Test.php">./tests/Feature/Controllers/Admin</directory>
<directory suffix="Test.php">./tests/Feature/Controllers/Budget</directory>
<directory suffix="Test.php">./tests/Feature/Controllers/Category</directory>
+ <directory suffix="Test.php">./tests/Feature/Controllers/Chart</directory>
+ <directory suffix="Test.php">./tests/Feature/Controllers/Import</directory>
</testsuite>
<!--
diff --git a/tests/Feature/Controllers/Chart/BudgetControllerTest.php b/tests/Feature/Controllers/Chart/BudgetControllerTest.php
index aa5d617290..68572aeebe 100644
--- a/tests/Feature/Controllers/Chart/BudgetControllerTest.php
+++ b/tests/Feature/Controllers/Chart/BudgetControllerTest.php
@@ -23,13 +23,12 @@ declare(strict_types=1);
namespace Tests\Feature\Controllers\Chart;
use Carbon\Carbon;
+use Exception;
use FireflyIII\Generator\Chart\Basic\GeneratorInterface;
-use FireflyIII\Helpers\Collector\TransactionCollectorInterface;
+use FireflyIII\Helpers\Collector\GroupCollectorInterface;
use FireflyIII\Helpers\Fiscal\FiscalHelperInterface;
-use FireflyIII\Models\Account;
use FireflyIII\Models\Budget;
use FireflyIII\Models\BudgetLimit;
-use FireflyIII\Models\Category;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionType;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
@@ -37,6 +36,7 @@ use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
use Illuminate\Support\Collection;
use Log;
+use Preferences;
use Tests\TestCase;
/**
@@ -63,8 +63,17 @@ class BudgetControllerTest extends TestCase
{
$repository = $this->mock(BudgetRepositoryInterface::class);
$generator = $this->mock(GeneratorInterface::class);
+ try {
+ $date = new Carbon('2015-01-01');
+ } catch (Exception $e) {
+ $e->getMessage();
+ }
- $repository->shouldReceive('firstUseDate')->andReturn(new Carbon('2015-01-01'))->once();
+ // mock default session
+ $this->mockDefaultSession();
+ Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
+
+ $repository->shouldReceive('firstUseDate')->andReturn($date)->once();
$repository->shouldReceive('spentInPeriod')->andReturn('-100');
$generator->shouldReceive('singleSet')->andReturn([])->once();
@@ -85,6 +94,10 @@ class BudgetControllerTest extends TestCase
$repository = $this->mock(BudgetRepositoryInterface::class);
$generator = $this->mock(GeneratorInterface::class);
+ // mock default session
+ $this->mockDefaultSession();
+ Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
+
$repository->shouldReceive('spentInPeriod')->andReturn('-100');
$generator->shouldReceive('singleSet')->once()->andReturn([]);
@@ -95,15 +108,20 @@ class BudgetControllerTest extends TestCase
}
/**
- * @covers \FireflyIII\Http\Controllers\Chart\BudgetController
+ * @covers \FireflyIII\Http\Controllers\Chart\BudgetController
*/
public function testBudgetLimitWrongLimit(): void
{
- $repository = $this->mock(BudgetRepositoryInterface::class);
- $generator = $this->mock(GeneratorInterface::class);
+ $this->mock(BudgetRepositoryInterface::class);
+ $this->mock(GeneratorInterface::class);
+ $budget = $this->getRandomBudget();
+ $limit = BudgetLimit::where('budget_id', '!=', $budget->id)->first();
+
+ // mock default session
+ $this->mockDefaultSession();
$this->be($this->user());
- $response = $this->get(route('chart.budget.budget-limit', [1, 8]));
+ $response = $this->get(route('chart.budget.budget-limit', [$budget->id, $limit->id]));
$response->assertStatus(500);
}
@@ -115,20 +133,21 @@ class BudgetControllerTest extends TestCase
*/
public function testExpenseAsset(string $range): void
{
- $this->markTestIncomplete('Needs to be rewritten for v4.8.0');
+ $this->mock(BudgetRepositoryInterface::class);
+ $generator = $this->mock(GeneratorInterface::class);
+ $collector = $this->mock(GroupCollectorInterface::class);
+ $accountRepos = $this->mock(AccountRepositoryInterface::class);
+ $withdrawal = $this->getRandomWithdrawalAsArray();
+ $destination = $this->user()->accounts()->find($withdrawal['destination_account_id']);
- return;
- $budgetRepository = $this->mock(BudgetRepositoryInterface::class);
- $generator = $this->mock(GeneratorInterface::class);
- $collector = $this->mock(TransactionCollectorInterface::class);
- $transactions = factory(Transaction::class, 10)->make();
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
+ // mock default session
+ $this->mockDefaultSession();
+ Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
- $accountRepos->shouldReceive('getAccountsByType')->andReturn(new Collection);
- $collector->shouldReceive('setAllAssetAccounts')->once()->andReturnSelf();
- $collector->shouldReceive('setBudget')->andReturnSelf();
- $collector->shouldReceive('setRange')->andReturnSelf();
- $collector->shouldReceive('getTransactions')->andReturn($transactions);
+ $accountRepos->shouldReceive('getAccountsByType')->andReturn(new Collection([$destination]))->atLeast()->once();
+ $collector->shouldReceive('setBudget')->andReturnSelf()->atLeast()->once();
+ $collector->shouldReceive('setRange')->andReturnSelf()->atLeast()->once();
+ $collector->shouldReceive('getExtractedJournals')->andReturn([$withdrawal])->atLeast()->once();
$generator->shouldReceive('pieChart')->once()->andReturn([]);
@@ -146,25 +165,23 @@ class BudgetControllerTest extends TestCase
*/
public function testExpenseCategory(string $range): void
{
- $this->markTestIncomplete('Needs to be rewritten for v4.8.0');
-
- return;
+ $this->mock(BudgetRepositoryInterface::class);
$generator = $this->mock(GeneratorInterface::class);
- $collector = $this->mock(TransactionCollectorInterface::class);
+ $collector = $this->mock(GroupCollectorInterface::class);
$catRepos = $this->mock(CategoryRepositoryInterface::class);
- $repository = $this->mock(BudgetRepositoryInterface::class);
+ $withdrawal = $this->getRandomWithdrawalAsArray();
+ $category = $this->user()->categories()->find($withdrawal['category_id']);
+ // mock default session
+ $this->mockDefaultSession();
+ Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
- $transactions = factory(Transaction::class, 10)->make();
- $categories = factory(Category::class, 10)->make();
+ $collector->shouldReceive('setBudget')->andReturnSelf()->atLeast()->once();
+ $collector->shouldReceive('setRange')->andReturnSelf()->atLeast()->once();
+ $collector->shouldReceive('withCategoryInformation')->andReturnSelf()->atLeast()->once();
+ $collector->shouldReceive('getExtractedJournals')->andReturn([$withdrawal])->atLeast()->once();
- $collector->shouldReceive('setAllAssetAccounts')->once()->andReturnSelf();
- $collector->shouldReceive('setBudget')->andReturnSelf();
- $collector->shouldReceive('setRange')->andReturnSelf();
- $collector->shouldReceive('withCategoryInformation')->andReturnSelf();
- $collector->shouldReceive('getTransactions')->andReturn($transactions);
-
- $catRepos->shouldReceive('getCategories')->andReturn($categories)->once();
+ $catRepos->shouldReceive('getCategories')->andReturn(new Collection([$category]))->once();
$generator->shouldReceive('pieChart')->once()->andReturn([]);
@@ -182,25 +199,25 @@ class BudgetControllerTest extends TestCase
*/
public function testExpenseExpense(string $range): void
{
- $this->markTestIncomplete('Needs to be rewritten for v4.8.0');
-
- return;
+ $this->mock(BudgetRepositoryInterface::class);
$generator = $this->mock(GeneratorInterface::class);
- $collector = $this->mock(TransactionCollectorInterface::class);
+ $collector = $this->mock(GroupCollectorInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
- $repository = $this->mock(BudgetRepositoryInterface::class);
+ $withdrawal = $this->getRandomWithdrawalAsArray();
+ $destination = $this->user()->accounts()->find($withdrawal['destination_account_id']);
+
+ // mock default session
+ $this->mockDefaultSession();
+ Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
- $transactions = factory(Transaction::class, 10)->make();
- $accounts = factory(Account::class, 10)->make();
- $collector->shouldReceive('setAllAssetAccounts')->once()->andReturnSelf();
+ $collector->shouldReceive('withAccountInformation')->once()->andReturnSelf();
$collector->shouldReceive('setTypes')->withArgs([[TransactionType::WITHDRAWAL]])->once()->andReturnSelf();
- $collector->shouldReceive('setBudget')->andReturnSelf();
- $collector->shouldReceive('setRange')->andReturnSelf();
- $collector->shouldReceive('withOpposingAccount')->andReturnSelf();
- $collector->shouldReceive('getTransactions')->andReturn($transactions);
+ $collector->shouldReceive('setBudget')->andReturnSelf()->atLeast()->once();
+ $collector->shouldReceive('setRange')->andReturnSelf()->atLeast()->once();
+ $collector->shouldReceive('getExtractedJournals')->andReturn([$withdrawal])->atLeast()->once();
- $accountRepos->shouldReceive('getAccountsByType')->andReturn($accounts)->once();
+ $accountRepos->shouldReceive('getAccountsByType')->andReturn(new Collection([$destination]))->once();
$generator->shouldReceive('pieChart')->once()->andReturn([]);
@@ -216,28 +233,27 @@ class BudgetControllerTest extends TestCase
*
* @param string $range
*/
- public function testFrontpage(string $range): void
+ public function testFrontPage(string $range): void
{
- $this->markTestIncomplete('Needs to be rewritten for v4.8.0');
+ $repository = $this->mock(BudgetRepositoryInterface::class);
+ $generator = $this->mock(GeneratorInterface::class);
+ $collector = $this->mock(GroupCollectorInterface::class);
+ $budget = $this->getRandomBudget();
+ $budgetLimit = $this->getRandomBudgetLimit();
+
+ // mock default session
+ $this->mockDefaultSession();
+ Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
- return;
- $repository = $this->mock(BudgetRepositoryInterface::class);
- $generator = $this->mock(GeneratorInterface::class);
- $collector = $this->mock(TransactionCollectorInterface::class);
- $budget = factory(Budget::class)->make();
- $budgetLimit = factory(BudgetLimit::class)->make();
- $budgetLimit->budget_id = $budget->id;
- $transaction = factory(Transaction::class)->make();
$repository->shouldReceive('getActiveBudgets')->andReturn(new Collection([$budget]))->once();
$repository->shouldReceive('getBudgetLimits')->once()->andReturn(new Collection([$budgetLimit]));
$repository->shouldReceive('spentInPeriod')->andReturn('-100');
- $collector->shouldReceive('setAllAssetAccounts')->andReturnSelf()->once();
$collector->shouldReceive('setTypes')->withArgs([[TransactionType::WITHDRAWAL]])->andReturnSelf()->once();
$collector->shouldReceive('setRange')->andReturnSelf()->once();
$collector->shouldReceive('withoutBudget')->andReturnSelf()->once();
- $collector->shouldReceive('getTransactions')->andReturn(new Collection([$transaction]))->once();
+ $collector->shouldReceive('getSum')->andReturn('-100')->atLeast()->once();
$generator->shouldReceive('multiSet')->once()->andReturn([]);
@@ -255,28 +271,26 @@ class BudgetControllerTest extends TestCase
*/
public function testFrontpageMultiLimit(string $range): void
{
- $this->markTestIncomplete('Needs to be rewritten for v4.8.0');
-
- return;
- $repository = $this->mock(BudgetRepositoryInterface::class);
- $generator = $this->mock(GeneratorInterface::class);
- $collector = $this->mock(TransactionCollectorInterface::class);
- $budget = factory(Budget::class)->make();
- $one = factory(BudgetLimit::class)->make();
- $two = factory(BudgetLimit::class)->make();
- $one->budget_id = $budget->id;
- $two->budget_id = $budget->id;
- $transaction = factory(Transaction::class)->make();
+
+ $repository = $this->mock(BudgetRepositoryInterface::class);
+ $generator = $this->mock(GeneratorInterface::class);
+ $collector = $this->mock(GroupCollectorInterface::class);
+ $budget = $this->getRandomBudget();
+ $limit1 = $this->getRandomBudgetLimit();
+ $limit2 = $this->getRandomBudgetLimit();
+
+ // mock default session
+ $this->mockDefaultSession();
+ Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
$repository->shouldReceive('getActiveBudgets')->andReturn(new Collection([$budget]))->once();
- $repository->shouldReceive('getBudgetLimits')->once()->andReturn(new Collection([$one, $two]));
- $repository->shouldReceive('spentInPeriod')->andReturn('-100');
+ $repository->shouldReceive('getBudgetLimits')->once()->andReturn(new Collection([$limit1, $limit2]));
+ $repository->shouldReceive('spentInPeriod')->andReturn('-100')->atLeast()->once();
- $collector->shouldReceive('setAllAssetAccounts')->andReturnSelf()->once();
$collector->shouldReceive('setTypes')->withArgs([[TransactionType::WITHDRAWAL]])->andReturnSelf()->once();
$collector->shouldReceive('setRange')->andReturnSelf()->once();
$collector->shouldReceive('withoutBudget')->andReturnSelf()->once();
- $collector->shouldReceive('getTransactions')->andReturn(new Collection([$transaction]))->once();
+ $collector->shouldReceive('getSum')->andReturn('-100')->atLeast()->once();
$generator->shouldReceive('multiSet')->once()->andReturn([]);
@@ -294,24 +308,25 @@ class BudgetControllerTest extends TestCase
*/
public function testFrontpageNoLimits(string $range): void
{
- $this->markTestIncomplete('Needs to be rewritten for v4.8.0');
- return;
$repository = $this->mock(BudgetRepositoryInterface::class);
$generator = $this->mock(GeneratorInterface::class);
- $collector = $this->mock(TransactionCollectorInterface::class);
- $budget = factory(Budget::class)->make();
- $transaction = factory(Transaction::class)->make();
+ $collector = $this->mock(GroupCollectorInterface::class);
+ $budget = $this->getRandomBudget();
+
+ // mock default session
+ $this->mockDefaultSession();
+ Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
$repository->shouldReceive('getActiveBudgets')->andReturn(new Collection([$budget]));
$repository->shouldReceive('getBudgetLimits')->once()->andReturn(new Collection);
$repository->shouldReceive('spentInPeriod')->andReturn('-100');
- $collector->shouldReceive('setAllAssetAccounts')->andReturnSelf()->once();
$collector->shouldReceive('setTypes')->withArgs([[TransactionType::WITHDRAWAL]])->andReturnSelf()->once();
$collector->shouldReceive('setRange')->andReturnSelf()->once();
$collector->shouldReceive('withoutBudget')->andReturnSelf()->once();
- $collector->shouldReceive('getTransactions')->andReturn(new Collection([$transaction]))->once();
+ //$collector->shouldReceive('getTransactions')->andReturn([$withdrawal])->once();
+ $collector->shouldReceive('getSum')->andReturn('-100')->atLeast()->once();
$generator->shouldReceive('multiSet')->once()->andReturn([]);
@@ -328,11 +343,15 @@ class BudgetControllerTest extends TestCase
{
$repository = $this->mock(BudgetRepositoryInterface::class);
$generator = $this->mock(GeneratorInterface::class);
- $budget = factory(Budget::class)->make();
- $budgetLimit = factory(BudgetLimit::class)->make();
- $budgetLimit->budget_id = $budget->id;
+ $budgetLimit = $this->getRandomBudgetLimit();
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
$date = new Carbon;
+
+ // mock default session
+ $this->mockDefaultSession();
+ Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
+
+
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
@@ -341,7 +360,7 @@ class BudgetControllerTest extends TestCase
$generator->shouldReceive('multiSet')->once()->andReturn([]);
$this->be($this->user());
- $response = $this->get(route('chart.budget.period', [1, '1', '20120101', '20120131']));
+ $response = $this->get(route('chart.budget.period', [$budgetLimit->budget_id, '1', '20120101', '20120131']));
$response->assertStatus(200);
}
@@ -354,6 +373,11 @@ class BudgetControllerTest extends TestCase
$generator = $this->mock(GeneratorInterface::class);
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
$date = new Carbon;
+
+ // mock default session
+ $this->mockDefaultSession();
+ 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/Chart/BudgetReportControllerTest.php b/tests/Feature/Controllers/Chart/BudgetReportControllerTest.php
index b58d30e43a..54adeb44c0 100644
--- a/tests/Feature/Controllers/Chart/BudgetReportControllerTest.php
+++ b/tests/Feature/Controllers/Chart/BudgetReportControllerTest.php
@@ -25,17 +25,18 @@ namespace Tests\Feature\Controllers\Chart;
use Carbon\Carbon;
use FireflyIII\Generator\Chart\Basic\GeneratorInterface;
use FireflyIII\Helpers\Chart\MetaPieChartInterface;
+use FireflyIII\Helpers\Collector\GroupCollectorInterface;
use FireflyIII\Helpers\Collector\TransactionCollectorInterface;
use FireflyIII\Helpers\Filter\OpposingAccountFilter;
use FireflyIII\Helpers\Filter\PositiveAmountFilter;
use FireflyIII\Helpers\Filter\TransferFilter;
use FireflyIII\Helpers\Fiscal\FiscalHelperInterface;
use FireflyIII\Models\BudgetLimit;
-use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionType;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use Illuminate\Support\Collection;
use Log;
+use Preferences;
use Tests\TestCase;
/**
@@ -65,6 +66,9 @@ class BudgetReportControllerTest extends TestCase
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
+ // mock default session
+ $this->mockDefaultSession();
+
$pieChart->shouldReceive('setAccounts')->once()->andReturnSelf();
$pieChart->shouldReceive('setBudgets')->once()->andReturnSelf();
$pieChart->shouldReceive('setStart')->once()->andReturnSelf();
@@ -91,6 +95,10 @@ class BudgetReportControllerTest extends TestCase
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
+ // mock default session
+ $this->mockDefaultSession();
+ //Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
+
$pieChart->shouldReceive('setAccounts')->once()->andReturnSelf();
$pieChart->shouldReceive('setBudgets')->once()->andReturnSelf();
$pieChart->shouldReceive('setStart')->once()->andReturnSelf();
@@ -109,45 +117,41 @@ class BudgetReportControllerTest extends TestCase
*/
public function testMainChart(): void
{
- $this->markTestIncomplete('Needs to be rewritten for v4.8.0');
-
- return;
$generator = $this->mock(GeneratorInterface::class);
- $collector = $this->mock(TransactionCollectorInterface::class);
+ $collector = $this->mock(GroupCollectorInterface::class);
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
$date = new Carbon;
+ $withdrawal = $this->getRandomWithdrawalAsArray();
+ $asset = $this->getRandomAsset();
+ $budget = $this->getRandomBudget();
+ $limit1 = $this->getRandomBudgetLimit();
+ $limit2 = $this->getRandomBudgetLimit();
+
+ // need to update at least one budget limit so it fits the limits that have been set below.
+ $limit3 = new BudgetLimit;
+ $limit3->budget_id = $budget->id;
+ $limit3->start_date = new Carbon('2012-01-01');
+ $limit3->end_date = new Carbon('2012-01-31');
+
+
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
+ $this->mockDefaultSession();
+ Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
+
+ $budgetRepos->shouldReceive('getAllBudgetLimits')->andReturn(new Collection([$limit1, $limit2, $limit3]))->once();
+ $collector->shouldReceive('setAccounts')->andReturnSelf()->atLeast()->once();
+ $collector->shouldReceive('setRange')->andReturnSelf()->atLeast()->once();
+ $collector->shouldReceive('withAccountInformation')->andReturnSelf()->atLeast()->once();
- $one = factory(BudgetLimit::class)->make();
- $one->budget_id = 1;
- $two = factory(BudgetLimit::class)->make();
- $two->budget_id = 1;
- $two->start_date = new Carbon('2012-01-01');
- $two->end_date = new Carbon('2012-01-31');
- $transaction = factory(Transaction::class)->make();
- $transaction->transaction_amount = '-100';
- $transaction->destination_amount = '-100';
- $transaction->amount = '-100';
- $transaction->opposing_account_id = 8;
-
- $budgetRepos->shouldReceive('getAllBudgetLimits')->andReturn(new Collection([$one, $two]))->once();
-
- $collector->shouldReceive('setAccounts')->andReturnSelf();
- $collector->shouldReceive('setRange')->andReturnSelf();
- $collector->shouldReceive('setTypes')->withArgs([[TransactionType::WITHDRAWAL, TransactionType::TRANSFER]])->andReturnSelf();
- $collector->shouldReceive('setTypes')->withArgs([[TransactionType::DEPOSIT, TransactionType::TRANSFER]])->andReturnSelf();
- $collector->shouldReceive('removeFilter')->withArgs([TransferFilter::class])->andReturnSelf();
- $collector->shouldReceive('addFilter')->withArgs([OpposingAccountFilter::class])->andReturnSelf();
- $collector->shouldReceive('addFilter')->withArgs([PositiveAmountFilter::class])->andReturnSelf();
- $collector->shouldReceive('setBudgets')->andReturnSelf();
- $collector->shouldReceive('withOpposingAccount')->andReturnSelf();
- $collector->shouldReceive('getTransactions')->andReturn(new Collection([$transaction]));
+ $collector->shouldReceive('setTypes')->withArgs([[TransactionType::WITHDRAWAL, TransactionType::TRANSFER]])->andReturnSelf()->atLeast()->once();
+ $collector->shouldReceive('setBudgets')->andReturnSelf()->atLeast()->once();
+ $collector->shouldReceive('getExtractedJournals')->andReturn([$withdrawal])->atLeast()->once();
$generator->shouldReceive('multiSet')->andReturn([])->once();
$this->be($this->user());
- $response = $this->get(route('chart.budget.main', ['1', '1', '20120101', '20120131', 0]));
+ $response = $this->get(route('chart.budget.main', [$asset->id, $budget->id, '20120101', '20120131']));
$response->assertStatus(200);
}
}
diff --git a/tests/Feature/Controllers/Chart/CategoryControllerTest.php b/tests/Feature/Controllers/Chart/CategoryControllerTest.php
index 2c78cabf2b..a36c18da3c 100644
--- a/tests/Feature/Controllers/Chart/CategoryControllerTest.php
+++ b/tests/Feature/Controllers/Chart/CategoryControllerTest.php
@@ -23,9 +23,9 @@ declare(strict_types=1);
namespace Tests\Feature\Controllers\Chart;
use Carbon\Carbon;
+use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Generator\Chart\Basic\GeneratorInterface;
use FireflyIII\Helpers\Fiscal\FiscalHelperInterface;
-use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType;
use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
@@ -33,6 +33,7 @@ use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
use Illuminate\Support\Collection;
use Log;
+use Preferences;
use Tests\TestCase;
/**
@@ -61,13 +62,39 @@ class CategoryControllerTest extends TestCase
$repository = $this->mock(CategoryRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$generator = $this->mock(GeneratorInterface::class);
- $firstUse = new Carbon;
- $firstUse->subDays(3);
-
-
- $repository->shouldReceive('spentInPeriod')->andReturn('0');
- $repository->shouldReceive('earnedInPeriod')->andReturn('0');
- $repository->shouldReceive('firstUseDate')->andReturn($firstUse)->once();
+ $firstUseDate = null;
+ switch ($range) {
+ default:
+ throw new FireflyException(sprintf('No case for %s', $range));
+ case '1D':
+ $firstUseDate = Carbon::now()->subDays(3);
+ break;
+ case '1W':
+ $firstUseDate = Carbon::now()->subDays(12);
+ break;
+ case '1M':
+ $firstUseDate = Carbon::now()->subDays(40);
+ break;
+ case '3M':
+ $firstUseDate = Carbon::now()->subDays(120);
+ break;
+ case '6M':
+ $firstUseDate = Carbon::now()->subDays(160);
+ break;
+ case '1Y':
+ $firstUseDate = Carbon::now()->subDays(365);
+ break;
+ case 'custom':
+ $firstUseDate = Carbon::now()->subDays(20);
+ break;
+ }
+
+ $this->mockDefaultSession();
+ Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
+
+ $repository->shouldReceive('spentInPeriod')->andReturn('0')->atLeast()->once();
+ $repository->shouldReceive('earnedInPeriod')->andReturn('0')->atLeast()->once();
+ $repository->shouldReceive('firstUseDate')->andReturn($firstUseDate)->once();
$accountRepos->shouldReceive('getAccountsByType')->withArgs([[AccountType::DEFAULT, AccountType::ASSET]])->andReturn(new Collection)->once();
$generator->shouldReceive('multiSet')->once()->andReturn([]);
@@ -90,6 +117,9 @@ class CategoryControllerTest extends TestCase
$generator = $this->mock(GeneratorInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
+ $this->mockDefaultSession();
+ Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
+
// spent per currency data:
$spentNoCategory = [
1 =>
@@ -147,6 +177,10 @@ class CategoryControllerTest extends TestCase
$generator = $this->mock(GeneratorInterface::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);
$repository->shouldReceive('periodExpenses')->andReturn([])->once();
@@ -167,6 +201,10 @@ class CategoryControllerTest extends TestCase
$generator = $this->mock(GeneratorInterface::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);
$repository->shouldReceive('periodExpensesNoCategory')->andReturn([])->once();
@@ -189,9 +227,13 @@ class CategoryControllerTest extends TestCase
$repository = $this->mock(CategoryRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$generator = $this->mock(GeneratorInterface::class);
- $account = factory(Account::class)->make();
+ $account = $this->getRandomAsset();
$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);
diff --git a/tests/Feature/Controllers/Chart/CategoryReportControllerTest.php b/tests/Feature/Controllers/Chart/CategoryReportControllerTest.php
index 5fc296cdff..6805d94335 100644
--- a/tests/Feature/Controllers/Chart/CategoryReportControllerTest.php
+++ b/tests/Feature/Controllers/Chart/CategoryReportControllerTest.php
@@ -25,6 +25,7 @@ namespace Tests\Feature\Controllers\Chart;
use Carbon\Carbon;
use FireflyIII\Generator\Chart\Basic\GeneratorInterface;
use FireflyIII\Helpers\Chart\MetaPieChartInterface;
+use FireflyIII\Helpers\Collector\GroupCollectorInterface;
use FireflyIII\Helpers\Collector\TransactionCollectorInterface;
use FireflyIII\Helpers\Filter\NegativeAmountFilter;
use FireflyIII\Helpers\Filter\OpposingAccountFilter;
@@ -34,6 +35,7 @@ use FireflyIII\Helpers\Fiscal\FiscalHelperInterface;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionType;
use Log;
+use Preferences;
use Tests\TestCase;
/**
@@ -59,6 +61,10 @@ class CategoryReportControllerTest extends TestCase
$pieChart = $this->mock(MetaPieChartInterface::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);
$pieChart->shouldReceive('setAccounts')->once()->andReturnSelf();
@@ -83,6 +89,10 @@ class CategoryReportControllerTest extends TestCase
$pieChart = $this->mock(MetaPieChartInterface::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);
$pieChart->shouldReceive('setAccounts')->once()->andReturnSelf();
@@ -107,6 +117,10 @@ class CategoryReportControllerTest extends TestCase
$pieChart = $this->mock(MetaPieChartInterface::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);
$pieChart->shouldReceive('setAccounts')->once()->andReturnSelf();
@@ -131,6 +145,10 @@ class CategoryReportControllerTest extends TestCase
$pieChart = $this->mock(MetaPieChartInterface::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);
$pieChart->shouldReceive('setAccounts')->once()->andReturnSelf();
@@ -151,27 +169,25 @@ class CategoryReportControllerTest extends TestCase
*/
public function testMainChart(): void
{
- $this->markTestIncomplete('Needs to be rewritten for v4.8.0');
-
- return;
$generator = $this->mock(GeneratorInterface::class);
- $collector = $this->mock(TransactionCollectorInterface::class);
- $transactions = factory(Transaction::class, 10)->make();
+ $collector = $this->mock(GroupCollectorInterface::class);
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
$date = new Carbon;
+ $withdrawal = $this->getRandomWithdrawalAsArray();
+
+ $this->mockDefaultSession();
+ Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
+
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
- $collector->shouldReceive('setAccounts')->andReturnSelf();
- $collector->shouldReceive('setRange')->andReturnSelf();
- $collector->shouldReceive('setTypes')->withArgs([[TransactionType::WITHDRAWAL, TransactionType::TRANSFER]])->andReturnSelf();
- $collector->shouldReceive('setTypes')->withArgs([[TransactionType::DEPOSIT, TransactionType::TRANSFER]])->andReturnSelf();
- $collector->shouldReceive('removeFilter')->withArgs([TransferFilter::class])->andReturnSelf();
- $collector->shouldReceive('addFilter')->withArgs([OpposingAccountFilter::class])->andReturnSelf();
- $collector->shouldReceive('addFilter')->withArgs([PositiveAmountFilter::class])->andReturnSelf();
- $collector->shouldReceive('addFilter')->withArgs([NegativeAmountFilter::class])->andReturnSelf();
- $collector->shouldReceive('setCategories')->andReturnSelf();
- $collector->shouldReceive('withOpposingAccount')->andReturnSelf();
- $collector->shouldReceive('getTransactions')->andReturn($transactions);
+ $collector->shouldReceive('setAccounts')->andReturnSelf()->atLeast()->once();
+ $collector->shouldReceive('withAccountInformation')->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('setCategories')->andReturnSelf()->atLeast()->once();
+ $collector->shouldReceive('getExtractedJournals')->andReturn([$withdrawal])->atLeast()->once();
$generator->shouldReceive('multiSet')->andReturn([])->once();
$this->be($this->user());
diff --git a/tests/Feature/Controllers/Chart/ExpenseReportControllerTest.php b/tests/Feature/Controllers/Chart/ExpenseReportControllerTest.php
index 9c7cb4bc1f..c94efb4877 100644
--- a/tests/Feature/Controllers/Chart/ExpenseReportControllerTest.php
+++ b/tests/Feature/Controllers/Chart/ExpenseReportControllerTest.php
@@ -24,13 +24,13 @@ namespace Tests\Feature\Controllers\Chart;
use Carbon\Carbon;
use FireflyIII\Generator\Chart\Basic\GeneratorInterface;
+use FireflyIII\Helpers\Collector\GroupCollectorInterface;
use FireflyIII\Helpers\Collector\TransactionCollectorInterface;
use FireflyIII\Helpers\Fiscal\FiscalHelperInterface;
-use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionType;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
-use Illuminate\Support\Collection;
use Log;
+use Preferences;
use Tests\TestCase;
/**
@@ -53,31 +53,28 @@ class ExpenseReportControllerTest extends TestCase
*/
public function testMainChart(): void
{
- $this->markTestIncomplete('Needs to be rewritten for v4.8.0');
-
- return;
- $expense = $this->user()->accounts()->where('account_type_id', 4)->first();
$generator = $this->mock(GeneratorInterface::class);
- $collector = $this->mock(TransactionCollectorInterface::class);
+ $collector = $this->mock(GroupCollectorInterface::class);
$accountRepository = $this->mock(AccountRepositoryInterface::class);
+ $fiscalHelper = $this->mock(FiscalHelperInterface::class);
+ $expense = $this->getRandomExpense();
+ $date = new Carbon;
+ $withdrawal = $this->getRandomWithdrawalAsArray();
+
$accountRepository->shouldReceive('findByName')->once()->andReturn($expense);
- $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);
- $set = new Collection;
- $transaction = new Transaction();
- $transaction->opposing_account_name = 'Somebody';
- $transaction->transaction_amount = '5';
- $set->push($transaction);
- $collector->shouldReceive('setAccounts')->andReturnSelf();
- $collector->shouldReceive('setRange')->andReturnSelf();
- $collector->shouldReceive('setTypes')->withArgs([[TransactionType::WITHDRAWAL]])->andReturnSelf();
- $collector->shouldReceive('setTypes')->withArgs([[TransactionType::DEPOSIT]])->andReturnSelf();
- $collector->shouldReceive('setOpposingAccounts')->andReturnSelf();
- $collector->shouldReceive('getTransactions')->andReturn($set);
+ $collector->shouldReceive('setAccounts')->andReturnSelf()->atLeast()->once();
+ $collector->shouldReceive('setRange')->andReturnSelf()->atLeast()->once();
+ $collector->shouldReceive('withAccountInformation')->andReturnSelf()->atLeast()->once();
+ $collector->shouldReceive('setTypes')->withArgs([[TransactionType::WITHDRAWAL]])->andReturnSelf()->atLeast()->once();
+ $collector->shouldReceive('setTypes')->withArgs([[TransactionType::DEPOSIT]])->andReturnSelf()->atLeast()->once();
+ $collector->shouldReceive('getExtractedJournals')->andReturn([$withdrawal])->atLeast()->once();
$generator->shouldReceive('multiSet')->andReturn([])->once();
$this->be($this->user());
diff --git a/tests/Feature/Controllers/Chart/PiggyBankControllerTest.php b/tests/Feature/Controllers/Chart/PiggyBankControllerTest.php
index 3f1915e4cc..c784b87b12 100644
--- a/tests/Feature/Controllers/Chart/PiggyBankControllerTest.php
+++ b/tests/Feature/Controllers/Chart/PiggyBankControllerTest.php
@@ -27,6 +27,7 @@ use FireflyIII\Models\PiggyBankEvent;
use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
use Illuminate\Support\Collection;
use Log;
+use Preferences;
use Tests\TestCase;
/**
@@ -50,13 +51,18 @@ class PiggyBankControllerTest extends TestCase
{
$generator = $this->mock(GeneratorInterface::class);
$repository = $this->mock(PiggyBankRepositoryInterface::class);
- $event = factory(PiggyBankEvent::class)->make();
+ /** @var PiggyBankEvent $event */
+ $event = PiggyBankEvent::inRandomOrder()->first();
+ $piggy = $event->piggy_bank_id;
+
+ $this->mockDefaultSession();
+ Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
$repository->shouldReceive('getEvents')->andReturn(new Collection([$event]));
$generator->shouldReceive('singleSet')->once()->andReturn([]);
$this->be($this->user());
- $response = $this->get(route('chart.piggy-bank.history', [1]));
+ $response = $this->get(route('chart.piggy-bank.history', [$piggy]));
$response->assertStatus(200);
}
}
diff --git a/tests/Feature/Controllers/Chart/ReportControllerTest.php b/tests/Feature/Controllers/Chart/ReportControllerTest.php
index a1597b738c..0ed0ea43ae 100644
--- a/tests/Feature/Controllers/Chart/ReportControllerTest.php
+++ b/tests/Feature/Controllers/Chart/ReportControllerTest.php
@@ -32,6 +32,7 @@ use FireflyIII\Repositories\Account\AccountTaskerInterface;
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
use Log;
use Mockery;
+use Preferences;
use Steam;
use Tests\TestCase;
@@ -62,8 +63,10 @@ class ReportControllerTest extends TestCase
$date = new Carbon;
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
- //$currencyRepos->shouldReceive('setUser');
- //$currencyRepos->shouldReceive('findNull')->withArgs([1])->andReturn(TransactionCurrency::find(1))->atLeast()->once();
+
+
+ $this->mockDefaultSession();
+ Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
$netWorth->shouldReceive('getNetWorthByCurrency')->andReturn(
[
@@ -104,6 +107,10 @@ class ReportControllerTest extends TestCase
$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 = [1 => ['sum' => '100']];
@@ -127,6 +134,10 @@ class ReportControllerTest extends TestCase
$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);
diff --git a/tests/Feature/Controllers/Chart/TagReportControllerTest.php b/tests/Feature/Controllers/Chart/TagReportControllerTest.php
index 7a8f25e352..9ef7d5b6c0 100644
--- a/tests/Feature/Controllers/Chart/TagReportControllerTest.php
+++ b/tests/Feature/Controllers/Chart/TagReportControllerTest.php
@@ -25,20 +25,16 @@ namespace Tests\Feature\Controllers\Chart;
use Carbon\Carbon;
use FireflyIII\Generator\Chart\Basic\GeneratorInterface;
use FireflyIII\Helpers\Chart\MetaPieChartInterface;
-use FireflyIII\Helpers\Collector\TransactionCollectorInterface;
-use FireflyIII\Helpers\Filter\NegativeAmountFilter;
-use FireflyIII\Helpers\Filter\OpposingAccountFilter;
-use FireflyIII\Helpers\Filter\PositiveAmountFilter;
-use FireflyIII\Helpers\Filter\TransferFilter;
+use FireflyIII\Helpers\Collector\GroupCollectorInterface;
use FireflyIII\Helpers\Fiscal\FiscalHelperInterface;
-use FireflyIII\Models\Tag;
-use FireflyIII\Models\Transaction;
-use FireflyIII\Models\TransactionType;
+use FireflyIII\Models\Preference;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Tag\TagRepositoryInterface;
use Illuminate\Support\Collection;
use Log;
+use Preferences;
use Tests\TestCase;
+use FireflyIII\Models\TransactionType;
/**
* Class TagReportControllerTest
@@ -64,6 +60,9 @@ class TagReportControllerTest extends TestCase
$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]));
@@ -100,6 +99,8 @@ class TagReportControllerTest extends TestCase
$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);
@@ -132,6 +133,8 @@ class TagReportControllerTest extends TestCase
$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);
@@ -163,6 +166,8 @@ class TagReportControllerTest extends TestCase
$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);
@@ -186,42 +191,35 @@ class TagReportControllerTest extends TestCase
*/
public function testMainChart(): void
{
- $this->markTestIncomplete('Needs to be rewritten for v4.8.0');
+ $this->mock(AccountRepositoryInterface::class);
+ $generator = $this->mock(GeneratorInterface::class);
+ $collector = $this->mock(GroupCollectorInterface::class);
+ $tagRepos = $this->mock(TagRepositoryInterface::class);
+ $fiscalHelper = $this->mock(FiscalHelperInterface::class);
- return;
- $generator = $this->mock(GeneratorInterface::class);
- $collector = $this->mock(TransactionCollectorInterface::class);
- $tagRepos = $this->mock(TagRepositoryInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
- $tag = $this->user()->tags()->first();
+ $withdrawal = $this->getRandomWithdrawalAsArray();
+ $tag = $this->user()->tags()->inRandomOrder()->first();
+ $date = new Carbon;
+ $false = new Preference;
+ $false->data = false;
+
+ $this->mockDefaultSession();
$tagRepos->shouldReceive('setUser');
$tagRepos->shouldReceive('get')->andReturn(new Collection([$tag]));
- $fiscalHelper = $this->mock(FiscalHelperInterface::class);
- $date = new Carbon;
+ 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);
-
- $set = new Collection;
- for ($i = 0; $i < 10; ++$i) {
- $transaction = factory(Transaction::class)->make();
- $tag = factory(Tag::class)->make();
- $transaction->transactionJournal->tags()->save($tag);
- $set->push($transaction);
- }
- $tag = $this->user()->tags()->first();
- $collector->shouldReceive('setAccounts')->andReturnSelf();
- $collector->shouldReceive('setRange')->andReturnSelf();
- $collector->shouldReceive('setTypes')->withArgs([[TransactionType::WITHDRAWAL, TransactionType::TRANSFER]])->andReturnSelf();
- $collector->shouldReceive('setTypes')->withArgs([[TransactionType::DEPOSIT, TransactionType::TRANSFER]])->andReturnSelf();
- $collector->shouldReceive('removeFilter')->withArgs([TransferFilter::class])->andReturnSelf();
- $collector->shouldReceive('addFilter')->withArgs([OpposingAccountFilter::class])->andReturnSelf();
- $collector->shouldReceive('addFilter')->withArgs([PositiveAmountFilter::class])->andReturnSelf();
- $collector->shouldReceive('addFilter')->withArgs([NegativeAmountFilter::class])->andReturnSelf();
- $collector->shouldReceive('setTags')->andReturnSelf();
- $collector->shouldReceive('withOpposingAccount')->andReturnSelf();
- $collector->shouldReceive('getTransactions')->andReturn($set);
- $generator->shouldReceive('multiSet')->andReturn([])->once();
+ $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']));
@@ -250,6 +248,7 @@ class TagReportControllerTest extends TestCase
$pieChart->shouldReceive('setTags')->once()->andReturnSelf();
$pieChart->shouldReceive('setStart')->once()->andReturnSelf();
$pieChart->shouldReceive('setEnd')->once()->andReturnSelf();
+
$pieChart->shouldReceive('setCollectOtherObjects')->once()->andReturnSelf()->withArgs([false]);
$pieChart->shouldReceive('generate')->withArgs(['expense', 'tag'])->andReturn([])->once();
$generator->shouldReceive('pieChart')->andReturn([])->once();
@@ -278,6 +277,7 @@ class TagReportControllerTest extends TestCase
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
$pieChart->shouldReceive('setAccounts')->once()->andReturnSelf();
+
$pieChart->shouldReceive('setTags')->once()->andReturnSelf();
$pieChart->shouldReceive('setStart')->once()->andReturnSelf();
$pieChart->shouldReceive('setEnd')->once()->andReturnSelf();
diff --git a/tests/Feature/Controllers/Import/CallbackControllerTest.php b/tests/Feature/Controllers/Import/CallbackControllerTest.php
index e9db45d598..dbb09ebdd8 100644
--- a/tests/Feature/Controllers/Import/CallbackControllerTest.php
+++ b/tests/Feature/Controllers/Import/CallbackControllerTest.php
@@ -56,6 +56,8 @@ class CallbackControllerTest extends TestCase
$config = [];
$newConfig = ['auth_code' => 'abc'];
+ $this->mockDefaultSession();
+
// mock calls.
$repository->shouldReceive('findByKey')->andReturn(new ImportJob)->once();
$repository->shouldReceive('getConfiguration')->andReturn($config)->once();
@@ -79,6 +81,7 @@ class CallbackControllerTest extends TestCase
// mock calls.
$repository->shouldReceive('findByKey')->andReturnNull()->once();
+ $this->mockDefaultSession();
$this->be($this->user());
$response = $this->get(route('import.callback.ynab') . '?code=abc&state=def');
@@ -91,11 +94,9 @@ class CallbackControllerTest extends TestCase
*/
public function testYnabBasicNoCode(): void
{
- $repository = $this->mock(ImportJobRepositoryInterface::class);
+ $this->mock(ImportJobRepositoryInterface::class);
- // config for job:
- $config = [];
- $newConfig = ['auth_code' => 'abc'];
+ $this->mockDefaultSession();
// mock calls.
diff --git a/tests/Feature/Controllers/Import/IndexControllerTest.php b/tests/Feature/Controllers/Import/IndexControllerTest.php
index 1cf2c841b4..e84b073f6c 100644
--- a/tests/Feature/Controllers/Import/IndexControllerTest.php
+++ b/tests/Feature/Controllers/Import/IndexControllerTest.php
@@ -70,6 +70,8 @@ class IndexControllerTest extends TestCase
$importJob->provider = 'fake';
$importJob->key = 'fake_job_1';
+ $this->mockDefaultSession();
+
// mock calls:
$ynabPrerequisites->shouldReceive('setUser')->once();
$fakePrerequisites->shouldReceive('setUser')->once();
@@ -105,6 +107,8 @@ class IndexControllerTest extends TestCase
$importJob->provider = 'spectre';
$importJob->key = 'fake_job_1';
+ $this->mockDefaultSession();
+
// mock calls:
$ynabPrerequisites->shouldReceive('setUser')->times(2);
$fakePrerequisites->shouldReceive('setUser')->times(2);
@@ -143,6 +147,8 @@ class IndexControllerTest extends TestCase
$importJob->key = 'fake_job_1';
$importJob->user_id = 1;
+ $this->mockDefaultSession();
+
// mock calls
$userRepository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(true)->times(3);
@@ -188,6 +194,8 @@ class IndexControllerTest extends TestCase
$importJob->key = 'fake_job_2';
$importJob->user_id = 1;
+ $this->mockDefaultSession();
+
// mock call:
$fakePrerequisites->shouldReceive('isComplete')->times(3)->andReturn(true);
@@ -235,6 +243,8 @@ class IndexControllerTest extends TestCase
$importJob->key = 'file_job_1';
$importJob->user_id = 1;
+ $this->mockDefaultSession();
+
// mock calls
$fakePrerequisites->shouldReceive('setUser')->times(2);
$bunqPrerequisites->shouldReceive('setUser')->times(2);
@@ -272,9 +282,11 @@ class IndexControllerTest extends TestCase
$filePrerequisites = $this->mock(FilePrerequisites::class);
$ynabPrerequisites = $this->mock(YnabPrerequisites::class);
+ $this->mockDefaultSession();
+
$job = new ImportJob;
$job->user_id = $this->user()->id;
- $job->key = 'dc_' . random_int(1, 10000);
+ $job->key = 'dc_' . $this->randomInt();
$job->status = 'ready_to_run';
$job->stage = 'go-for-import';
$job->provider = 'file';
@@ -325,6 +337,8 @@ class IndexControllerTest extends TestCase
$ynabPrerequisites = $this->mock(YnabPrerequisites::class);
$repository = $this->mock(ImportJobRepositoryInterface::class);
+ $this->mockDefaultSession();
+
// call methods:
$userRepository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false);
$userRepository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(false);
@@ -360,6 +374,8 @@ class IndexControllerTest extends TestCase
$ynabPrerequisites = $this->mock(YnabPrerequisites::class);
$repository = $this->mock(ImportJobRepositoryInterface::class);
+ $this->mockDefaultSession();
+
// call methods:
$fakePrerequisites->shouldReceive('setUser')->once();
$bunqPrerequisites->shouldReceive('setUser')->once();
diff --git a/tests/Feature/Controllers/Import/JobConfigurationControllerTest.php b/tests/Feature/Controllers/Import/JobConfigurationControllerTest.php
index 45e5261854..5f8f9f6e00 100644
--- a/tests/Feature/Controllers/Import/JobConfigurationControllerTest.php
+++ b/tests/Feature/Controllers/Import/JobConfigurationControllerTest.php
@@ -54,12 +54,14 @@ class JobConfigurationControllerTest extends TestCase
{
$job = new ImportJob;
$job->user_id = $this->user()->id;
- $job->key = '1Afake_job_' . random_int(1, 10000);
+ $job->key = '1Afake_job_' . $this->randomInt();
$job->status = 'has_prereq';
$job->provider = 'fake';
$job->file_type = '';
$job->save();
+ $this->mockDefaultSession();
+
// mock repositories and configuration handling classes:
$repository = $this->mock(ImportJobRepositoryInterface::class);
$configurator = $this->mock(FakeJobConfiguration::class);
@@ -89,12 +91,14 @@ class JobConfigurationControllerTest extends TestCase
{
$job = new ImportJob;
$job->user_id = $this->user()->id;
- $job->key = '2Bfake_job_' . random_int(1, 10000);
+ $job->key = '2Bfake_job_' . $this->randomInt();
$job->status = 'some_bad_state';
$job->provider = 'fake';
$job->file_type = '';
$job->save();
+ $this->mockDefaultSession();
+
// mock repositories and configuration handling classes:
$repository = $this->mock(ImportJobRepositoryInterface::class);
$configurator = $this->mock(FakeJobConfiguration::class);
@@ -115,12 +119,14 @@ class JobConfigurationControllerTest extends TestCase
{
$job = new ImportJob;
$job->user_id = $this->user()->id;
- $job->key = '3Cfake_job_' . random_int(1, 10000);
+ $job->key = '3Cfake_job_' . $this->randomInt();
$job->status = 'has_prereq';
$job->provider = 'fake';
$job->file_type = '';
$job->save();
+ $this->mockDefaultSession();
+
// mock repositories and configuration handling classes:
$repository = $this->mock(ImportJobRepositoryInterface::class);
$configurator = $this->mock(FakeJobConfiguration::class);
@@ -145,12 +151,14 @@ class JobConfigurationControllerTest extends TestCase
$job = new ImportJob;
$job->user_id = $this->user()->id;
- $job->key = '4Dfake_job_' . random_int(1, 10000);
+ $job->key = '4Dfake_job_' . $this->randomInt();
$job->status = 'has_prereq';
$job->provider = 'fake';
$job->file_type = '';
$job->save();
+ $this->mockDefaultSession();
+
$messages = new MessageBag;
$messages->add('some', 'srrange message');
@@ -180,12 +188,14 @@ class JobConfigurationControllerTest extends TestCase
$job = new ImportJob;
$job->user_id = $this->user()->id;
- $job->key = '5Ffake_job_' . random_int(1, 10000);
+ $job->key = '5Ffake_job_' . $this->randomInt();
$job->status = 'some_bad_state';
$job->provider = 'fake';
$job->file_type = '';
$job->save();
+ $this->mockDefaultSession();
+
$messages = new MessageBag;
$messages->add('some', 'srrange message');
@@ -210,12 +220,14 @@ class JobConfigurationControllerTest extends TestCase
$job = new ImportJob;
$job->user_id = $this->user()->id;
- $job->key = '6Efake_job_' . random_int(1, 10000);
+ $job->key = '6Efake_job_' . $this->randomInt();
$job->status = 'has_prereq';
$job->provider = 'fake';
$job->file_type = '';
$job->save();
+ $this->mockDefaultSession();
+
// mock repositories and configuration handling classes:
$repository = $this->mock(ImportJobRepositoryInterface::class);
$configurator = $this->mock(FakeJobConfiguration::class);
@@ -242,12 +254,14 @@ class JobConfigurationControllerTest extends TestCase
$file = UploadedFile::fake()->image('avatar.jpg');
$job = new ImportJob;
$job->user_id = $this->user()->id;
- $job->key = '7Dfake_job_' . random_int(1, 10000);
+ $job->key = '7Dfake_job_' . $this->randomInt();
$job->status = 'has_prereq';
$job->provider = 'fake';
$job->file_type = '';
$job->save();
+ $this->mockDefaultSession();
+
$messages = new MessageBag;
$messages->add('some', 'srrange message');
diff --git a/tests/Feature/Controllers/Import/JobStatusControllerTest.php b/tests/Feature/Controllers/Import/JobStatusControllerTest.php
index 345343c17b..587f7251a4 100644
--- a/tests/Feature/Controllers/Import/JobStatusControllerTest.php
+++ b/tests/Feature/Controllers/Import/JobStatusControllerTest.php
@@ -61,12 +61,14 @@ class JobStatusControllerTest extends TestCase
$userRepos = $this->mock(UserRepositoryInterface::class);
$job = new ImportJob;
$job->user_id = $this->user()->id;
- $job->key = 'Afake_job_' . random_int(1, 10000);
+ $job->key = 'Afake_job_' . $this->randomInt();
$job->status = 'ready_to_run';
$job->provider = 'fake';
$job->file_type = '';
$job->save();
+ $this->mockDefaultSession();
+
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
// call thing.
@@ -86,13 +88,15 @@ class JobStatusControllerTest extends TestCase
$job = new ImportJob;
$job->user_id = $this->user()->id;
- $job->key = 'Bfake_job_' . random_int(1, 10000);
+ $job->key = 'Bfake_job_' . $this->randomInt();
$job->status = 'ready_to_run';
$job->provider = 'file';
$job->transactions = [];
$job->file_type = '';
$job->save();
+ $this->mockDefaultSession();
+
$importRepos->shouldReceive('countTransactions')->once()->andReturn(0);
// call thing.
@@ -114,7 +118,7 @@ class JobStatusControllerTest extends TestCase
$tag = $this->user()->tags()->first();
$job = new ImportJob;
$job->user_id = $this->user()->id;
- $job->key = 'Cfake_job_' . random_int(1, 10000);
+ $job->key = 'Cfake_job_' . $this->randomInt();
$job->status = 'ready_to_run';
$job->provider = 'fake';
$job->transactions = [];
@@ -122,6 +126,8 @@ class JobStatusControllerTest extends TestCase
$job->tag()->associate($tag);
$job->save();
+ $this->mockDefaultSession();
+
$importRepos->shouldReceive('countTransactions')->once()->andReturn(0);
// call thing.
@@ -147,11 +153,13 @@ class JobStatusControllerTest extends TestCase
$second = $this->user()->transactionJournals()->where('id', '!=', $journal->id)->first();
$tag->transactionJournals()->sync([$journal->id, $second->id]);
+ $this->mockDefaultSession();
+
$importRepos->shouldReceive('countTransactions')->once()->andReturn(2);
$job = new ImportJob;
$job->user_id = $this->user()->id;
- $job->key = 'Dfake_job_' . random_int(1, 10000);
+ $job->key = 'Dfake_job_' . $this->randomInt();
$job->status = 'ready_to_run';
$job->provider = 'fake';
$job->transactions = [];
@@ -181,11 +189,13 @@ class JobStatusControllerTest extends TestCase
$journal = $this->user()->transactionJournals()->first();
$tag->transactionJournals()->sync([$journal->id]);
+ $this->mockDefaultSession();
+
$importRepos->shouldReceive('countTransactions')->once()->andReturn(1);
$job = new ImportJob;
$job->user_id = $this->user()->id;
- $job->key = 'Efake_job_' . random_int(1, 10000);
+ $job->key = 'Efake_job_' . $this->randomInt();
$job->status = 'ready_to_run';
$job->provider = 'fake';
$job->transactions = [];
@@ -211,13 +221,15 @@ class JobStatusControllerTest extends TestCase
$job = new ImportJob;
$job->user_id = $this->user()->id;
- $job->key = 'Ffake_job_' . random_int(1, 10000);
+ $job->key = 'Ffake_job_' . $this->randomInt();
$job->status = 'ready_to_run';
$job->provider = 'fake';
$job->transactions = [];
$job->file_type = '';
$job->save();
+ $this->mockDefaultSession();
+
// mock stuff
$repository = $this->mock(ImportJobRepositoryInterface::class);
$routine = $this->mock(FakeRoutine::class);
@@ -242,13 +254,15 @@ class JobStatusControllerTest extends TestCase
$job = new ImportJob;
$job->user_id = $this->user()->id;
- $job->key = 'Gfake_job_' . random_int(1, 10000);
+ $job->key = 'Gfake_job_' . $this->randomInt();
$job->status = 'ready_to_run';
$job->provider = 'fake';
$job->transactions = [];
$job->file_type = '';
$job->save();
+ $this->mockDefaultSession();
+
// mock stuff
$repository = $this->mock(ImportJobRepositoryInterface::class);
$routine = $this->mock(FakeRoutine::class);
@@ -273,13 +287,15 @@ class JobStatusControllerTest extends TestCase
$userRepos = $this->mock(UserRepositoryInterface::class);
$job = new ImportJob;
$job->user_id = $this->user()->id;
- $job->key = 'Hfake_job_' . random_int(1, 10000);
+ $job->key = 'Hfake_job_' . $this->randomInt();
$job->status = 'ready_to_run';
$job->provider = 'fake';
$job->transactions = [];
$job->file_type = '';
$job->save();
+ $this->mockDefaultSession();
+
// mock stuff
$repository = $this->mock(ImportJobRepositoryInterface::class);
$routine = $this->mock(FakeRoutine::class);
@@ -307,9 +323,11 @@ class JobStatusControllerTest extends TestCase
$importRepos->shouldReceive('setStatus')->withArgs([Mockery::any(), 'error'])
->atLeast()->once();
+ $this->mockDefaultSession();
+
$job = new ImportJob;
$job->user_id = $this->user()->id;
- $job->key = 'Ifake_job_' . random_int(1, 10000);
+ $job->key = 'Ifake_job_' . $this->randomInt();
$job->status = 'bad_state';
$job->provider = 'fake';
$job->transactions = [];
@@ -330,13 +348,15 @@ class JobStatusControllerTest extends TestCase
{
$job = new ImportJob;
$job->user_id = $this->user()->id;
- $job->key = 'Jfake_job_' . random_int(1, 10000);
+ $job->key = 'Jfake_job_' . $this->randomInt();
$job->status = 'provider_finished';
$job->provider = 'fake';
$job->transactions = [];
$job->file_type = '';
$job->save();
+ $this->mockDefaultSession();
+
// mock stuff
$repository = $this->mock(ImportJobRepositoryInterface::class);
$storage = $this->mock(ImportArrayStorage::class);
@@ -362,13 +382,15 @@ class JobStatusControllerTest extends TestCase
{
$job = new ImportJob;
$job->user_id = $this->user()->id;
- $job->key = 'Lfake_job_' . random_int(1, 10000);
+ $job->key = 'Lfake_job_' . $this->randomInt();
$job->status = 'provider_finished';
$job->provider = 'fake';
$job->transactions = [];
$job->file_type = '';
$job->save();
+ $this->mockDefaultSession();
+
// mock stuff
$repository = $this->mock(ImportJobRepositoryInterface::class);
$storage = $this->mock(ImportArrayStorage::class);
@@ -395,13 +417,15 @@ class JobStatusControllerTest extends TestCase
$importRepos = $this->mock(ImportJobRepositoryInterface::class);
$job = new ImportJob;
$job->user_id = $this->user()->id;
- $job->key = 'Kfake_job_' . random_int(1, 10000);
+ $job->key = 'Kfake_job_' . $this->randomInt();
$job->status = 'some_bad_state';
$job->provider = 'fake';
$job->transactions = [];
$job->file_type = '';
$job->save();
+ $this->mockDefaultSession();
+
$this->be($this->user());
$response = $this->post(route('import.job.store', [$job->key]));
$response->assertStatus(200);
diff --git a/tests/Feature/Controllers/Import/PrerequisitesControllerTest.php b/tests/Feature/Controllers/Import/PrerequisitesControllerTest.php
index 3196a1e7d3..15a4a09bfb 100644
--- a/tests/Feature/Controllers/Import/PrerequisitesControllerTest.php
+++ b/tests/Feature/Controllers/Import/PrerequisitesControllerTest.php
@@ -60,7 +60,7 @@ class PrerequisitesControllerTest extends TestCase
$job = new ImportJob;
$job->user_id = $this->user()->id;
- $job->key = 'A_pre_job_' . random_int(1, 10000);
+ $job->key = 'A_pre_job_' . $this->randomInt();
$job->status = 'new';
$job->provider = 'fake';
$job->transactions = [];
@@ -93,7 +93,7 @@ class PrerequisitesControllerTest extends TestCase
$job = new ImportJob;
$job->user_id = $this->user()->id;
- $job->key = 'B_pre_job_' . random_int(1, 10000);
+ $job->key = 'B_pre_job_' . $this->randomInt();
$job->status = 'some_Bad_state';
$job->provider = 'fake';
$job->transactions = [];
@@ -121,7 +121,7 @@ class PrerequisitesControllerTest extends TestCase
$job = new ImportJob;
$job->user_id = $this->user()->id;
- $job->key = 'C_pre_job_' . random_int(1, 10000);
+ $job->key = 'C_pre_job_' . $this->randomInt();
$job->status = 'new';
$job->provider = 'fake';
$job->transactions = [];
@@ -153,7 +153,7 @@ class PrerequisitesControllerTest extends TestCase
$job = new ImportJob;
$job->user_id = $this->user()->id;
- $job->key = 'D_pre_job_' . random_int(1, 10000);
+ $job->key = 'D_pre_job_' . $this->randomInt();
$job->status = 'new';
$job->provider = 'fake';
$job->transactions = [];
@@ -185,7 +185,7 @@ class PrerequisitesControllerTest extends TestCase
$job = new ImportJob;
$job->user_id = $this->user()->id;
- $job->key = 'D_pre_job_' . random_int(1, 10000);
+ $job->key = 'D_pre_job_' . $this->randomInt();
$job->status = 'badstate';
$job->provider = 'fake';
$job->transactions = [];
@@ -241,7 +241,7 @@ class PrerequisitesControllerTest extends TestCase
$job = new ImportJob;
$job->user_id = $this->user()->id;
- $job->key = 'D_pre_job_' . random_int(1, 10000);
+ $job->key = 'D_pre_job_' . $this->randomInt();
$job->status = 'new';
$job->provider = 'fake';
$job->transactions = [];
diff --git a/tests/Feature/Controllers/PiggyBankControllerTest.php b/tests/Feature/Controllers/PiggyBankControllerTest.php
index 6a864c6941..2e6f0a6af4 100644
--- a/tests/Feature/Controllers/PiggyBankControllerTest.php
+++ b/tests/Feature/Controllers/PiggyBankControllerTest.php
@@ -502,7 +502,7 @@ class PiggyBankControllerTest extends TestCase
$this->session(['piggy-banks.create.uri' => 'http://localhost']);
$data = [
- 'name' => 'Piggy ' . random_int(999, 10000),
+ 'name' => 'Piggy ' . $this->randomInt(),
'targetamount' => '100.123',
'account_id' => 2,
'amount_currency_id_targetamount' => 1,
@@ -533,7 +533,7 @@ class PiggyBankControllerTest extends TestCase
$this->session(['piggy-banks.edit.uri' => 'http://localhost']);
$data = [
'id' => 3,
- 'name' => 'Updated Piggy ' . random_int(999, 10000),
+ 'name' => 'Updated Piggy ' . $this->randomInt(),
'targetamount' => '100.123',
'account_id' => 2,
'amount_currency_id_targetamount' => 1,
diff --git a/tests/Feature/Controllers/Recurring/CreateControllerTest.php b/tests/Feature/Controllers/Recurring/CreateControllerTest.php
index a25a89f608..73658580cf 100644
--- a/tests/Feature/Controllers/Recurring/CreateControllerTest.php
+++ b/tests/Feature/Controllers/Recurring/CreateControllerTest.php
@@ -101,11 +101,11 @@ class CreateControllerTest extends TestCase
$tomorrow = Carbon::now()->addDays(2);
$recurrence = $this->user()->recurrences()->first();
$data = [
- 'title' => 'hello' . random_int(1, 100000),
+ 'title' => 'hello' . $this->randomInt(),
'first_date' => $tomorrow->format('Y-m-d'),
'repetition_type' => 'daily',
'skip' => 0,
- 'recurring_description' => 'Some descr' . random_int(1, 100000),
+ 'recurring_description' => 'Some descr' . $this->randomInt(),
'active' => '1',
'apply_rules' => '1',
'foreign_amount' => '1',
@@ -160,11 +160,11 @@ class CreateControllerTest extends TestCase
$tomorrow = Carbon::now()->addDays(2);
$recurrence = $this->user()->recurrences()->first();
$data = [
- 'title' => 'hello' . random_int(1, 100000),
+ 'title' => 'hello' . $this->randomInt(),
'first_date' => $tomorrow->format('Y-m-d'),
'repetition_type' => 'daily',
'skip' => 0,
- 'recurring_description' => 'Some descr' . random_int(1, 100000),
+ 'recurring_description' => 'Some descr' . $this->randomInt(),
'active' => '1',
'apply_rules' => '1',
'foreign_amount' => '1',
@@ -220,11 +220,11 @@ class CreateControllerTest extends TestCase
$tomorrow = Carbon::now()->addDays(2);
$recurrence = $this->user()->recurrences()->first();
$data = [
- 'title' => 'hello' . random_int(1, 100000),
+ 'title' => 'hello' . $this->randomInt(),
'first_date' => $tomorrow->format('Y-m-d'),
'repetition_type' => 'monthly,5',
'skip' => 0,
- 'recurring_description' => 'Some descr' . random_int(1, 100000),
+ 'recurring_description' => 'Some descr' . $this->randomInt(),
'active' => '1',
'apply_rules' => '1',
'foreign_amount' => '1',
@@ -278,11 +278,11 @@ class CreateControllerTest extends TestCase
$tomorrow = Carbon::now()->addDays(2);
$recurrence = $this->user()->recurrences()->first();
$data = [
- 'title' => 'hello' . random_int(1, 100000),
+ 'title' => 'hello' . $this->randomInt(),
'first_date' => $tomorrow->format('Y-m-d'),
'repetition_type' => 'ndom,3,5',
'skip' => 0,
- 'recurring_description' => 'Some descr' . random_int(1, 100000),
+ 'recurring_description' => 'Some descr' . $this->randomInt(),
'active' => '1',
'apply_rules' => '1',
'foreign_amount' => '1',
@@ -337,11 +337,11 @@ class CreateControllerTest extends TestCase
$tomorrow = Carbon::now()->addDays(2);
$recurrence = $this->user()->recurrences()->first();
$data = [
- 'title' => 'hello' . random_int(1, 100000),
+ 'title' => 'hello' . $this->randomInt(),
'first_date' => $tomorrow->format('Y-m-d'),
'repetition_type' => 'daily',
'skip' => 0,
- 'recurring_description' => 'Some descr' . random_int(1, 100000),
+ 'recurring_description' => 'Some descr' . $this->randomInt(),
'active' => '1',
'apply_rules' => '1',
'foreign_amount' => '1',
@@ -398,11 +398,11 @@ class CreateControllerTest extends TestCase
$tomorrow = Carbon::now()->addDays(2);
$recurrence = $this->user()->recurrences()->first();
$data = [
- 'title' => 'hello' . random_int(1, 100000),
+ 'title' => 'hello' . $this->randomInt(),
'first_date' => $tomorrow->format('Y-m-d'),
'repetition_type' => 'daily',
'skip' => 0,
- 'recurring_description' => 'Some descr' . random_int(1, 100000),
+ 'recurring_description' => 'Some descr' . $this->randomInt(),
'active' => '1',
'apply_rules' => '1',
'foreign_amount' => '1',
@@ -456,11 +456,11 @@ class CreateControllerTest extends TestCase
$tomorrow = Carbon::now()->addDays(2);
$recurrence = $this->user()->recurrences()->first();
$data = [
- 'title' => 'hello' . random_int(1, 100000),
+ 'title' => 'hello' . $this->randomInt(),
'first_date' => $tomorrow->format('Y-m-d'),
'repetition_type' => 'yearly,2018-01-01',
'skip' => 0,
- 'recurring_description' => 'Some descr' . random_int(1, 100000),
+ 'recurring_description' => 'Some descr' . $this->randomInt(),
'active' => '1',
'apply_rules' => '1',
'foreign_amount' => '1',
diff --git a/tests/Feature/Controllers/RuleGroupControllerTest.php b/tests/Feature/Controllers/RuleGroupControllerTest.php
index 84ad21dfad..89fb3a515e 100644
--- a/tests/Feature/Controllers/RuleGroupControllerTest.php
+++ b/tests/Feature/Controllers/RuleGroupControllerTest.php
@@ -143,7 +143,7 @@ class RuleGroupControllerTest extends TestCase
/** @var RuleGroup $ruleGroup */
$ruleGroup = $this->user()->ruleGroups()->first();
- $ruleGroup->description = 'Some description ' . random_int(1, 10000);
+ $ruleGroup->description = 'Some description ' . periods|length(1, 10000);
$ruleGroup->save();
$this->be($this->user());
diff --git a/tests/Feature/Controllers/TagControllerTest.php b/tests/Feature/Controllers/TagControllerTest.php
index da72e65f28..590fa046ab 100644
--- a/tests/Feature/Controllers/TagControllerTest.php
+++ b/tests/Feature/Controllers/TagControllerTest.php
@@ -316,7 +316,7 @@ class TagControllerTest extends TestCase
$this->session(['tags.create.uri' => 'http://localhost']);
$data = [
- 'tag' => 'Hello new tag' . random_int(999, 10000),
+ 'tag' => 'Hello new tag' . $this->randomInt(),
'tagMode' => 'nothing',
'tag_position_has_tag' => 'true',
@@ -342,7 +342,7 @@ class TagControllerTest extends TestCase
$this->session(['tags.edit.uri' => 'http://localhost']);
$data = [
'id' => 1,
- 'tag' => 'Hello updated tag' . random_int(999, 10000),
+ 'tag' => 'Hello updated tag' . $this->randomInt(),
'tagMode' => 'nothing',
];
diff --git a/tests/TestCase.php b/tests/TestCase.php
index 1da9b1e977..b7282a5d2c 100644
--- a/tests/TestCase.php
+++ b/tests/TestCase.php
@@ -143,6 +143,7 @@ abstract class TestCase extends BaseTestCase
$euro = $this->getEuro();
$budget = $this->getRandomBudget();
$category = $this->getRandomCategory();
+ $expense = $this->getRandomExpense();
try {
$date = new Carbon;
} catch (Exception $e) {
@@ -150,15 +151,18 @@ abstract class TestCase extends BaseTestCase
}
return [
- 'transaction_journal_id' => $withdrawal->id,
- 'currency_id' => $euro->id,
- 'foreign_currency_id' => null,
- 'date' => $date,
- 'source_account_id' => 1,
- 'destination_account_id' => 4,
- 'currency_name' => $euro->name,
- 'currency_code' => $euro->code,
- 'currency_symbol' => $euro->symbol,
+ 'transaction_journal_id' => $withdrawal->id,
+ 'transaction_type_type' => 'Withdrawal',
+ 'currency_id' => $euro->id,
+ 'foreign_currency_id' => null,
+ 'date' => $date,
+ 'source_account_id' => 1,
+ 'destination_account_id' => $expense->id,
+ 'destination_account_name' => $expense->name,
+ 'currency_name' => $euro->name,
+ 'currency_code' => $euro->code,
+ 'currency_symbol' => $euro->symbol,
+
'currency_decimal_places' => $euro->decimal_places,
'amount' => '-30',
'budget_id' => $budget->id,
diff --git a/tests/Unit/Console/Commands/Upgrade/MigrateJournalNotesTest.php b/tests/Unit/Console/Commands/Upgrade/MigrateJournalNotesTest.php
index 7e17aec891..07048bcc47 100644
--- a/tests/Unit/Console/Commands/Upgrade/MigrateJournalNotesTest.php
+++ b/tests/Unit/Console/Commands/Upgrade/MigrateJournalNotesTest.php
@@ -69,7 +69,11 @@ class MigrateJournalNotesTest extends TestCase
FireflyConfig::shouldReceive('set')->withArgs(['4780_migrate_notes', true]);
$journal = $this->getRandomWithdrawal();
- $meta = TransactionJournalMeta::create(
+
+ // delete any notes the journal may have already:
+ $journal->notes()->forceDelete();
+
+ $meta = TransactionJournalMeta::create(
[
'transaction_journal_id' => $journal->id,
'name' => 'notes',