mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Various code coverage and test related fixes.
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
* See the LICENSE file for details.
|
||||
*/
|
||||
|
||||
declare(strict_types = 1);
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Feature\Controllers;
|
||||
|
||||
@@ -16,6 +16,7 @@ use FireflyIII\Helpers\Collector\JournalCollectorInterface;
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\AccountType;
|
||||
use FireflyIII\Models\Transaction;
|
||||
use FireflyIII\Models\TransactionCurrency;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\Repositories\Account\AccountTaskerInterface;
|
||||
@@ -105,6 +106,7 @@ class AccountControllerTest extends TestCase
|
||||
$repository = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$repository->shouldReceive('get')->andReturn(new Collection);
|
||||
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
||||
$repository->shouldReceive('find')->once()->andReturn(new TransactionCurrency());
|
||||
|
||||
$this->be($this->user());
|
||||
$account = $this->user()->accounts()->where('account_type_id', 3)->whereNull('deleted_at')->first();
|
||||
@@ -162,14 +164,16 @@ class AccountControllerTest extends TestCase
|
||||
|
||||
$repository = $this->mock(AccountRepositoryInterface::class);
|
||||
$repository->shouldReceive('oldestJournalDate')->andReturn(clone $date)->once();
|
||||
$repository->shouldReceive('getAccountsByType')->andReturn(new Collection)->once();
|
||||
|
||||
$transaction = factory(Transaction::class)->make();
|
||||
$collector = $this->mock(JournalCollectorInterface::class);
|
||||
$collector->shouldReceive('setAccounts')->andReturnSelf();
|
||||
$collector->shouldReceive('setRange')->andReturnSelf();
|
||||
$collector->shouldReceive('setLimit')->andReturnSelf();
|
||||
$collector->shouldReceive('withOpposingAccount')->andReturnSelf();
|
||||
$collector->shouldReceive('setPage')->andReturnSelf();
|
||||
$collector->shouldReceive('setTypes')->andReturnSelf();
|
||||
$collector->shouldReceive('getJournals')->andReturn(new Collection([$transaction]));
|
||||
$collector->shouldReceive('getPaginatedJournals')->andReturn(new LengthAwarePaginator([$transaction], 0, 10));
|
||||
|
||||
|
||||
@@ -198,6 +202,9 @@ class AccountControllerTest extends TestCase
|
||||
$collector->shouldReceive('setRange')->andReturnSelf();
|
||||
$collector->shouldReceive('setLimit')->andReturnSelf();
|
||||
$collector->shouldReceive('setPage')->andReturnSelf();
|
||||
|
||||
$collector->shouldReceive('setTypes')->andReturnSelf();
|
||||
|
||||
$collector->shouldReceive('getPaginatedJournals')->andReturn(new LengthAwarePaginator([$transaction], 0, 10));
|
||||
|
||||
|
||||
@@ -249,14 +256,14 @@ class AccountControllerTest extends TestCase
|
||||
$collector->shouldReceive('setRange')->andReturnSelf();
|
||||
$collector->shouldReceive('setLimit')->andReturnSelf();
|
||||
$collector->shouldReceive('setPage')->andReturnSelf();
|
||||
|
||||
$collector->shouldReceive('setTypes')->andReturnSelf();
|
||||
$collector->shouldReceive('withOpposingAccount')->andReturnSelf();
|
||||
$collector->shouldReceive('getJournals')->andReturn(new Collection([$transaction]));
|
||||
$collector->shouldReceive('getPaginatedJournals')->andReturn(new LengthAwarePaginator([$transaction], 0, 10));
|
||||
|
||||
$tasker = $this->mock(AccountTaskerInterface::class);
|
||||
$repository = $this->mock(AccountRepositoryInterface::class);
|
||||
$repository->shouldReceive('oldestJournalDate')->andReturn(new Carbon)->once();
|
||||
$repository->shouldReceive('getAccountsByType')->withArgs([[AccountType::ASSET, AccountType::DEFAULT]])->once()->andReturn(new Collection);
|
||||
$tasker->shouldReceive('amountOutInPeriod')->withAnyArgs()->andReturn('-1');
|
||||
$tasker->shouldReceive('amountInInPeriod')->withAnyArgs()->andReturn('1');
|
||||
|
||||
$this->be($this->user());
|
||||
$this->changeDateRange($this->user(), $range);
|
||||
@@ -284,12 +291,12 @@ class AccountControllerTest extends TestCase
|
||||
$collector->shouldReceive('setPage')->andReturnSelf();
|
||||
$collector->shouldReceive('getPaginatedJournals')->andReturn(new LengthAwarePaginator([], 0, 10));
|
||||
|
||||
$tasker = $this->mock(AccountTaskerInterface::class);
|
||||
$repository = $this->mock(AccountRepositoryInterface::class);
|
||||
$repository->shouldReceive('oldestJournalDate')->andReturn(new Carbon);
|
||||
$repository->shouldReceive('getAccountsByType')->withArgs([[AccountType::ASSET, AccountType::DEFAULT]])->once()->andReturn(new Collection);
|
||||
$tasker->shouldReceive('amountOutInPeriod')->withAnyArgs()->andReturn('-1');
|
||||
$tasker->shouldReceive('amountInInPeriod')->withAnyArgs()->andReturn('1');
|
||||
|
||||
$collector->shouldReceive('setTypes')->andReturnSelf();
|
||||
$collector->shouldReceive('withOpposingAccount')->andReturnSelf();
|
||||
$collector->shouldReceive('getJournals')->andReturn(new Collection);
|
||||
|
||||
$this->be($this->user());
|
||||
$this->changeDateRange($this->user(), $range);
|
||||
|
@@ -304,17 +304,6 @@ class AccountControllerTest extends TestCase
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Chart\AccountController::period
|
||||
* @expectedExceptionMessage YYYY-MM-DD
|
||||
*/
|
||||
public function testPeriodBadDate()
|
||||
{
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('chart.account.period', [1, 'bcdefed']));
|
||||
$response->assertStatus(500);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Chart\AccountController::report
|
||||
* @covers \FireflyIII\Http\Controllers\Chart\AccountController::accountBalanceChart
|
||||
|
@@ -123,7 +123,7 @@ class CategoryReportControllerTest extends TestCase
|
||||
{
|
||||
$generator = $this->mock(GeneratorInterface::class);
|
||||
$collector = $this->mock(JournalCollectorInterface::class);
|
||||
$transaction = factory(Transaction::class)->make();
|
||||
$transactions = factory(Transaction::class, 10)->make();
|
||||
|
||||
$collector->shouldReceive('setAccounts')->andReturnSelf();
|
||||
$collector->shouldReceive('setRange')->andReturnSelf();
|
||||
@@ -132,7 +132,7 @@ class CategoryReportControllerTest extends TestCase
|
||||
$collector->shouldReceive('disableFilter')->andReturnSelf();
|
||||
$collector->shouldReceive('setCategories')->andReturnSelf();
|
||||
$collector->shouldReceive('withOpposingAccount')->andReturnSelf();
|
||||
$collector->shouldReceive('getJournals')->andReturn(new Collection([$transaction]));
|
||||
$collector->shouldReceive('getJournals')->andReturn($transactions);
|
||||
$generator->shouldReceive('multiSet')->andReturn([])->once();
|
||||
|
||||
$this->be($this->user());
|
||||
|
@@ -7,7 +7,7 @@
|
||||
* See the LICENSE file for details.
|
||||
*/
|
||||
|
||||
declare(strict_types = 1);
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Feature\Controllers\Chart;
|
||||
|
||||
@@ -33,6 +33,7 @@ class ReportControllerTest extends TestCase
|
||||
public function testNetWorth()
|
||||
{
|
||||
$generator = $this->mock(GeneratorInterface::class);
|
||||
$tasker = $this->mock(AccountTaskerInterface::class);
|
||||
|
||||
Steam::shouldReceive('balancesById')->andReturn(['5', '10']);
|
||||
$generator->shouldReceive('singleSet')->andReturn([]);
|
||||
@@ -50,9 +51,10 @@ class ReportControllerTest extends TestCase
|
||||
{
|
||||
$generator = $this->mock(GeneratorInterface::class);
|
||||
$tasker = $this->mock(AccountTaskerInterface::class);
|
||||
|
||||
$tasker->shouldReceive('amountOutInPeriod')->andReturn('-1');
|
||||
$tasker->shouldReceive('amountInInPeriod')->andReturn('1');
|
||||
$income = [1 => ['sum' => '100']];
|
||||
$expense = [2 => ['sum' => '-100']];
|
||||
$tasker->shouldReceive('getIncomeReport')->once()->andReturn($income);
|
||||
$tasker->shouldReceive('getExpenseReport')->once()->andReturn($expense);
|
||||
$generator->shouldReceive('multiSet')->andReturn([]);
|
||||
|
||||
$this->be($this->user());
|
||||
@@ -69,8 +71,11 @@ class ReportControllerTest extends TestCase
|
||||
$generator = $this->mock(GeneratorInterface::class);
|
||||
$tasker = $this->mock(AccountTaskerInterface::class);
|
||||
|
||||
$tasker->shouldReceive('amountOutInPeriod')->andReturn('-1');
|
||||
$tasker->shouldReceive('amountInInPeriod')->andReturn('1');
|
||||
$income = [];
|
||||
$expense = [];
|
||||
$tasker->shouldReceive('getIncomeReport')->andReturn($income)->times(1);
|
||||
$tasker->shouldReceive('getExpenseReport')->andReturn($expense)->times(1);
|
||||
|
||||
$generator->shouldReceive('multiSet')->andReturn([]);
|
||||
|
||||
$this->be($this->user());
|
||||
|
@@ -122,11 +122,17 @@ class TagReportControllerTest extends TestCase
|
||||
*/
|
||||
public function testMainChart()
|
||||
{
|
||||
$generator = $this->mock(GeneratorInterface::class);
|
||||
$collector = $this->mock(JournalCollectorInterface::class);
|
||||
$transaction = factory(Transaction::class)->make();
|
||||
$tag = factory(Tag::class)->make();
|
||||
$transaction->transactionJournal->tags()->save($tag);
|
||||
$generator = $this->mock(GeneratorInterface::class);
|
||||
$collector = $this->mock(JournalCollectorInterface::class);
|
||||
$set = new Collection;
|
||||
for ($i = 0; $i < 10; $i++) {
|
||||
|
||||
|
||||
$transaction = factory(Transaction::class)->make();
|
||||
$tag = factory(Tag::class)->make();
|
||||
$transaction->transactionJournal->tags()->save($tag);
|
||||
$set->push($transaction);
|
||||
}
|
||||
|
||||
|
||||
$collector->shouldReceive('setAccounts')->andReturnSelf();
|
||||
@@ -136,7 +142,7 @@ class TagReportControllerTest extends TestCase
|
||||
$collector->shouldReceive('disableFilter')->andReturnSelf();
|
||||
$collector->shouldReceive('setTags')->andReturnSelf();
|
||||
$collector->shouldReceive('withOpposingAccount')->andReturnSelf();
|
||||
$collector->shouldReceive('getJournals')->andReturn(new Collection([$transaction]));
|
||||
$collector->shouldReceive('getJournals')->andReturn($set);
|
||||
$generator->shouldReceive('multiSet')->andReturn([])->once();
|
||||
|
||||
$this->be($this->user());
|
||||
|
@@ -26,6 +26,20 @@ use Tests\TestCase;
|
||||
*/
|
||||
class JavascriptControllerTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\JavascriptController::currencies
|
||||
*/
|
||||
public function testCurrencies()
|
||||
{
|
||||
$repository = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$currency = factory(TransactionCurrency::class)->make();
|
||||
$repository->shouldReceive('get')->andReturn(new Collection([$currency]));
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('javascript.currencies'));
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\JavascriptController::accounts
|
||||
*/
|
||||
|
55
tests/Feature/Controllers/Json/ExchangeControllerTest.php
Normal file
55
tests/Feature/Controllers/Json/ExchangeControllerTest.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
/**
|
||||
* ExchangeControllerTest.php
|
||||
* Copyright (c) 2017 thegrumpydictator@gmail.com
|
||||
* This software may be modified and distributed under the terms of the Creative Commons Attribution-ShareAlike 4.0 International License.
|
||||
*
|
||||
* See the LICENSE file for details.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Feature\Controllers\Json;
|
||||
|
||||
|
||||
use FireflyIII\Models\CurrencyExchangeRate;
|
||||
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Class ExchangeControllerTest
|
||||
*
|
||||
* @package Tests\Feature\Controllers
|
||||
*/
|
||||
class ExchangeControllerTest extends TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Json\ExchangeController::getRate
|
||||
*/
|
||||
public function testGetRate()
|
||||
{
|
||||
$repository = $this->mock(CurrencyRepositoryInterface::class);
|
||||
|
||||
$rate = factory(CurrencyExchangeRate::class)->make();
|
||||
$repository->shouldReceive('getExchangeRate')->andReturn($rate);
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('json.rate', ['EUR', 'USD', '20170101']));
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Json\ExchangeController::getRate
|
||||
*/
|
||||
public function testGetRateAmount()
|
||||
{
|
||||
$repository = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$rate = factory(CurrencyExchangeRate::class)->make();
|
||||
$repository->shouldReceive('getExchangeRate')->andReturn($rate);
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('json.rate', ['EUR', 'USD', '20170101']) . '?amount=10');
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
}
|
@@ -7,7 +7,7 @@
|
||||
* See the LICENSE file for details.
|
||||
*/
|
||||
|
||||
declare(strict_types = 1);
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Feature\Controllers;
|
||||
|
||||
@@ -17,7 +17,9 @@ use FireflyIII\Models\AccountType;
|
||||
use FireflyIII\Models\Budget;
|
||||
use FireflyIII\Models\Category;
|
||||
use FireflyIII\Models\Tag;
|
||||
use FireflyIII\Models\Transaction;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Models\TransactionType;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\Repositories\Account\AccountTaskerInterface;
|
||||
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
|
||||
@@ -123,13 +125,18 @@ class JsonControllerTest extends TestCase
|
||||
// mock stuff
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$tasker = $this->mock(AccountTaskerInterface::class);
|
||||
$collector = $this->mock(JournalCollectorInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
||||
$accountRepos->shouldReceive('getAccountsByType')->withArgs([([AccountType::DEFAULT, AccountType::ASSET, AccountType::CASH])])->once()->andReturn(
|
||||
new Collection
|
||||
);
|
||||
$accountRepos->shouldReceive('getAccountsByType')->withArgs([([AccountType::DEFAULT, AccountType::ASSET])])->once()->andReturn(new Collection);
|
||||
$tasker->shouldReceive('amountInInPeriod')->andReturn('100');
|
||||
$transaction = factory(Transaction::class)->make();
|
||||
$transaction->transaction_amount = '100.00';
|
||||
|
||||
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf()->once();
|
||||
$collector->shouldReceive('setRange')->andReturnSelf()->once();
|
||||
$collector->shouldReceive('getJournals')->andReturn(new Collection([$transaction]))->once();
|
||||
$collector->shouldReceive('setTypes')->withArgs([[TransactionType::DEPOSIT]])->andReturnSelf()->once();
|
||||
$collector->shouldReceive('withOpposingAccount')->andReturnSelf()->once();
|
||||
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('json.box.in'));
|
||||
@@ -145,13 +152,17 @@ class JsonControllerTest extends TestCase
|
||||
// mock stuff
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$tasker = $this->mock(AccountTaskerInterface::class);
|
||||
$collector = $this->mock(JournalCollectorInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
||||
$accountRepos->shouldReceive('getAccountsByType')->withArgs([([AccountType::DEFAULT, AccountType::ASSET, AccountType::CASH])])->once()->andReturn(
|
||||
new Collection
|
||||
);
|
||||
$accountRepos->shouldReceive('getAccountsByType')->withArgs([([AccountType::DEFAULT, AccountType::ASSET])])->once()->andReturn(new Collection);
|
||||
$tasker->shouldReceive('amountOutInPeriod')->andReturn('100');
|
||||
$transaction = factory(Transaction::class)->make();
|
||||
$transaction->transaction_amount = '100.00';
|
||||
|
||||
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf()->once();
|
||||
$collector->shouldReceive('setRange')->andReturnSelf()->once();
|
||||
$collector->shouldReceive('getJournals')->andReturn(new Collection([$transaction]))->once();
|
||||
$collector->shouldReceive('setTypes')->withArgs([[TransactionType::WITHDRAWAL]])->andReturnSelf()->once();
|
||||
$collector->shouldReceive('withOpposingAccount')->andReturnSelf()->once();
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('json.box.out'));
|
||||
@@ -165,7 +176,7 @@ class JsonControllerTest extends TestCase
|
||||
public function testBudgets()
|
||||
{
|
||||
// mock stuff
|
||||
$budget = factory(Budget::class)->make();
|
||||
$budget = factory(Budget::class)->make();
|
||||
$categoryRepos = $this->mock(BudgetRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
||||
@@ -280,22 +291,6 @@ class JsonControllerTest extends TestCase
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\JsonController::transactionTypes
|
||||
*/
|
||||
public function testTransactionTypes()
|
||||
{
|
||||
// mock stuff
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
||||
$journalRepos->shouldReceive('getTransactionTypes')->once()->andReturn(new Collection);
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('json.transaction-types', ['deposit']));
|
||||
$response->assertStatus(200);
|
||||
$response->assertExactJson([]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\JsonController::transactionJournals
|
||||
*/
|
||||
@@ -316,6 +311,22 @@ class JsonControllerTest extends TestCase
|
||||
$response->assertExactJson([]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\JsonController::transactionTypes
|
||||
*/
|
||||
public function testTransactionTypes()
|
||||
{
|
||||
// mock stuff
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
||||
$journalRepos->shouldReceive('getTransactionTypes')->once()->andReturn(new Collection);
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('json.transaction-types', ['deposit']));
|
||||
$response->assertStatus(200);
|
||||
$response->assertExactJson([]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\JsonController::trigger
|
||||
*/
|
||||
|
@@ -161,9 +161,11 @@ class PiggyBankControllerTest extends TestCase
|
||||
// mock stuff
|
||||
$repository = $this->mock(PiggyBankRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$piggyBank = factory(PiggyBank::class)->make();
|
||||
$one = factory(PiggyBank::class)->make();
|
||||
$two = factory(PiggyBank::class)->make();
|
||||
$two->account_id = $one->account_id;
|
||||
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
||||
$repository->shouldReceive('getPiggyBanks')->andReturn(new Collection([$piggyBank]));
|
||||
$repository->shouldReceive('getPiggyBanks')->andReturn(new Collection([$one, $two]));
|
||||
|
||||
Steam::shouldReceive('balanceIgnoreVirtual')->twice()->andReturn('1');
|
||||
|
||||
|
@@ -26,8 +26,6 @@ class OperationsControllerTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Report\OperationsController::expenses
|
||||
* @covers \FireflyIII\Http\Controllers\Report\OperationsController::getExpenseReport
|
||||
* @covers \FireflyIII\Http\Controllers\Report\OperationsController::groupByOpposing
|
||||
*/
|
||||
public function testExpenses()
|
||||
{
|
||||
@@ -49,7 +47,6 @@ class OperationsControllerTest extends TestCase
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Report\OperationsController::income
|
||||
* @covers \FireflyIII\Http\Controllers\Report\OperationsController::getIncomeReport
|
||||
*/
|
||||
public function testIncome()
|
||||
{
|
||||
|
Reference in New Issue
Block a user