Improve test coverage.

This commit is contained in:
James Cole
2019-07-24 19:02:41 +02:00
parent 226e2f7185
commit ee95606ec0
39 changed files with 378 additions and 234 deletions

View File

@@ -125,15 +125,15 @@ class ShowControllerTest extends TestCase
$this->session(['start' => $date, 'end' => clone $date]);
// mock stuff:
$this->mock(AccountTaskerInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$this->mock(CurrencyRepositoryInterface::class);
$this->mock(AccountRepositoryInterface::class);
$collector = $this->mock(GroupCollectorInterface::class);
$repository = $this->mock(AccountRepositoryInterface::class);
$journal = $this->getRandomWithdrawalAsArray();
$group = $this->getRandomWithdrawalGroup();
$euro = $this->getEuro();
$asset = $this->getRandomAsset();
$collector = $this->mock(GroupCollectorInterface::class);
$repository = $this->mock(AccountRepositoryInterface::class);
$journal = $this->getRandomWithdrawalAsArray();
$group = $this->getRandomWithdrawalGroup();
$euro = $this->getEuro();
$asset = $this->getRandomAsset();
$this->mockDefaultSession();

View File

@@ -50,7 +50,7 @@ class ConfigurationControllerTest extends TestCase
public function testIndex(): void
{
$this->mockDefaultSession();
$userRepos = $this->mock(UserRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
// for session

View File

@@ -28,8 +28,8 @@ use FireflyIII\Repositories\User\UserRepositoryInterface;
use Illuminate\Support\Collection;
use Log;
use Mockery;
use Tests\TestCase;
use Preferences;
use Tests\TestCase;
/**
* Class LinkControllerTest
@@ -85,7 +85,7 @@ class LinkControllerTest extends TestCase
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false)->atLeast()->once();
$linkType = LinkType::where('editable', 1)->first();
$another= LinkType::where('editable', 0)->first();
$another = LinkType::where('editable', 0)->first();
$repository->shouldReceive('get')->once()->andReturn(new Collection([$linkType, $another]));
$repository->shouldReceive('countJournals')->andReturn(2);
$this->be($this->user());
@@ -100,9 +100,9 @@ class LinkControllerTest extends TestCase
*/
public function testDeleteNonEditable(): void
{
$userRepos = $this->mock(UserRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$this->mock(LinkTypeRepositoryInterface::class);
$linkType = LinkType::where('editable', 0)->first();
$linkType = LinkType::where('editable', 0)->first();
// mock default session stuff
$this->mockDefaultSession();
@@ -216,7 +216,7 @@ class LinkControllerTest extends TestCase
*/
public function testShow(): void
{
$userRepos = $this->mock(UserRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$repository = $this->mock(LinkTypeRepositoryInterface::class);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
@@ -327,7 +327,7 @@ class LinkControllerTest extends TestCase
*/
public function testUpdateNonEditable(): void
{
$userRepos = $this->mock(UserRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$this->mock(LinkTypeRepositoryInterface::class);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();

View File

@@ -60,8 +60,8 @@ class UpdateControllerTest extends TestCase
$this->mockDefaultSession();
// mock update calls.
$config = new Configuration;
$config->data = -1;
$config = new Configuration;
$config->data = -1;
FireflyConfig::shouldReceive('get')->withArgs(['permission_update_check', -1])->once()->andReturn($config);
// call service

View File

@@ -51,7 +51,6 @@ class TwoFactorControllerTest extends TestCase
$this->be($this->user());
$truePref = new Preference;
$truePref->data = true;
$secretPreference = new Preference;

View File

@@ -27,11 +27,8 @@ use FireflyIII\Helpers\Attachments\AttachmentHelperInterface;
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
use FireflyIII\Models\Bill;
use FireflyIII\Models\Preference;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface;
use FireflyIII\Repositories\User\UserRepositoryInterface;
use FireflyIII\TransactionRules\TransactionMatcher;
use FireflyIII\Transformers\BillTransformer;
@@ -175,7 +172,9 @@ class BillControllerTest extends TestCase
$transformer->shouldReceive('setParameters')->atLeast()->once();
$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(
['id' => 5, 'active' => true, 'name' => 'x', 'next_expected_match' => '2018-01-01']
['id' => 5, 'active' => true, 'name' => 'x', 'next_expected_match' => '2018-01-01',
'currency' => $this->getEuro(),
]
);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();

View File

@@ -28,9 +28,7 @@ use Amount;
use Carbon\Carbon;
use FireflyIII\Helpers\Fiscal\FiscalHelperInterface;
use FireflyIII\Models\BudgetLimit;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use Log;
use Preferences;
use Tests\TestCase;

View File

@@ -24,7 +24,6 @@ declare(strict_types=1);
namespace Tests\Feature\Controllers\Budget;
use FireflyIII\Models\Budget;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use FireflyIII\Repositories\User\UserRepositoryInterface;
use Log;

View File

@@ -23,10 +23,7 @@ declare(strict_types=1);
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;

View File

@@ -23,25 +23,27 @@ declare(strict_types=1);
namespace Tests\Feature\Controllers\Budget;
use Amount;
use Carbon\Carbon;
use Exception;
use FireflyIII\Helpers\Fiscal\FiscalHelperInterface;
use FireflyIII\Models\Budget;
use FireflyIII\Models\Preference;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\Repositories\User\UserRepositoryInterface;
use Illuminate\Support\Collection;
use Log;
use Mockery;
use Preferences;
use Amount;
use Tests\TestCase;
/**
*
* Class IndexControllerTest
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class IndexControllerTest extends TestCase
{
@@ -63,7 +65,7 @@ class IndexControllerTest extends TestCase
public function testIndex(string $range): void
{
// mock stuff
$budget = $this->getRandomBudget();
$budget = $this->getRandomBudget();
$budgetLimit = $this->getRandomBudgetLimit();
$budgetLimit->start_date = Carbon::now()->startOfMonth();
$budgetLimit->end_date = Carbon::now()->endOfMonth();
@@ -100,7 +102,7 @@ class IndexControllerTest extends TestCase
$this->be($this->user());
$this->changeDateRange($this->user(), $range);
$response = $this->get(route('budgets.index'));
$response = $this->get(route('budgets.index'));
$response->assertStatus(200);
// has bread crumb
$response->assertSee('<ol class="breadcrumb">');
@@ -111,6 +113,7 @@ class IndexControllerTest extends TestCase
* @dataProvider dateRangeProvider
*
* @param string $range
* @throws Exception
*/
public function testIndexOutOfRange(string $range): void
{
@@ -170,6 +173,7 @@ class IndexControllerTest extends TestCase
* @dataProvider dateRangeProvider
*
* @param string $range
* @throws Exception
*/
public function testIndexWithDate(string $range): void
{
@@ -225,6 +229,7 @@ class IndexControllerTest extends TestCase
* @dataProvider dateRangeProvider
*
* @param string $range
* @throws Exception
*/
public function testIndexWithInvalidDate(string $range): void
{
@@ -233,8 +238,8 @@ class IndexControllerTest extends TestCase
// 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);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$repository = $this->mock(BudgetRepositoryInterface::class);
$this->mock(UserRepositoryInterface::class);
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
$date = new Carbon;

View File

@@ -29,10 +29,8 @@ 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;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\Repositories\User\UserRepositoryInterface;
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\Collection;
@@ -44,7 +42,9 @@ use Tests\TestCase;
/**
*
* Class ShowControllerTest
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class ShowControllerTest extends TestCase
{
@@ -71,7 +71,9 @@ class ShowControllerTest extends TestCase
$collector = $this->mock(GroupCollectorInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
$date = null;
$this->mockDefaultSession();
try {
$date = new Carbon;
} catch (Exception $e) {
@@ -118,6 +120,7 @@ class ShowControllerTest extends TestCase
$this->mock(BudgetRepositoryInterface::class);
$collector = $this->mock(GroupCollectorInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$date = null;
$this->mockDefaultSession();
try {
$date = new Carbon;

View File

@@ -23,10 +23,7 @@ namespace Tests\Feature\Controllers\Category;
use FireflyIII\Models\Category;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\Repositories\User\UserRepositoryInterface;
use Log;
use Mockery;
@@ -75,7 +72,7 @@ class CreateControllerTest extends TestCase
{
Log::debug('Test store()');
$repository = $this->mock(CategoryRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$this->mock(UserRepositoryInterface::class);
$this->mockDefaultSession();
$repository->shouldReceive('findNull')->andReturn(new Category);
$repository->shouldReceive('store')->andReturn(new Category);

View File

@@ -51,8 +51,8 @@ class DeleteControllerTest extends TestCase
{
Log::debug('Test Delete()');
// mock stuff
$categoryRepos = $this->mock(CategoryRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$this->mock(CategoryRepositoryInterface::class);
$this->mock(AccountRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$this->mockDefaultSession();
@@ -74,7 +74,7 @@ class DeleteControllerTest extends TestCase
Log::debug('Test destroy()');
// mock stuff
$categoryRepos = $this->mock(CategoryRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$this->mock(AccountRepositoryInterface::class);
$this->mockDefaultSession();
Preferences::shouldReceive('mark')->atLeast()->once()->withNoArgs();
$categoryRepos->shouldReceive('destroy')->andReturn(true);

View File

@@ -23,10 +23,8 @@ namespace Tests\Feature\Controllers\Category;
use FireflyIII\Models\Category;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\Repositories\User\UserRepositoryInterface;
use Log;
use Mockery;
@@ -79,8 +77,8 @@ class EditControllerTest extends TestCase
Log::debug('Test update()');
$category = Category::first();
$repository = $this->mock(CategoryRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$this->mock(AccountRepositoryInterface::class);
$this->mock(UserRepositoryInterface::class);
$this->mockDefaultSession();
Preferences::shouldReceive('mark')->atLeast()->once()->withNoArgs();

View File

@@ -23,7 +23,6 @@ namespace Tests\Feature\Controllers\Category;
use Carbon\Carbon;
use FireflyIII\Models\Category;
use FireflyIII\Models\Preference;
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
use FireflyIII\Repositories\User\UserRepositoryInterface;

View File

@@ -25,27 +25,27 @@ namespace Tests\Feature\Controllers\Category;
use Carbon\Carbon;
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\Category\CategoryRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\Repositories\User\UserRepositoryInterface;
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\Collection;
use Log;
use Mockery;
use Navigation;
use Preferences;
use Tests\TestCase;
/**
*
* Class NoCategoryControllerTest
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
*/
class NoCategoryControllerTest extends TestCase
{
@@ -68,8 +68,8 @@ class NoCategoryControllerTest extends TestCase
public function testNoCategory(string $range): void
{
$collector = $this->mock(GroupCollectorInterface::class);
$categoryRepos = $this->mock(CategoryRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$this->mock(CategoryRepositoryInterface::class);
$this->mock(AccountRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$this->mockDefaultSession();
@@ -104,13 +104,13 @@ class NoCategoryControllerTest extends TestCase
* @dataProvider dateRangeProvider
*
* @param string $range
*
* @throws Exception
*/
public function testNoCategoryAll(string $range): void
{
$collector = $this->mock(GroupCollectorInterface::class);
$categoryRepos = $this->mock(CategoryRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$this->mock(CategoryRepositoryInterface::class);
$this->mock(AccountRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
@@ -146,12 +146,13 @@ class NoCategoryControllerTest extends TestCase
* @dataProvider dateRangeProvider
*
* @param string $range
* @throws Exception
*/
public function testNoCategoryDate(string $range): void
{
$collector = $this->mock(GroupCollectorInterface::class);
$categoryRepos = $this->mock(CategoryRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$this->mock(CategoryRepositoryInterface::class);
$this->mock(AccountRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
$date = new Carbon;

View File

@@ -25,16 +25,10 @@ namespace Tests\Feature\Controllers\Category;
use Carbon\Carbon;
use Exception;
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
use FireflyIII\Helpers\Fiscal\FiscalHelperInterface;
use FireflyIII\Models\Preference;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\Repositories\User\UserRepositoryInterface;
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\Collection;
@@ -44,9 +38,13 @@ use Navigation;
use Preferences;
use Tests\TestCase;
/**
*
* Class ShowControllerTest
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
*/
class ShowControllerTest extends TestCase
{
@@ -65,6 +63,7 @@ class ShowControllerTest extends TestCase
* @dataProvider dateRangeProvider
*
* @param string $range
* @throws Exception
*/
public function testShow(string $range): void
{
@@ -91,14 +90,14 @@ class ShowControllerTest extends TestCase
$collector->shouldReceive('setPage')->andReturnSelf()->once();
$collector->shouldReceive('setLimit')->andReturnSelf()->once();
$collector->shouldReceive('setRange')->andReturnSelf()->atLeast(2);
$collector->shouldReceive('setRange')->andReturnSelf()->atLeast()->times(2);
$collector->shouldReceive('withBudgetInformation')->andReturnSelf()->once();
$collector->shouldReceive('withCategoryInformation')->andReturnSelf()->once();
$collector->shouldReceive('withAccountInformation')->andReturnSelf()->once();
$collector->shouldReceive('setCategory')->andReturnSelf()->atLeast(2);
$collector->shouldReceive('setCategory')->andReturnSelf()->atLeast()->times(2);
$collector->shouldReceive('getPaginatedGroups')->andReturn(new LengthAwarePaginator([$withdrawal], 0, 10))->once();
$collector->shouldReceive('setTypes')->andReturnSelf()->atLeast(1);
$collector->shouldReceive('setTypes')->andReturnSelf()->atLeast()->once();
$collector->shouldReceive('getExtractedJournals')->andReturn([])->atLeast()->once();
Navigation::shouldReceive('updateStartDate')->andReturn(new Carbon);
@@ -120,6 +119,7 @@ class ShowControllerTest extends TestCase
* @dataProvider dateRangeProvider
*
* @param string $range
* @throws Exception
*/
public function testShowAll(string $range): void
{
@@ -142,7 +142,7 @@ class ShowControllerTest extends TestCase
$collector->shouldReceive('withBudgetInformation')->andReturnSelf()->once();
$collector->shouldReceive('withCategoryInformation')->andReturnSelf()->once();
$collector->shouldReceive('withAccountInformation')->andReturnSelf()->once();
$collector->shouldReceive('setCategory')->andReturnSelf()->atLeast(2);
$collector->shouldReceive('setCategory')->andReturnSelf()->atLeast()->once();
$collector->shouldReceive('getPaginatedGroups')->andReturn(new LengthAwarePaginator([$withdrawal], 0, 10))->once();
$repository->shouldReceive('firstUseDate')->andReturn(new Carbon);

View File

@@ -23,6 +23,7 @@ declare(strict_types=1);
namespace Tests\Feature\Controllers\Chart;
use Carbon\Carbon;
use Exception;
use FireflyIII\Generator\Chart\Basic\GeneratorInterface;
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
@@ -46,6 +47,9 @@ use Tests\TestCase;
/**
* Class AccountControllerTest
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
*/
class AccountControllerTest extends TestCase
{
@@ -110,14 +114,15 @@ class AccountControllerTest extends TestCase
* @dataProvider dateRangeProvider
*
* @param string $range
* @throws Exception
*/
public function testExpenseBudget(string $range): void
{
$generator = $this->mock(GeneratorInterface::class);
$collector = $this->mock(GroupCollectorInterface::class);
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$this->mock(AccountRepositoryInterface::class);
$this->mock(CurrencyRepositoryInterface::class);
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
$withdrawal = $this->getRandomWithdrawalAsArray();
$budget = $this->user()->budgets()->find($withdrawal['budget_id']);
@@ -157,8 +162,8 @@ class AccountControllerTest extends TestCase
$collector = $this->mock(GroupCollectorInterface::class);
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
$this->mock(CurrencyRepositoryInterface::class);
$this->mock(FiscalHelperInterface::class);
$withdrawal = $this->getRandomWithdrawalAsArray();
$budget = $this->user()->budgets()->find($withdrawal['budget_id']);
@@ -188,14 +193,15 @@ class AccountControllerTest extends TestCase
* @dataProvider dateRangeProvider
*
* @param string $range
* @throws Exception
*/
public function testExpenseCategory(string $range): void
{
$generator = $this->mock(GeneratorInterface::class);
$collector = $this->mock(GroupCollectorInterface::class);
$categoryRepos = $this->mock(CategoryRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$this->mock(AccountRepositoryInterface::class);
$this->mock(CurrencyRepositoryInterface::class);
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
$withdrawal = $this->getRandomWithdrawalAsArray();
$category = $this->user()->categories()->find($withdrawal['category_id']);
@@ -238,7 +244,7 @@ class AccountControllerTest extends TestCase
$collector = $this->mock(GroupCollectorInterface::class);
$categoryRepos = $this->mock(CategoryRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$this->mock(CurrencyRepositoryInterface::class);
$withdrawal = $this->getRandomWithdrawalAsArray();
$category = $this->user()->categories()->find($withdrawal['category_id']);
@@ -267,6 +273,7 @@ class AccountControllerTest extends TestCase
* @dataProvider dateRangeProvider
*
* @param string $range
* @throws Exception
*/
public function testFrontpage(string $range): void
{
@@ -304,6 +311,7 @@ class AccountControllerTest extends TestCase
* @dataProvider dateRangeProvider
*
* @param string $range
* @throws Exception
*/
public function testIncomeCategory(string $range): void
{
@@ -382,6 +390,7 @@ class AccountControllerTest extends TestCase
* @dataProvider dateRangeProvider
*
* @param string $range
* @throws Exception
*/
public function testPeriod(string $range): void
{
@@ -444,6 +453,7 @@ class AccountControllerTest extends TestCase
* @dataProvider dateRangeProvider
*
* @param string $range
* @throws Exception
*/
public function testRevenueAccounts(string $range): void
{

View File

@@ -23,6 +23,7 @@ declare(strict_types=1);
namespace Tests\Feature\Controllers\Chart;
use Carbon\Carbon;
use Exception;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Generator\Chart\Basic\GeneratorInterface;
use FireflyIII\Helpers\Fiscal\FiscalHelperInterface;
@@ -38,6 +39,9 @@ use Tests\TestCase;
/**
* Class CategoryControllerTest
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
*/
class CategoryControllerTest extends TestCase
{
@@ -55,6 +59,7 @@ class CategoryControllerTest extends TestCase
* @dataProvider dateRangeProvider
*
* @param string $range
* @throws FireflyException
*/
public function testAll(string $range): void
{
@@ -221,6 +226,7 @@ class CategoryControllerTest extends TestCase
* @dataProvider dateRangeProvider
*
* @param string $range
* @throws Exception
*/
public function testSpecificPeriod(string $range): void
{

View File

@@ -25,7 +25,6 @@ namespace Tests\Feature\Controllers\Chart;
use Carbon\Carbon;
use FireflyIII\Generator\Chart\Basic\GeneratorInterface;
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
use FireflyIII\Helpers\Fiscal\FiscalHelperInterface;
use FireflyIII\Models\TransactionType;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
@@ -82,4 +81,40 @@ class ExpenseReportControllerTest extends TestCase
$response->assertStatus(200);
}
/**
* Same test, but with a deposit
* @covers \FireflyIII\Http\Controllers\Chart\ExpenseReportController
*/
public function testMainChartDeposit(): void
{
$generator = $this->mock(GeneratorInterface::class);
$collector = $this->mock(GroupCollectorInterface::class);
$accountRepository = $this->mock(AccountRepositoryInterface::class);
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
$expense = $this->getRandomExpense();
$date = new Carbon;
$deposit = $this->getRandomDepositAsArray();
$accountRepository->shouldReceive('findByName')->once()->andReturn($expense);
$this->mockDefaultSession();
Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
$collector->shouldReceive('setAccounts')->andReturnSelf()->atLeast()->once();
$collector->shouldReceive('setRange')->andReturnSelf()->atLeast()->once();
$collector->shouldReceive('withAccountInformation')->andReturnSelf()->atLeast()->once();
$collector->shouldReceive('setTypes')->withArgs([[TransactionType::WITHDRAWAL]])->andReturnSelf()->atLeast()->once();
$collector->shouldReceive('setTypes')->withArgs([[TransactionType::DEPOSIT]])->andReturnSelf()->atLeast()->once();
$collector->shouldReceive('getExtractedJournals')->andReturn([$deposit])->atLeast()->once();
$generator->shouldReceive('multiSet')->andReturn([])->once();
$this->be($this->user());
$response = $this->get(route('chart.expense.main', ['1', $expense->id, '20120101', '20120131']));
$response->assertStatus(200);
}
}

View File

@@ -200,7 +200,7 @@ class TagReportControllerTest extends TestCase
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
$withdrawal = $this->getRandomWithdrawalAsArray();
$tag = $this->user()->tags()->where('tag','Expensive')->first();
$tag = $this->user()->tags()->where('tag', 'Expensive')->first();
$date = new Carbon;
$false = new Preference;
$false->data = false;
@@ -237,7 +237,7 @@ class TagReportControllerTest extends TestCase
$generator = $this->mock(GeneratorInterface::class);
$pieChart = $this->mock(MetaPieChartInterface::class);
$tagRepos = $this->mock(TagRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$this->mock(AccountRepositoryInterface::class);
$tag = $this->user()->tags()->first();
$tagRepos->shouldReceive('setUser');
$tagRepos->shouldReceive('get')->andReturn(new Collection([$tag]));

View File

@@ -31,6 +31,7 @@ use Log;
use Mockery;
use Tests\TestCase;
use Preferences;
/**
* Class AccountControllerTest
*
@@ -57,7 +58,7 @@ class PrerequisitesControllerTest extends TestCase
$this->mockDefaultSession();
$userRepos = $this->mock(UserRepositoryInterface::class);
$prereq = $this->mock(FakePrerequisites::class);
$repository = $this->mock(ImportJobRepositoryInterface::class);
$this->mock(ImportJobRepositoryInterface::class);
$job = new ImportJob;
$job->user_id = $this->user()->id;
@@ -68,6 +69,12 @@ class PrerequisitesControllerTest extends TestCase
$job->file_type = '';
$job->save();
Preferences::shouldReceive('getForUser')->atLeast()->once()->withArgs([Mockery::any(),'bunq_api_key',null])->andReturnNull();
Preferences::shouldReceive('getForUser')->atLeast()->once()->withArgs([Mockery::any(),'spectre_app_id',null])->andReturnNull();
Preferences::shouldReceive('getForUser')->atLeast()->once()->withArgs([Mockery::any(),'ynab_client_id',null])->andReturnNull();
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->atLeast()->once()->andReturn(false);
@@ -91,7 +98,8 @@ class PrerequisitesControllerTest extends TestCase
{
$this->mockDefaultSession();
$userRepos = $this->mock(UserRepositoryInterface::class);
$repository = $this->mock(ImportJobRepositoryInterface::class);
$this->mock(ImportJobRepositoryInterface::class);
$job = new ImportJob;
$job->user_id = $this->user()->id;
@@ -102,6 +110,10 @@ class PrerequisitesControllerTest extends TestCase
$job->file_type = '';
$job->save();
Preferences::shouldReceive('getForUser')->atLeast()->once()->withArgs([Mockery::any(),'bunq_api_key',null])->andReturnNull();
Preferences::shouldReceive('getForUser')->atLeast()->once()->withArgs([Mockery::any(),'spectre_app_id',null])->andReturnNull();
Preferences::shouldReceive('getForUser')->atLeast()->once()->withArgs([Mockery::any(),'ynab_client_id',null])->andReturnNull();
Preferences::shouldReceive('getForUser')->atLeast()->once()->withArgs([Mockery::any(),'fake_api_key',null])->andReturnNull();
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->atLeast()->once()->andReturn(false);
@@ -122,6 +134,10 @@ class PrerequisitesControllerTest extends TestCase
$prereq = $this->mock(FakePrerequisites::class);
$repository = $this->mock(ImportJobRepositoryInterface::class);
Preferences::shouldReceive('getForUser')->atLeast()->once()->withArgs([Mockery::any(),'bunq_api_key',null])->andReturnNull();
Preferences::shouldReceive('getForUser')->atLeast()->once()->withArgs([Mockery::any(),'spectre_app_id',null])->andReturnNull();
Preferences::shouldReceive('getForUser')->atLeast()->once()->withArgs([Mockery::any(),'ynab_client_id',null])->andReturnNull();
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'C_pre_job_' . $this->randomInt();
@@ -155,6 +171,12 @@ class PrerequisitesControllerTest extends TestCase
$prereq = $this->mock(FakePrerequisites::class);
$repository = $this->mock(ImportJobRepositoryInterface::class);
Preferences::shouldReceive('getForUser')->atLeast()->once()->withArgs([Mockery::any(),'bunq_api_key',null])->andReturnNull();
Preferences::shouldReceive('getForUser')->atLeast()->once()->withArgs([Mockery::any(),'spectre_app_id',null])->andReturnNull();
Preferences::shouldReceive('getForUser')->atLeast()->once()->withArgs([Mockery::any(),'ynab_client_id',null])->andReturnNull();
//Preferences::shouldReceive('getForUser')->atLeast()->once()->withArgs([Mockery::any(),'fake_api_key',null])->andReturnNull();
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'D_pre_job_' . $this->randomInt();
@@ -186,7 +208,11 @@ class PrerequisitesControllerTest extends TestCase
$this->mockDefaultSession();
$userRepos = $this->mock(UserRepositoryInterface::class);
$prereq = $this->mock(FakePrerequisites::class);
$repository = $this->mock(ImportJobRepositoryInterface::class);
$this->mock(ImportJobRepositoryInterface::class);
Preferences::shouldReceive('getForUser')->atLeast()->once()->withArgs([Mockery::any(),'bunq_api_key',null])->andReturnNull();
Preferences::shouldReceive('getForUser')->atLeast()->once()->withArgs([Mockery::any(),'spectre_app_id',null])->andReturnNull();
Preferences::shouldReceive('getForUser')->atLeast()->once()->withArgs([Mockery::any(),'ynab_client_id',null])->andReturnNull();
$job = new ImportJob;
$job->user_id = $this->user()->id;
@@ -218,7 +244,11 @@ class PrerequisitesControllerTest extends TestCase
$this->mockDefaultSession();
$userRepos = $this->mock(UserRepositoryInterface::class);
$prereq = $this->mock(FakePrerequisites::class);
$repository = $this->mock(ImportJobRepositoryInterface::class);
$this->mock(ImportJobRepositoryInterface::class);
Preferences::shouldReceive('getForUser')->atLeast()->once()->withArgs([Mockery::any(),'bunq_api_key',null])->andReturnNull();
Preferences::shouldReceive('getForUser')->atLeast()->once()->withArgs([Mockery::any(),'spectre_app_id',null])->andReturnNull();
Preferences::shouldReceive('getForUser')->atLeast()->once()->withArgs([Mockery::any(),'ynab_client_id',null])->andReturnNull();
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->atLeast()->once()->andReturn(false);
@@ -244,7 +274,12 @@ class PrerequisitesControllerTest extends TestCase
$this->mockDefaultSession();
$userRepos = $this->mock(UserRepositoryInterface::class);
$prereq = $this->mock(FakePrerequisites::class);
$repository = $this->mock(ImportJobRepositoryInterface::class);
$this->mock(ImportJobRepositoryInterface::class);
Preferences::shouldReceive('getForUser')->atLeast()->once()->withArgs([Mockery::any(),'bunq_api_key',null])->andReturnNull();
Preferences::shouldReceive('getForUser')->atLeast()->once()->withArgs([Mockery::any(),'spectre_app_id',null])->andReturnNull();
Preferences::shouldReceive('getForUser')->atLeast()->once()->withArgs([Mockery::any(),'ynab_client_id',null])->andReturnNull();
//Preferences::shouldReceive('getForUser')->atLeast()->once()->withArgs([Mockery::any(),'fake_api_key',null])->andReturnNull();
$job = new ImportJob;
$job->user_id = $this->user()->id;

View File

@@ -23,22 +23,8 @@ declare(strict_types=1);
namespace Tests\Feature\Controllers\Json;
use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType;
use FireflyIII\Models\Bill;
use FireflyIII\Models\Budget;
use FireflyIII\Models\Category;
use FireflyIII\Models\Tag;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\Repositories\Tag\TagRepositoryInterface;
use Illuminate\Support\Collection;
use Log;
use Tests\TestCase;
@@ -68,8 +54,6 @@ class AutoCompleteControllerTest extends TestCase
$account = $this->getRandomAsset();
$euro = $this->getEuro();
$accountRepos->shouldReceive('searchAccount')->atLeast()->once()->andReturn(new Collection([$account]));
$accountRepos->shouldReceive('getAccountCurrency')->atLeast()->once()->andReturn($euro);
$this->mockDefaultSession();
@@ -82,4 +66,106 @@ class AutoCompleteControllerTest extends TestCase
}
/**
* Request a list of revenue accounts
*
* @covers \FireflyIII\Http\Controllers\Json\AutoCompleteController
*/
public function testRevenueAccounts(): void
{
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$account = $this->getRandomAsset();
$accountRepos->shouldReceive('searchAccount')->atLeast()->once()->andReturn(new Collection([$account]));
$this->mockDefaultSession();
$this->be($this->user());
$response = $this->get(route('json.autocomplete.revenue-accounts'));
$response->assertStatus(200);
$response->assertSee($account->name);
}
/**
* Request a list of expense accounts
*
* @covers \FireflyIII\Http\Controllers\Json\AutoCompleteController
*/
public function testExpenseAccounts(): void
{
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$account = $this->getRandomAsset();
$accountRepos->shouldReceive('searchAccount')->atLeast()->once()->andReturn(new Collection([$account]));
$this->mockDefaultSession();
$this->be($this->user());
$response = $this->get(route('json.autocomplete.expense-accounts'));
$response->assertStatus(200);
$response->assertSee($account->name);
}
/**
* Request a list of expense accounts
*
* @covers \FireflyIII\Http\Controllers\Json\AutoCompleteController
*/
public function testAllJournals(): void
{
$journalRepos = $this->mockDefaultSession();
$journal = $this->getRandomWithdrawalAsArray();
$journalRepos->shouldReceive('searchJournalDescriptions')->atLeast()->once()->andReturn(new Collection([$journal]));
$this->be($this->user());
$response = $this->get(route('json.autocomplete.all-journals'));
$response->assertStatus(200);
$response->assertSee($journal['description']);
}
/**
* Request a list of expense accounts
*
* @covers \FireflyIII\Http\Controllers\Json\AutoCompleteController
*/
public function testAllJournalsWithId(): void
{
$journalRepos = $this->mockDefaultSession();
$journal = $this->getRandomWithdrawalAsArray();
$journalRepos->shouldReceive('searchJournalDescriptions')->atLeast()->once()->andReturn(new Collection([$journal]));
$this->be($this->user());
$response = $this->get(route('json.autocomplete.all-journals-with-id'));
$response->assertStatus(200);
$response->assertSee($journal['description']);
$response->assertSee($journal['id']);
}
/**
* Request a list of expense accounts
*
* @covers \FireflyIII\Http\Controllers\Json\AutoCompleteController
*/
public function testAllJournalsWithIdNumeric(): void
{
$journalRepos = $this->mockDefaultSession();
$journal = $this->getRandomWithdrawalAsArray();
$journalObject = $this->getRandomWithdrawal();
$journalRepos->shouldReceive('searchJournalDescriptions')->atLeast()->once()->andReturn(new Collection([$journal]));
$journalRepos->shouldReceive('findNull')->atLeast()->once()->andReturn($journalObject);
$this->be($this->user());
$response = $this->get(route('json.autocomplete.all-journals-with-id') . '?search=' . $journal['id']);
$response->assertStatus(200);
$response->assertSee($journal['description']);
$response->assertSee($journal['id']);
}
}

View File

@@ -25,9 +25,7 @@ namespace Tests\Feature\Controllers\Json;
use Amount;
use Carbon\Carbon;
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
use FireflyIII\Helpers\Report\NetWorthInterface;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
@@ -58,6 +56,7 @@ class BoxControllerTest extends TestCase
*/
public function testAvailable(): void
{
$this->mockDefaultSession();
$return = [
0 => [
'spent' => '-1200', // more than budgeted.
@@ -66,7 +65,7 @@ class BoxControllerTest extends TestCase
$repository = $this->mock(BudgetRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$this->mockDefaultSession();
Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
Amount::shouldReceive('formatAnything')->atLeast()->once()->andReturn('-100');
@@ -85,6 +84,7 @@ class BoxControllerTest extends TestCase
*/
public function testAvailableDays(): void
{
$this->mockDefaultSession();
$return = [
0 => [
'spent' => '-800', // more than budgeted.
@@ -93,7 +93,6 @@ class BoxControllerTest extends TestCase
$repository = $this->mock(BudgetRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$this->mockDefaultSession();
Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
Amount::shouldReceive('formatAnything')->atLeast()->once()->andReturn('-100');
@@ -112,12 +111,12 @@ class BoxControllerTest extends TestCase
* @covers \FireflyIII\Http\Controllers\Json\BoxController
*/
public function testBalance(): void
{
{ $this->mockDefaultSession();
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$collector = $this->mock(GroupCollectorInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$this->mockDefaultSession();
Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
Amount::shouldReceive('formatAnything')->atLeast()->once()->andReturn('-100');
@@ -169,9 +168,12 @@ class BoxControllerTest extends TestCase
*/
public function testBills(): void
{
$this->mockDefaultSession();
$billRepos = $this->mock(BillRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
Amount::shouldReceive('formatAnything')->andReturn('-100');
$billRepos->shouldReceive('getBillsPaidInRange')->andReturn('0');
$billRepos->shouldReceive('getBillsUnpaidInRange')->andReturn('0');
@@ -195,7 +197,7 @@ class BoxControllerTest extends TestCase
$netWorthHelper = $this->mock(NetWorthInterface::class);
Amount::shouldReceive('formatAnything')->andReturn('-100');
$netWorthHelper->shouldReceive('setUser')->once();
$netWorthHelper->shouldReceive('getNetWorthByCurrency')->once()->andReturn($result);
@@ -228,7 +230,7 @@ class BoxControllerTest extends TestCase
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
Amount::shouldReceive('formatAnything')->andReturn('-100');
$netWorthHelper = $this->mock(NetWorthInterface::class);
$netWorthHelper->shouldReceive('setUser')->once();
$netWorthHelper->shouldReceive('getNetWorthByCurrency')->once()->andReturn($result);
@@ -264,7 +266,7 @@ class BoxControllerTest extends TestCase
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
Amount::shouldReceive('formatAnything')->andReturn('-100');
$netWorthHelper = $this->mock(NetWorthInterface::class);
$netWorthHelper->shouldReceive('setUser')->once();
$netWorthHelper->shouldReceive('getNetWorthByCurrency')->once()->andReturn($result);
@@ -297,7 +299,7 @@ class BoxControllerTest extends TestCase
$netWorthHelper = $this->mock(NetWorthInterface::class);
$netWorthHelper->shouldReceive('setUser')->once();
$netWorthHelper->shouldReceive('getNetWorthByCurrency')->once()->andReturn($result);
Amount::shouldReceive('formatAnything')->andReturn('-100');
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$accountRepos->shouldReceive('getActiveAccountsByType')->andReturn(new Collection([$this->user()->accounts()->first()]));
@@ -329,7 +331,7 @@ class BoxControllerTest extends TestCase
$account->virtual_balance = '1000';
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
Amount::shouldReceive('formatAnything')->andReturn('-100');
$netWorthHelper = $this->mock(NetWorthInterface::class);
$netWorthHelper->shouldReceive('setUser')->once();
$netWorthHelper->shouldReceive('getNetWorthByCurrency')->once()->andReturn($result);

View File

@@ -26,6 +26,7 @@ use Carbon\Carbon;
use FireflyIII\Helpers\Fiscal\FiscalHelperInterface;
use FireflyIII\Repositories\Account\AccountTaskerInterface;
use Log;
use Preferences;
use Tests\TestCase;
/**
@@ -62,6 +63,8 @@ class AccountControllerTest extends TestCase
$tasker = $this->mock(AccountTaskerInterface::class);
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
$date = new Carbon;
Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
$tasker->shouldReceive('getAccountReport')->andReturn($return);

View File

@@ -27,6 +27,7 @@ use FireflyIII\Helpers\Collection\Balance;
use FireflyIII\Helpers\Fiscal\FiscalHelperInterface;
use FireflyIII\Helpers\Report\BalanceReportHelperInterface;
use Log;
use Preferences;
use Tests\TestCase;
/**
@@ -57,6 +58,8 @@ class BalanceControllerTest extends TestCase
$balance = $this->mock(BalanceReportHelperInterface::class);
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
$date = new Carbon;
Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
$balance->shouldReceive('getBalanceReport')->andReturn(new Balance);

View File

@@ -22,12 +22,14 @@ declare(strict_types=1);
namespace Tests\Feature\Controllers\Report;
use Amount;
use Carbon\Carbon;
use FireflyIII\Helpers\Fiscal\FiscalHelperInterface;
use FireflyIII\Helpers\Report\BudgetReportHelperInterface;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use Illuminate\Support\Collection;
use Log;
use Preferences;
use Tests\TestCase;
/**
@@ -59,6 +61,9 @@ class BudgetControllerTest extends TestCase
$helper = $this->mock(BudgetReportHelperInterface::class);
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
$date = new Carbon;
Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
Amount::shouldReceive('formatAnything')->atLeast()->once()->andReturn('x');
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
$helper->shouldReceive('getBudgetReport')->andReturn($return);
@@ -79,6 +84,9 @@ class BudgetControllerTest extends TestCase
$repository = $this->mock(BudgetRepositoryInterface::class);
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
$date = new Carbon;
Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
Amount::shouldReceive('formatAnything')->atLeast()->once()->andReturn('x');
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
$repository->shouldReceive('getBudgets')->andReturn(new Collection);

View File

@@ -22,12 +22,13 @@ declare(strict_types=1);
namespace Tests\Feature\Controllers\Report;
use Amount;
use Carbon\Carbon;
use FireflyIII\Helpers\Fiscal\FiscalHelperInterface;
use FireflyIII\Models\Category;
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
use Illuminate\Support\Collection;
use Log;
use Preferences;
use Tests\TestCase;
/**
@@ -60,6 +61,9 @@ class CategoryControllerTest extends TestCase
$repository = $this->mock(CategoryRepositoryInterface::class);
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
$date = new Carbon;
Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
Amount::shouldReceive('formatAnything')->atLeast()->once()->andReturn('x');
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
$repository->shouldReceive('getCategories')->andReturn(new Collection);
@@ -77,11 +81,15 @@ class CategoryControllerTest extends TestCase
public function testIncome(): void
{
$this->mockDefaultSession();
$first = [1 => ['entries' => ['1', '1']]];
$first = [
1 => ['entries' => ['1', '1']],
2 => ['entries' => ['0']],
];
$second = ['entries' => ['1', '1']];
$repository = $this->mock(CategoryRepositoryInterface::class);
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
$date = new Carbon;
Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
$repository->shouldReceive('getCategories')->andReturn(new Collection);
@@ -103,6 +111,7 @@ class CategoryControllerTest extends TestCase
$category = $this->getRandomCategory();
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
$date = new Carbon;
Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
$repository->shouldReceive('getCategories')->andReturn(new Collection([$category]));
@@ -113,5 +122,6 @@ class CategoryControllerTest extends TestCase
$this->be($this->user());
$response = $this->get(route('report-data.category.operations', ['1', '20120101', '20120131']));
$response->assertStatus(200);
$response->assertDontSee('An error prevented Firefly III from rendering: %s. Apologies.');
}
}

View File

@@ -66,9 +66,7 @@ class ExpenseControllerTest extends TestCase
$transactions = [$this->getRandomWithdrawalAsArray()];
$this->mockDefaultSession();
Preferences::shouldReceive('lastActivity')->atLeast()->once();
Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
$repository->shouldReceive('findByName')->once()->withArgs([$expense->name, [AccountType::REVENUE]])->andReturn($revenue);

View File

@@ -26,6 +26,7 @@ use Carbon\Carbon;
use FireflyIII\Helpers\Fiscal\FiscalHelperInterface;
use FireflyIII\Repositories\Account\AccountTaskerInterface;
use Log;
use Preferences;
use Tests\TestCase;
/**
@@ -65,6 +66,8 @@ class OperationsControllerTest extends TestCase
$tasker = $this->mock(AccountTaskerInterface::class);
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
$date = new Carbon;
Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
$tasker->shouldReceive('getExpenseReport')->andReturn($return);
@@ -83,6 +86,8 @@ class OperationsControllerTest extends TestCase
$tasker = $this->mock(AccountTaskerInterface::class);
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
$date = new Carbon;
Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
$tasker->shouldReceive('getIncomeReport')->andReturn([]);
@@ -111,6 +116,8 @@ class OperationsControllerTest extends TestCase
$tasker = $this->mock(AccountTaskerInterface::class);
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
$date = new Carbon;
Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
$tasker->shouldReceive('getExpenseReport')->andReturn($return);

View File

@@ -54,11 +54,12 @@ class LinkControllerTest extends TestCase
*/
public function testDelete(): void
{
$this->mockDefaultSession();
$this->mock(LinkTypeRepositoryInterface::class);
$link = $this->getRandomLink();
$userRepos = $this->mock(UserRepositoryInterface::class);
$this->mockDefaultSession();
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
@@ -74,10 +75,11 @@ class LinkControllerTest extends TestCase
*/
public function testModal(): void
{
$this->mockDefaultSession();
$journal = $this->getRandomWithdrawal();
$linkRepos = $this->mock(LinkTypeRepositoryInterface::class);
$this->mockDefaultSession();
$linkRepos->shouldReceive('get')->atLeast()->once()->andReturn(new Collection);
@@ -91,11 +93,12 @@ class LinkControllerTest extends TestCase
*/
public function testDestroy(): void
{
$this->mockDefaultSession();
$link = $this->getRandomLink();
$repository = $this->mock(LinkTypeRepositoryInterface::class);
Preferences::shouldReceive('mark')->once();
$this->mockDefaultSession();
$repository->shouldReceive('destroyLink')->atLeast()->once();
$this->be($this->user());
@@ -113,6 +116,7 @@ class LinkControllerTest extends TestCase
*/
public function testStore(): void
{
$this->mockDefaultSession();
$withdrawal = $this->getRandomWithdrawal();
$deposit = $this->getRandomDeposit();
$repository = $this->mock(LinkTypeRepositoryInterface::class);
@@ -142,6 +146,7 @@ class LinkControllerTest extends TestCase
*/
public function testStoreAlreadyLinked(): void
{
$this->mockDefaultSession();
$repository = $this->mock(LinkTypeRepositoryInterface::class);
$journalRepos = $this->mockDefaultSession();
$link = $this->getRandomLink();
@@ -168,6 +173,7 @@ class LinkControllerTest extends TestCase
*/
public function testStoreInvalid(): void
{
$this->mockDefaultSession();
$this->mock(LinkTypeRepositoryInterface::class);
$journalRepos = $this->mockDefaultSession();
$withdrawal = $this->getRandomWithdrawal();
@@ -192,6 +198,7 @@ class LinkControllerTest extends TestCase
*/
public function testStoreSame(): void
{
$this->mockDefaultSession();
$withdrawal = $this->getRandomWithdrawal();
$repository = $this->mock(LinkTypeRepositoryInterface::class);
$journalRepos = $this->mockDefaultSession();
@@ -216,11 +223,10 @@ class LinkControllerTest extends TestCase
*/
public function testSwitchLink(): void
{
$this->mockDefaultSession();
$link = $this->getRandomLink();
$withdrawal = $this->getRandomWithdrawal();
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$repository = $this->mock(LinkTypeRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$this->mock(UserRepositoryInterface::class);
$repository->shouldReceive('switchLink')->andReturn(false);