Expand tests.

This commit is contained in:
James Cole 2017-03-12 09:22:33 +01:00
parent 65dbfcba5c
commit b67dfeced2
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E
13 changed files with 226 additions and 35 deletions

View File

@ -78,11 +78,8 @@ class CategoryReportController extends Controller
{ {
/** @var MetaPieChartInterface $helper */ /** @var MetaPieChartInterface $helper */
$helper = app(MetaPieChartInterface::class); $helper = app(MetaPieChartInterface::class);
$helper->setAccounts($accounts); $helper->setAccounts($accounts)->setCategories($categories)->setStart($start)->setEnd($end)->setCollectOtherObjects(intval($others) === 1);
$helper->setCategories($categories);
$helper->setStart($start);
$helper->setEnd($end);
$helper->setCollectOtherObjects(intval($others) === 1);
$chartData = $helper->generate('expense', 'account'); $chartData = $helper->generate('expense', 'account');
$data = $this->generator->pieChart($chartData); $data = $this->generator->pieChart($chartData);

View File

@ -60,6 +60,18 @@ $factory->define(
} }
); );
$factory->define(
FireflyIII\Models\PiggyBankEvent::class, function (Faker\Generator $faker) {
return [
'id' => $faker->numberBetween(1, 10),
'piggy_bank_id' => $faker->numberBetween(1, 10),
'transaction_journal_id' => $faker->numberBetween(1, 10),
'date' => $faker->date('Y-m-d'),
'amount' => '100',
];
}
);
$factory->define( $factory->define(
FireflyIII\Models\BudgetLimit::class, function (Faker\Generator $faker) { FireflyIII\Models\BudgetLimit::class, function (Faker\Generator $faker) {
return [ return [

View File

@ -16,6 +16,11 @@ use FireflyConfig;
use FireflyIII\Models\Configuration; use FireflyIII\Models\Configuration;
use Tests\TestCase; use Tests\TestCase;
/**
* Class ConfigurationControllerTest
*
* @package Tests\Feature\Controllers\Admin
*/
class ConfigurationControllerTest extends TestCase class ConfigurationControllerTest extends TestCase
{ {

View File

@ -13,6 +13,11 @@ namespace Tests\Feature\Controllers\Admin;
use Tests\TestCase; use Tests\TestCase;
/**
* Class HomeControllerTest
*
* @package Tests\Feature\Controllers\Admin
*/
class HomeControllerTest extends TestCase class HomeControllerTest extends TestCase
{ {

View File

@ -18,6 +18,11 @@ use FireflyIII\Support\Facades\Preferences;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Tests\TestCase; use Tests\TestCase;
/**
* Class UserControllerTest
*
* @package Tests\Feature\Controllers\Admin
*/
class UserControllerTest extends TestCase class UserControllerTest extends TestCase
{ {
/** /**
@ -25,8 +30,6 @@ class UserControllerTest extends TestCase
*/ */
public function testEdit() public function testEdit()
{ {
$repository = $this->mock(UserRepositoryInterface::class);
$this->be($this->user()); $this->be($this->user());
$response = $this->get(route('admin.users.edit', [1])); $response = $this->get(route('admin.users.edit', [1]));
$response->assertStatus(200); $response->assertStatus(200);

View File

@ -16,6 +16,11 @@ use FireflyIII\Models\Preference;
use Preferences; use Preferences;
use Tests\TestCase; use Tests\TestCase;
/**
* Class TwoFactorControllerTest
*
* @package Tests\Feature\Controllers\Auth
*/
class TwoFactorControllerTest extends TestCase class TwoFactorControllerTest extends TestCase
{ {
/** /**

View File

@ -24,6 +24,11 @@ use Illuminate\Support\Collection;
use Steam; use Steam;
use Tests\TestCase; use Tests\TestCase;
/**
* Class AccountControllerTest
*
* @package Tests\Feature\Controllers\Chart
*/
class AccountControllerTest extends TestCase class AccountControllerTest extends TestCase
{ {
/** /**

View File

@ -18,6 +18,11 @@ use FireflyIII\Repositories\Bill\BillRepositoryInterface;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Tests\TestCase; use Tests\TestCase;
/**
* Class BillControllerTest
*
* @package Tests\Feature\Controllers\Chart
*/
class BillControllerTest extends TestCase class BillControllerTest extends TestCase
{ {
/** /**

View File

@ -22,6 +22,11 @@ use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Tests\TestCase; use Tests\TestCase;
/**
* Class BudgetControllerTest
*
* @package Tests\Feature\Controllers\Chart
*/
class BudgetControllerTest extends TestCase class BudgetControllerTest extends TestCase
{ {

View File

@ -13,11 +13,20 @@ namespace Tests\Feature\Controllers\Chart;
use Carbon\Carbon; use Carbon\Carbon;
use FireflyIII\Generator\Chart\Basic\GeneratorInterface;
use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType;
use FireflyIII\Models\Category;
use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Category\CategoryRepositoryInterface; use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Tests\TestCase; use Tests\TestCase;
/**
* Class CategoryControllerTest
*
* @package Tests\Feature\Controllers\Chart
*/
class CategoryControllerTest extends TestCase class CategoryControllerTest extends TestCase
{ {
@ -30,11 +39,15 @@ class CategoryControllerTest extends TestCase
*/ */
public function testAll(string $range) public function testAll(string $range)
{ {
$catRepository = $this->mock(CategoryRepositoryInterface::class); $repository = $this->mock(CategoryRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$generator = $this->mock(GeneratorInterface::class);
$catRepository->shouldReceive('spentInPeriod')->andReturn('0'); $repository->shouldReceive('spentInPeriod')->andReturn('0');
$catRepository->shouldReceive('earnedInPeriod')->andReturn('0'); $repository->shouldReceive('earnedInPeriod')->andReturn('0');
$catRepository->shouldReceive('firstUseDate')->andReturn(new Carbon); $repository->shouldReceive('firstUseDate')->andReturn(new Carbon)->once();
$accountRepos->shouldReceive('getAccountsByType')->withArgs([[AccountType::DEFAULT, AccountType::ASSET]])->andReturn(new Collection)->once();
$generator->shouldReceive('multiSet')->once()->andReturn([]);
$this->be($this->user()); $this->be($this->user());
@ -52,15 +65,17 @@ class CategoryControllerTest extends TestCase
*/ */
public function testCurrentPeriod(string $range) public function testCurrentPeriod(string $range)
{ {
// this is actually for makePeriodChart $repository = $this->mock(CategoryRepositoryInterface::class);
$accountRepository = $this->mock(AccountRepositoryInterface::class); $accountRepos = $this->mock(AccountRepositoryInterface::class);
$categoryRepository = $this->mock(CategoryRepositoryInterface::class); $generator = $this->mock(GeneratorInterface::class);
$account = $this->user()->accounts()->where('account_type_id', 5)->first(); $account = factory(Account::class)->make();
$accountRepository->shouldReceive('getAccountsByType')->andReturn(new Collection([$account]));
$categoryRepository->shouldReceive('spentInPeriod')->andReturn('0');
$categoryRepository->shouldReceive('earnedInPeriod')->andReturn('0');
$accountRepos->shouldReceive('getAccountsByType')->andReturn(new Collection([$account]));
$repository->shouldReceive('spentInPeriod')->andReturn('0');
$repository->shouldReceive('earnedInPeriod')->andReturn('0');
$generator->shouldReceive('multiSet')->andReturn([])->once();
$this->be($this->user()); $this->be($this->user());
$this->changeDateRange($this->user(), $range); $this->changeDateRange($this->user(), $range);
$response = $this->get(route('chart.category.current', [1])); $response = $this->get(route('chart.category.current', [1]));
@ -75,17 +90,17 @@ class CategoryControllerTest extends TestCase
*/ */
public function testFrontpage(string $range) public function testFrontpage(string $range)
{ {
$accountRepository = $this->mock(AccountRepositoryInterface::class); $repository = $this->mock(CategoryRepositoryInterface::class);
$categoryRepository = $this->mock(CategoryRepositoryInterface::class); $accountRepos = $this->mock(AccountRepositoryInterface::class);
$category = $this->user()->categories()->first(); $generator = $this->mock(GeneratorInterface::class);
$account = $this->user()->accounts()->where('account_type_id', 5)->first(); $category = factory(Category::class)->make();
// get one category $account = factory(Account::class)->make();
$categoryRepository->shouldReceive('getCategories')->andReturn(new Collection([$category]));
// get one account $repository->shouldReceive('getCategories')->andReturn(new Collection([$category]));
$accountRepository->shouldReceive('getAccountsByType')->andReturn(new Collection([$account])); $accountRepos->shouldReceive('getAccountsByType')->andReturn(new Collection([$account]));
// always return zero $repository->shouldReceive('spentInPeriod')->andReturn('0');
$categoryRepository->shouldReceive('spentInPeriod')->andReturn('0'); $repository->shouldReceive('spentInPeriodWithoutCategory')->andReturn('0');
$categoryRepository->shouldReceive('spentInPeriodWithoutCategory')->andReturn('0'); $generator->shouldReceive('singleSet')->andReturn([]);
$this->be($this->user()); $this->be($this->user());
$this->changeDateRange($this->user(), $range); $this->changeDateRange($this->user(), $range);
@ -98,6 +113,14 @@ class CategoryControllerTest extends TestCase
*/ */
public function testReportPeriod() public function testReportPeriod()
{ {
$repository = $this->mock(CategoryRepositoryInterface::class);
$generator = $this->mock(GeneratorInterface::class);
$repository->shouldReceive('periodExpenses')->andReturn([])->once();
$repository->shouldReceive('periodIncome')->andReturn([])->once();
$generator->shouldReceive('multiSet')->andReturn([])->once();
$this->be($this->user()); $this->be($this->user());
$response = $this->get(route('chart.category.period', [1, '1', '20120101', '20120131'])); $response = $this->get(route('chart.category.period', [1, '1', '20120101', '20120131']));
$response->assertStatus(200); $response->assertStatus(200);
@ -108,6 +131,13 @@ class CategoryControllerTest extends TestCase
*/ */
public function testReportPeriodNoCategory() public function testReportPeriodNoCategory()
{ {
$repository = $this->mock(CategoryRepositoryInterface::class);
$generator = $this->mock(GeneratorInterface::class);
$repository->shouldReceive('periodExpensesNoCategory')->andReturn([])->once();
$repository->shouldReceive('periodIncomeNoCategory')->andReturn([])->once();
$generator->shouldReceive('multiSet')->andReturn([])->once();
$this->be($this->user()); $this->be($this->user());
$response = $this->get(route('chart.category.period.no-category', ['1', '20120101', '20120131'])); $response = $this->get(route('chart.category.period.no-category', ['1', '20120101', '20120131']));
$response->assertStatus(200); $response->assertStatus(200);
@ -122,12 +152,15 @@ class CategoryControllerTest extends TestCase
*/ */
public function testSpecificPeriod(string $range) public function testSpecificPeriod(string $range)
{ {
$accountRepository = $this->mock(AccountRepositoryInterface::class); $repository = $this->mock(CategoryRepositoryInterface::class);
$categoryRepository = $this->mock(CategoryRepositoryInterface::class); $accountRepos = $this->mock(AccountRepositoryInterface::class);
$account = $this->user()->accounts()->where('account_type_id', 5)->first(); $generator = $this->mock(GeneratorInterface::class);
$accountRepository->shouldReceive('getAccountsByType')->andReturn(new Collection([$account])); $account = factory(Account::class)->make();
$categoryRepository->shouldReceive('spentInPeriod')->andReturn('0');
$categoryRepository->shouldReceive('earnedInPeriod')->andReturn('0'); $accountRepos->shouldReceive('getAccountsByType')->andReturn(new Collection([$account]));
$repository->shouldReceive('spentInPeriod')->andReturn('0');
$repository->shouldReceive('earnedInPeriod')->andReturn('0');
$generator->shouldReceive('multiSet')->andReturn([])->once();
$this->be($this->user()); $this->be($this->user());
$this->changeDateRange($this->user(), $range); $this->changeDateRange($this->user(), $range);

View File

@ -12,8 +12,18 @@ declare(strict_types = 1);
namespace Tests\Feature\Controllers\Chart; namespace Tests\Feature\Controllers\Chart;
use FireflyIII\Generator\Chart\Basic\GeneratorInterface;
use FireflyIII\Helpers\Chart\MetaPieChartInterface;
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
use FireflyIII\Models\TransactionType;
use Illuminate\Support\Collection;
use Tests\TestCase; use Tests\TestCase;
/**
* Class CategoryReportControllerTest
*
* @package Tests\Feature\Controllers\Chart
*/
class CategoryReportControllerTest extends TestCase class CategoryReportControllerTest extends TestCase
{ {
@ -23,6 +33,17 @@ class CategoryReportControllerTest extends TestCase
*/ */
public function testAccountExpense() public function testAccountExpense()
{ {
$generator = $this->mock(GeneratorInterface::class);
$pieChart = $this->mock(MetaPieChartInterface::class);
$pieChart->shouldReceive('setAccounts')->once()->andReturnSelf();
$pieChart->shouldReceive('setCategories')->once()->andReturnSelf();
$pieChart->shouldReceive('setStart')->once()->andReturnSelf();
$pieChart->shouldReceive('setEnd')->once()->andReturnSelf();
$pieChart->shouldReceive('setCollectOtherObjects')->once()->andReturnSelf()->withArgs([false]);
$pieChart->shouldReceive('generate')->withArgs(['expense', 'account'])->andReturn([])->once();
$generator->shouldReceive('pieChart')->andReturn([])->once();
$this->be($this->user()); $this->be($this->user());
$response = $this->get(route('chart.category.account-expense', ['1', '1', '20120101', '20120131', 0])); $response = $this->get(route('chart.category.account-expense', ['1', '1', '20120101', '20120131', 0]));
$response->assertStatus(200); $response->assertStatus(200);
@ -33,6 +54,17 @@ class CategoryReportControllerTest extends TestCase
*/ */
public function testAccountIncome() public function testAccountIncome()
{ {
$generator = $this->mock(GeneratorInterface::class);
$pieChart = $this->mock(MetaPieChartInterface::class);
$pieChart->shouldReceive('setAccounts')->once()->andReturnSelf();
$pieChart->shouldReceive('setCategories')->once()->andReturnSelf();
$pieChart->shouldReceive('setStart')->once()->andReturnSelf();
$pieChart->shouldReceive('setEnd')->once()->andReturnSelf();
$pieChart->shouldReceive('setCollectOtherObjects')->once()->andReturnSelf()->withArgs([false]);
$pieChart->shouldReceive('generate')->withArgs(['income', 'account'])->andReturn([])->once();
$generator->shouldReceive('pieChart')->andReturn([])->once();
$this->be($this->user()); $this->be($this->user());
$response = $this->get(route('chart.category.account-income', ['1', '1', '20120101', '20120131', 0])); $response = $this->get(route('chart.category.account-income', ['1', '1', '20120101', '20120131', 0]));
$response->assertStatus(200); $response->assertStatus(200);
@ -43,6 +75,17 @@ class CategoryReportControllerTest extends TestCase
*/ */
public function testCategoryExpense() public function testCategoryExpense()
{ {
$generator = $this->mock(GeneratorInterface::class);
$pieChart = $this->mock(MetaPieChartInterface::class);
$pieChart->shouldReceive('setAccounts')->once()->andReturnSelf();
$pieChart->shouldReceive('setCategories')->once()->andReturnSelf();
$pieChart->shouldReceive('setStart')->once()->andReturnSelf();
$pieChart->shouldReceive('setEnd')->once()->andReturnSelf();
$pieChart->shouldReceive('setCollectOtherObjects')->once()->andReturnSelf()->withArgs([false]);
$pieChart->shouldReceive('generate')->withArgs(['expense', 'category'])->andReturn([])->once();
$generator->shouldReceive('pieChart')->andReturn([])->once();
$this->be($this->user()); $this->be($this->user());
$response = $this->get(route('chart.category.category-expense', ['1', '1', '20120101', '20120131', 0])); $response = $this->get(route('chart.category.category-expense', ['1', '1', '20120101', '20120131', 0]));
$response->assertStatus(200); $response->assertStatus(200);
@ -53,6 +96,17 @@ class CategoryReportControllerTest extends TestCase
*/ */
public function testCategoryIncome() public function testCategoryIncome()
{ {
$generator = $this->mock(GeneratorInterface::class);
$pieChart = $this->mock(MetaPieChartInterface::class);
$pieChart->shouldReceive('setAccounts')->once()->andReturnSelf();
$pieChart->shouldReceive('setCategories')->once()->andReturnSelf();
$pieChart->shouldReceive('setStart')->once()->andReturnSelf();
$pieChart->shouldReceive('setEnd')->once()->andReturnSelf();
$pieChart->shouldReceive('setCollectOtherObjects')->once()->andReturnSelf()->withArgs([false]);
$pieChart->shouldReceive('generate')->withArgs(['income', 'category'])->andReturn([])->once();
$generator->shouldReceive('pieChart')->andReturn([])->once();
$this->be($this->user()); $this->be($this->user());
$response = $this->get(route('chart.category.category-income', ['1', '1', '20120101', '20120131', 0])); $response = $this->get(route('chart.category.category-income', ['1', '1', '20120101', '20120131', 0]));
$response->assertStatus(200); $response->assertStatus(200);
@ -60,9 +114,25 @@ class CategoryReportControllerTest extends TestCase
/** /**
* @covers \FireflyIII\Http\Controllers\Chart\CategoryReportController::mainChart * @covers \FireflyIII\Http\Controllers\Chart\CategoryReportController::mainChart
* @covers \FireflyIII\Http\Controllers\Chart\CategoryReportController::groupByCategory
* @covers \FireflyIII\Http\Controllers\Chart\CategoryReportController::getExpenses
* @covers \FireflyIII\Http\Controllers\Chart\CategoryReportController::getIncome
*/ */
public function testMainChart() public function testMainChart()
{ {
$generator = $this->mock(GeneratorInterface::class);
$collector = $this->mock(JournalCollectorInterface::class);
$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('disableFilter')->andReturnSelf();
$collector->shouldReceive('setCategories')->andReturnSelf();
$collector->shouldReceive('withOpposingAccount')->andReturnSelf();
$collector->shouldReceive('getJournals')->andReturn(new Collection);
$generator->shouldReceive('multiSet')->andReturn([])->once();
$this->be($this->user()); $this->be($this->user());
$response = $this->get(route('chart.category.main', ['1', '1', '20120101', '20120131'])); $response = $this->get(route('chart.category.main', ['1', '1', '20120101', '20120131']));
$response->assertStatus(200); $response->assertStatus(200);

View File

@ -12,8 +12,17 @@ declare(strict_types = 1);
namespace Tests\Feature\Controllers\Chart; namespace Tests\Feature\Controllers\Chart;
use FireflyIII\Generator\Chart\Basic\GeneratorInterface;
use FireflyIII\Models\PiggyBankEvent;
use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
use Illuminate\Support\Collection;
use Tests\TestCase; use Tests\TestCase;
/**
* Class PiggyBankControllerTest
*
* @package Tests\Feature\Controllers\Chart
*/
class PiggyBankControllerTest extends TestCase class PiggyBankControllerTest extends TestCase
{ {
/** /**
@ -22,6 +31,13 @@ class PiggyBankControllerTest extends TestCase
*/ */
public function testHistory() public function testHistory()
{ {
$generator = $this->mock(GeneratorInterface::class);
$repository = $this->mock(PiggyBankRepositoryInterface::class);
$event = factory(PiggyBankEvent::class)->make();
$repository->shouldReceive('getEvents')->andReturn(new Collection([$event]));
$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', [1]));
$response->assertStatus(200); $response->assertStatus(200);

View File

@ -12,17 +12,31 @@ declare(strict_types = 1);
namespace Tests\Feature\Controllers\Chart; namespace Tests\Feature\Controllers\Chart;
use FireflyIII\Generator\Chart\Basic\GeneratorInterface;
use FireflyIII\Repositories\Account\AccountTaskerInterface;
use Steam;
use Tests\TestCase; use Tests\TestCase;
/**
* Class ReportControllerTest
*
* @package Tests\Feature\Controllers\Chart
*/
class ReportControllerTest extends TestCase class ReportControllerTest extends TestCase
{ {
/** /**
* @covers \FireflyIII\Http\Controllers\Chart\ReportController::netWorth * @covers \FireflyIII\Http\Controllers\Chart\ReportController::netWorth
* @covers \FireflyIII\Http\Controllers\Chart\ReportController::arraySum
* @covers \FireflyIII\Http\Controllers\Chart\ReportController::__construct * @covers \FireflyIII\Http\Controllers\Chart\ReportController::__construct
*/ */
public function testNetWorth() public function testNetWorth()
{ {
$generator = $this->mock(GeneratorInterface::class);
Steam::shouldReceive('balancesById')->andReturn(['5', '10']);
$generator->shouldReceive('singleSet')->andReturn([]);
$this->be($this->user()); $this->be($this->user());
$response = $this->get(route('chart.report.net-worth', [1, '20120101', '20120131'])); $response = $this->get(route('chart.report.net-worth', [1, '20120101', '20120131']));
$response->assertStatus(200); $response->assertStatus(200);
@ -30,9 +44,17 @@ class ReportControllerTest extends TestCase
/** /**
* @covers \FireflyIII\Http\Controllers\Chart\ReportController::operations * @covers \FireflyIII\Http\Controllers\Chart\ReportController::operations
* @covers \FireflyIII\Http\Controllers\Chart\ReportController::getChartData
*/ */
public function testOperations() public function testOperations()
{ {
$generator = $this->mock(GeneratorInterface::class);
$tasker = $this->mock(AccountTaskerInterface::class);
$tasker->shouldReceive('amountOutInPeriod')->andReturn('-1');
$tasker->shouldReceive('amountInInPeriod')->andReturn('1');
$generator->shouldReceive('multiSet')->andReturn([]);
$this->be($this->user()); $this->be($this->user());
$response = $this->get(route('chart.report.operations', [1, '20120101', '20120131'])); $response = $this->get(route('chart.report.operations', [1, '20120101', '20120131']));
$response->assertStatus(200); $response->assertStatus(200);
@ -40,9 +62,17 @@ class ReportControllerTest extends TestCase
/** /**
* @covers \FireflyIII\Http\Controllers\Chart\ReportController::sum * @covers \FireflyIII\Http\Controllers\Chart\ReportController::sum
* @covers \FireflyIII\Http\Controllers\Chart\ReportController::getChartData
*/ */
public function testSum() public function testSum()
{ {
$generator = $this->mock(GeneratorInterface::class);
$tasker = $this->mock(AccountTaskerInterface::class);
$tasker->shouldReceive('amountOutInPeriod')->andReturn('-1');
$tasker->shouldReceive('amountInInPeriod')->andReturn('1');
$generator->shouldReceive('multiSet')->andReturn([]);
$this->be($this->user()); $this->be($this->user());
$response = $this->get(route('chart.report.sum', [1, '20120101', '20120131'])); $response = $this->get(route('chart.report.sum', [1, '20120101', '20120131']));
$response->assertStatus(200); $response->assertStatus(200);