Expand tests.

This commit is contained in:
James Cole
2017-03-12 08:38:13 +01:00
parent 8f14c78ba1
commit 65dbfcba5c
4 changed files with 102 additions and 18 deletions

View File

@@ -36,7 +36,7 @@ $factory->define(
$factory->define(
FireflyIII\Models\Tag::class, function (Faker\Generator $faker) {
return [
'id' => $faker->numberBetween(1, 10),
'id' => $faker->numberBetween(1, 10),
'tag' => $faker->words(1, true),
];
}
@@ -60,6 +60,19 @@ $factory->define(
}
);
$factory->define(
FireflyIII\Models\BudgetLimit::class, function (Faker\Generator $faker) {
return [
'id' => $faker->numberBetween(1, 10),
'start_date' => '2017-01-01',
'end_date' => '2017-01-31',
'amount' => '300',
'budget_id' => $faker->numberBetween(1, 6),
];
}
);
$factory->define(
FireflyIII\Models\Account::class, function (Faker\Generator $faker) {
return [

View File

@@ -58,9 +58,9 @@ class AccountControllerTest extends TestCase
*/
public function testExpenseBudget(string $range)
{
$generator = $this->mock(GeneratorInterface::class);
$collector = $this->mock(JournalCollectorInterface::class);
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
$generator = $this->mock(GeneratorInterface::class);
$collector = $this->mock(JournalCollectorInterface::class);
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
$collector->shouldReceive('setAccounts')->andReturnSelf();
$collector->shouldReceive('setRange')->andReturnSelf();
@@ -114,8 +114,8 @@ class AccountControllerTest extends TestCase
*/
public function testFrontpage(string $range)
{
$generator = $this->mock(GeneratorInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$generator = $this->mock(GeneratorInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$accountRepos->shouldReceive('getAccountsByType')->withArgs([[AccountType::DEFAULT, AccountType::ASSET]])->andReturn(new Collection);
$accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection);
@@ -162,8 +162,8 @@ class AccountControllerTest extends TestCase
*/
public function testPeriod(string $range)
{
$generator = $this->mock(GeneratorInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$generator = $this->mock(GeneratorInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$accountRepos->shouldReceive('oldestJournalDate')->andReturn(new Carbon);
Steam::shouldReceive('balanceInRange')->andReturn(['2012-01-01' => '0']);
@@ -181,7 +181,7 @@ class AccountControllerTest extends TestCase
*/
public function testReport()
{
$generator = $this->mock(GeneratorInterface::class);
$generator = $this->mock(GeneratorInterface::class);
$generator->shouldReceive('multiSet')->andreturn([]);
$this->be($this->user());
@@ -197,8 +197,8 @@ class AccountControllerTest extends TestCase
*/
public function testRevenueAccounts(string $range)
{
$generator = $this->mock(GeneratorInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$generator = $this->mock(GeneratorInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$accountRepos->shouldReceive('getAccountsByType')->withArgs([[AccountType::REVENUE]])->andReturn(new Collection);
$generator->shouldReceive('singleSet')->andReturn([]);
@@ -218,7 +218,7 @@ class AccountControllerTest extends TestCase
*/
public function testSingle(string $range)
{
$generator = $this->mock(GeneratorInterface::class);
$generator = $this->mock(GeneratorInterface::class);
Steam::shouldReceive('balanceInRange')->andReturn(['2012-01-01' => '0']);
$generator->shouldReceive('singleSet')->andReturn([]);

View File

@@ -12,9 +12,12 @@ declare(strict_types = 1);
namespace Tests\Feature\Controllers\Chart;
use FireflyIII\Generator\Chart\Basic\GeneratorInterface;
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
use Illuminate\Support\Collection;
use Tests\TestCase;
class BillControllerTest extends TestCase
{
/**
@@ -26,6 +29,13 @@ class BillControllerTest extends TestCase
*/
public function testFrontpage(string $range)
{
$generator = $this->mock(GeneratorInterface::class);
$repository = $this->mock(BillRepositoryInterface::class);
$repository->shouldReceive('getBillsPaidInRange')->once()->andReturn('-1');
$repository->shouldReceive('getBillsUnpaidInRange')->once()->andReturn('2');
$generator->shouldReceive('pieChart')->once()->andReturn([]);
$this->be($this->user());
$this->changeDateRange($this->user(), $range);
$response = $this->get(route('chart.bill.frontpage'));
@@ -37,6 +47,15 @@ class BillControllerTest extends TestCase
*/
public function testSingle()
{
$generator = $this->mock(GeneratorInterface::class);
$collector = $this->mock(JournalCollectorInterface::class);
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf()->once();
$collector->shouldReceive('setBills')->andReturnSelf()->once();
$collector->shouldReceive('getJournals')->andReturn(new Collection)->once();
$generator->shouldReceive('multiSet')->once()->andReturn([]);
$this->be($this->user());
$response = $this->get(route('chart.bill.single', [1]));
$response->assertStatus(200);

View File

@@ -13,7 +13,13 @@ namespace Tests\Feature\Controllers\Chart;
use Carbon\Carbon;
use FireflyIII\Generator\Chart\Basic\GeneratorInterface;
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
use FireflyIII\Models\Budget;
use FireflyIII\Models\BudgetLimit;
use FireflyIII\Models\TransactionType;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use Illuminate\Support\Collection;
use Tests\TestCase;
class BudgetControllerTest extends TestCase
@@ -28,9 +34,12 @@ class BudgetControllerTest extends TestCase
*/
public function testBudget(string $range)
{
$budgetRepository = $this->mock(BudgetRepositoryInterface::class);
$budgetRepository->shouldReceive('firstUseDate')->andReturn(new Carbon('2015-01-01'));
$budgetRepository->shouldReceive('spentInPeriod')->andReturn('-100');
$repository = $this->mock(BudgetRepositoryInterface::class);
$generator = $this->mock(GeneratorInterface::class);
$repository->shouldReceive('firstUseDate')->andReturn(new Carbon('2015-01-01'))->once();
$repository->shouldReceive('spentInPeriod')->andReturn('-100');
$generator->shouldReceive('singleSet')->andReturn([])->once();
$this->be($this->user());
@@ -47,8 +56,12 @@ class BudgetControllerTest extends TestCase
*/
public function testBudgetLimit(string $range)
{
$budgetRepository = $this->mock(BudgetRepositoryInterface::class);
$budgetRepository->shouldReceive('spentInPeriod')->andReturn('-100');
$repository = $this->mock(BudgetRepositoryInterface::class);
$generator = $this->mock(GeneratorInterface::class);
$repository->shouldReceive('spentInPeriod')->andReturn('-100');
$generator->shouldReceive('singleSet')->once()->andReturn([]);
$this->be($this->user());
$this->changeDateRange($this->user(), $range);
@@ -58,12 +71,33 @@ class BudgetControllerTest extends TestCase
/**
* @covers \FireflyIII\Http\Controllers\Chart\BudgetController::frontpage
* @covers \FireflyIII\Http\Controllers\Chart\BudgetController::getExpensesForBudget
* @covers \FireflyIII\Http\Controllers\Chart\BudgetController::spentInPeriodWithout
* @dataProvider dateRangeProvider
*
* @param string $range
*/
public function testFrontpage(string $range)
{
$repository = $this->mock(BudgetRepositoryInterface::class);
$generator = $this->mock(GeneratorInterface::class);
$collector = $this->mock(JournalCollectorInterface::class);
$budget = factory(Budget::class)->make();
$budgetLimit = factory(BudgetLimit::class)->make();
$budgetLimit->budget_id = $budget->id;
$repository->shouldReceive('getActiveBudgets')->andReturn(new Collection([$budget]));
$repository->shouldReceive('getBudgetLimits')->once()->andReturn(new Collection([$budgetLimit]));
$repository->shouldReceive('spentInPeriod')->andReturn('-100');
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf();
$collector->shouldReceive('setTypes')->withArgs([[TransactionType::WITHDRAWAL]])->andReturnSelf();
$collector->shouldReceive('setRange')->andReturnSelf();
$collector->shouldReceive('withoutBudget')->andReturnSelf();
$collector->shouldReceive('getJournals')->andReturn(new Collection);
$generator->shouldReceive('multiSet')->once()->andReturn([]);
$this->be($this->user());
$this->changeDateRange($this->user(), $range);
$response = $this->get(route('chart.budget.frontpage'));
@@ -72,9 +106,21 @@ class BudgetControllerTest extends TestCase
/**
* @covers \FireflyIII\Http\Controllers\Chart\BudgetController::period
* @covers \FireflyIII\Http\Controllers\Chart\BudgetController::getBudgetedInPeriod
*/
public function testPeriod()
{
$repository = $this->mock(BudgetRepositoryInterface::class);
$generator = $this->mock(GeneratorInterface::class);
$budget = factory(Budget::class)->make();
$budgetLimit = factory(BudgetLimit::class)->make();
$budgetLimit->budget_id = $budget->id;
$repository->shouldReceive('getBudgetPeriodReport')->andReturn([])->once();
$repository->shouldReceive('getBudgetLimits')->andReturn(new Collection([$budgetLimit]));
$generator->shouldReceive('multiSet')->once()->andReturn([]);
$this->be($this->user());
$response = $this->get(route('chart.budget.period', [1, '1', '20120101', '20120131']));
$response->assertStatus(200);
@@ -85,6 +131,12 @@ class BudgetControllerTest extends TestCase
*/
public function testPeriodNoBudget()
{
$repository = $this->mock(BudgetRepositoryInterface::class);
$generator = $this->mock(GeneratorInterface::class);
$repository->shouldReceive('getNoBudgetPeriodReport')->andReturn([])->once();
$generator->shouldReceive('singleSet')->once()->andReturn([]);
$this->be($this->user());
$response = $this->get(route('chart.budget.period.no-budget', ['1', '20120101', '20120131']));
$response->assertStatus(200);