Improve test coverage and efficiency for accounts and budgets.

This commit is contained in:
James Cole
2019-06-23 11:13:36 +02:00
parent 8f25562923
commit 43d753e5bd
47 changed files with 919 additions and 985 deletions

View File

@@ -24,17 +24,15 @@ declare(strict_types=1);
namespace Tests\Feature\Controllers\Budget;
use Amount;
use Carbon\Carbon;
use FireflyIII\Helpers\Collector\TransactionCollectorInterface;
use FireflyIII\Helpers\FiscalHelperInterface;
use FireflyIII\Helpers\Fiscal\FiscalHelperInterface;
use FireflyIII\Models\BudgetLimit;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use Illuminate\Support\Collection;
use Log;
use Preferences;
use Tests\TestCase;
/**
@@ -57,24 +55,24 @@ class AmountControllerTest extends TestCase
*/
public function testAmount(): void
{
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
Log::info('Now in testAmount()');
// mock stuff
$repository = $this->mock(BudgetRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$collector = $this->mock(TransactionCollectorInterface::class);
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
$repository = $this->mock(BudgetRepositoryInterface::class);
$budget = $this->getRandomBudget();
$repository->shouldReceive('updateLimitAmount')->andReturn(new BudgetLimit);
$repository->shouldReceive('spentInPeriod')->andReturn('0');
$repository->shouldReceive('budgetedPerDay')->andReturn('10');
$this->mockDefaultSession();
Amount::shouldReceive('formatAnything')->atLeast()->once()->andReturn('200');
Preferences::shouldReceive('mark')->atLeast()->once();
$data = ['amount' => 200, 'start' => '2017-01-01', 'end' => '2017-01-31'];
$this->be($this->user());
$response = $this->post(route('budgets.amount', [1]), $data);
$response = $this->post(route('budgets.amount', [$budget->id]), $data);
$response->assertStatus(200);
// assert some reactions:
$response->assertSee($budget->name);
$response->assertSee('"amount":"200"');
}
@@ -83,211 +81,23 @@ class AmountControllerTest extends TestCase
*/
public function testAmountLargeDiff(): void
{
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
$repository = $this->mock(BudgetRepositoryInterface::class);
$budget = $this->getRandomBudget();
return;
Log::info('Now in testAmountLargeDiff()');
// mock stuff
$repository = $this->mock(BudgetRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$collector = $this->mock(TransactionCollectorInterface::class);
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
$repository->shouldReceive('updateLimitAmount')->andReturn(new BudgetLimit);
$repository->shouldReceive('spentInPeriod')->andReturn('0');
$repository->shouldReceive('budgetedPerDay')->andReturn('10');
$this->mockDefaultSession();
Amount::shouldReceive('formatAnything')->atLeast()->once()->andReturn('200');
Preferences::shouldReceive('mark')->atLeast()->once();
$data = ['amount' => 20000, 'start' => '2017-01-01', 'end' => '2017-01-31'];
$this->be($this->user());
$response = $this->post(route('budgets.amount', [1]), $data);
$response->assertStatus(200);
$response->assertSee('Normally you budget about \u20ac10.00 per day.');
}
/**
* @covers \FireflyIII\Http\Controllers\Budget\AmountController
*/
public function testAmountOutOfRange(): void
{
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
Log::info('Now in testAmountOutOfRange()');
// mock stuff
$repository = $this->mock(BudgetRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$collector = $this->mock(TransactionCollectorInterface::class);
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
$repository->shouldReceive('updateLimitAmount')->andReturn(new BudgetLimit);
$repository->shouldReceive('spentInPeriod')->andReturn('0');
$repository->shouldReceive('budgetedPerDay')->andReturn('10');
$today = new Carbon;
$start = $today->startOfMonth()->format('Y-m-d');
$end = $today->endOfMonth()->format('Y-m-d');
$data = ['amount' => 200, 'start' => $start, 'end' => $end];
$this->be($this->user());
$response = $this->post(route('budgets.amount', [1]), $data);
$response->assertStatus(200);
}
/**
* @covers \FireflyIII\Http\Controllers\Budget\AmountController
*/
public function testAmountZero(): void
{
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
Log::info('Now in testAmountZero()');
// mock stuff
$repository = $this->mock(BudgetRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$collector = $this->mock(TransactionCollectorInterface::class);
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
$repository->shouldReceive('updateLimitAmount')->andReturn(new BudgetLimit);
$repository->shouldReceive('spentInPeriod')->andReturn('0');
$repository->shouldReceive('budgetedPerDay')->andReturn('10');
$data = ['amount' => 0, 'start' => '2017-01-01', 'end' => '2017-01-31'];
$this->be($this->user());
$response = $this->post(route('budgets.amount', [1]), $data);
$response->assertStatus(200);
}
/**
* @covers \FireflyIII\Http\Controllers\Budget\AmountController
*/
public function testInfoIncome(): void
{
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
Log::info('Now in testInfoIncome()');
// mock stuff
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$repository = $this->mock(BudgetRepositoryInterface::class);
$collector = $this->mock(TransactionCollectorInterface::class);
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
$date = new Carbon;
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf()->times(2);
$collector->shouldReceive('setRange')->andReturnSelf()->times(2);
$collector->shouldReceive('setTypes')->andReturnSelf()->times(2);
$collector->shouldReceive('withOpposingAccount')->andReturnSelf()->times(2);
// collect transactions to return. First an expense, then income.
$income = new Transaction;
$income->transaction_amount = '150';
$incomeCollection = new Collection([$income]);
$expense = new Transaction;
$expense->transaction_amount = '100';
$expenseCollection = new Collection([$expense]);
$collector->shouldReceive('getTransactions')->andReturn($incomeCollection, $expenseCollection)->times(2);
$repository->shouldReceive('getAvailableBudget')->andReturn('100.123');
$accountRepos->shouldReceive('setUser');
$accountRepos->shouldReceive('getAccountsByType')->andReturn(new Collection);
$repository->shouldReceive('getAverageAvailable')->andReturn('100.123')->once();
$this->be($this->user());
$response = $this->get(route('budgets.income.info', ['20170101', '20170131']));
$response->assertStatus(200);
}
/**
* @covers \FireflyIII\Http\Controllers\Budget\AmountController
* @dataProvider dateRangeProvider
*
* @param string $range
*/
public function testInfoIncomeExpanded(string $range): void
{
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
Log::info(sprintf('Now in testInfoIncomeExpanded(%s)', $range));
// mock stuff
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$repository = $this->mock(BudgetRepositoryInterface::class);
$collector = $this->mock(TransactionCollectorInterface::class);
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
$date = new Carbon;
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
$repository->shouldReceive('getAvailableBudget')->andReturn('100.123');
$accountRepos->shouldReceive('setUser');
$accountRepos->shouldReceive('getAccountsByType')->andReturn(new Collection);
$repository->shouldReceive('getAverageAvailable')->andReturn('100.123')->once();
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf()->times(2);
$collector->shouldReceive('setRange')->andReturnSelf()->times(2);
$collector->shouldReceive('setTypes')->andReturnSelf()->times(2);
$collector->shouldReceive('withOpposingAccount')->andReturnSelf()->times(2);
// collect transactions to return. First an expense, then income.
$income = new Transaction;
$income->transaction_amount = '150';
$incomeCollection = new Collection([$income]);
$expense = new Transaction;
$expense->transaction_amount = '100';
$expenseCollection = new Collection([$expense]);
$collector->shouldReceive('getTransactions')->andReturn($incomeCollection, $expenseCollection)->times(2);
$this->be($this->user());
$this->changeDateRange($this->user(), $range);
$response = $this->get(route('budgets.income.info', ['20170301', '20170430']));
$response->assertStatus(200);
}
/**
* @covers \FireflyIII\Http\Controllers\Budget\AmountController
*/
public function testInfoIncomeInversed(): void
{
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
Log::info('Now in testInfoIncomeInversed()');
// mock stuff
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$repository = $this->mock(BudgetRepositoryInterface::class);
$collector = $this->mock(TransactionCollectorInterface::class);
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
$date = new Carbon;
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf()->times(2);
$collector->shouldReceive('setRange')->andReturnSelf()->times(2);
$collector->shouldReceive('setTypes')->andReturnSelf()->times(2);
$collector->shouldReceive('withOpposingAccount')->andReturnSelf()->times(2);
// collect transactions to return. First an expense, then income.
$income = new Transaction;
$income->transaction_amount = '100';
$incomeCollection = new Collection([$income]);
$expense = new Transaction;
$expense->transaction_amount = '150';
$expenseCollection = new Collection([$expense]);
$collector->shouldReceive('getTransactions')->andReturn($incomeCollection, $expenseCollection)->times(2);
$repository->shouldReceive('getAvailableBudget')->andReturn('100.123');
$accountRepos->shouldReceive('setUser');
$accountRepos->shouldReceive('getAccountsByType')->andReturn(new Collection);
$repository->shouldReceive('getAverageAvailable')->andReturn('100.123')->once();
$this->be($this->user());
$response = $this->get(route('budgets.income.info', ['20170101', '20170131']));
$response = $this->post(route('budgets.amount', [$budget->id]), $data);
$response->assertStatus(200);
$response->assertSee('Usually you budget about 200 per day.');
$response->assertSee($budget->name);
}
/**
@@ -295,23 +105,13 @@ class AmountControllerTest extends TestCase
*/
public function testPostUpdateIncome(): void
{
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
Log::info('Now in testPostUpdateIncome()');
// mock stuff
$repository = $this->mock(BudgetRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$collector = $this->mock(TransactionCollectorInterface::class);
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
$date = new Carbon;
//$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
//$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
$repository = $this->mock(BudgetRepositoryInterface::class);
$repository->shouldReceive('setAvailableBudget');
$repository->shouldReceive('cleanupBudgets');
$this->mockDefaultSession();
Preferences::shouldReceive('mark')->atLeast()->once();
$data = ['amount' => '200', 'start' => '2017-01-01', 'end' => '2017-01-31'];
$this->be($this->user());
$response = $this->post(route('budgets.income.post'), $data);
@@ -324,26 +124,19 @@ class AmountControllerTest extends TestCase
*/
public function testUpdateIncome(): void
{
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
Log::info('Now in testUpdateIncome()');
// must be in list
$this->be($this->user());
// mock stuff
$repository = $this->mock(BudgetRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$collector = $this->mock(TransactionCollectorInterface::class);
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
$date = new Carbon;
$this->mockDefaultSession();
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
$repository->shouldReceive('getAvailableBudget')->andReturn('1');
$repository->shouldReceive('cleanupBudgets');
$this->be($this->user());
$response = $this->get(route('budgets.income', ['2017-01-01', '2017-01-31']));
$response->assertStatus(200);
}

View File

@@ -25,12 +25,11 @@ namespace Tests\Feature\Controllers\Budget;
use FireflyIII\Models\Budget;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\Repositories\User\UserRepositoryInterface;
use Log;
use Mockery;
use Preferences;
use Tests\TestCase;
/**
@@ -54,14 +53,13 @@ class CreateControllerTest extends TestCase
*/
public function testCreate(): void
{
Log::debug('Now in testCreate()');
// mock stuff
$repository = $this->mock(BudgetRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$this->mock(BudgetRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
$this->mockDefaultSession();
$this->be($this->user());
$response = $this->get(route('budgets.create'));
@@ -78,20 +76,20 @@ class CreateControllerTest extends TestCase
{
Log::debug('Now in testStore()');
// mock stuff
$budget = factory(Budget::class)->make();
$repository = $this->mock(BudgetRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$budget = $this->getRandomBudget();
$repository = $this->mock(BudgetRepositoryInterface::class);
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
$repository->shouldReceive('findNull')->andReturn($budget);
$repository->shouldReceive('store')->andReturn($budget);
$repository->shouldReceive('cleanupBudgets');
$this->mockDefaultSession();
Preferences::shouldReceive('mark')->atLeast()->once();
$this->session(['budgets.create.uri' => 'http://localhost']);
$data = [
'name' => 'New Budget ' . $this->randomInt(),
'name' => sprintf('New Budget %s', $this->randomInt()),
];
$this->be($this->user());
$response = $this->post(route('budgets.store'), $data);

View File

@@ -29,6 +29,7 @@ use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\Repositories\User\UserRepositoryInterface;
use Log;
use Mockery;
use Preferences;
use Tests\TestCase;
/**
@@ -54,12 +55,13 @@ class DeleteControllerTest extends TestCase
{
Log::debug('Now in testDelete()');
// mock stuff
$repository = $this->mock(BudgetRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$this->mock(BudgetRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
$this->mockDefaultSession();
$this->be($this->user());
$response = $this->get(route('budgets.delete', [1]));
@@ -75,11 +77,11 @@ class DeleteControllerTest extends TestCase
{
Log::debug('Now in testDestroy()');
// mock stuff
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$repository = $this->mock(BudgetRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$this->mock(UserRepositoryInterface::class);
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
$this->mockDefaultSession();
Preferences::shouldReceive('mark')->atLeast()->once();
$repository->shouldReceive('destroy')->andReturn(true);

View File

@@ -30,6 +30,7 @@ use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\Repositories\User\UserRepositoryInterface;
use Log;
use Mockery;
use Preferences;
use Tests\TestCase;
/**
@@ -55,13 +56,11 @@ class EditControllerTest extends TestCase
{
Log::debug('Now in testEdit()');
// mock stuff
$repository = $this->mock(BudgetRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$this->mock(BudgetRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
$this->mockDefaultSession();
$this->be($this->user());
$response = $this->get(route('budgets.edit', [1]));
$response->assertStatus(200);
@@ -77,16 +76,17 @@ class EditControllerTest extends TestCase
{
Log::debug('Now in testUpdate()');
// mock stuff
$budget = factory(Budget::class)->make();
$budget = $this->getRandomBudget();
$repository = $this->mock(BudgetRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$this->mock(UserRepositoryInterface::class);
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
$repository->shouldReceive('findNull')->andReturn($budget);
$repository->shouldReceive('update');
$repository->shouldReceive('cleanupBudgets');
$this->mockDefaultSession();
Preferences::shouldReceive('mark')->atLeast()->once();
$this->session(['budgets.edit.uri' => 'http://localhost']);
$data = [

View File

@@ -24,9 +24,9 @@ declare(strict_types=1);
namespace Tests\Feature\Controllers\Budget;
use Carbon\Carbon;
use FireflyIII\Helpers\FiscalHelperInterface;
use FireflyIII\Helpers\Fiscal\FiscalHelperInterface;
use FireflyIII\Models\Budget;
use FireflyIII\Models\BudgetLimit;
use FireflyIII\Models\Preference;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
@@ -35,6 +35,8 @@ use FireflyIII\Repositories\User\UserRepositoryInterface;
use Illuminate\Support\Collection;
use Log;
use Mockery;
use Preferences;
use Amount;
use Tests\TestCase;
/**
@@ -60,14 +62,9 @@ class IndexControllerTest extends TestCase
*/
public function testIndex(string $range): void
{
Log::info(sprintf('Now in testIndex(%s)', $range));
// mock stuff
$budget = factory(Budget::class)->make();
$budgetLimit = factory(BudgetLimit::class)->make();
// set budget limit to current month:
$budget = $this->getRandomBudget();
$budgetLimit = $this->getRandomBudgetLimit();
$budgetLimit->start_date = Carbon::now()->startOfMonth();
$budgetLimit->end_date = Carbon::now()->endOfMonth();
$budgetInfo = [
@@ -80,11 +77,9 @@ class IndexControllerTest extends TestCase
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$repository = $this->mock(BudgetRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
$accountRepos->shouldReceive('getAccountsByType')->andReturn(new Collection);
$repository->shouldReceive('cleanupBudgets');
@@ -95,6 +90,14 @@ class IndexControllerTest extends TestCase
$repository->shouldReceive('collectBudgetInformation')->andReturn($budgetInfo);
$repository->shouldReceive('getBudgetLimits')->andReturn(new Collection([$budgetLimit]));
$this->mockDefaultSession();
$this->mockIntroPreference('shown_demo_budgets_index');
// list size
$pref = new Preference;
$pref->data = 50;
Preferences::shouldReceive('get')->withArgs(['listPageSize', 50])->atLeast()->once()->andReturn($pref);
Amount::shouldReceive('formatAnything')->andReturn('123');
$this->be($this->user());
$this->changeDateRange($this->user(), $range);
$response = $this->get(route('budgets.index'));
@@ -111,10 +114,8 @@ class IndexControllerTest extends TestCase
*/
public function testIndexOutOfRange(string $range): void
{
Log::info(sprintf('Now in testIndexOutOfRange(%s)', $range));
// mock stuff
$budget = factory(Budget::class)->make();
$budgetLimit = factory(BudgetLimit::class)->make();
$budget = $this->getRandomBudget();
$budgetLimit = $this->getRandomBudgetLimit();
$budgetInfo = [
$budget->id => [
'spent' => '0',
@@ -129,7 +130,6 @@ class IndexControllerTest extends TestCase
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$repository = $this->mock(BudgetRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
$date = new Carbon;
@@ -137,7 +137,6 @@ class IndexControllerTest extends TestCase
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
$accountRepos->shouldReceive('getAccountsByType')->andReturn(new Collection);
$repository->shouldReceive('cleanupBudgets');
@@ -148,6 +147,14 @@ class IndexControllerTest extends TestCase
$repository->shouldReceive('getBudgetLimits')->andReturn(new Collection([$budgetLimit]));
$repository->shouldReceive('collectBudgetInformation')->andReturn($budgetInfo);
$this->mockDefaultSession();
$this->mockIntroPreference('shown_demo_budgets_index');
// list size
$pref = new Preference;
$pref->data = 50;
Preferences::shouldReceive('get')->withArgs(['listPageSize', 50])->atLeast()->once()->andReturn($pref);
Amount::shouldReceive('formatAnything')->andReturn('123');
$this->be($this->user());
$today = new Carbon;
$today->startOfMonth();
@@ -166,10 +173,8 @@ class IndexControllerTest extends TestCase
*/
public function testIndexWithDate(string $range): void
{
Log::info(sprintf('Now in testIndexWithDate(%s)', $range));
// mock stuff
$budget = factory(Budget::class)->make();
$budgetLimit = factory(BudgetLimit::class)->make();
$budget = $this->getRandomBudget();
$budgetLimit = $this->getRandomBudgetLimit();
$budgetInfo = [
$budget->id => [
'spent' => '0',
@@ -184,17 +189,13 @@ class IndexControllerTest extends TestCase
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$repository = $this->mock(BudgetRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
$date = new Carbon;
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
$accountRepos->shouldReceive('getAccountsByType')->andReturn(new Collection);
$repository->shouldReceive('cleanupBudgets');
$repository->shouldReceive('getActiveBudgets')->andReturn(new Collection([$budget]));
$repository->shouldReceive('getInactiveBudgets')->andReturn(new Collection);
@@ -203,6 +204,14 @@ class IndexControllerTest extends TestCase
$repository->shouldReceive('getBudgetLimits')->andReturn(new Collection([$budgetLimit]));
$repository->shouldReceive('collectBudgetInformation')->andReturn($budgetInfo);
$this->mockDefaultSession();
$this->mockIntroPreference('shown_demo_budgets_index');
// list size
$pref = new Preference;
$pref->data = 50;
Preferences::shouldReceive('get')->withArgs(['listPageSize', 50])->atLeast()->once()->andReturn($pref);
Amount::shouldReceive('formatAnything')->andReturn('123');
$this->be($this->user());
$this->changeDateRange($this->user(), $range);
$response = $this->get(route('budgets.index', ['2017-01-01']));
@@ -219,36 +228,24 @@ class IndexControllerTest extends TestCase
*/
public function testIndexWithInvalidDate(string $range): void
{
Log::info(sprintf('Now in testIndexWithInvalidDate(%s)', $range));
// mock stuff
$budget = factory(Budget::class)->make();
$budgetLimit = factory(BudgetLimit::class)->make();
$budgetLimit = $this->getRandomBudgetLimit();
// set budget limit to current month:
$budgetLimit->start_date = Carbon::now()->startOfMonth();
$budgetLimit->end_date = Carbon::now()->endOfMonth();
$budgetInfo = [
$budget->id => [
'spent' => '0',
'budgeted' => '0',
'currentRep' => false,
],
];
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$repository = $this->mock(BudgetRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$this->mock(UserRepositoryInterface::class);
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
$date = new Carbon;
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
$accountRepos->shouldReceive('getAccountsByType')->andReturn(new Collection);
$repository->shouldReceive('cleanupBudgets');
$this->mockDefaultSession();
Amount::shouldReceive('formatAnything')->andReturn('123');
$this->be($this->user());
$this->changeDateRange($this->user(), $range);
$response = $this->get(route('budgets.index', ['Hello-there']));

View File

@@ -23,10 +23,12 @@ declare(strict_types=1);
namespace Tests\Feature\Controllers\Budget;
use Amount;
use Carbon\Carbon;
use FireflyIII\Helpers\Collector\TransactionCollectorInterface;
use FireflyIII\Helpers\FiscalHelperInterface;
use FireflyIII\Models\BudgetLimit;
use Exception;
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
use FireflyIII\Helpers\Fiscal\FiscalHelperInterface;
use FireflyIII\Models\Preference;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
@@ -36,11 +38,13 @@ use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\Collection;
use Log;
use Mockery;
use Preferences;
use Tests\TestCase;
/**
*
* Class ShowControllerTest
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
class ShowControllerTest extends TestCase
{
@@ -63,36 +67,41 @@ class ShowControllerTest extends TestCase
*/
public function testNoBudget(string $range): void
{
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
Log::info(sprintf('Now in testNoBudget(%s)', $range));
// mock stuff
$repository = $this->mock(BudgetRepositoryInterface::class);
$collector = $this->mock(TransactionCollectorInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$this->mock(BudgetRepositoryInterface::class);
$collector = $this->mock(GroupCollectorInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
$this->mockDefaultSession();
try {
$date = new Carbon;
} catch (Exception $e) {
$e->getMessage();
}
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
// mock calls
$pref = new Preference;
$pref->data = 50;
Preferences::shouldReceive('get')->withArgs(['listPageSize', 50])->atLeast()->once()->andReturn($pref);
Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
$collector->shouldReceive('setRange')->andReturnSelf()->atLeast()->once();
$collector->shouldReceive('setLimit')->andReturnSelf()->atLeast()->once();
$collector->shouldReceive('setPage')->andReturnSelf()->atLeast()->once();
$collector->shouldReceive('setTypes')->andReturnSelf()->atLeast()->once();
$collector->shouldReceive('withoutBudget')->andReturnSelf()->atLeast()->once();
$collector->shouldReceive('withAccountInformation')->andReturnSelf()->atLeast()->once();
$collector->shouldReceive('getPaginatedGroups')->andReturn(new LengthAwarePaginator([], 0, 10))->atLeast()->once();
$collector->shouldReceive('getExtractedJournals')->andReturn([])->atLeast()->once();
$journalRepos->shouldReceive('firstNull')->andReturn(null);
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf();
$collector->shouldReceive('setRange')->andReturnSelf();
$collector->shouldReceive('getTransactions')->andReturn(new Collection);
$collector->shouldReceive('setLimit')->andReturnSelf();
$collector->shouldReceive('setPage')->andReturnSelf();
$collector->shouldReceive('setTypes')->andReturnSelf();
$collector->shouldReceive('withoutBudget')->andReturnSelf();
$collector->shouldReceive('withOpposingAccount')->andReturnSelf();
$collector->shouldReceive('getPaginatedTransactions')->andReturn(new LengthAwarePaginator([], 0, 10));
$date = new Carbon();
$this->session(['start' => $date, 'end' => clone $date]);
$this->be($this->user());
$this->changeDateRange($this->user(), $range);
$response = $this->get(route('budgets.no-budget'));
$response = $this->get(route('budgets.no-budget', ['2019-01-01', '2019-01-31']));
$response->assertStatus(200);
// has bread crumb
$response->assertSee('<ol class="breadcrumb">');
@@ -106,30 +115,35 @@ class ShowControllerTest extends TestCase
*/
public function testNoBudgetAll(string $range): void
{
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
$this->mock(BudgetRepositoryInterface::class);
$collector = $this->mock(GroupCollectorInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$this->mockDefaultSession();
try {
$date = new Carbon;
} catch (Exception $e) {
$e->getMessage();
}
return;
Log::info(sprintf('Now in testNoBudgetAll(%s)', $range));
// mock stuff
$repository = $this->mock(BudgetRepositoryInterface::class);
$collector = $this->mock(TransactionCollectorInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
// mock calls
$pref = new Preference;
$pref->data = 50;
Preferences::shouldReceive('get')->withArgs(['listPageSize', 50])->atLeast()->once()->andReturn($pref);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
$journalRepos->shouldReceive('firstNull')->andReturn(null);
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf();
$collector->shouldReceive('setRange')->andReturnSelf();
$collector->shouldReceive('setLimit')->andReturnSelf();
$collector->shouldReceive('setTypes')->andReturnSelf();
$collector->shouldReceive('setPage')->andReturnSelf();
$collector->shouldReceive('withOpposingAccount')->andReturnSelf();
$collector->shouldReceive('withoutBudget')->andReturnSelf();
$collector->shouldReceive('setTypes')->andReturnSelf();
$collector->shouldReceive('getTransactions')->andReturn(new Collection);
$collector->shouldReceive('getPaginatedTransactions')->andReturn(new LengthAwarePaginator([], 0, 10));
$collector->shouldReceive('setRange')->andReturnSelf()->atLeast()->once();
$collector->shouldReceive('setLimit')->andReturnSelf()->atLeast()->once();
$collector->shouldReceive('setPage')->andReturnSelf()->atLeast()->once();
$collector->shouldReceive('setTypes')->andReturnSelf()->atLeast()->once();
$collector->shouldReceive('withoutBudget')->andReturnSelf()->atLeast()->once();
$collector->shouldReceive('withAccountInformation')->andReturnSelf()->atLeast()->once();
$collector->shouldReceive('getPaginatedGroups')->andReturn(new LengthAwarePaginator([], 0, 10))->atLeast()->once();
$date = new Carbon();
try {
$date = new Carbon;
} catch (Exception $e) {
$e->getMessage();
}
$this->session(['start' => $date, 'end' => clone $date]);
$this->be($this->user());
@@ -140,53 +154,6 @@ class ShowControllerTest extends TestCase
$response->assertSee('<ol class="breadcrumb">');
}
/**
* @covers \FireflyIII\Http\Controllers\Budget\ShowController
* @dataProvider dateRangeProvider
*
* @param string $range
*/
public function testNoBudgetDate(string $range): void
{
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
Log::info(sprintf('Now in testNoBudgetDate(%s)', $range));
// mock stuff
$repository = $this->mock(BudgetRepositoryInterface::class);
$collector = $this->mock(TransactionCollectorInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
$date = new Carbon;
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
$journalRepos->shouldReceive('firstNull')->andReturn(null);
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf();
$collector->shouldReceive('setRange')->andReturnSelf();
$collector->shouldReceive('getTransactions')->andReturn(new Collection);
$collector->shouldReceive('setLimit')->andReturnSelf();
$collector->shouldReceive('setPage')->andReturnSelf();
$collector->shouldReceive('withOpposingAccount')->andReturnSelf();
$collector->shouldReceive('setTypes')->andReturnSelf();
$collector->shouldReceive('withoutBudget')->andReturnSelf();
$collector->shouldReceive('getPaginatedTransactions')->andReturn(new LengthAwarePaginator([], 0, 10));
$date = new Carbon();
$this->session(['start' => $date, 'end' => clone $date]);
$this->be($this->user());
$this->changeDateRange($this->user(), $range);
$response = $this->get(route('budgets.no-budget', ['2016-01-01']));
$response->assertStatus(200);
// has bread crumb
$response->assertSee('<ol class="breadcrumb">');
}
/**
* @covers \FireflyIII\Http\Controllers\Budget\ShowController
* @dataProvider dateRangeProvider
@@ -195,31 +162,29 @@ class ShowControllerTest extends TestCase
*/
public function testShow(string $range): void
{
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
Log::info(sprintf('Now in testShow(%s)', $range));
// mock stuff
$budgetLimit = factory(BudgetLimit::class)->make();
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$budgetLimit = $this->getRandomBudgetLimit();
$userRepos = $this->mock(UserRepositoryInterface::class);
$collector = $this->mock(TransactionCollectorInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$repository = $this->mock(BudgetRepositoryInterface::class);
$collector = $this->mock(GroupCollectorInterface::class);
$this->mockDefaultSession();
// mock calls
$pref = new Preference;
$pref->data = 50;
Preferences::shouldReceive('get')->withArgs(['listPageSize', 50])->atLeast()->once()->andReturn($pref);
Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
Amount::shouldReceive('formatAnything')->atLeast()->once()->andReturn('-100');
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
$journalRepos->shouldReceive('firstNull')->andReturn(new TransactionJournal);
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf();
$collector->shouldReceive('setRange')->andReturnSelf();
$collector->shouldReceive('setLimit')->andReturnSelf();
$collector->shouldReceive('setPage')->andReturnSelf();
$collector->shouldReceive('setBudget')->andReturnSelf();
$collector->shouldReceive('getPaginatedTransactions')->andReturn(new LengthAwarePaginator([], 0, 10));
$collector->shouldReceive('withBudgetInformation')->andReturnSelf();
$collector->shouldReceive('setRange')->andReturnSelf()->atLeast()->once();
$collector->shouldReceive('setLimit')->andReturnSelf()->atLeast()->once();
$collector->shouldReceive('setPage')->andReturnSelf()->atLeast()->once();
$collector->shouldReceive('setBudget')->andReturnSelf()->atLeast()->once();
$collector->shouldReceive('withBudgetInformation')->andReturnSelf()->atLeast()->once();
$collector->shouldReceive('getPaginatedGroups')->andReturn(new LengthAwarePaginator([], 0, 10))->atLeast()->once();
$accountRepos->shouldReceive('getAccountsByType')->andReturn(new Collection);
@@ -228,9 +193,14 @@ class ShowControllerTest extends TestCase
$repository->shouldReceive('getBudgetLimits')->andReturn(new Collection([$budgetLimit]));
$repository->shouldReceive('spentInPeriod')->andReturn('-1');
$date = new Carbon();
$date->subDay();
$this->session(['first' => $date]);
try {
$date = new Carbon;
$date->subDay();
$this->session(['first' => $date]);
} catch (Exception $e) {
$e->getMessage();
}
$this->be($this->user());
$this->changeDateRange($this->user(), $range);
@@ -239,24 +209,6 @@ class ShowControllerTest extends TestCase
$response->assertSee('<ol class="breadcrumb">');
}
/**
* @covers \FireflyIII\Http\Controllers\Budget\ShowController
*/
public function testShowByBadBudgetLimit(): void
{
Log::info('Now in testShowByBadBudgetLimit()');
// mock stuff
$repository = $this->mock(BudgetRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
$this->be($this->user());
$response = $this->get(route('budgets.show.limit', [1, 8]));
$response->assertStatus(500);
}
/**
* @covers \FireflyIII\Http\Controllers\Budget\ShowController
* @dataProvider dateRangeProvider
@@ -265,29 +217,32 @@ class ShowControllerTest extends TestCase
*/
public function testShowByBudgetLimit(string $range): void
{
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
Log::info(sprintf('Now in testShowByBudgetLimit(%s)', $range));
// mock stuff
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$accountRepository = $this->mock(AccountRepositoryInterface::class);
$budgetRepository = $this->mock(BudgetRepositoryInterface::class);
$collector = $this->mock(TransactionCollectorInterface::class);
$collector = $this->mock(GroupCollectorInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$this->mockDefaultSession();
// mock calls
$pref = new Preference;
$pref->data = 50;
Preferences::shouldReceive('get')->withArgs(['listPageSize', 50])->atLeast()->once()->andReturn($pref);
Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
$accountRepository->shouldReceive('getAccountsByType')->andReturn(new Collection);
$budgetRepository->shouldReceive('spentInPeriod')->andReturn('1');
$budgetRepository->shouldReceive('getBudgetLimits')->andReturn(new Collection);
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf();
$collector->shouldReceive('setRange')->andReturnSelf();
$collector->shouldReceive('setLimit')->andReturnSelf();
$collector->shouldReceive('setPage')->andReturnSelf();
$collector->shouldReceive('setBudget')->andReturnSelf();
$collector->shouldReceive('withBudgetInformation')->andReturnSelf();
$collector->shouldReceive('getPaginatedTransactions')->andReturn(new LengthAwarePaginator([], 0, 10));
$collector->shouldReceive('setRange')->andReturnSelf()->atLeast()->once();
$collector->shouldReceive('setLimit')->andReturnSelf()->atLeast()->once();
$collector->shouldReceive('setPage')->andReturnSelf()->atLeast()->once();
$collector->shouldReceive('setBudget')->andReturnSelf()->atLeast()->once();
$collector->shouldReceive('withBudgetInformation')->andReturnSelf()->atLeast()->once();
$collector->shouldReceive('getPaginatedGroups')->andReturn(new LengthAwarePaginator([], 0, 10))->atLeast()->once();
$this->be($this->user());
$this->changeDateRange($this->user(), $range);