Improve test coverage.

This commit is contained in:
James Cole
2019-06-29 08:14:28 +02:00
parent cf904eb677
commit 003d07504f
33 changed files with 447 additions and 269 deletions

View File

@@ -55,6 +55,7 @@ class BudgetController extends Controller
/** /**
* BudgetController constructor. * BudgetController constructor.
* @codeCoverageIgnore
*/ */
public function __construct() public function __construct()
{ {
@@ -297,7 +298,6 @@ class BudgetController extends Controller
/** @var GroupCollectorInterface $collector */ /** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class); $collector = app(GroupCollectorInterface::class);
$collector->setTypes([TransactionType::WITHDRAWAL])->setBudget($budget)->withAccountInformation(); $collector->setTypes([TransactionType::WITHDRAWAL])->setBudget($budget)->withAccountInformation();
if (null !== $budgetLimit) { if (null !== $budgetLimit) {
$collector->setRange($budgetLimit->start_date, $budgetLimit->end_date); $collector->setRange($budgetLimit->start_date, $budgetLimit->end_date);

View File

@@ -51,6 +51,7 @@ class BudgetReportController extends Controller
/** /**
* BudgetReportController constructor. * BudgetReportController constructor.
* @codeCoverageIgnore
*/ */
public function __construct() public function __construct()
{ {

View File

@@ -50,6 +50,7 @@ class CategoryController extends Controller
/** /**
* CategoryController constructor. * CategoryController constructor.
* @codeCoverageIgnore
*/ */
public function __construct() public function __construct()
{ {
@@ -106,6 +107,7 @@ class CategoryController extends Controller
], ],
]; ];
$step = $this->calculateStep($start, $end); $step = $this->calculateStep($start, $end);
/** @var Carbon $current */
$current = clone $start; $current = clone $start;
Log::debug(sprintf('abc Step is %s', $step)); Log::debug(sprintf('abc Step is %s', $step));
@@ -124,9 +126,12 @@ class CategoryController extends Controller
$current->addDay(); $current->addDay();
} }
break; break;
// @codeCoverageIgnoreStart
// for some reason it doesn't pick up on these case entries.
case '1W': case '1W':
case '1M': case '1M':
case '1Y': case '1Y':
// @codeCoverageIgnoreEnd
while ($current <= $end) { while ($current <= $end) {
$currentEnd = app('navigation')->endOfPeriod($current, $step); $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'))); 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); $start = app('navigation')->startOfPeriod($date, $range);
$end = session()->get('end'); $end = session()->get('end');
if ($end < $start) { if ($end < $start) {
[$end, $start] = [$start, $end]; [$end, $start] = [$start, $end]; // @codeCoverageIgnore
} }
$data = $this->makePeriodChart($category, $start, $end); $data = $this->makePeriodChart($category, $start, $end);

View File

@@ -47,6 +47,7 @@ class CategoryReportController extends Controller
/** /**
* CategoryReportController constructor. * CategoryReportController constructor.
* @codeCoverageIgnore
*/ */
public function __construct() public function __construct()
{ {
@@ -285,7 +286,7 @@ class CategoryReportController extends Controller
$newSet = []; $newSet = [];
foreach ($chartData as $key => $entry) { foreach ($chartData as $key => $entry) {
if (0 === !array_sum($entry['entries'])) { if (0 === !array_sum($entry['entries'])) {
$newSet[$key] = $chartData[$key]; $newSet[$key] = $chartData[$key]; // @codeCoverageIgnore
} }
} }
if (0 === count($newSet)) { if (0 === count($newSet)) {

View File

@@ -49,6 +49,7 @@ class ExpenseReportController extends Controller
/** /**
* ExpenseReportController constructor. * ExpenseReportController constructor.
* @codeCoverageIgnore
*/ */
public function __construct() public function __construct()
{ {
@@ -89,7 +90,7 @@ class ExpenseReportController extends Controller
$cache->addProperty($start); $cache->addProperty($start);
$cache->addProperty($end); $cache->addProperty($end);
if ($cache->has()) { if ($cache->has()) {
// return response()->json($cache->get()); // @codeCoverageIgnore return response()->json($cache->get()); // @codeCoverageIgnore
} }
$format = app('navigation')->preferredCarbonLocalizedFormat($start, $end); $format = app('navigation')->preferredCarbonLocalizedFormat($start, $end);
@@ -185,7 +186,7 @@ class ExpenseReportController extends Controller
$newSet = []; $newSet = [];
foreach ($chartData as $key => $entry) { foreach ($chartData as $key => $entry) {
if (0 === !array_sum($entry['entries'])) { if (0 === !array_sum($entry['entries'])) {
$newSet[$key] = $chartData[$key]; $newSet[$key] = $chartData[$key]; // @codeCoverageIgnore
} }
} }
if (0 === count($newSet)) { if (0 === count($newSet)) {

View File

@@ -44,6 +44,7 @@ class PiggyBankController extends Controller
/** /**
* PiggyBankController constructor. * PiggyBankController constructor.
* @codeCoverageIgnore
*/ */
public function __construct() public function __construct()
{ {

View File

@@ -46,6 +46,7 @@ class ReportController extends Controller
/** /**
* ReportController constructor. * ReportController constructor.
* @codeCoverageIgnore
*/ */
public function __construct() public function __construct()
{ {

View File

@@ -44,6 +44,7 @@ class TagReportController extends Controller
/** /**
* TagReportController constructor. * TagReportController constructor.
* @codeCoverageIgnore
*/ */
public function __construct() public function __construct()
{ {
@@ -279,7 +280,7 @@ class TagReportController extends Controller
$newSet = []; $newSet = [];
foreach ($chartData as $key => $entry) { foreach ($chartData as $key => $entry) {
if (0 === !array_sum($entry['entries'])) { if (0 === !array_sum($entry['entries'])) {
$newSet[$key] = $chartData[$key]; $newSet[$key] = $chartData[$key]; // @codeCoverageIgnore
} }
} }
if (0 === count($newSet)) { if (0 === count($newSet)) {

View File

@@ -222,7 +222,7 @@ trait AugumentData
protected function filterBudgetLimits(Collection $budgetLimits, Budget $budget, Carbon $start, Carbon $end): Collection // filter data protected function filterBudgetLimits(Collection $budgetLimits, Budget $budget, Carbon $start, Carbon $end): Collection // filter data
{ {
$set = $budgetLimits->filter( $set = $budgetLimits->filter(
function (BudgetLimit $budgetLimit) use ($budget, $start, $end) { static function (BudgetLimit $budgetLimit) use ($budget, $start, $end) {
if ($budgetLimit->budget_id === $budget->id if ($budgetLimit->budget_id === $budget->id
&& $budgetLimit->start_date->lte($start) // start of budget limit is on or before start && $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 && $budgetLimit->end_date->gte($end) // end of budget limit is on or after end

View File

@@ -55,9 +55,7 @@ trait TransactionCalculation
->withAccountInformation() ->withAccountInformation()
->setTypes([TransactionType::WITHDRAWAL]); ->setTypes([TransactionType::WITHDRAWAL]);
$result = $collector->getExtractedJournals(); return $collector->getExtractedJournals();
return $result;
} }
/** /**

View File

@@ -49,6 +49,8 @@
<directory suffix="Test.php">./tests/Feature/Controllers/Admin</directory> <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/Budget</directory>
<directory suffix="Test.php">./tests/Feature/Controllers/Category</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> </testsuite>

View File

@@ -49,6 +49,8 @@
<directory suffix="Test.php">./tests/Feature/Controllers/Admin</directory> <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/Budget</directory>
<directory suffix="Test.php">./tests/Feature/Controllers/Category</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> </testsuite>

View File

@@ -49,6 +49,8 @@
<directory suffix="Test.php">./tests/Feature/Controllers/Admin</directory> <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/Budget</directory>
<directory suffix="Test.php">./tests/Feature/Controllers/Category</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> </testsuite>
<!-- <!--

View File

@@ -23,13 +23,12 @@ declare(strict_types=1);
namespace Tests\Feature\Controllers\Chart; namespace Tests\Feature\Controllers\Chart;
use Carbon\Carbon; use Carbon\Carbon;
use Exception;
use FireflyIII\Generator\Chart\Basic\GeneratorInterface; use FireflyIII\Generator\Chart\Basic\GeneratorInterface;
use FireflyIII\Helpers\Collector\TransactionCollectorInterface; use FireflyIII\Helpers\Collector\GroupCollectorInterface;
use FireflyIII\Helpers\Fiscal\FiscalHelperInterface; use FireflyIII\Helpers\Fiscal\FiscalHelperInterface;
use FireflyIII\Models\Account;
use FireflyIII\Models\Budget; use FireflyIII\Models\Budget;
use FireflyIII\Models\BudgetLimit; use FireflyIII\Models\BudgetLimit;
use FireflyIII\Models\Category;
use FireflyIII\Models\Transaction; use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionType; use FireflyIII\Models\TransactionType;
use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Repositories\Account\AccountRepositoryInterface;
@@ -37,6 +36,7 @@ use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use FireflyIII\Repositories\Category\CategoryRepositoryInterface; use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Log; use Log;
use Preferences;
use Tests\TestCase; use Tests\TestCase;
/** /**
@@ -63,8 +63,17 @@ class BudgetControllerTest extends TestCase
{ {
$repository = $this->mock(BudgetRepositoryInterface::class); $repository = $this->mock(BudgetRepositoryInterface::class);
$generator = $this->mock(GeneratorInterface::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'); $repository->shouldReceive('spentInPeriod')->andReturn('-100');
$generator->shouldReceive('singleSet')->andReturn([])->once(); $generator->shouldReceive('singleSet')->andReturn([])->once();
@@ -85,6 +94,10 @@ class BudgetControllerTest extends TestCase
$repository = $this->mock(BudgetRepositoryInterface::class); $repository = $this->mock(BudgetRepositoryInterface::class);
$generator = $this->mock(GeneratorInterface::class); $generator = $this->mock(GeneratorInterface::class);
// mock default session
$this->mockDefaultSession();
Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
$repository->shouldReceive('spentInPeriod')->andReturn('-100'); $repository->shouldReceive('spentInPeriod')->andReturn('-100');
$generator->shouldReceive('singleSet')->once()->andReturn([]); $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 public function testBudgetLimitWrongLimit(): void
{ {
$repository = $this->mock(BudgetRepositoryInterface::class); $this->mock(BudgetRepositoryInterface::class);
$generator = $this->mock(GeneratorInterface::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()); $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); $response->assertStatus(500);
} }
@@ -115,20 +133,21 @@ class BudgetControllerTest extends TestCase
*/ */
public function testExpenseAsset(string $range): void 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; // mock default session
$budgetRepository = $this->mock(BudgetRepositoryInterface::class); $this->mockDefaultSession();
$generator = $this->mock(GeneratorInterface::class); Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
$collector = $this->mock(TransactionCollectorInterface::class);
$transactions = factory(Transaction::class, 10)->make();
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$accountRepos->shouldReceive('getAccountsByType')->andReturn(new Collection); $accountRepos->shouldReceive('getAccountsByType')->andReturn(new Collection([$destination]))->atLeast()->once();
$collector->shouldReceive('setAllAssetAccounts')->once()->andReturnSelf(); $collector->shouldReceive('setBudget')->andReturnSelf()->atLeast()->once();
$collector->shouldReceive('setBudget')->andReturnSelf(); $collector->shouldReceive('setRange')->andReturnSelf()->atLeast()->once();
$collector->shouldReceive('setRange')->andReturnSelf(); $collector->shouldReceive('getExtractedJournals')->andReturn([$withdrawal])->atLeast()->once();
$collector->shouldReceive('getTransactions')->andReturn($transactions);
$generator->shouldReceive('pieChart')->once()->andReturn([]); $generator->shouldReceive('pieChart')->once()->andReturn([]);
@@ -146,25 +165,23 @@ class BudgetControllerTest extends TestCase
*/ */
public function testExpenseCategory(string $range): void public function testExpenseCategory(string $range): void
{ {
$this->markTestIncomplete('Needs to be rewritten for v4.8.0'); $this->mock(BudgetRepositoryInterface::class);
return;
$generator = $this->mock(GeneratorInterface::class); $generator = $this->mock(GeneratorInterface::class);
$collector = $this->mock(TransactionCollectorInterface::class); $collector = $this->mock(GroupCollectorInterface::class);
$catRepos = $this->mock(CategoryRepositoryInterface::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(); $collector->shouldReceive('setBudget')->andReturnSelf()->atLeast()->once();
$categories = factory(Category::class, 10)->make(); $collector->shouldReceive('setRange')->andReturnSelf()->atLeast()->once();
$collector->shouldReceive('withCategoryInformation')->andReturnSelf()->atLeast()->once();
$collector->shouldReceive('getExtractedJournals')->andReturn([$withdrawal])->atLeast()->once();
$collector->shouldReceive('setAllAssetAccounts')->once()->andReturnSelf(); $catRepos->shouldReceive('getCategories')->andReturn(new Collection([$category]))->once();
$collector->shouldReceive('setBudget')->andReturnSelf();
$collector->shouldReceive('setRange')->andReturnSelf();
$collector->shouldReceive('withCategoryInformation')->andReturnSelf();
$collector->shouldReceive('getTransactions')->andReturn($transactions);
$catRepos->shouldReceive('getCategories')->andReturn($categories)->once();
$generator->shouldReceive('pieChart')->once()->andReturn([]); $generator->shouldReceive('pieChart')->once()->andReturn([]);
@@ -182,25 +199,25 @@ class BudgetControllerTest extends TestCase
*/ */
public function testExpenseExpense(string $range): void public function testExpenseExpense(string $range): void
{ {
$this->markTestIncomplete('Needs to be rewritten for v4.8.0'); $this->mock(BudgetRepositoryInterface::class);
return;
$generator = $this->mock(GeneratorInterface::class); $generator = $this->mock(GeneratorInterface::class);
$collector = $this->mock(TransactionCollectorInterface::class); $collector = $this->mock(GroupCollectorInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class); $accountRepos = $this->mock(AccountRepositoryInterface::class);
$repository = $this->mock(BudgetRepositoryInterface::class); $withdrawal = $this->getRandomWithdrawalAsArray();
$destination = $this->user()->accounts()->find($withdrawal['destination_account_id']);
$transactions = factory(Transaction::class, 10)->make(); // mock default session
$accounts = factory(Account::class, 10)->make(); $this->mockDefaultSession();
Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
$collector->shouldReceive('setAllAssetAccounts')->once()->andReturnSelf();
$collector->shouldReceive('withAccountInformation')->once()->andReturnSelf();
$collector->shouldReceive('setTypes')->withArgs([[TransactionType::WITHDRAWAL]])->once()->andReturnSelf(); $collector->shouldReceive('setTypes')->withArgs([[TransactionType::WITHDRAWAL]])->once()->andReturnSelf();
$collector->shouldReceive('setBudget')->andReturnSelf(); $collector->shouldReceive('setBudget')->andReturnSelf()->atLeast()->once();
$collector->shouldReceive('setRange')->andReturnSelf(); $collector->shouldReceive('setRange')->andReturnSelf()->atLeast()->once();
$collector->shouldReceive('withOpposingAccount')->andReturnSelf(); $collector->shouldReceive('getExtractedJournals')->andReturn([$withdrawal])->atLeast()->once();
$collector->shouldReceive('getTransactions')->andReturn($transactions);
$accountRepos->shouldReceive('getAccountsByType')->andReturn($accounts)->once(); $accountRepos->shouldReceive('getAccountsByType')->andReturn(new Collection([$destination]))->once();
$generator->shouldReceive('pieChart')->once()->andReturn([]); $generator->shouldReceive('pieChart')->once()->andReturn([]);
@@ -216,28 +233,27 @@ class BudgetControllerTest extends TestCase
* *
* @param string $range * @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('getActiveBudgets')->andReturn(new Collection([$budget]))->once();
$repository->shouldReceive('getBudgetLimits')->once()->andReturn(new Collection([$budgetLimit])); $repository->shouldReceive('getBudgetLimits')->once()->andReturn(new Collection([$budgetLimit]));
$repository->shouldReceive('spentInPeriod')->andReturn('-100'); $repository->shouldReceive('spentInPeriod')->andReturn('-100');
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf()->once();
$collector->shouldReceive('setTypes')->withArgs([[TransactionType::WITHDRAWAL]])->andReturnSelf()->once(); $collector->shouldReceive('setTypes')->withArgs([[TransactionType::WITHDRAWAL]])->andReturnSelf()->once();
$collector->shouldReceive('setRange')->andReturnSelf()->once(); $collector->shouldReceive('setRange')->andReturnSelf()->once();
$collector->shouldReceive('withoutBudget')->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([]); $generator->shouldReceive('multiSet')->once()->andReturn([]);
@@ -255,28 +271,26 @@ class BudgetControllerTest extends TestCase
*/ */
public function testFrontpageMultiLimit(string $range): void public function testFrontpageMultiLimit(string $range): void
{ {
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return; $repository = $this->mock(BudgetRepositoryInterface::class);
$repository = $this->mock(BudgetRepositoryInterface::class); $generator = $this->mock(GeneratorInterface::class);
$generator = $this->mock(GeneratorInterface::class); $collector = $this->mock(GroupCollectorInterface::class);
$collector = $this->mock(TransactionCollectorInterface::class); $budget = $this->getRandomBudget();
$budget = factory(Budget::class)->make(); $limit1 = $this->getRandomBudgetLimit();
$one = factory(BudgetLimit::class)->make(); $limit2 = $this->getRandomBudgetLimit();
$two = factory(BudgetLimit::class)->make();
$one->budget_id = $budget->id; // mock default session
$two->budget_id = $budget->id; $this->mockDefaultSession();
$transaction = factory(Transaction::class)->make(); Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
$repository->shouldReceive('getActiveBudgets')->andReturn(new Collection([$budget]))->once(); $repository->shouldReceive('getActiveBudgets')->andReturn(new Collection([$budget]))->once();
$repository->shouldReceive('getBudgetLimits')->once()->andReturn(new Collection([$one, $two])); $repository->shouldReceive('getBudgetLimits')->once()->andReturn(new Collection([$limit1, $limit2]));
$repository->shouldReceive('spentInPeriod')->andReturn('-100'); $repository->shouldReceive('spentInPeriod')->andReturn('-100')->atLeast()->once();
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf()->once();
$collector->shouldReceive('setTypes')->withArgs([[TransactionType::WITHDRAWAL]])->andReturnSelf()->once(); $collector->shouldReceive('setTypes')->withArgs([[TransactionType::WITHDRAWAL]])->andReturnSelf()->once();
$collector->shouldReceive('setRange')->andReturnSelf()->once(); $collector->shouldReceive('setRange')->andReturnSelf()->once();
$collector->shouldReceive('withoutBudget')->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([]); $generator->shouldReceive('multiSet')->once()->andReturn([]);
@@ -294,24 +308,25 @@ class BudgetControllerTest extends TestCase
*/ */
public function testFrontpageNoLimits(string $range): void public function testFrontpageNoLimits(string $range): void
{ {
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
$repository = $this->mock(BudgetRepositoryInterface::class); $repository = $this->mock(BudgetRepositoryInterface::class);
$generator = $this->mock(GeneratorInterface::class); $generator = $this->mock(GeneratorInterface::class);
$collector = $this->mock(TransactionCollectorInterface::class); $collector = $this->mock(GroupCollectorInterface::class);
$budget = factory(Budget::class)->make(); $budget = $this->getRandomBudget();
$transaction = factory(Transaction::class)->make();
// mock default session
$this->mockDefaultSession();
Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
$repository->shouldReceive('getActiveBudgets')->andReturn(new Collection([$budget])); $repository->shouldReceive('getActiveBudgets')->andReturn(new Collection([$budget]));
$repository->shouldReceive('getBudgetLimits')->once()->andReturn(new Collection); $repository->shouldReceive('getBudgetLimits')->once()->andReturn(new Collection);
$repository->shouldReceive('spentInPeriod')->andReturn('-100'); $repository->shouldReceive('spentInPeriod')->andReturn('-100');
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf()->once();
$collector->shouldReceive('setTypes')->withArgs([[TransactionType::WITHDRAWAL]])->andReturnSelf()->once(); $collector->shouldReceive('setTypes')->withArgs([[TransactionType::WITHDRAWAL]])->andReturnSelf()->once();
$collector->shouldReceive('setRange')->andReturnSelf()->once(); $collector->shouldReceive('setRange')->andReturnSelf()->once();
$collector->shouldReceive('withoutBudget')->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([]); $generator->shouldReceive('multiSet')->once()->andReturn([]);
@@ -328,11 +343,15 @@ class BudgetControllerTest extends TestCase
{ {
$repository = $this->mock(BudgetRepositoryInterface::class); $repository = $this->mock(BudgetRepositoryInterface::class);
$generator = $this->mock(GeneratorInterface::class); $generator = $this->mock(GeneratorInterface::class);
$budget = factory(Budget::class)->make(); $budgetLimit = $this->getRandomBudgetLimit();
$budgetLimit = factory(BudgetLimit::class)->make();
$budgetLimit->budget_id = $budget->id;
$fiscalHelper = $this->mock(FiscalHelperInterface::class); $fiscalHelper = $this->mock(FiscalHelperInterface::class);
$date = new Carbon; $date = new Carbon;
// mock default session
$this->mockDefaultSession();
Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date); $fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date); $fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
@@ -341,7 +360,7 @@ class BudgetControllerTest extends TestCase
$generator->shouldReceive('multiSet')->once()->andReturn([]); $generator->shouldReceive('multiSet')->once()->andReturn([]);
$this->be($this->user()); $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); $response->assertStatus(200);
} }
@@ -354,6 +373,11 @@ class BudgetControllerTest extends TestCase
$generator = $this->mock(GeneratorInterface::class); $generator = $this->mock(GeneratorInterface::class);
$fiscalHelper = $this->mock(FiscalHelperInterface::class); $fiscalHelper = $this->mock(FiscalHelperInterface::class);
$date = new Carbon; $date = new Carbon;
// mock default session
$this->mockDefaultSession();
Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date); $fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date); $fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);

View File

@@ -25,17 +25,18 @@ namespace Tests\Feature\Controllers\Chart;
use Carbon\Carbon; use Carbon\Carbon;
use FireflyIII\Generator\Chart\Basic\GeneratorInterface; use FireflyIII\Generator\Chart\Basic\GeneratorInterface;
use FireflyIII\Helpers\Chart\MetaPieChartInterface; use FireflyIII\Helpers\Chart\MetaPieChartInterface;
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
use FireflyIII\Helpers\Collector\TransactionCollectorInterface; use FireflyIII\Helpers\Collector\TransactionCollectorInterface;
use FireflyIII\Helpers\Filter\OpposingAccountFilter; use FireflyIII\Helpers\Filter\OpposingAccountFilter;
use FireflyIII\Helpers\Filter\PositiveAmountFilter; use FireflyIII\Helpers\Filter\PositiveAmountFilter;
use FireflyIII\Helpers\Filter\TransferFilter; use FireflyIII\Helpers\Filter\TransferFilter;
use FireflyIII\Helpers\Fiscal\FiscalHelperInterface; use FireflyIII\Helpers\Fiscal\FiscalHelperInterface;
use FireflyIII\Models\BudgetLimit; use FireflyIII\Models\BudgetLimit;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionType; use FireflyIII\Models\TransactionType;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface; use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Log; use Log;
use Preferences;
use Tests\TestCase; use Tests\TestCase;
/** /**
@@ -65,6 +66,9 @@ class BudgetReportControllerTest extends TestCase
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date); $fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date); $fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
// mock default session
$this->mockDefaultSession();
$pieChart->shouldReceive('setAccounts')->once()->andReturnSelf(); $pieChart->shouldReceive('setAccounts')->once()->andReturnSelf();
$pieChart->shouldReceive('setBudgets')->once()->andReturnSelf(); $pieChart->shouldReceive('setBudgets')->once()->andReturnSelf();
$pieChart->shouldReceive('setStart')->once()->andReturnSelf(); $pieChart->shouldReceive('setStart')->once()->andReturnSelf();
@@ -91,6 +95,10 @@ class BudgetReportControllerTest extends TestCase
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date); $fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
$fiscalHelper->shouldReceive('startOfFiscalYear')->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('setAccounts')->once()->andReturnSelf();
$pieChart->shouldReceive('setBudgets')->once()->andReturnSelf(); $pieChart->shouldReceive('setBudgets')->once()->andReturnSelf();
$pieChart->shouldReceive('setStart')->once()->andReturnSelf(); $pieChart->shouldReceive('setStart')->once()->andReturnSelf();
@@ -109,45 +117,41 @@ class BudgetReportControllerTest extends TestCase
*/ */
public function testMainChart(): void public function testMainChart(): void
{ {
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
$generator = $this->mock(GeneratorInterface::class); $generator = $this->mock(GeneratorInterface::class);
$collector = $this->mock(TransactionCollectorInterface::class); $collector = $this->mock(GroupCollectorInterface::class);
$budgetRepos = $this->mock(BudgetRepositoryInterface::class); $budgetRepos = $this->mock(BudgetRepositoryInterface::class);
$fiscalHelper = $this->mock(FiscalHelperInterface::class); $fiscalHelper = $this->mock(FiscalHelperInterface::class);
$date = new Carbon; $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('endOfFiscalYear')->atLeast()->once()->andReturn($date);
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date); $fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
$this->mockDefaultSession();
Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
$one = factory(BudgetLimit::class)->make(); $budgetRepos->shouldReceive('getAllBudgetLimits')->andReturn(new Collection([$limit1, $limit2, $limit3]))->once();
$one->budget_id = 1; $collector->shouldReceive('setAccounts')->andReturnSelf()->atLeast()->once();
$two = factory(BudgetLimit::class)->make(); $collector->shouldReceive('setRange')->andReturnSelf()->atLeast()->once();
$two->budget_id = 1; $collector->shouldReceive('withAccountInformation')->andReturnSelf()->atLeast()->once();
$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('setTypes')->withArgs([[TransactionType::WITHDRAWAL, TransactionType::TRANSFER]])->andReturnSelf()->atLeast()->once();
$collector->shouldReceive('setBudgets')->andReturnSelf()->atLeast()->once();
$collector->shouldReceive('setAccounts')->andReturnSelf(); $collector->shouldReceive('getExtractedJournals')->andReturn([$withdrawal])->atLeast()->once();
$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]));
$generator->shouldReceive('multiSet')->andReturn([])->once(); $generator->shouldReceive('multiSet')->andReturn([])->once();
$this->be($this->user()); $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); $response->assertStatus(200);
} }
} }

View File

@@ -23,9 +23,9 @@ declare(strict_types=1);
namespace Tests\Feature\Controllers\Chart; namespace Tests\Feature\Controllers\Chart;
use Carbon\Carbon; use Carbon\Carbon;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Generator\Chart\Basic\GeneratorInterface; use FireflyIII\Generator\Chart\Basic\GeneratorInterface;
use FireflyIII\Helpers\Fiscal\FiscalHelperInterface; use FireflyIII\Helpers\Fiscal\FiscalHelperInterface;
use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType; use FireflyIII\Models\AccountType;
use FireflyIII\Models\TransactionCurrency; use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Repositories\Account\AccountRepositoryInterface;
@@ -33,6 +33,7 @@ use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface; use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Log; use Log;
use Preferences;
use Tests\TestCase; use Tests\TestCase;
/** /**
@@ -61,13 +62,39 @@ class CategoryControllerTest extends TestCase
$repository = $this->mock(CategoryRepositoryInterface::class); $repository = $this->mock(CategoryRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class); $accountRepos = $this->mock(AccountRepositoryInterface::class);
$generator = $this->mock(GeneratorInterface::class); $generator = $this->mock(GeneratorInterface::class);
$firstUse = new Carbon; $firstUseDate = null;
$firstUse->subDays(3); 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'); $repository->shouldReceive('spentInPeriod')->andReturn('0')->atLeast()->once();
$repository->shouldReceive('earnedInPeriod')->andReturn('0'); $repository->shouldReceive('earnedInPeriod')->andReturn('0')->atLeast()->once();
$repository->shouldReceive('firstUseDate')->andReturn($firstUse)->once(); $repository->shouldReceive('firstUseDate')->andReturn($firstUseDate)->once();
$accountRepos->shouldReceive('getAccountsByType')->withArgs([[AccountType::DEFAULT, AccountType::ASSET]])->andReturn(new Collection)->once(); $accountRepos->shouldReceive('getAccountsByType')->withArgs([[AccountType::DEFAULT, AccountType::ASSET]])->andReturn(new Collection)->once();
$generator->shouldReceive('multiSet')->once()->andReturn([]); $generator->shouldReceive('multiSet')->once()->andReturn([]);
@@ -90,6 +117,9 @@ class CategoryControllerTest extends TestCase
$generator = $this->mock(GeneratorInterface::class); $generator = $this->mock(GeneratorInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class); $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$this->mockDefaultSession();
Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
// spent per currency data: // spent per currency data:
$spentNoCategory = [ $spentNoCategory = [
1 => 1 =>
@@ -147,6 +177,10 @@ class CategoryControllerTest extends TestCase
$generator = $this->mock(GeneratorInterface::class); $generator = $this->mock(GeneratorInterface::class);
$fiscalHelper = $this->mock(FiscalHelperInterface::class); $fiscalHelper = $this->mock(FiscalHelperInterface::class);
$date = new Carbon; $date = new Carbon;
$this->mockDefaultSession();
Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date); $fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date); $fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
$repository->shouldReceive('periodExpenses')->andReturn([])->once(); $repository->shouldReceive('periodExpenses')->andReturn([])->once();
@@ -167,6 +201,10 @@ class CategoryControllerTest extends TestCase
$generator = $this->mock(GeneratorInterface::class); $generator = $this->mock(GeneratorInterface::class);
$fiscalHelper = $this->mock(FiscalHelperInterface::class); $fiscalHelper = $this->mock(FiscalHelperInterface::class);
$date = new Carbon; $date = new Carbon;
$this->mockDefaultSession();
Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date); $fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date); $fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
$repository->shouldReceive('periodExpensesNoCategory')->andReturn([])->once(); $repository->shouldReceive('periodExpensesNoCategory')->andReturn([])->once();
@@ -189,9 +227,13 @@ class CategoryControllerTest extends TestCase
$repository = $this->mock(CategoryRepositoryInterface::class); $repository = $this->mock(CategoryRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class); $accountRepos = $this->mock(AccountRepositoryInterface::class);
$generator = $this->mock(GeneratorInterface::class); $generator = $this->mock(GeneratorInterface::class);
$account = factory(Account::class)->make(); $account = $this->getRandomAsset();
$fiscalHelper = $this->mock(FiscalHelperInterface::class); $fiscalHelper = $this->mock(FiscalHelperInterface::class);
$date = new Carbon; $date = new Carbon;
$this->mockDefaultSession();
Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date); $fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date); $fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);

View File

@@ -25,6 +25,7 @@ namespace Tests\Feature\Controllers\Chart;
use Carbon\Carbon; use Carbon\Carbon;
use FireflyIII\Generator\Chart\Basic\GeneratorInterface; use FireflyIII\Generator\Chart\Basic\GeneratorInterface;
use FireflyIII\Helpers\Chart\MetaPieChartInterface; use FireflyIII\Helpers\Chart\MetaPieChartInterface;
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
use FireflyIII\Helpers\Collector\TransactionCollectorInterface; use FireflyIII\Helpers\Collector\TransactionCollectorInterface;
use FireflyIII\Helpers\Filter\NegativeAmountFilter; use FireflyIII\Helpers\Filter\NegativeAmountFilter;
use FireflyIII\Helpers\Filter\OpposingAccountFilter; use FireflyIII\Helpers\Filter\OpposingAccountFilter;
@@ -34,6 +35,7 @@ use FireflyIII\Helpers\Fiscal\FiscalHelperInterface;
use FireflyIII\Models\Transaction; use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionType; use FireflyIII\Models\TransactionType;
use Log; use Log;
use Preferences;
use Tests\TestCase; use Tests\TestCase;
/** /**
@@ -59,6 +61,10 @@ class CategoryReportControllerTest extends TestCase
$pieChart = $this->mock(MetaPieChartInterface::class); $pieChart = $this->mock(MetaPieChartInterface::class);
$fiscalHelper = $this->mock(FiscalHelperInterface::class); $fiscalHelper = $this->mock(FiscalHelperInterface::class);
$date = new Carbon; $date = new Carbon;
$this->mockDefaultSession();
//Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date); $fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date); $fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
$pieChart->shouldReceive('setAccounts')->once()->andReturnSelf(); $pieChart->shouldReceive('setAccounts')->once()->andReturnSelf();
@@ -83,6 +89,10 @@ class CategoryReportControllerTest extends TestCase
$pieChart = $this->mock(MetaPieChartInterface::class); $pieChart = $this->mock(MetaPieChartInterface::class);
$fiscalHelper = $this->mock(FiscalHelperInterface::class); $fiscalHelper = $this->mock(FiscalHelperInterface::class);
$date = new Carbon; $date = new Carbon;
$this->mockDefaultSession();
//Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date); $fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date); $fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
$pieChart->shouldReceive('setAccounts')->once()->andReturnSelf(); $pieChart->shouldReceive('setAccounts')->once()->andReturnSelf();
@@ -107,6 +117,10 @@ class CategoryReportControllerTest extends TestCase
$pieChart = $this->mock(MetaPieChartInterface::class); $pieChart = $this->mock(MetaPieChartInterface::class);
$fiscalHelper = $this->mock(FiscalHelperInterface::class); $fiscalHelper = $this->mock(FiscalHelperInterface::class);
$date = new Carbon; $date = new Carbon;
$this->mockDefaultSession();
//Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date); $fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date); $fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
$pieChart->shouldReceive('setAccounts')->once()->andReturnSelf(); $pieChart->shouldReceive('setAccounts')->once()->andReturnSelf();
@@ -131,6 +145,10 @@ class CategoryReportControllerTest extends TestCase
$pieChart = $this->mock(MetaPieChartInterface::class); $pieChart = $this->mock(MetaPieChartInterface::class);
$fiscalHelper = $this->mock(FiscalHelperInterface::class); $fiscalHelper = $this->mock(FiscalHelperInterface::class);
$date = new Carbon; $date = new Carbon;
$this->mockDefaultSession();
//Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date); $fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date); $fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
$pieChart->shouldReceive('setAccounts')->once()->andReturnSelf(); $pieChart->shouldReceive('setAccounts')->once()->andReturnSelf();
@@ -151,27 +169,25 @@ class CategoryReportControllerTest extends TestCase
*/ */
public function testMainChart(): void public function testMainChart(): void
{ {
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
$generator = $this->mock(GeneratorInterface::class); $generator = $this->mock(GeneratorInterface::class);
$collector = $this->mock(TransactionCollectorInterface::class); $collector = $this->mock(GroupCollectorInterface::class);
$transactions = factory(Transaction::class, 10)->make();
$fiscalHelper = $this->mock(FiscalHelperInterface::class); $fiscalHelper = $this->mock(FiscalHelperInterface::class);
$date = new Carbon; $date = new Carbon;
$withdrawal = $this->getRandomWithdrawalAsArray();
$this->mockDefaultSession();
Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date); $fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date); $fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
$collector->shouldReceive('setAccounts')->andReturnSelf(); $collector->shouldReceive('setAccounts')->andReturnSelf()->atLeast()->once();
$collector->shouldReceive('setRange')->andReturnSelf(); $collector->shouldReceive('withAccountInformation')->andReturnSelf()->atLeast()->once();
$collector->shouldReceive('setTypes')->withArgs([[TransactionType::WITHDRAWAL, TransactionType::TRANSFER]])->andReturnSelf();
$collector->shouldReceive('setTypes')->withArgs([[TransactionType::DEPOSIT, TransactionType::TRANSFER]])->andReturnSelf(); $collector->shouldReceive('setRange')->andReturnSelf()->atLeast()->once();
$collector->shouldReceive('removeFilter')->withArgs([TransferFilter::class])->andReturnSelf(); $collector->shouldReceive('setTypes')->withArgs([[TransactionType::WITHDRAWAL, TransactionType::TRANSFER]])->andReturnSelf()->atLeast()->once();
$collector->shouldReceive('addFilter')->withArgs([OpposingAccountFilter::class])->andReturnSelf(); $collector->shouldReceive('setTypes')->withArgs([[TransactionType::DEPOSIT, TransactionType::TRANSFER]])->andReturnSelf()->atLeast()->once();
$collector->shouldReceive('addFilter')->withArgs([PositiveAmountFilter::class])->andReturnSelf(); $collector->shouldReceive('setCategories')->andReturnSelf()->atLeast()->once();
$collector->shouldReceive('addFilter')->withArgs([NegativeAmountFilter::class])->andReturnSelf(); $collector->shouldReceive('getExtractedJournals')->andReturn([$withdrawal])->atLeast()->once();
$collector->shouldReceive('setCategories')->andReturnSelf();
$collector->shouldReceive('withOpposingAccount')->andReturnSelf();
$collector->shouldReceive('getTransactions')->andReturn($transactions);
$generator->shouldReceive('multiSet')->andReturn([])->once(); $generator->shouldReceive('multiSet')->andReturn([])->once();
$this->be($this->user()); $this->be($this->user());

View File

@@ -24,13 +24,13 @@ namespace Tests\Feature\Controllers\Chart;
use Carbon\Carbon; use Carbon\Carbon;
use FireflyIII\Generator\Chart\Basic\GeneratorInterface; use FireflyIII\Generator\Chart\Basic\GeneratorInterface;
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
use FireflyIII\Helpers\Collector\TransactionCollectorInterface; use FireflyIII\Helpers\Collector\TransactionCollectorInterface;
use FireflyIII\Helpers\Fiscal\FiscalHelperInterface; use FireflyIII\Helpers\Fiscal\FiscalHelperInterface;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionType; use FireflyIII\Models\TransactionType;
use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use Illuminate\Support\Collection;
use Log; use Log;
use Preferences;
use Tests\TestCase; use Tests\TestCase;
/** /**
@@ -53,31 +53,28 @@ class ExpenseReportControllerTest extends TestCase
*/ */
public function testMainChart(): void 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); $generator = $this->mock(GeneratorInterface::class);
$collector = $this->mock(TransactionCollectorInterface::class); $collector = $this->mock(GroupCollectorInterface::class);
$accountRepository = $this->mock(AccountRepositoryInterface::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); $accountRepository->shouldReceive('findByName')->once()->andReturn($expense);
$fiscalHelper = $this->mock(FiscalHelperInterface::class); $this->mockDefaultSession();
$date = new Carbon; Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date); $fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date); $fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
$set = new Collection; $collector->shouldReceive('setAccounts')->andReturnSelf()->atLeast()->once();
$transaction = new Transaction(); $collector->shouldReceive('setRange')->andReturnSelf()->atLeast()->once();
$transaction->opposing_account_name = 'Somebody'; $collector->shouldReceive('withAccountInformation')->andReturnSelf()->atLeast()->once();
$transaction->transaction_amount = '5'; $collector->shouldReceive('setTypes')->withArgs([[TransactionType::WITHDRAWAL]])->andReturnSelf()->atLeast()->once();
$set->push($transaction); $collector->shouldReceive('setTypes')->withArgs([[TransactionType::DEPOSIT]])->andReturnSelf()->atLeast()->once();
$collector->shouldReceive('setAccounts')->andReturnSelf(); $collector->shouldReceive('getExtractedJournals')->andReturn([$withdrawal])->atLeast()->once();
$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);
$generator->shouldReceive('multiSet')->andReturn([])->once(); $generator->shouldReceive('multiSet')->andReturn([])->once();
$this->be($this->user()); $this->be($this->user());

View File

@@ -27,6 +27,7 @@ use FireflyIII\Models\PiggyBankEvent;
use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface; use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Log; use Log;
use Preferences;
use Tests\TestCase; use Tests\TestCase;
/** /**
@@ -50,13 +51,18 @@ class PiggyBankControllerTest extends TestCase
{ {
$generator = $this->mock(GeneratorInterface::class); $generator = $this->mock(GeneratorInterface::class);
$repository = $this->mock(PiggyBankRepositoryInterface::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])); $repository->shouldReceive('getEvents')->andReturn(new Collection([$event]));
$generator->shouldReceive('singleSet')->once()->andReturn([]); $generator->shouldReceive('singleSet')->once()->andReturn([]);
$this->be($this->user()); $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); $response->assertStatus(200);
} }
} }

View File

@@ -32,6 +32,7 @@ use FireflyIII\Repositories\Account\AccountTaskerInterface;
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface; use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
use Log; use Log;
use Mockery; use Mockery;
use Preferences;
use Steam; use Steam;
use Tests\TestCase; use Tests\TestCase;
@@ -62,8 +63,10 @@ class ReportControllerTest extends TestCase
$date = new Carbon; $date = new Carbon;
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date); $fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
$fiscalHelper->shouldReceive('startOfFiscalYear')->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( $netWorth->shouldReceive('getNetWorthByCurrency')->andReturn(
[ [
@@ -104,6 +107,10 @@ class ReportControllerTest extends TestCase
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class); $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$fiscalHelper = $this->mock(FiscalHelperInterface::class); $fiscalHelper = $this->mock(FiscalHelperInterface::class);
$date = new Carbon; $date = new Carbon;
$this->mockDefaultSession();
Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date); $fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date); $fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
$income = [1 => ['sum' => '100']]; $income = [1 => ['sum' => '100']];
@@ -127,6 +134,10 @@ class ReportControllerTest extends TestCase
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class); $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$fiscalHelper = $this->mock(FiscalHelperInterface::class); $fiscalHelper = $this->mock(FiscalHelperInterface::class);
$date = new Carbon; $date = new Carbon;
$this->mockDefaultSession();
Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date); $fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date); $fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);

View File

@@ -25,20 +25,16 @@ namespace Tests\Feature\Controllers\Chart;
use Carbon\Carbon; use Carbon\Carbon;
use FireflyIII\Generator\Chart\Basic\GeneratorInterface; use FireflyIII\Generator\Chart\Basic\GeneratorInterface;
use FireflyIII\Helpers\Chart\MetaPieChartInterface; use FireflyIII\Helpers\Chart\MetaPieChartInterface;
use FireflyIII\Helpers\Collector\TransactionCollectorInterface; use FireflyIII\Helpers\Collector\GroupCollectorInterface;
use FireflyIII\Helpers\Filter\NegativeAmountFilter;
use FireflyIII\Helpers\Filter\OpposingAccountFilter;
use FireflyIII\Helpers\Filter\PositiveAmountFilter;
use FireflyIII\Helpers\Filter\TransferFilter;
use FireflyIII\Helpers\Fiscal\FiscalHelperInterface; use FireflyIII\Helpers\Fiscal\FiscalHelperInterface;
use FireflyIII\Models\Tag; use FireflyIII\Models\Preference;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionType;
use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Tag\TagRepositoryInterface; use FireflyIII\Repositories\Tag\TagRepositoryInterface;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Log; use Log;
use Preferences;
use Tests\TestCase; use Tests\TestCase;
use FireflyIII\Models\TransactionType;
/** /**
* Class TagReportControllerTest * Class TagReportControllerTest
@@ -64,6 +60,9 @@ class TagReportControllerTest extends TestCase
$tagRepos = $this->mock(TagRepositoryInterface::class); $tagRepos = $this->mock(TagRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class); $accountRepos = $this->mock(AccountRepositoryInterface::class);
$tag = $this->user()->tags()->first(); $tag = $this->user()->tags()->first();
$this->mockDefaultSession();
$tagRepos->shouldReceive('setUser'); $tagRepos->shouldReceive('setUser');
$tagRepos->shouldReceive('get')->andReturn(new Collection([$tag])); $tagRepos->shouldReceive('get')->andReturn(new Collection([$tag]));
@@ -100,6 +99,8 @@ class TagReportControllerTest extends TestCase
$tagRepos->shouldReceive('setUser'); $tagRepos->shouldReceive('setUser');
$tagRepos->shouldReceive('get')->andReturn(new Collection([$tag])); $tagRepos->shouldReceive('get')->andReturn(new Collection([$tag]));
$this->mockDefaultSession();
$fiscalHelper = $this->mock(FiscalHelperInterface::class); $fiscalHelper = $this->mock(FiscalHelperInterface::class);
$date = new Carbon; $date = new Carbon;
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date); $fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
@@ -132,6 +133,8 @@ class TagReportControllerTest extends TestCase
$tagRepos->shouldReceive('setUser'); $tagRepos->shouldReceive('setUser');
$tagRepos->shouldReceive('get')->andReturn(new Collection([$tag])); $tagRepos->shouldReceive('get')->andReturn(new Collection([$tag]));
$this->mockDefaultSession();
$fiscalHelper = $this->mock(FiscalHelperInterface::class); $fiscalHelper = $this->mock(FiscalHelperInterface::class);
$date = new Carbon; $date = new Carbon;
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date); $fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
@@ -163,6 +166,8 @@ class TagReportControllerTest extends TestCase
$tagRepos->shouldReceive('setUser'); $tagRepos->shouldReceive('setUser');
$tagRepos->shouldReceive('get')->andReturn(new Collection([$tag])); $tagRepos->shouldReceive('get')->andReturn(new Collection([$tag]));
$this->mockDefaultSession();
$fiscalHelper = $this->mock(FiscalHelperInterface::class); $fiscalHelper = $this->mock(FiscalHelperInterface::class);
$date = new Carbon; $date = new Carbon;
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date); $fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
@@ -186,42 +191,35 @@ class TagReportControllerTest extends TestCase
*/ */
public function testMainChart(): void 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; $withdrawal = $this->getRandomWithdrawalAsArray();
$generator = $this->mock(GeneratorInterface::class); $tag = $this->user()->tags()->inRandomOrder()->first();
$collector = $this->mock(TransactionCollectorInterface::class); $date = new Carbon;
$tagRepos = $this->mock(TagRepositoryInterface::class); $false = new Preference;
$accountRepos = $this->mock(AccountRepositoryInterface::class); $false->data = false;
$tag = $this->user()->tags()->first();
$this->mockDefaultSession();
$tagRepos->shouldReceive('setUser'); $tagRepos->shouldReceive('setUser');
$tagRepos->shouldReceive('get')->andReturn(new Collection([$tag])); $tagRepos->shouldReceive('get')->andReturn(new Collection([$tag]));
$fiscalHelper = $this->mock(FiscalHelperInterface::class); Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
$date = new Carbon; Preferences::shouldReceive('get')->withArgs(['customFiscalYear', false])->andReturn($false);
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date); $fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date); $fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
$collector->shouldReceive('setAccounts')->andReturnSelf()->atLeast()->once();
$set = new Collection; $collector->shouldReceive('setRange')->andReturnSelf()->atLeast()->once();
for ($i = 0; $i < 10; ++$i) { $collector->shouldReceive('setTypes')->withArgs([[TransactionType::WITHDRAWAL, TransactionType::TRANSFER]])->andReturnSelf()->atLeast()->once();
$transaction = factory(Transaction::class)->make(); $collector->shouldReceive('setTypes')->withArgs([[TransactionType::DEPOSIT, TransactionType::TRANSFER]])->andReturnSelf()->atLeast()->once();
$tag = factory(Tag::class)->make(); $collector->shouldReceive('setTags')->andReturnSelf()->atLeast()->once();
$transaction->transactionJournal->tags()->save($tag); $collector->shouldReceive('withAccountInformation')->andReturnSelf()->atLeast()->once();
$set->push($transaction); $collector->shouldReceive('getExtractedJournals')->andReturn([$withdrawal])->atLeast()->once();
} $generator->shouldReceive('multiSet')->andReturn([])->once()->atLeast()->once();
$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();
$this->be($this->user()); $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->tag, '20120101', '20120131']));
@@ -250,6 +248,7 @@ class TagReportControllerTest extends TestCase
$pieChart->shouldReceive('setTags')->once()->andReturnSelf(); $pieChart->shouldReceive('setTags')->once()->andReturnSelf();
$pieChart->shouldReceive('setStart')->once()->andReturnSelf(); $pieChart->shouldReceive('setStart')->once()->andReturnSelf();
$pieChart->shouldReceive('setEnd')->once()->andReturnSelf(); $pieChart->shouldReceive('setEnd')->once()->andReturnSelf();
$pieChart->shouldReceive('setCollectOtherObjects')->once()->andReturnSelf()->withArgs([false]); $pieChart->shouldReceive('setCollectOtherObjects')->once()->andReturnSelf()->withArgs([false]);
$pieChart->shouldReceive('generate')->withArgs(['expense', 'tag'])->andReturn([])->once(); $pieChart->shouldReceive('generate')->withArgs(['expense', 'tag'])->andReturn([])->once();
$generator->shouldReceive('pieChart')->andReturn([])->once(); $generator->shouldReceive('pieChart')->andReturn([])->once();
@@ -278,6 +277,7 @@ class TagReportControllerTest extends TestCase
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date); $fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
$pieChart->shouldReceive('setAccounts')->once()->andReturnSelf(); $pieChart->shouldReceive('setAccounts')->once()->andReturnSelf();
$pieChart->shouldReceive('setTags')->once()->andReturnSelf(); $pieChart->shouldReceive('setTags')->once()->andReturnSelf();
$pieChart->shouldReceive('setStart')->once()->andReturnSelf(); $pieChart->shouldReceive('setStart')->once()->andReturnSelf();
$pieChart->shouldReceive('setEnd')->once()->andReturnSelf(); $pieChart->shouldReceive('setEnd')->once()->andReturnSelf();

View File

@@ -56,6 +56,8 @@ class CallbackControllerTest extends TestCase
$config = []; $config = [];
$newConfig = ['auth_code' => 'abc']; $newConfig = ['auth_code' => 'abc'];
$this->mockDefaultSession();
// mock calls. // mock calls.
$repository->shouldReceive('findByKey')->andReturn(new ImportJob)->once(); $repository->shouldReceive('findByKey')->andReturn(new ImportJob)->once();
$repository->shouldReceive('getConfiguration')->andReturn($config)->once(); $repository->shouldReceive('getConfiguration')->andReturn($config)->once();
@@ -79,6 +81,7 @@ class CallbackControllerTest extends TestCase
// mock calls. // mock calls.
$repository->shouldReceive('findByKey')->andReturnNull()->once(); $repository->shouldReceive('findByKey')->andReturnNull()->once();
$this->mockDefaultSession();
$this->be($this->user()); $this->be($this->user());
$response = $this->get(route('import.callback.ynab') . '?code=abc&state=def'); $response = $this->get(route('import.callback.ynab') . '?code=abc&state=def');
@@ -91,11 +94,9 @@ class CallbackControllerTest extends TestCase
*/ */
public function testYnabBasicNoCode(): void public function testYnabBasicNoCode(): void
{ {
$repository = $this->mock(ImportJobRepositoryInterface::class); $this->mock(ImportJobRepositoryInterface::class);
// config for job: $this->mockDefaultSession();
$config = [];
$newConfig = ['auth_code' => 'abc'];
// mock calls. // mock calls.

View File

@@ -70,6 +70,8 @@ class IndexControllerTest extends TestCase
$importJob->provider = 'fake'; $importJob->provider = 'fake';
$importJob->key = 'fake_job_1'; $importJob->key = 'fake_job_1';
$this->mockDefaultSession();
// mock calls: // mock calls:
$ynabPrerequisites->shouldReceive('setUser')->once(); $ynabPrerequisites->shouldReceive('setUser')->once();
$fakePrerequisites->shouldReceive('setUser')->once(); $fakePrerequisites->shouldReceive('setUser')->once();
@@ -105,6 +107,8 @@ class IndexControllerTest extends TestCase
$importJob->provider = 'spectre'; $importJob->provider = 'spectre';
$importJob->key = 'fake_job_1'; $importJob->key = 'fake_job_1';
$this->mockDefaultSession();
// mock calls: // mock calls:
$ynabPrerequisites->shouldReceive('setUser')->times(2); $ynabPrerequisites->shouldReceive('setUser')->times(2);
$fakePrerequisites->shouldReceive('setUser')->times(2); $fakePrerequisites->shouldReceive('setUser')->times(2);
@@ -143,6 +147,8 @@ class IndexControllerTest extends TestCase
$importJob->key = 'fake_job_1'; $importJob->key = 'fake_job_1';
$importJob->user_id = 1; $importJob->user_id = 1;
$this->mockDefaultSession();
// mock calls // mock calls
$userRepository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(true)->times(3); $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->key = 'fake_job_2';
$importJob->user_id = 1; $importJob->user_id = 1;
$this->mockDefaultSession();
// mock call: // mock call:
$fakePrerequisites->shouldReceive('isComplete')->times(3)->andReturn(true); $fakePrerequisites->shouldReceive('isComplete')->times(3)->andReturn(true);
@@ -235,6 +243,8 @@ class IndexControllerTest extends TestCase
$importJob->key = 'file_job_1'; $importJob->key = 'file_job_1';
$importJob->user_id = 1; $importJob->user_id = 1;
$this->mockDefaultSession();
// mock calls // mock calls
$fakePrerequisites->shouldReceive('setUser')->times(2); $fakePrerequisites->shouldReceive('setUser')->times(2);
$bunqPrerequisites->shouldReceive('setUser')->times(2); $bunqPrerequisites->shouldReceive('setUser')->times(2);
@@ -272,9 +282,11 @@ class IndexControllerTest extends TestCase
$filePrerequisites = $this->mock(FilePrerequisites::class); $filePrerequisites = $this->mock(FilePrerequisites::class);
$ynabPrerequisites = $this->mock(YnabPrerequisites::class); $ynabPrerequisites = $this->mock(YnabPrerequisites::class);
$this->mockDefaultSession();
$job = new ImportJob; $job = new ImportJob;
$job->user_id = $this->user()->id; $job->user_id = $this->user()->id;
$job->key = 'dc_' . random_int(1, 10000); $job->key = 'dc_' . $this->randomInt();
$job->status = 'ready_to_run'; $job->status = 'ready_to_run';
$job->stage = 'go-for-import'; $job->stage = 'go-for-import';
$job->provider = 'file'; $job->provider = 'file';
@@ -325,6 +337,8 @@ class IndexControllerTest extends TestCase
$ynabPrerequisites = $this->mock(YnabPrerequisites::class); $ynabPrerequisites = $this->mock(YnabPrerequisites::class);
$repository = $this->mock(ImportJobRepositoryInterface::class); $repository = $this->mock(ImportJobRepositoryInterface::class);
$this->mockDefaultSession();
// call methods: // call methods:
$userRepository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false); $userRepository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false);
$userRepository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(false); $userRepository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(false);
@@ -360,6 +374,8 @@ class IndexControllerTest extends TestCase
$ynabPrerequisites = $this->mock(YnabPrerequisites::class); $ynabPrerequisites = $this->mock(YnabPrerequisites::class);
$repository = $this->mock(ImportJobRepositoryInterface::class); $repository = $this->mock(ImportJobRepositoryInterface::class);
$this->mockDefaultSession();
// call methods: // call methods:
$fakePrerequisites->shouldReceive('setUser')->once(); $fakePrerequisites->shouldReceive('setUser')->once();
$bunqPrerequisites->shouldReceive('setUser')->once(); $bunqPrerequisites->shouldReceive('setUser')->once();

View File

@@ -54,12 +54,14 @@ class JobConfigurationControllerTest extends TestCase
{ {
$job = new ImportJob; $job = new ImportJob;
$job->user_id = $this->user()->id; $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->status = 'has_prereq';
$job->provider = 'fake'; $job->provider = 'fake';
$job->file_type = ''; $job->file_type = '';
$job->save(); $job->save();
$this->mockDefaultSession();
// mock repositories and configuration handling classes: // mock repositories and configuration handling classes:
$repository = $this->mock(ImportJobRepositoryInterface::class); $repository = $this->mock(ImportJobRepositoryInterface::class);
$configurator = $this->mock(FakeJobConfiguration::class); $configurator = $this->mock(FakeJobConfiguration::class);
@@ -89,12 +91,14 @@ class JobConfigurationControllerTest extends TestCase
{ {
$job = new ImportJob; $job = new ImportJob;
$job->user_id = $this->user()->id; $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->status = 'some_bad_state';
$job->provider = 'fake'; $job->provider = 'fake';
$job->file_type = ''; $job->file_type = '';
$job->save(); $job->save();
$this->mockDefaultSession();
// mock repositories and configuration handling classes: // mock repositories and configuration handling classes:
$repository = $this->mock(ImportJobRepositoryInterface::class); $repository = $this->mock(ImportJobRepositoryInterface::class);
$configurator = $this->mock(FakeJobConfiguration::class); $configurator = $this->mock(FakeJobConfiguration::class);
@@ -115,12 +119,14 @@ class JobConfigurationControllerTest extends TestCase
{ {
$job = new ImportJob; $job = new ImportJob;
$job->user_id = $this->user()->id; $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->status = 'has_prereq';
$job->provider = 'fake'; $job->provider = 'fake';
$job->file_type = ''; $job->file_type = '';
$job->save(); $job->save();
$this->mockDefaultSession();
// mock repositories and configuration handling classes: // mock repositories and configuration handling classes:
$repository = $this->mock(ImportJobRepositoryInterface::class); $repository = $this->mock(ImportJobRepositoryInterface::class);
$configurator = $this->mock(FakeJobConfiguration::class); $configurator = $this->mock(FakeJobConfiguration::class);
@@ -145,12 +151,14 @@ class JobConfigurationControllerTest extends TestCase
$job = new ImportJob; $job = new ImportJob;
$job->user_id = $this->user()->id; $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->status = 'has_prereq';
$job->provider = 'fake'; $job->provider = 'fake';
$job->file_type = ''; $job->file_type = '';
$job->save(); $job->save();
$this->mockDefaultSession();
$messages = new MessageBag; $messages = new MessageBag;
$messages->add('some', 'srrange message'); $messages->add('some', 'srrange message');
@@ -180,12 +188,14 @@ class JobConfigurationControllerTest extends TestCase
$job = new ImportJob; $job = new ImportJob;
$job->user_id = $this->user()->id; $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->status = 'some_bad_state';
$job->provider = 'fake'; $job->provider = 'fake';
$job->file_type = ''; $job->file_type = '';
$job->save(); $job->save();
$this->mockDefaultSession();
$messages = new MessageBag; $messages = new MessageBag;
$messages->add('some', 'srrange message'); $messages->add('some', 'srrange message');
@@ -210,12 +220,14 @@ class JobConfigurationControllerTest extends TestCase
$job = new ImportJob; $job = new ImportJob;
$job->user_id = $this->user()->id; $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->status = 'has_prereq';
$job->provider = 'fake'; $job->provider = 'fake';
$job->file_type = ''; $job->file_type = '';
$job->save(); $job->save();
$this->mockDefaultSession();
// mock repositories and configuration handling classes: // mock repositories and configuration handling classes:
$repository = $this->mock(ImportJobRepositoryInterface::class); $repository = $this->mock(ImportJobRepositoryInterface::class);
$configurator = $this->mock(FakeJobConfiguration::class); $configurator = $this->mock(FakeJobConfiguration::class);
@@ -242,12 +254,14 @@ class JobConfigurationControllerTest extends TestCase
$file = UploadedFile::fake()->image('avatar.jpg'); $file = UploadedFile::fake()->image('avatar.jpg');
$job = new ImportJob; $job = new ImportJob;
$job->user_id = $this->user()->id; $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->status = 'has_prereq';
$job->provider = 'fake'; $job->provider = 'fake';
$job->file_type = ''; $job->file_type = '';
$job->save(); $job->save();
$this->mockDefaultSession();
$messages = new MessageBag; $messages = new MessageBag;
$messages->add('some', 'srrange message'); $messages->add('some', 'srrange message');

View File

@@ -61,12 +61,14 @@ class JobStatusControllerTest extends TestCase
$userRepos = $this->mock(UserRepositoryInterface::class); $userRepos = $this->mock(UserRepositoryInterface::class);
$job = new ImportJob; $job = new ImportJob;
$job->user_id = $this->user()->id; $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->status = 'ready_to_run';
$job->provider = 'fake'; $job->provider = 'fake';
$job->file_type = ''; $job->file_type = '';
$job->save(); $job->save();
$this->mockDefaultSession();
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true); $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
// call thing. // call thing.
@@ -86,13 +88,15 @@ class JobStatusControllerTest extends TestCase
$job = new ImportJob; $job = new ImportJob;
$job->user_id = $this->user()->id; $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->status = 'ready_to_run';
$job->provider = 'file'; $job->provider = 'file';
$job->transactions = []; $job->transactions = [];
$job->file_type = ''; $job->file_type = '';
$job->save(); $job->save();
$this->mockDefaultSession();
$importRepos->shouldReceive('countTransactions')->once()->andReturn(0); $importRepos->shouldReceive('countTransactions')->once()->andReturn(0);
// call thing. // call thing.
@@ -114,7 +118,7 @@ class JobStatusControllerTest extends TestCase
$tag = $this->user()->tags()->first(); $tag = $this->user()->tags()->first();
$job = new ImportJob; $job = new ImportJob;
$job->user_id = $this->user()->id; $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->status = 'ready_to_run';
$job->provider = 'fake'; $job->provider = 'fake';
$job->transactions = []; $job->transactions = [];
@@ -122,6 +126,8 @@ class JobStatusControllerTest extends TestCase
$job->tag()->associate($tag); $job->tag()->associate($tag);
$job->save(); $job->save();
$this->mockDefaultSession();
$importRepos->shouldReceive('countTransactions')->once()->andReturn(0); $importRepos->shouldReceive('countTransactions')->once()->andReturn(0);
// call thing. // call thing.
@@ -147,11 +153,13 @@ class JobStatusControllerTest extends TestCase
$second = $this->user()->transactionJournals()->where('id', '!=', $journal->id)->first(); $second = $this->user()->transactionJournals()->where('id', '!=', $journal->id)->first();
$tag->transactionJournals()->sync([$journal->id, $second->id]); $tag->transactionJournals()->sync([$journal->id, $second->id]);
$this->mockDefaultSession();
$importRepos->shouldReceive('countTransactions')->once()->andReturn(2); $importRepos->shouldReceive('countTransactions')->once()->andReturn(2);
$job = new ImportJob; $job = new ImportJob;
$job->user_id = $this->user()->id; $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->status = 'ready_to_run';
$job->provider = 'fake'; $job->provider = 'fake';
$job->transactions = []; $job->transactions = [];
@@ -181,11 +189,13 @@ class JobStatusControllerTest extends TestCase
$journal = $this->user()->transactionJournals()->first(); $journal = $this->user()->transactionJournals()->first();
$tag->transactionJournals()->sync([$journal->id]); $tag->transactionJournals()->sync([$journal->id]);
$this->mockDefaultSession();
$importRepos->shouldReceive('countTransactions')->once()->andReturn(1); $importRepos->shouldReceive('countTransactions')->once()->andReturn(1);
$job = new ImportJob; $job = new ImportJob;
$job->user_id = $this->user()->id; $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->status = 'ready_to_run';
$job->provider = 'fake'; $job->provider = 'fake';
$job->transactions = []; $job->transactions = [];
@@ -211,13 +221,15 @@ class JobStatusControllerTest extends TestCase
$job = new ImportJob; $job = new ImportJob;
$job->user_id = $this->user()->id; $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->status = 'ready_to_run';
$job->provider = 'fake'; $job->provider = 'fake';
$job->transactions = []; $job->transactions = [];
$job->file_type = ''; $job->file_type = '';
$job->save(); $job->save();
$this->mockDefaultSession();
// mock stuff // mock stuff
$repository = $this->mock(ImportJobRepositoryInterface::class); $repository = $this->mock(ImportJobRepositoryInterface::class);
$routine = $this->mock(FakeRoutine::class); $routine = $this->mock(FakeRoutine::class);
@@ -242,13 +254,15 @@ class JobStatusControllerTest extends TestCase
$job = new ImportJob; $job = new ImportJob;
$job->user_id = $this->user()->id; $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->status = 'ready_to_run';
$job->provider = 'fake'; $job->provider = 'fake';
$job->transactions = []; $job->transactions = [];
$job->file_type = ''; $job->file_type = '';
$job->save(); $job->save();
$this->mockDefaultSession();
// mock stuff // mock stuff
$repository = $this->mock(ImportJobRepositoryInterface::class); $repository = $this->mock(ImportJobRepositoryInterface::class);
$routine = $this->mock(FakeRoutine::class); $routine = $this->mock(FakeRoutine::class);
@@ -273,13 +287,15 @@ class JobStatusControllerTest extends TestCase
$userRepos = $this->mock(UserRepositoryInterface::class); $userRepos = $this->mock(UserRepositoryInterface::class);
$job = new ImportJob; $job = new ImportJob;
$job->user_id = $this->user()->id; $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->status = 'ready_to_run';
$job->provider = 'fake'; $job->provider = 'fake';
$job->transactions = []; $job->transactions = [];
$job->file_type = ''; $job->file_type = '';
$job->save(); $job->save();
$this->mockDefaultSession();
// mock stuff // mock stuff
$repository = $this->mock(ImportJobRepositoryInterface::class); $repository = $this->mock(ImportJobRepositoryInterface::class);
$routine = $this->mock(FakeRoutine::class); $routine = $this->mock(FakeRoutine::class);
@@ -307,9 +323,11 @@ class JobStatusControllerTest extends TestCase
$importRepos->shouldReceive('setStatus')->withArgs([Mockery::any(), 'error']) $importRepos->shouldReceive('setStatus')->withArgs([Mockery::any(), 'error'])
->atLeast()->once(); ->atLeast()->once();
$this->mockDefaultSession();
$job = new ImportJob; $job = new ImportJob;
$job->user_id = $this->user()->id; $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->status = 'bad_state';
$job->provider = 'fake'; $job->provider = 'fake';
$job->transactions = []; $job->transactions = [];
@@ -330,13 +348,15 @@ class JobStatusControllerTest extends TestCase
{ {
$job = new ImportJob; $job = new ImportJob;
$job->user_id = $this->user()->id; $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->status = 'provider_finished';
$job->provider = 'fake'; $job->provider = 'fake';
$job->transactions = []; $job->transactions = [];
$job->file_type = ''; $job->file_type = '';
$job->save(); $job->save();
$this->mockDefaultSession();
// mock stuff // mock stuff
$repository = $this->mock(ImportJobRepositoryInterface::class); $repository = $this->mock(ImportJobRepositoryInterface::class);
$storage = $this->mock(ImportArrayStorage::class); $storage = $this->mock(ImportArrayStorage::class);
@@ -362,13 +382,15 @@ class JobStatusControllerTest extends TestCase
{ {
$job = new ImportJob; $job = new ImportJob;
$job->user_id = $this->user()->id; $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->status = 'provider_finished';
$job->provider = 'fake'; $job->provider = 'fake';
$job->transactions = []; $job->transactions = [];
$job->file_type = ''; $job->file_type = '';
$job->save(); $job->save();
$this->mockDefaultSession();
// mock stuff // mock stuff
$repository = $this->mock(ImportJobRepositoryInterface::class); $repository = $this->mock(ImportJobRepositoryInterface::class);
$storage = $this->mock(ImportArrayStorage::class); $storage = $this->mock(ImportArrayStorage::class);
@@ -395,13 +417,15 @@ class JobStatusControllerTest extends TestCase
$importRepos = $this->mock(ImportJobRepositoryInterface::class); $importRepos = $this->mock(ImportJobRepositoryInterface::class);
$job = new ImportJob; $job = new ImportJob;
$job->user_id = $this->user()->id; $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->status = 'some_bad_state';
$job->provider = 'fake'; $job->provider = 'fake';
$job->transactions = []; $job->transactions = [];
$job->file_type = ''; $job->file_type = '';
$job->save(); $job->save();
$this->mockDefaultSession();
$this->be($this->user()); $this->be($this->user());
$response = $this->post(route('import.job.store', [$job->key])); $response = $this->post(route('import.job.store', [$job->key]));
$response->assertStatus(200); $response->assertStatus(200);

View File

@@ -60,7 +60,7 @@ class PrerequisitesControllerTest extends TestCase
$job = new ImportJob; $job = new ImportJob;
$job->user_id = $this->user()->id; $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->status = 'new';
$job->provider = 'fake'; $job->provider = 'fake';
$job->transactions = []; $job->transactions = [];
@@ -93,7 +93,7 @@ class PrerequisitesControllerTest extends TestCase
$job = new ImportJob; $job = new ImportJob;
$job->user_id = $this->user()->id; $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->status = 'some_Bad_state';
$job->provider = 'fake'; $job->provider = 'fake';
$job->transactions = []; $job->transactions = [];
@@ -121,7 +121,7 @@ class PrerequisitesControllerTest extends TestCase
$job = new ImportJob; $job = new ImportJob;
$job->user_id = $this->user()->id; $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->status = 'new';
$job->provider = 'fake'; $job->provider = 'fake';
$job->transactions = []; $job->transactions = [];
@@ -153,7 +153,7 @@ class PrerequisitesControllerTest extends TestCase
$job = new ImportJob; $job = new ImportJob;
$job->user_id = $this->user()->id; $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->status = 'new';
$job->provider = 'fake'; $job->provider = 'fake';
$job->transactions = []; $job->transactions = [];
@@ -185,7 +185,7 @@ class PrerequisitesControllerTest extends TestCase
$job = new ImportJob; $job = new ImportJob;
$job->user_id = $this->user()->id; $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->status = 'badstate';
$job->provider = 'fake'; $job->provider = 'fake';
$job->transactions = []; $job->transactions = [];
@@ -241,7 +241,7 @@ class PrerequisitesControllerTest extends TestCase
$job = new ImportJob; $job = new ImportJob;
$job->user_id = $this->user()->id; $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->status = 'new';
$job->provider = 'fake'; $job->provider = 'fake';
$job->transactions = []; $job->transactions = [];

View File

@@ -502,7 +502,7 @@ class PiggyBankControllerTest extends TestCase
$this->session(['piggy-banks.create.uri' => 'http://localhost']); $this->session(['piggy-banks.create.uri' => 'http://localhost']);
$data = [ $data = [
'name' => 'Piggy ' . random_int(999, 10000), 'name' => 'Piggy ' . $this->randomInt(),
'targetamount' => '100.123', 'targetamount' => '100.123',
'account_id' => 2, 'account_id' => 2,
'amount_currency_id_targetamount' => 1, 'amount_currency_id_targetamount' => 1,
@@ -533,7 +533,7 @@ class PiggyBankControllerTest extends TestCase
$this->session(['piggy-banks.edit.uri' => 'http://localhost']); $this->session(['piggy-banks.edit.uri' => 'http://localhost']);
$data = [ $data = [
'id' => 3, 'id' => 3,
'name' => 'Updated Piggy ' . random_int(999, 10000), 'name' => 'Updated Piggy ' . $this->randomInt(),
'targetamount' => '100.123', 'targetamount' => '100.123',
'account_id' => 2, 'account_id' => 2,
'amount_currency_id_targetamount' => 1, 'amount_currency_id_targetamount' => 1,

View File

@@ -101,11 +101,11 @@ class CreateControllerTest extends TestCase
$tomorrow = Carbon::now()->addDays(2); $tomorrow = Carbon::now()->addDays(2);
$recurrence = $this->user()->recurrences()->first(); $recurrence = $this->user()->recurrences()->first();
$data = [ $data = [
'title' => 'hello' . random_int(1, 100000), 'title' => 'hello' . $this->randomInt(),
'first_date' => $tomorrow->format('Y-m-d'), 'first_date' => $tomorrow->format('Y-m-d'),
'repetition_type' => 'daily', 'repetition_type' => 'daily',
'skip' => 0, 'skip' => 0,
'recurring_description' => 'Some descr' . random_int(1, 100000), 'recurring_description' => 'Some descr' . $this->randomInt(),
'active' => '1', 'active' => '1',
'apply_rules' => '1', 'apply_rules' => '1',
'foreign_amount' => '1', 'foreign_amount' => '1',
@@ -160,11 +160,11 @@ class CreateControllerTest extends TestCase
$tomorrow = Carbon::now()->addDays(2); $tomorrow = Carbon::now()->addDays(2);
$recurrence = $this->user()->recurrences()->first(); $recurrence = $this->user()->recurrences()->first();
$data = [ $data = [
'title' => 'hello' . random_int(1, 100000), 'title' => 'hello' . $this->randomInt(),
'first_date' => $tomorrow->format('Y-m-d'), 'first_date' => $tomorrow->format('Y-m-d'),
'repetition_type' => 'daily', 'repetition_type' => 'daily',
'skip' => 0, 'skip' => 0,
'recurring_description' => 'Some descr' . random_int(1, 100000), 'recurring_description' => 'Some descr' . $this->randomInt(),
'active' => '1', 'active' => '1',
'apply_rules' => '1', 'apply_rules' => '1',
'foreign_amount' => '1', 'foreign_amount' => '1',
@@ -220,11 +220,11 @@ class CreateControllerTest extends TestCase
$tomorrow = Carbon::now()->addDays(2); $tomorrow = Carbon::now()->addDays(2);
$recurrence = $this->user()->recurrences()->first(); $recurrence = $this->user()->recurrences()->first();
$data = [ $data = [
'title' => 'hello' . random_int(1, 100000), 'title' => 'hello' . $this->randomInt(),
'first_date' => $tomorrow->format('Y-m-d'), 'first_date' => $tomorrow->format('Y-m-d'),
'repetition_type' => 'monthly,5', 'repetition_type' => 'monthly,5',
'skip' => 0, 'skip' => 0,
'recurring_description' => 'Some descr' . random_int(1, 100000), 'recurring_description' => 'Some descr' . $this->randomInt(),
'active' => '1', 'active' => '1',
'apply_rules' => '1', 'apply_rules' => '1',
'foreign_amount' => '1', 'foreign_amount' => '1',
@@ -278,11 +278,11 @@ class CreateControllerTest extends TestCase
$tomorrow = Carbon::now()->addDays(2); $tomorrow = Carbon::now()->addDays(2);
$recurrence = $this->user()->recurrences()->first(); $recurrence = $this->user()->recurrences()->first();
$data = [ $data = [
'title' => 'hello' . random_int(1, 100000), 'title' => 'hello' . $this->randomInt(),
'first_date' => $tomorrow->format('Y-m-d'), 'first_date' => $tomorrow->format('Y-m-d'),
'repetition_type' => 'ndom,3,5', 'repetition_type' => 'ndom,3,5',
'skip' => 0, 'skip' => 0,
'recurring_description' => 'Some descr' . random_int(1, 100000), 'recurring_description' => 'Some descr' . $this->randomInt(),
'active' => '1', 'active' => '1',
'apply_rules' => '1', 'apply_rules' => '1',
'foreign_amount' => '1', 'foreign_amount' => '1',
@@ -337,11 +337,11 @@ class CreateControllerTest extends TestCase
$tomorrow = Carbon::now()->addDays(2); $tomorrow = Carbon::now()->addDays(2);
$recurrence = $this->user()->recurrences()->first(); $recurrence = $this->user()->recurrences()->first();
$data = [ $data = [
'title' => 'hello' . random_int(1, 100000), 'title' => 'hello' . $this->randomInt(),
'first_date' => $tomorrow->format('Y-m-d'), 'first_date' => $tomorrow->format('Y-m-d'),
'repetition_type' => 'daily', 'repetition_type' => 'daily',
'skip' => 0, 'skip' => 0,
'recurring_description' => 'Some descr' . random_int(1, 100000), 'recurring_description' => 'Some descr' . $this->randomInt(),
'active' => '1', 'active' => '1',
'apply_rules' => '1', 'apply_rules' => '1',
'foreign_amount' => '1', 'foreign_amount' => '1',
@@ -398,11 +398,11 @@ class CreateControllerTest extends TestCase
$tomorrow = Carbon::now()->addDays(2); $tomorrow = Carbon::now()->addDays(2);
$recurrence = $this->user()->recurrences()->first(); $recurrence = $this->user()->recurrences()->first();
$data = [ $data = [
'title' => 'hello' . random_int(1, 100000), 'title' => 'hello' . $this->randomInt(),
'first_date' => $tomorrow->format('Y-m-d'), 'first_date' => $tomorrow->format('Y-m-d'),
'repetition_type' => 'daily', 'repetition_type' => 'daily',
'skip' => 0, 'skip' => 0,
'recurring_description' => 'Some descr' . random_int(1, 100000), 'recurring_description' => 'Some descr' . $this->randomInt(),
'active' => '1', 'active' => '1',
'apply_rules' => '1', 'apply_rules' => '1',
'foreign_amount' => '1', 'foreign_amount' => '1',
@@ -456,11 +456,11 @@ class CreateControllerTest extends TestCase
$tomorrow = Carbon::now()->addDays(2); $tomorrow = Carbon::now()->addDays(2);
$recurrence = $this->user()->recurrences()->first(); $recurrence = $this->user()->recurrences()->first();
$data = [ $data = [
'title' => 'hello' . random_int(1, 100000), 'title' => 'hello' . $this->randomInt(),
'first_date' => $tomorrow->format('Y-m-d'), 'first_date' => $tomorrow->format('Y-m-d'),
'repetition_type' => 'yearly,2018-01-01', 'repetition_type' => 'yearly,2018-01-01',
'skip' => 0, 'skip' => 0,
'recurring_description' => 'Some descr' . random_int(1, 100000), 'recurring_description' => 'Some descr' . $this->randomInt(),
'active' => '1', 'active' => '1',
'apply_rules' => '1', 'apply_rules' => '1',
'foreign_amount' => '1', 'foreign_amount' => '1',

View File

@@ -143,7 +143,7 @@ class RuleGroupControllerTest extends TestCase
/** @var RuleGroup $ruleGroup */ /** @var RuleGroup $ruleGroup */
$ruleGroup = $this->user()->ruleGroups()->first(); $ruleGroup = $this->user()->ruleGroups()->first();
$ruleGroup->description = 'Some description ' . random_int(1, 10000); $ruleGroup->description = 'Some description ' . periods|length(1, 10000);
$ruleGroup->save(); $ruleGroup->save();
$this->be($this->user()); $this->be($this->user());

View File

@@ -316,7 +316,7 @@ class TagControllerTest extends TestCase
$this->session(['tags.create.uri' => 'http://localhost']); $this->session(['tags.create.uri' => 'http://localhost']);
$data = [ $data = [
'tag' => 'Hello new tag' . random_int(999, 10000), 'tag' => 'Hello new tag' . $this->randomInt(),
'tagMode' => 'nothing', 'tagMode' => 'nothing',
'tag_position_has_tag' => 'true', 'tag_position_has_tag' => 'true',
@@ -342,7 +342,7 @@ class TagControllerTest extends TestCase
$this->session(['tags.edit.uri' => 'http://localhost']); $this->session(['tags.edit.uri' => 'http://localhost']);
$data = [ $data = [
'id' => 1, 'id' => 1,
'tag' => 'Hello updated tag' . random_int(999, 10000), 'tag' => 'Hello updated tag' . $this->randomInt(),
'tagMode' => 'nothing', 'tagMode' => 'nothing',
]; ];

View File

@@ -143,6 +143,7 @@ abstract class TestCase extends BaseTestCase
$euro = $this->getEuro(); $euro = $this->getEuro();
$budget = $this->getRandomBudget(); $budget = $this->getRandomBudget();
$category = $this->getRandomCategory(); $category = $this->getRandomCategory();
$expense = $this->getRandomExpense();
try { try {
$date = new Carbon; $date = new Carbon;
} catch (Exception $e) { } catch (Exception $e) {
@@ -150,15 +151,18 @@ abstract class TestCase extends BaseTestCase
} }
return [ return [
'transaction_journal_id' => $withdrawal->id, 'transaction_journal_id' => $withdrawal->id,
'currency_id' => $euro->id, 'transaction_type_type' => 'Withdrawal',
'foreign_currency_id' => null, 'currency_id' => $euro->id,
'date' => $date, 'foreign_currency_id' => null,
'source_account_id' => 1, 'date' => $date,
'destination_account_id' => 4, 'source_account_id' => 1,
'currency_name' => $euro->name, 'destination_account_id' => $expense->id,
'currency_code' => $euro->code, 'destination_account_name' => $expense->name,
'currency_symbol' => $euro->symbol, 'currency_name' => $euro->name,
'currency_code' => $euro->code,
'currency_symbol' => $euro->symbol,
'currency_decimal_places' => $euro->decimal_places, 'currency_decimal_places' => $euro->decimal_places,
'amount' => '-30', 'amount' => '-30',
'budget_id' => $budget->id, 'budget_id' => $budget->id,

View File

@@ -69,7 +69,11 @@ class MigrateJournalNotesTest extends TestCase
FireflyConfig::shouldReceive('set')->withArgs(['4780_migrate_notes', true]); FireflyConfig::shouldReceive('set')->withArgs(['4780_migrate_notes', true]);
$journal = $this->getRandomWithdrawal(); $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, 'transaction_journal_id' => $journal->id,
'name' => 'notes', 'name' => 'notes',