mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-24 22:48:18 +00:00
Improve test coverage.
This commit is contained in:
@@ -103,7 +103,7 @@ class BudgetControllerTest extends TestCase
|
||||
|
||||
$repository->shouldReceive('destroy')->andReturn(true);
|
||||
|
||||
$this->session(['budgets.delete.url' => 'http://localhost']);
|
||||
$this->session(['budgets.delete.uri' => 'http://localhost']);
|
||||
$this->be($this->user());
|
||||
$response = $this->post(route('budgets.destroy', [1]));
|
||||
$response->assertStatus(302);
|
||||
@@ -137,6 +137,13 @@ class BudgetControllerTest extends TestCase
|
||||
public function testIndex(string $range)
|
||||
{
|
||||
// mock stuff
|
||||
$budget = factory(Budget::class)->make();
|
||||
$budgetLimit = factory(BudgetLimit::class)->make();
|
||||
|
||||
// set budget limit to current month:
|
||||
$budgetLimit->start_date = Carbon::now()->startOfMonth();
|
||||
$budgetLimit->end_date = Carbon::now()->endOfMonth();
|
||||
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
@@ -144,9 +151,11 @@ class BudgetControllerTest extends TestCase
|
||||
$accountRepos->shouldReceive('getAccountsByType')->andReturn(new Collection);
|
||||
|
||||
$repository->shouldReceive('cleanupBudgets');
|
||||
$repository->shouldReceive('getActiveBudgets')->andReturn(new Collection);
|
||||
$repository->shouldReceive('getActiveBudgets')->andReturn(new Collection([$budget]));
|
||||
$repository->shouldReceive('getInactiveBudgets')->andReturn(new Collection);
|
||||
$repository->shouldReceive('getAvailableBudget')->andReturn('100.123');
|
||||
$repository->shouldReceive('spentInPeriod')->andReturn('-1');
|
||||
$repository->shouldReceive('getBudgetLimits')->andReturn(new Collection([$budgetLimit]));
|
||||
|
||||
|
||||
$this->be($this->user());
|
||||
@@ -292,6 +301,9 @@ class BudgetControllerTest extends TestCase
|
||||
public function testShow(string $range)
|
||||
{
|
||||
// mock stuff
|
||||
|
||||
$budgetLimit = factory(BudgetLimit::class)->make();
|
||||
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$journalRepos->shouldReceive('first')->andReturn(new TransactionJournal);
|
||||
|
||||
@@ -308,8 +320,8 @@ class BudgetControllerTest extends TestCase
|
||||
$accountRepos->shouldReceive('getAccountsByType')->andReturn(new Collection);
|
||||
|
||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||
$repository->shouldReceive('getBudgetLimits')->andReturn(new Collection);
|
||||
$repository->shouldReceive('spentInPeriod')->andReturn('1');
|
||||
$repository->shouldReceive('getBudgetLimits')->andReturn(new Collection([$budgetLimit]));
|
||||
$repository->shouldReceive('spentInPeriod')->andReturn('-1');
|
||||
|
||||
$date = new Carbon();
|
||||
$date->subDay();
|
||||
@@ -322,6 +334,22 @@ class BudgetControllerTest extends TestCase
|
||||
$response->assertSee('<ol class="breadcrumb">');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\BudgetController::showByBudgetLimit
|
||||
* @expectedExceptionMessage This budget limit is not part of
|
||||
*
|
||||
*/
|
||||
public function testShowByBadBudgetLimit()
|
||||
{
|
||||
// mock stuff
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('budgets.show.limit', [1, 8]));
|
||||
$response->assertStatus(500);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\BudgetController::showByBudgetLimit()
|
||||
* @dataProvider dateRangeProvider
|
||||
@@ -375,7 +403,7 @@ class BudgetControllerTest extends TestCase
|
||||
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
||||
$repository->shouldReceive('find')->andReturn($budget);
|
||||
$repository->shouldReceive('store')->andReturn($budget);
|
||||
$this->session(['budgets.create.url' => 'http://localhost']);
|
||||
$this->session(['budgets.create.uri' => 'http://localhost']);
|
||||
|
||||
$data = [
|
||||
'name' => 'New Budget ' . rand(1000, 9999),
|
||||
@@ -399,7 +427,7 @@ class BudgetControllerTest extends TestCase
|
||||
$repository->shouldReceive('find')->andReturn($budget);
|
||||
$repository->shouldReceive('update');
|
||||
|
||||
$this->session(['budgets.edit.url' => 'http://localhost']);
|
||||
$this->session(['budgets.edit.uri' => 'http://localhost']);
|
||||
|
||||
$data = [
|
||||
'name' => 'Updated Budget ' . rand(1000, 9999),
|
||||
|
Reference in New Issue
Block a user