Improve test coverage.

This commit is contained in:
James Cole 2019-07-25 14:19:49 +02:00
parent ee95606ec0
commit 6ff4a0b45c
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E
61 changed files with 822 additions and 599 deletions

View File

@ -86,6 +86,7 @@ class Note extends Model
/**
* @param $value
* @codeCoverageIgnore
*/
public function setTextAttribute($value): void
{

View File

@ -38,7 +38,6 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
* @property int $id
* @property User user
* @property int $user_id
* @property-read \FireflyIII\User $user
* @method static \Illuminate\Database\Eloquent\Builder|\FireflyIII\Models\Preference newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|\FireflyIII\Models\Preference newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|\FireflyIII\Models\Preference query()

View File

@ -147,6 +147,7 @@ class Rule extends Model
/**
* @param $value
* @codeCoverageIgnore
*/
public function setDescriptionAttribute($value): void
{

View File

@ -102,10 +102,7 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
* @property Carbon updated_at
* @property string foreign_currency_code
* @SuppressWarnings (PHPMD.TooManyPublicMethods)
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @property \Illuminate\Support\Carbon|null $deleted_at
* @property bool $reconciled
* @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\Budget[] $budgets
* @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\Category[] $categories
* @method static \Illuminate\Database\Eloquent\Builder|\FireflyIII\Models\Transaction after(\Carbon\Carbon $date)
@ -185,30 +182,6 @@ class Transaction extends Model
return false;
}
/**
* Route binder. Converts the key in the URL to the specified object (or throw 404).
*
* @param string $value
*
* @return Transaction
* @throws NotFoundHttpException
*/
public static function routeBinder(string $value): Transaction
{
if (auth()->check()) {
$transactionId = (int)$value;
/** @var User $user */
$user = auth()->user();
/** @var Transaction $transaction */
$transaction = $user->transactions()->where('transactions.id', $transactionId)->first(['transactions.*']);
if (null !== $transaction) {
return $transaction;
}
}
throw new NotFoundHttpException;
}
/**
* Get the account this object belongs to.

View File

@ -46,11 +46,13 @@ class BudgetList implements BinderInterface
//Log::debug(sprintf('Now in BudgetList::routeBinder("%s")', $value));
if (auth()->check()) {
$list = array_unique(array_map('\intval', explode(',', $value)));
//Log::debug('List is now', $list);
// @codeCoverageIgnoreStart
if (0 === count($list)) {
Log::warning('Budget list count is zero, return 404.');
throw new NotFoundHttpException; // @codeCoverageIgnore
throw new NotFoundHttpException;
}
// @codeCoverageIgnoreEnd
/** @var Collection $collection */
$collection = auth()->user()->budgets()

View File

@ -44,8 +44,14 @@ class ImportProvider implements BinderInterface
{
$repository = app(UserRepositoryInterface::class);
// get and filter all import routines:
if (!auth()->check()) {
return [];
}
/** @var User $user */
$user = auth()->user();
/** @var array $config */
$providerNames = array_keys(config('import.enabled'));
$providers = [];
@ -55,13 +61,20 @@ class ImportProvider implements BinderInterface
// only consider enabled providers
$enabled = (bool)config(sprintf('import.enabled.%s', $providerName));
$allowedForUser = (bool)config(sprintf('import.allowed_for_user.%s', $providerName));
$allowedForDemo = (bool)config(sprintf('import.allowed_for_demo.%s', $providerName));
if (false === $enabled) {
continue;
}
if (false === $isDemoUser && false === $allowedForUser && false === $isDebug) {
continue; // @codeCoverageIgnore
if (false === $allowedForUser && !$isDemoUser) {
continue;
}
if (false === $allowedForDemo && $isDemoUser) {
continue;
}
// if (false === $isDemoUser && false === $allowedForUser && false === $isDebug) {
// continue;
// }
$providers[$providerName] = [
'has_prereq' => (bool)config('import.has_prereq.' . $providerName),

View File

@ -46,17 +46,20 @@ class TagList implements BinderInterface
if (auth()->check()) {
$list = array_unique(array_map('\strtolower', explode(',', $value)));
Log::debug('List of tags is', $list);
// @codeCoverageIgnoreStart
if (0 === count($list)) {
Log::error('Tag list is empty.');
throw new NotFoundHttpException; // @codeCoverageIgnore
throw new NotFoundHttpException;
}
// @codeCoverageIgnoreEnd
/** @var TagRepositoryInterface $repository */
$repository = app(TagRepositoryInterface::class);
$repository->setUser(auth()->user());
$allTags = $repository->get();
$collection = $allTags->filter(
function (Tag $tag) use ($list) {
static function (Tag $tag) use ($list) {
if (in_array(strtolower($tag->tag), $list, true)) {
return true;
}

View File

@ -1,53 +0,0 @@
<?php
/**
* TransactionGroup.php
* Copyright (c) 2019 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
*
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Support\Binder;
use FireflyIII\Models\TransactionJournal;
use Illuminate\Routing\Route;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/**
* Class TransactionGroup.
*/
class TransactionGroup implements BinderInterface
{
/**
* @param string $value
* @param Route $route
*
* @return TransactionGroup
* @throws NotFoundHttpException
*/
public static function routeBinder(string $value, Route $route): TransactionGroup
{
if (auth()->check()) {
$group = auth()->user()->transactionGroups()
->find($value);
if (null !== $group) {
return $group;
}
}
throw new NotFoundHttpException;
}
}

View File

@ -1,55 +0,0 @@
<?php
/**
* UnfinishedJournal.php
* Copyright (c) 2017 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
*
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace FireflyIII\Support\Binder;
use FireflyIII\Models\TransactionJournal;
use Illuminate\Routing\Route;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/**
* Class Date.
*/
class UnfinishedJournal implements BinderInterface
{
/**
* @param string $value
* @param Route $route
*
* @return TransactionJournal
* @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
*/
public static function routeBinder(string $value, Route $route): TransactionJournal
{
if (auth()->check()) {
$journal = auth()->user()->transactionJournals()->where('transaction_journals.id', $value)
->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id')
->where('completed', 0)
->where('user_id', auth()->user()->id)->first(['transaction_journals.*']);
if (null !== $journal) {
return $journal;
}
}
throw new NotFoundHttpException;
}
}

View File

@ -23,7 +23,6 @@
declare(strict_types=1);
use FireflyIII\Export\Exporter\CsvExporter;
use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType;
use FireflyIII\Models\Attachment;
@ -32,7 +31,6 @@ use FireflyIII\Models\Bill;
use FireflyIII\Models\Budget;
use FireflyIII\Models\BudgetLimit;
use FireflyIII\Models\Category;
use FireflyIII\Models\ExportJob;
use FireflyIII\Models\ImportJob;
use FireflyIII\Models\LinkType;
use FireflyIII\Models\PiggyBank;
@ -41,7 +39,6 @@ use FireflyIII\Models\Recurrence;
use FireflyIII\Models\Rule;
use FireflyIII\Models\RuleGroup;
use FireflyIII\Models\Tag;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Models\TransactionGroup;
use FireflyIII\Models\TransactionJournal;
@ -60,7 +57,6 @@ use FireflyIII\Support\Binder\ImportProvider;
use FireflyIII\Support\Binder\JournalList;
use FireflyIII\Support\Binder\TagList;
use FireflyIII\Support\Binder\TagOrId;
use FireflyIII\Support\Binder\UnfinishedJournal;
use FireflyIII\TransactionRules\Actions\AddTag;
use FireflyIII\TransactionRules\Actions\AppendDescription;
use FireflyIII\TransactionRules\Actions\AppendNotes;
@ -377,7 +373,6 @@ return [
'rule' => Rule::class,
'ruleGroup' => RuleGroup::class,
'importJob' => ImportJob::class,
'transaction' => Transaction::class,
'transactionGroup' => TransactionGroup::class,
'user' => User::class,
@ -401,7 +396,6 @@ return [
// others
'fromCurrencyCode' => CurrencyCode::class,
'toCurrencyCode' => CurrencyCode::class,
'unfinishedJournal' => UnfinishedJournal::class,
'cliToken' => CLIToken::class,
'tagOrId' => TagOrId::class,
'configName' => ConfigurationName::class,

View File

@ -23,9 +23,7 @@ declare(strict_types=1);
namespace Tests\Feature\Controllers;
use FireflyIII\Models\Attachment;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Attachment\AttachmentRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\Repositories\User\UserRepositoryInterface;
use Illuminate\Support\Collection;
use Log;
@ -63,7 +61,7 @@ class AttachmentControllerTest extends TestCase
// mock stuff
$this->mock(AttachmentRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
@ -122,8 +120,8 @@ class AttachmentControllerTest extends TestCase
$this->mockDefaultSession();
// mock stuff
$attachment = $this->getRandomAttachment();
$repository = $this->mock(AttachmentRepositoryInterface::class);
$attachment = $this->getRandomAttachment();
$repository = $this->mock(AttachmentRepositoryInterface::class);
$repository->shouldReceive('exists')->once()->andReturn(false);
@ -207,7 +205,7 @@ class AttachmentControllerTest extends TestCase
$attachment = $this->getRandomAttachment();
$this->mockDefaultSession();
$repository = $this->mock(AttachmentRepositoryInterface::class);
$repository = $this->mock(AttachmentRepositoryInterface::class);
$repository->shouldReceive('exists')->once()->andReturn(true);
$repository->shouldReceive('getContent')->once()->andReturn('This is attachment number one.');

View File

@ -160,10 +160,10 @@ class BillControllerTest extends TestCase
// mock stuff
$this->mock(AttachmentHelperInterface::class);
$bill = $this->getRandomBill();
$repository = $this->mock(BillRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$transformer = $this->mock(BillTransformer::class);
$bill = $this->getRandomBill();
$repository = $this->mock(BillRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$transformer = $this->mock(BillTransformer::class);
$pref = new Preference;
$pref->data = 50;
@ -172,8 +172,8 @@ 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',
'currency' => $this->getEuro(),
['id' => 5, 'active' => true, 'name' => 'x', 'next_expected_match' => '2018-01-01',
'currency' => $this->getEuro(),
]
);
@ -201,8 +201,8 @@ class BillControllerTest extends TestCase
$this->mockDefaultSession();
// mock stuff
$rule = $this->getRandomRule();
$repository = $this->mock(BillRepositoryInterface::class);
$rule = $this->getRandomRule();
$repository = $this->mock(BillRepositoryInterface::class);
$this->mock(AttachmentHelperInterface::class);
@ -414,8 +414,8 @@ class BillControllerTest extends TestCase
$this->mockDefaultSession();
// mock stuff
$attachHelper = $this->mock(AttachmentHelperInterface::class);
$repository = $this->mock(BillRepositoryInterface::class);
$attachHelper = $this->mock(AttachmentHelperInterface::class);
$repository = $this->mock(BillRepositoryInterface::class);
$repository->shouldReceive('store')->andReturn(new Bill);
$attachHelper->shouldReceive('saveAttachmentsForModel');
@ -450,8 +450,8 @@ class BillControllerTest extends TestCase
$this->mockDefaultSession();
// mock stuff
$attachHelper = $this->mock(AttachmentHelperInterface::class);
$repository = $this->mock(BillRepositoryInterface::class);
$attachHelper = $this->mock(AttachmentHelperInterface::class);
$repository = $this->mock(BillRepositoryInterface::class);
$repository->shouldReceive('update')->andReturn(new Bill);
$attachHelper->shouldReceive('saveAttachmentsForModel');

View File

@ -57,7 +57,7 @@ class DeleteControllerTest extends TestCase
// mock stuff
$this->mock(BudgetRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
@ -77,7 +77,7 @@ class DeleteControllerTest extends TestCase
$budget = $this->getRandomBudget();
Log::debug('Now in testDestroy()');
// mock stuff
$repository = $this->mock(BudgetRepositoryInterface::class);
$repository = $this->mock(BudgetRepositoryInterface::class);
$this->mock(UserRepositoryInterface::class);

View File

@ -54,7 +54,7 @@ class EditControllerTest extends TestCase
Log::debug('Now in testEdit()');
// mock stuff
$this->mock(BudgetRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
$this->mockDefaultSession();
@ -74,7 +74,7 @@ class EditControllerTest extends TestCase
Log::debug('Now in testUpdate()');
// mock stuff
$budget = $this->getRandomBudget();
$repository = $this->mock(BudgetRepositoryInterface::class);
$repository = $this->mock(BudgetRepositoryInterface::class);
$this->mock(UserRepositoryInterface::class);
$repository->shouldReceive('findNull')->andReturn($budget);

View File

@ -65,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();
@ -102,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">');

View File

@ -222,7 +222,7 @@ class ShowControllerTest extends TestCase
{
$accountRepository = $this->mock(AccountRepositoryInterface::class);
$budgetRepository = $this->mock(BudgetRepositoryInterface::class);
$collector = $this->mock(GroupCollectorInterface::class);
$collector = $this->mock(GroupCollectorInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);

View File

@ -52,7 +52,7 @@ class CreateControllerTest extends TestCase
Log::debug('TestCreate()');
// mock stuff
$this->mock(CategoryRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
$this->mockDefaultSession();
@ -71,7 +71,7 @@ class CreateControllerTest extends TestCase
public function testStore(): void
{
Log::debug('Test store()');
$repository = $this->mock(CategoryRepositoryInterface::class);
$repository = $this->mock(CategoryRepositoryInterface::class);
$this->mock(UserRepositoryInterface::class);
$this->mockDefaultSession();
$repository->shouldReceive('findNull')->andReturn(new Category);

View File

@ -53,7 +53,7 @@ class DeleteControllerTest extends TestCase
// mock stuff
$this->mock(CategoryRepositoryInterface::class);
$this->mock(AccountRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$this->mockDefaultSession();
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);

View File

@ -67,7 +67,6 @@ class EditControllerTest extends TestCase
}
/**
* @covers \FireflyIII\Http\Controllers\Category\EditController
* @covers \FireflyIII\Http\Requests\CategoryFormRequest
@ -75,8 +74,8 @@ class EditControllerTest extends TestCase
public function testUpdate(): void
{
Log::debug('Test update()');
$category = Category::first();
$repository = $this->mock(CategoryRepositoryInterface::class);
$category = Category::first();
$repository = $this->mock(CategoryRepositoryInterface::class);
$this->mock(AccountRepositoryInterface::class);
$this->mock(UserRepositoryInterface::class);
$this->mockDefaultSession();

View File

@ -67,10 +67,10 @@ class NoCategoryControllerTest extends TestCase
*/
public function testNoCategory(string $range): void
{
$collector = $this->mock(GroupCollectorInterface::class);
$collector = $this->mock(GroupCollectorInterface::class);
$this->mock(CategoryRepositoryInterface::class);
$this->mock(AccountRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$this->mockDefaultSession();
// list size
@ -108,11 +108,11 @@ class NoCategoryControllerTest extends TestCase
*/
public function testNoCategoryAll(string $range): void
{
$collector = $this->mock(GroupCollectorInterface::class);
$collector = $this->mock(GroupCollectorInterface::class);
$this->mock(CategoryRepositoryInterface::class);
$this->mock(AccountRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
$this->mockDefaultSession();
// list size
@ -150,12 +150,12 @@ class NoCategoryControllerTest extends TestCase
*/
public function testNoCategoryDate(string $range): void
{
$collector = $this->mock(GroupCollectorInterface::class);
$collector = $this->mock(GroupCollectorInterface::class);
$this->mock(CategoryRepositoryInterface::class);
$this->mock(AccountRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
$date = new Carbon;
$userRepos = $this->mock(UserRepositoryInterface::class);
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
$date = new Carbon;
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);

View File

@ -123,10 +123,10 @@ class ShowControllerTest extends TestCase
*/
public function testShowAll(string $range): void
{
$withdrawal = $this->getRandomWithdrawalAsArray();
$repository = $this->mock(CategoryRepositoryInterface::class);
$collector = $this->mock(GroupCollectorInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$withdrawal = $this->getRandomWithdrawalAsArray();
$repository = $this->mock(CategoryRepositoryInterface::class);
$collector = $this->mock(GroupCollectorInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$this->mockDefaultSession();
$pref = new Preference;

View File

@ -26,12 +26,9 @@ use Carbon\Carbon;
use Exception;
use FireflyIII\Generator\Chart\Basic\GeneratorInterface;
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
use FireflyIII\Helpers\Fiscal\FiscalHelperInterface;
use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType;
use FireflyIII\Models\Preference;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Models\TransactionType;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
@ -118,14 +115,14 @@ class AccountControllerTest extends TestCase
*/
public function testExpenseBudget(string $range): void
{
$generator = $this->mock(GeneratorInterface::class);
$collector = $this->mock(GroupCollectorInterface::class);
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
$generator = $this->mock(GeneratorInterface::class);
$collector = $this->mock(GroupCollectorInterface::class);
$budgetRepos = $this->mock(BudgetRepositoryInterface::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']);
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
$withdrawal = $this->getRandomWithdrawalAsArray();
$budget = $this->user()->budgets()->find($withdrawal['budget_id']);
// mock default session
$this->mockDefaultSession();
@ -158,14 +155,14 @@ class AccountControllerTest extends TestCase
*/
public function testExpenseBudgetAll(string $range): void
{
$generator = $this->mock(GeneratorInterface::class);
$collector = $this->mock(GroupCollectorInterface::class);
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$generator = $this->mock(GeneratorInterface::class);
$collector = $this->mock(GroupCollectorInterface::class);
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$this->mock(CurrencyRepositoryInterface::class);
$this->mock(FiscalHelperInterface::class);
$withdrawal = $this->getRandomWithdrawalAsArray();
$budget = $this->user()->budgets()->find($withdrawal['budget_id']);
$withdrawal = $this->getRandomWithdrawalAsArray();
$budget = $this->user()->budgets()->find($withdrawal['budget_id']);
// mock default session
$this->mockDefaultSession();
@ -202,9 +199,9 @@ class AccountControllerTest extends TestCase
$categoryRepos = $this->mock(CategoryRepositoryInterface::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']);
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
$withdrawal = $this->getRandomWithdrawalAsArray();
$category = $this->user()->categories()->find($withdrawal['category_id']);
// mock default session
$this->mockDefaultSession();
@ -245,8 +242,8 @@ class AccountControllerTest extends TestCase
$categoryRepos = $this->mock(CategoryRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$this->mock(CurrencyRepositoryInterface::class);
$withdrawal = $this->getRandomWithdrawalAsArray();
$category = $this->user()->categories()->find($withdrawal['category_id']);
$withdrawal = $this->getRandomWithdrawalAsArray();
$category = $this->user()->categories()->find($withdrawal['category_id']);
// mock default session
$this->mockDefaultSession();
@ -404,7 +401,7 @@ class AccountControllerTest extends TestCase
Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
$date = new Carbon;
$date = new Carbon;
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
$accountRepos->shouldReceive('oldestJournalDate')->andReturn(new Carbon);
@ -433,7 +430,7 @@ class AccountControllerTest extends TestCase
Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
$date = new Carbon;
$date = new Carbon;
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1')->atLeast()->once();

View File

@ -27,9 +27,7 @@ use Exception;
use FireflyIII\Generator\Chart\Basic\GeneratorInterface;
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
use FireflyIII\Helpers\Fiscal\FiscalHelperInterface;
use FireflyIII\Models\Budget;
use FireflyIII\Models\BudgetLimit;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionType;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
@ -309,8 +307,8 @@ class BudgetControllerTest extends TestCase
public function testFrontpageNoLimits(string $range): void
{
$repository = $this->mock(BudgetRepositoryInterface::class);
$generator = $this->mock(GeneratorInterface::class);
$repository = $this->mock(BudgetRepositoryInterface::class);
$generator = $this->mock(GeneratorInterface::class);
$collector = $this->mock(GroupCollectorInterface::class);
$budget = $this->getRandomBudget();
@ -341,11 +339,11 @@ class BudgetControllerTest extends TestCase
*/
public function testPeriod(): void
{
$repository = $this->mock(BudgetRepositoryInterface::class);
$generator = $this->mock(GeneratorInterface::class);
$budgetLimit = $this->getRandomBudgetLimit();
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
$date = new Carbon;
$repository = $this->mock(BudgetRepositoryInterface::class);
$generator = $this->mock(GeneratorInterface::class);
$budgetLimit = $this->getRandomBudgetLimit();
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
$date = new Carbon;
// mock default session
$this->mockDefaultSession();

View File

@ -26,10 +26,6 @@ use Carbon\Carbon;
use FireflyIII\Generator\Chart\Basic\GeneratorInterface;
use FireflyIII\Helpers\Chart\MetaPieChartInterface;
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
use FireflyIII\Helpers\Fiscal\FiscalHelperInterface;
use FireflyIII\Models\BudgetLimit;
use FireflyIII\Models\TransactionType;
@ -39,6 +35,7 @@ use Log;
use Preferences;
use Tests\TestCase;
/**
* Class BudgetReportControllerTest
*/
@ -134,7 +131,7 @@ class BudgetReportControllerTest extends TestCase
$limit3->budget_id = $budget->id;
$limit3->start_date = new Carbon('2012-01-01');
$limit3->end_date = new Carbon('2012-01-31');
$limit3->amount = '100';
$limit3->amount = '100';
$limit3->save();

View File

@ -26,18 +26,13 @@ use Carbon\Carbon;
use FireflyIII\Generator\Chart\Basic\GeneratorInterface;
use FireflyIII\Helpers\Chart\MetaPieChartInterface;
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
use FireflyIII\Helpers\Fiscal\FiscalHelperInterface;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionType;
use Log;
use Preferences;
use Tests\TestCase;
/**
* Class CategoryReportControllerTest
*/
@ -173,7 +168,7 @@ class CategoryReportControllerTest extends TestCase
$collector = $this->mock(GroupCollectorInterface::class);
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
$date = new Carbon;
$withdrawal = $this->getRandomWithdrawalAsArray();
$withdrawal = $this->getRandomWithdrawalAsArray();
$this->mockDefaultSession();
Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');

View File

@ -58,7 +58,7 @@ class ExpenseReportControllerTest extends TestCase
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
$expense = $this->getRandomExpense();
$date = new Carbon;
$withdrawal = $this->getRandomWithdrawalAsArray();
$withdrawal = $this->getRandomWithdrawalAsArray();
$accountRepository->shouldReceive('findByName')->once()->andReturn($expense);

View File

@ -52,7 +52,7 @@ class PiggyBankControllerTest extends TestCase
$generator = $this->mock(GeneratorInterface::class);
$repository = $this->mock(PiggyBankRepositoryInterface::class);
/** @var PiggyBankEvent $event */
$event = PiggyBankEvent::inRandomOrder()->first();
$event = PiggyBankEvent::inRandomOrder()->first();
$piggy = $event->piggy_bank_id;
$this->mockDefaultSession();

View File

@ -194,9 +194,9 @@ class TagReportControllerTest extends TestCase
public function testMainChart(): void
{
$this->mock(AccountRepositoryInterface::class);
$generator = $this->mock(GeneratorInterface::class);
$collector = $this->mock(GroupCollectorInterface::class);
$tagRepos = $this->mock(TagRepositoryInterface::class);
$generator = $this->mock(GeneratorInterface::class);
$collector = $this->mock(GroupCollectorInterface::class);
$tagRepos = $this->mock(TagRepositoryInterface::class);
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
$withdrawal = $this->getRandomWithdrawalAsArray();
@ -234,11 +234,11 @@ class TagReportControllerTest extends TestCase
public function testTagExpense(): void
{
$this->mockDefaultSession();
$generator = $this->mock(GeneratorInterface::class);
$pieChart = $this->mock(MetaPieChartInterface::class);
$tagRepos = $this->mock(TagRepositoryInterface::class);
$generator = $this->mock(GeneratorInterface::class);
$pieChart = $this->mock(MetaPieChartInterface::class);
$tagRepos = $this->mock(TagRepositoryInterface::class);
$this->mock(AccountRepositoryInterface::class);
$tag = $this->user()->tags()->first();
$tag = $this->user()->tags()->first();
$tagRepos->shouldReceive('setUser');
$tagRepos->shouldReceive('get')->andReturn(new Collection([$tag]));

View File

@ -24,9 +24,7 @@ namespace Tests\Feature\Controllers;
use FireflyIII\Models\Preference;
use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\Repositories\User\UserRepositoryInterface;
use Illuminate\Support\Collection;
use Log;
@ -169,9 +167,9 @@ class CurrencyControllerTest extends TestCase
$this->mockDefaultSession();
// mock stuff
$repository = $this->mock(CurrencyRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$euro = $this->getEuro();
$repository = $this->mock(CurrencyRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$euro = $this->getEuro();
$repository->shouldReceive('currencyInUse')->andReturn(false);
@ -192,9 +190,9 @@ class CurrencyControllerTest extends TestCase
$this->mockDefaultSession();
// mock stuff
$repository = $this->mock(CurrencyRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$euro = $this->getEuro();
$repository = $this->mock(CurrencyRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$euro = $this->getEuro();
$repository->shouldReceive('currencyInUse')->andReturn(false);
$repository->shouldReceive('destroy')->andReturn(true)->once();
@ -350,8 +348,8 @@ class CurrencyControllerTest extends TestCase
$this->mockIntroPreference('shown_demo_currencies_index');
// mock stuff
$repository = $this->mock(CurrencyRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$repository = $this->mock(CurrencyRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$currencies = TransactionCurrency::get();
@ -385,8 +383,8 @@ class CurrencyControllerTest extends TestCase
$this->mockIntroPreference('shown_demo_currencies_index');
// mock stuff
$repository = $this->mock(CurrencyRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$repository = $this->mock(CurrencyRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$repository->shouldReceive('getCurrencyByPreference')->andReturn(new TransactionCurrency);
@ -418,8 +416,8 @@ class CurrencyControllerTest extends TestCase
$this->mockDefaultSession();
// mock stuff
$repository = $this->mock(CurrencyRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$repository = $this->mock(CurrencyRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$repository->shouldReceive('store')->andReturn(new TransactionCurrency);
@ -447,8 +445,8 @@ class CurrencyControllerTest extends TestCase
$this->mockDefaultSession();
// mock stuff
$repository = $this->mock(CurrencyRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$repository = $this->mock(CurrencyRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$repository->shouldReceive('store')->andReturnNull();
@ -476,8 +474,8 @@ class CurrencyControllerTest extends TestCase
$this->mockDefaultSession();
// mock stuff
$repository = $this->mock(CurrencyRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$repository = $this->mock(CurrencyRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$repository->shouldReceive('store')->andReturn(new TransactionCurrency);
@ -505,8 +503,8 @@ class CurrencyControllerTest extends TestCase
$this->mockDefaultSession();
// mock stuff
$repository = $this->mock(CurrencyRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$repository = $this->mock(CurrencyRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$repository->shouldReceive('update')->andReturn(new TransactionCurrency);

View File

@ -22,8 +22,6 @@ declare(strict_types=1);
namespace Tests\Feature\Controllers;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\Repositories\User\UserRepositoryInterface;
use Log;
use Mockery;
@ -55,7 +53,7 @@ class DebugControllerTest extends TestCase
{
$this->mockDefaultSession();
// mock stuff
$userRepos = $this->mock(UserRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->atLeast()->once()->andReturn(false);
$this->be($this->user());
@ -71,7 +69,7 @@ class DebugControllerTest extends TestCase
{
$this->mockDefaultSession();
// mock stuff
$userRepos = $this->mock(UserRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->atLeast()->once()->andReturn(false);
Preferences::shouldReceive('mark')->atLeast()->once();
@ -115,7 +113,7 @@ class DebugControllerTest extends TestCase
{
$this->mockDefaultSession();
// mock stuff
$userRepos = $this->mock(UserRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->atLeast()->once()->andReturn(false);

View File

@ -29,9 +29,9 @@ use FireflyIII\Repositories\User\UserRepositoryInterface;
use Illuminate\Support\MessageBag;
use Log;
use Mockery;
use Preferences;
use Tests\TestCase;
use Preferences;
/**
* Class AccountControllerTest
*
@ -56,8 +56,8 @@ class PrerequisitesControllerTest extends TestCase
public function testIndex(): void
{
$this->mockDefaultSession();
$userRepos = $this->mock(UserRepositoryInterface::class);
$prereq = $this->mock(FakePrerequisites::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$prereq = $this->mock(FakePrerequisites::class);
$this->mock(ImportJobRepositoryInterface::class);
$job = new ImportJob;
@ -69,10 +69,9 @@ 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(), '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);
@ -97,7 +96,7 @@ class PrerequisitesControllerTest extends TestCase
public function testIndexBadState(): void
{
$this->mockDefaultSession();
$userRepos = $this->mock(UserRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$this->mock(ImportJobRepositoryInterface::class);
@ -110,10 +109,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();
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);
@ -134,9 +133,9 @@ 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(), '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;
@ -171,9 +170,9 @@ 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(), '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();
@ -206,13 +205,13 @@ class PrerequisitesControllerTest extends TestCase
public function testPostBadState(): void
{
$this->mockDefaultSession();
$userRepos = $this->mock(UserRepositoryInterface::class);
$prereq = $this->mock(FakePrerequisites::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$prereq = $this->mock(FakePrerequisites::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(), '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;
@ -242,13 +241,13 @@ class PrerequisitesControllerTest extends TestCase
public function testPostNoJob(): void
{
$this->mockDefaultSession();
$userRepos = $this->mock(UserRepositoryInterface::class);
$prereq = $this->mock(FakePrerequisites::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$prereq = $this->mock(FakePrerequisites::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(), '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);
@ -272,13 +271,13 @@ class PrerequisitesControllerTest extends TestCase
public function testPostWithMessages(): void
{
$this->mockDefaultSession();
$userRepos = $this->mock(UserRepositoryInterface::class);
$prereq = $this->mock(FakePrerequisites::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$prereq = $this->mock(FakePrerequisites::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(), '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;

View File

@ -62,8 +62,8 @@ class JavascriptControllerTest extends TestCase
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$account = $this->getRandomAsset();
$euro = $this->getEuro();
$pref = new Preference;
$pref->data = 'EUR';
$pref = new Preference;
$pref->data = 'EUR';
Preferences::shouldReceive('get')->withArgs(['currencyPreference', 'EUR'])->atLeast()->once()->andReturn($pref);

View File

@ -111,7 +111,8 @@ class BoxControllerTest extends TestCase
* @covers \FireflyIII\Http\Controllers\Json\BoxController
*/
public function testBalance(): void
{ $this->mockDefaultSession();
{
$this->mockDefaultSession();
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$collector = $this->mock(GroupCollectorInterface::class);
@ -138,11 +139,11 @@ class BoxControllerTest extends TestCase
*/
public function testBalanceTransactions(): void
{
$withdrawal = $this->getRandomWithdrawalAsArray();
$withdrawal = $this->getRandomWithdrawalAsArray();
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$collector = $this->mock(GroupCollectorInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$euro =$this->getEuro();
$euro = $this->getEuro();
$this->mockDefaultSession();
Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');

View File

@ -24,7 +24,6 @@ namespace Tests\Feature\Controllers\Json;
use Carbon\Carbon;
use FireflyIII\Helpers\Fiscal\FiscalHelperInterface;
use FireflyIII\Models\CurrencyExchangeRate;
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
use FireflyIII\Services\Currency\ExchangeRateInterface;
use Log;
@ -58,7 +57,7 @@ class ExchangeControllerTest extends TestCase
$this->mockDefaultSession();
$date = new Carbon;
$date = new Carbon;
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
$rate = $this->getRandomCer();
@ -77,7 +76,7 @@ class ExchangeControllerTest extends TestCase
$this->mockDefaultSession();
$repository = $this->mock(CurrencyRepositoryInterface::class);
$rate = $this->getRandomCer();
$rate = $this->getRandomCer();
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
$date = new Carbon;
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);

View File

@ -23,8 +23,8 @@ declare(strict_types=1);
namespace Tests\Feature\Controllers\Json;
use Log;
use Tests\TestCase;
use Preferences;
use Tests\TestCase;
/**
* Class IntroControllerTest

View File

@ -27,14 +27,10 @@ namespace Tests\Feature\Controllers\Json;
use Amount;
use Carbon\Carbon;
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
use FireflyIII\Helpers\Fiscal\FiscalHelperInterface;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
use FireflyIII\Repositories\Recurring\RecurringRepositoryInterface;
use Illuminate\Support\Collection;
use Log;
use Mockery;
use Preferences;
@ -110,13 +106,13 @@ class ReconcileControllerTest extends TestCase
$this->mock(RecurringRepositoryInterface::class);
$this->mockDefaultSession();
$repository = $this->mock(CurrencyRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
$collector = $this->mock(GroupCollectorInterface::class);
$date = new Carbon;
$euro =$this->getEuro();
$withdrawal = $this->getRandomWithdrawalAsArray();
$repository = $this->mock(CurrencyRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
$collector = $this->mock(GroupCollectorInterface::class);
$date = new Carbon;
$euro = $this->getEuro();
$withdrawal = $this->getRandomWithdrawalAsArray();
$accountRepos->shouldReceive('getAccountCurrency')->atLeast()->once()->andReturn($euro);

View File

@ -22,8 +22,6 @@ declare(strict_types=1);
namespace Tests\Feature\Controllers;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use Log;
use Tests\TestCase;

View File

@ -22,7 +22,6 @@ declare(strict_types=1);
namespace Tests\Feature\Controllers;
use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
use FireflyIII\Repositories\User\UserRepositoryInterface;

View File

@ -425,7 +425,7 @@ class PiggyBankControllerTest extends TestCase
$userRepos = $this->mock(UserRepositoryInterface::class);
$piggyRepos = $this->mock(PiggyBankRepositoryInterface::class);
$repetition = PiggyBankRepetition::first();
$piggyBank = $this->getRandomPiggyBank();
$piggyBank = $this->getRandomPiggyBank();
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1')->atLeast()->once();
$currencyRepos->shouldReceive('findNull')->withArgs([1])->andReturn(TransactionCurrency::find(1))->atLeast()->once();
@ -449,8 +449,8 @@ class PiggyBankControllerTest extends TestCase
{
$this->mockDefaultSession();
// mock stuff
$repository = $this->mock(PiggyBankRepositoryInterface::class);
$piggyBank = $this->getRandomPiggyBank();
$repository = $this->mock(PiggyBankRepositoryInterface::class);
$piggyBank = $this->getRandomPiggyBank();
$this->mock(CurrencyRepositoryInterface::class);
$this->mock(AccountRepositoryInterface::class);
@ -471,12 +471,12 @@ class PiggyBankControllerTest extends TestCase
$this->mockDefaultSession();
$this->mockIntroPreference('shown_demo_piggy-banks_show');
// mock stuff
$first = $this->user()->transactionJournals()->inRandomOrder()->first();
$repository = $this->mock(PiggyBankRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$transformer = $this->mock(PiggyBankTransformer::class);
$piggyBank = $this->getRandomPiggyBank();
$first = $this->user()->transactionJournals()->inRandomOrder()->first();
$repository = $this->mock(PiggyBankRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$transformer = $this->mock(PiggyBankTransformer::class);
$piggyBank = $this->getRandomPiggyBank();
$this->mock(CurrencyRepositoryInterface::class);
$this->mock(AccountRepositoryInterface::class);
@ -506,7 +506,7 @@ class PiggyBankControllerTest extends TestCase
{
$this->mockDefaultSession();
// mock stuff
$repository = $this->mock(PiggyBankRepositoryInterface::class);
$repository = $this->mock(PiggyBankRepositoryInterface::class);
$this->mock(CurrencyRepositoryInterface::class);
$this->mock(AccountRepositoryInterface::class);
@ -535,8 +535,8 @@ class PiggyBankControllerTest extends TestCase
{
$this->mockDefaultSession();
// mock stuff
$repository = $this->mock(PiggyBankRepositoryInterface::class);
$piggyBank = $this->getRandomPiggyBank();
$repository = $this->mock(PiggyBankRepositoryInterface::class);
$piggyBank = $this->getRandomPiggyBank();
$this->mock(CurrencyRepositoryInterface::class);
$this->mock(AccountRepositoryInterface::class);

View File

@ -25,13 +25,10 @@ namespace Tests\Feature\Controllers\Popup;
use Amount;
use Carbon\Carbon;
use FireflyIII\Helpers\Report\PopupReportInterface;
use FireflyIII\Models\Account;
use FireflyIII\Models\Budget;
use FireflyIII\Models\Category;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
use Illuminate\Support\Collection;
use Log;
use Tests\TestCase;
@ -192,8 +189,8 @@ class ReportControllerTest extends TestCase
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
$popupReport = $this->mock(PopupReportInterface::class);
$account = $this->getRandomAsset();
$budget = $this->getRandomBudget();
$account = $this->getRandomAsset();
$budget = $this->getRandomBudget();
$this->mockDefaultSession();
$budgetRepos->shouldReceive('findNull')->andReturn($budget)->once()->withArgs([1]);
@ -227,7 +224,7 @@ class ReportControllerTest extends TestCase
$categoryRepos = $this->mock(CategoryRepositoryInterface::class);
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
$popupHelper = $this->mock(PopupReportInterface::class);
$budget = $this->getRandomBudget();
$budget = $this->getRandomBudget();
$this->mockDefaultSession();
$budgetRepos->shouldReceive('findNull')->andReturn($budget)->once()->withArgs([1]);
@ -259,7 +256,7 @@ class ReportControllerTest extends TestCase
$this->mock(AccountRepositoryInterface::class);
$categoryRepos = $this->mock(CategoryRepositoryInterface::class);
$popupHelper = $this->mock(PopupReportInterface::class);
$category = $this->getRandomCategory();
$category = $this->getRandomCategory();
$this->mockDefaultSession();
$categoryRepos->shouldReceive('findNull')->andReturn($category)->once()->withArgs([1]);
@ -292,7 +289,7 @@ class ReportControllerTest extends TestCase
$categoryRepos = $this->mock(CategoryRepositoryInterface::class);
$popupHelper = $this->mock(PopupReportInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$account = $this->getRandomAsset();
$account = $this->getRandomAsset();
$this->mockDefaultSession();
$accountRepos->shouldReceive('findNull')->withArgs([1])->andReturn($account)->once();
@ -325,7 +322,7 @@ class ReportControllerTest extends TestCase
$categoryRepos = $this->mock(CategoryRepositoryInterface::class);
$popupHelper = $this->mock(PopupReportInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$account = $this->getRandomAsset();
$account = $this->getRandomAsset();
$this->mockDefaultSession();
$accountRepos->shouldReceive('findNull')->withArgs([1])->andReturn($account)->once();

View File

@ -24,9 +24,7 @@ namespace Tests\Feature\Controllers;
use FireflyIII\Models\AccountType;
use FireflyIII\Models\Preference;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\Repositories\User\UserRepositoryInterface;
use Illuminate\Support\Collection;
use Log;
@ -104,7 +102,7 @@ class PreferencesControllerTest extends TestCase
{
$this->mockDefaultSession();
// mock stuff
$userRepos = $this->mock(UserRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$userRepos->shouldReceive('hasRole')->andReturn(false);

View File

@ -24,8 +24,6 @@ namespace Tests\Feature\Controllers;
use Amount;
use FireflyIII\Models\Preference;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\Repositories\User\UserRepositoryInterface;
use FireflyIII\User;
use Google2FA;
@ -33,6 +31,7 @@ use Illuminate\Support\Collection;
use Log;
use Mockery;
use Preferences;
use stdClass;
use Tests\TestCase;
/**
@ -133,7 +132,7 @@ class ProfileControllerTest extends TestCase
$repository->shouldReceive('unblockUser');
$preference = new Preference;
$preference->data = 'existing-token';
/** @var \stdClass $preference */
/** @var stdClass $preference */
$preference->user = $this->user();
Preferences::shouldReceive('findByName')->withArgs(['email_change_confirm_token'])->andReturn(new Collection([$preference]));
// email_change_confirm_token
@ -205,8 +204,8 @@ class ProfileControllerTest extends TestCase
{
//$this->mockDefaultSession(); // DISABLED ON PURPOSE
$this->mockDefaultConfiguration();
$repository = $this->mock(UserRepositoryInterface::class);
$euro = $this->getEuro();
$repository = $this->mock(UserRepositoryInterface::class);
$euro = $this->getEuro();
$repository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->times(1)->andReturn(false);
@ -534,12 +533,12 @@ class ProfileControllerTest extends TestCase
$hash = hash('sha256', 'previous@example.com');
$tokenPreference = new Preference;
$tokenPreference->data = 'token';
/** @var \stdClass $tokenPreference */
/** @var stdClass $tokenPreference */
$tokenPreference->user = $this->user();
$hashPreference = new Preference;
$hashPreference->data = 'previous@example.com';
/** @var \stdClass $hashPreference */
/** @var stdClass $hashPreference */
$hashPreference->user = $this->user();
Preferences::shouldReceive('findByName')->once()->andReturn(new Collection([$tokenPreference]));
@ -567,12 +566,12 @@ class ProfileControllerTest extends TestCase
$hash = hash('sha256', 'previous@example.comX');
$tokenPreference = new Preference;
$tokenPreference->data = 'token';
/** @var \stdClass $tokenPreference */
/** @var stdClass $tokenPreference */
$tokenPreference->user = $this->user();
$hashPreference = new Preference;
$hashPreference->data = 'previous@example.com';
/** @var \stdClass $hashPreference */
/** @var stdClass $hashPreference */
$hashPreference->user = $this->user();
Preferences::shouldReceive('findByName')->once()->andReturn(new Collection([$tokenPreference]));

View File

@ -29,7 +29,6 @@ use Carbon\Carbon;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
use FireflyIII\Repositories\Recurring\RecurringRepositoryInterface;

View File

@ -23,6 +23,7 @@ declare(strict_types=1);
namespace Tests\Feature\Controllers\Recurring;
use FireflyConfig;
use FireflyIII\Factory\CategoryFactory;
use FireflyIII\Models\Configuration;
use FireflyIII\Models\Preference;
@ -91,7 +92,7 @@ class IndexControllerTest extends TestCase
$collection = $this->user()->recurrences()->take(2)->get();
// mock cron job config:
\FireflyConfig::shouldReceive('get')->withArgs(['last_rt_job', 0])->once()->andReturn($config);
FireflyConfig::shouldReceive('get')->withArgs(['last_rt_job', 0])->once()->andReturn($config);
$repository->shouldReceive('get')->andReturn($collection)->once();
@ -125,9 +126,9 @@ class IndexControllerTest extends TestCase
'recurrence_repetitions' => [
[
'occurrences' => [
'2019-01-01'
]
]
'2019-01-01',
],
],
],
]
);

View File

@ -295,7 +295,7 @@ class ReportControllerTest extends TestCase
$this->mockDefaultSession();
$this->mock(BudgetRepositoryInterface::class);
$this->mock(ReportHelperInterface::class);
$repository = $this->mock(AccountRepositoryInterface::class);
$repository = $this->mock(AccountRepositoryInterface::class);
$account = new Account();
$account->name = 'Something';
@ -338,7 +338,7 @@ class ReportControllerTest extends TestCase
{
Log::debug(sprintf('Now in test %s', __METHOD__));
$this->mockDefaultSession();
$categoryRepos = $this->mock(CategoryRepositoryInterface::class);
$categoryRepos = $this->mock(CategoryRepositoryInterface::class);
$this->mock(BudgetRepositoryInterface::class);
$this->mock(ReportHelperInterface::class);
$category = $this->getRandomCategory();
@ -383,8 +383,8 @@ class ReportControllerTest extends TestCase
$this->mock(ReportHelperInterface::class);
$this->mock(CategoryRepositoryInterface::class);
$this->mock(TagRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$asset = $this->getRandomAsset();
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$asset = $this->getRandomAsset();
// find the user's asset account
$accountRepos->shouldReceive('findNull')->withArgs([1])->andReturn($asset)->atLeast()->once();
@ -414,7 +414,7 @@ class ReportControllerTest extends TestCase
{
Log::debug(sprintf('Now in test %s', __METHOD__));
$this->mockDefaultSession();
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$this->mock(BudgetRepositoryInterface::class);
$this->mock(ReportHelperInterface::class);
$this->mock(CategoryRepositoryInterface::class);
@ -446,7 +446,7 @@ class ReportControllerTest extends TestCase
$this->mock(ReportHelperInterface::class);
$this->mock(CategoryRepositoryInterface::class);
$this->mock(TagRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$accountRepos->shouldReceive('findNull')->andReturn($this->user()->accounts()->find(1))->twice();
$data = [
@ -472,7 +472,7 @@ class ReportControllerTest extends TestCase
$this->mock(ReportHelperInterface::class);
$this->mock(CategoryRepositoryInterface::class);
$this->mock(TagRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$accountRepos->shouldReceive('findNull')->andReturn($this->user()->accounts()->find(1))->twice();
$data = [
@ -530,7 +530,7 @@ class ReportControllerTest extends TestCase
$this->mock(ReportHelperInterface::class);
$this->mock(CategoryRepositoryInterface::class);
$this->mock(TagRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$accountRepos->shouldReceive('findNull')->andReturn($this->user()->accounts()->find(1))->twice();
@ -558,8 +558,8 @@ class ReportControllerTest extends TestCase
$this->mock(BudgetRepositoryInterface::class);
$this->mock(ReportHelperInterface::class);
$this->mock(TagRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$categoryRepos = $this->mock(CategoryRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$categoryRepos = $this->mock(CategoryRepositoryInterface::class);
$categoryRepos->shouldReceive('findNull')->andReturn($this->user()->categories()->find(1))->twice();
$accountRepos->shouldReceive('findNull')->andReturn($this->user()->accounts()->find(1))->twice();
@ -588,7 +588,7 @@ class ReportControllerTest extends TestCase
$this->mock(ReportHelperInterface::class);
$this->mock(CategoryRepositoryInterface::class);
$this->mock(TagRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$accountRepos->shouldReceive('findNull')->andReturn($this->user()->accounts()->find(1))->twice();
@ -615,7 +615,7 @@ class ReportControllerTest extends TestCase
$this->mock(ReportHelperInterface::class);
$this->mock(CategoryRepositoryInterface::class);
$this->mock(TagRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$accountRepos->shouldReceive('findNull')->andReturn($this->user()->accounts()->find(1))->twice();
@ -642,7 +642,7 @@ class ReportControllerTest extends TestCase
$this->mock(ReportHelperInterface::class);
$this->mock(CategoryRepositoryInterface::class);
$this->mock(TagRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$accountRepos->shouldReceive('findNull')->andReturn($this->user()->accounts()->find(1))->twice();
@ -672,8 +672,8 @@ class ReportControllerTest extends TestCase
$this->mock(CategoryRepositoryInterface::class);
$this->mock(TagRepositoryInterface::class);
Log::debug(sprintf('Now in test %s', __METHOD__));
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$tagRepos = $this->mock(TagRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$tagRepos = $this->mock(TagRepositoryInterface::class);
/** @var Tag $tag */
$tag = $this->user()->tags()->find(1);
@ -710,8 +710,8 @@ class ReportControllerTest extends TestCase
$this->mock(CategoryRepositoryInterface::class);
$this->mock(TagRepositoryInterface::class);
Log::debug(sprintf('Now in test %s', __METHOD__));
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$tagRepos = $this->mock(TagRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$tagRepos = $this->mock(TagRepositoryInterface::class);
$tag2 = $this->user()->tags()->find(3);

View File

@ -25,9 +25,7 @@ namespace tests\Feature\Controllers\Rule;
use FireflyIII\Models\Rule;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\Repositories\Rule\RuleRepositoryInterface;
use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface;
use FireflyIII\Repositories\User\UserRepositoryInterface;

View File

@ -24,8 +24,6 @@ declare(strict_types=1);
namespace tests\Feature\Controllers\Rule;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\Repositories\Rule\RuleRepositoryInterface;
use FireflyIII\Repositories\User\UserRepositoryInterface;
use Log;
@ -55,15 +53,14 @@ class DeleteControllerTest extends TestCase
public function testDelete(): void
{
// mock stuff
$ruleRepos = $this->mock(RuleRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$ruleRepos = $this->mock(RuleRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$this->mockDefaultSession();
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
$this->be($this->user());
$response = $this->get(route('rules.delete', [1]));
$response->assertStatus(200);
@ -76,7 +73,7 @@ class DeleteControllerTest extends TestCase
public function testDestroy(): void
{
// mock stuff
$repository = $this->mock(RuleRepositoryInterface::class);
$repository = $this->mock(RuleRepositoryInterface::class);
$repository->shouldReceive('destroy');
$this->mockDefaultSession();

View File

@ -25,8 +25,6 @@ namespace tests\Feature\Controllers\Rule;
use FireflyIII\Models\Rule;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\Repositories\Rule\RuleRepositoryInterface;
use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface;
use FireflyIII\Repositories\User\UserRepositoryInterface;
@ -56,9 +54,9 @@ class EditControllerTest extends TestCase
public function testEdit(): void
{
// mock stuff
$groupRepos = $this->mock(RuleGroupRepositoryInterface::class);
$repository = $this->mock(RuleRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$groupRepos = $this->mock(RuleGroupRepositoryInterface::class);
$repository = $this->mock(RuleRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$this->mockDefaultSession();
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
@ -88,9 +86,9 @@ class EditControllerTest extends TestCase
$this->session(['_old_input' => $old]);
// mock stuff
$groupRepos = $this->mock(RuleGroupRepositoryInterface::class);
$repository = $this->mock(RuleRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$groupRepos = $this->mock(RuleGroupRepositoryInterface::class);
$repository = $this->mock(RuleRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
$this->mockDefaultSession();
@ -111,8 +109,8 @@ class EditControllerTest extends TestCase
public function testUpdate(): void
{
// mock stuff
$repository = $this->mock(RuleRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$repository = $this->mock(RuleRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$this->mockDefaultSession();

View File

@ -23,8 +23,6 @@ declare(strict_types=1);
namespace Tests\Feature\Controllers\Rule;
use FireflyIII\Models\RuleGroup;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\Repositories\Rule\RuleRepositoryInterface;
use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface;
use FireflyIII\Repositories\User\UserRepositoryInterface;

View File

@ -26,10 +26,7 @@ namespace tests\Feature\Controllers\Rule;
use Carbon\Carbon;
use FireflyIII\Jobs\ExecuteRuleOnExistingTransactions;
use FireflyIII\Jobs\Job;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\Repositories\Rule\RuleRepositoryInterface;
use FireflyIII\Repositories\User\UserRepositoryInterface;
use FireflyIII\TransactionRules\TransactionMatcher;
@ -82,7 +79,7 @@ class SelectControllerTest extends TestCase
Queue::assertPushed(
ExecuteRuleOnExistingTransactions::class, function (Job $job) {
return 1=== $job->getRule()->id;
return 1 === $job->getRule()->id;
}
);
}
@ -193,7 +190,6 @@ class SelectControllerTest extends TestCase
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$matcher->shouldReceive('setStrict')->once()->withArgs([false]);
$matcher->shouldReceive('setTriggeredLimit')->withArgs([10])->andReturnSelf()->once();

View File

@ -52,7 +52,7 @@ class CreateControllerTest extends TestCase
{
$this->mockDefaultSession();
$this->mock(RuleGroupRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
$this->be($this->user());
@ -69,7 +69,7 @@ class CreateControllerTest extends TestCase
public function testStore(): void
{
$this->mockDefaultSession();
$repository = $this->mock(RuleGroupRepositoryInterface::class);
$repository = $this->mock(RuleGroupRepositoryInterface::class);
Preferences::shouldReceive('mark')->atLeast()->once();

View File

@ -24,9 +24,7 @@ namespace Tests\Feature\Controllers\RuleGroup;
use Carbon\Carbon;
use FireflyIII\Jobs\ExecuteRuleGroupOnExistingTransactions;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\Repositories\User\UserRepositoryInterface;
use Illuminate\Support\Collection;
use Log;

View File

@ -75,7 +75,7 @@ class SearchControllerTest extends TestCase
public function testSearch(): void
{
$this->mockDefaultSession();
$search = $this->mock(SearchInterface::class);
$search = $this->mock(SearchInterface::class);
$search->shouldReceive('parseQuery')->once();
$search->shouldReceive('setLimit')->withArgs([50])->once();

View File

@ -30,6 +30,7 @@ use FireflyIII\Support\Cronjobs\RecurringCronjob;
use Illuminate\Support\Collection;
use Log;
use Mockery;
use Preferences;
use Tests\TestCase;
/**
@ -61,7 +62,7 @@ class CronControllerTest extends TestCase
$job->shouldReceive('fire')->once()->andReturn(true);
$repository = $this->mock(UserRepositoryInterface::class);
$repository->shouldReceive('all')->andReturn($users);
\Preferences::shouldReceive('getForUser')
Preferences::shouldReceive('getForUser')
->withArgs([Mockery::any(), 'access_token', null])
->andReturn($preference)->once();
$response = $this->get(route('cron.cron', ['token']));
@ -83,7 +84,7 @@ class CronControllerTest extends TestCase
$job->shouldReceive('fire')->once()->andThrow(new FireflyException('Exception noted.'));
$repository = $this->mock(UserRepositoryInterface::class);
$repository->shouldReceive('all')->andReturn($users);
\Preferences::shouldReceive('getForUser')
Preferences::shouldReceive('getForUser')
->withArgs([Mockery::any(), 'access_token', null])
->andReturn($preference)->once();
$response = $this->get(route('cron.cron', ['token']));
@ -105,7 +106,7 @@ class CronControllerTest extends TestCase
$job->shouldReceive('fire')->once()->andReturn(false);
$repository = $this->mock(UserRepositoryInterface::class);
$repository->shouldReceive('all')->andReturn($users);
\Preferences::shouldReceive('getForUser')
Preferences::shouldReceive('getForUser')
->withArgs([Mockery::any(), 'access_token', null])
->andReturn($preference)->once();
$response = $this->get(route('cron.cron', ['token']));

View File

@ -29,11 +29,9 @@ use FireflyIII\Helpers\Fiscal\FiscalHelperInterface;
use FireflyIII\Models\Preference;
use FireflyIII\Models\Tag;
use FireflyIII\Models\TransactionType;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\Repositories\Tag\TagRepositoryInterface;
use FireflyIII\Repositories\User\UserRepositoryInterface;
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\Collection;
use Log;
use Mockery;
use Preferences;
@ -65,8 +63,8 @@ class TagControllerTest extends TestCase
{
$this->mockDefaultSession();
$this->mock(TagRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
$this->be($this->user());
@ -82,9 +80,9 @@ class TagControllerTest extends TestCase
{
$this->mockDefaultSession();
$this->mock(TagRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
$this->be($this->user());
@ -99,7 +97,7 @@ class TagControllerTest extends TestCase
public function testDestroy(): void
{
$this->mockDefaultSession();
$repository = $this->mock(TagRepositoryInterface::class);
$repository = $this->mock(TagRepositoryInterface::class);
$repository->shouldReceive('destroy');
Preferences::shouldReceive('mark')->atLeast()->once();
@ -117,8 +115,8 @@ class TagControllerTest extends TestCase
{
$this->mockDefaultSession();
$this->mock(TagRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
$this->be($this->user());
@ -133,11 +131,11 @@ class TagControllerTest extends TestCase
public function testIndex(): void
{
$this->mockDefaultSession();
$repository = $this->mock(TagRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$repository = $this->mock(TagRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
$repository->shouldReceive('count')->andReturn(0);
$repository->shouldReceive('tagCloud')->andReturn([]);
$repository->shouldReceive('oldestTag')->andReturn(null)->once();
@ -315,7 +313,7 @@ class TagControllerTest extends TestCase
public function testStore(): void
{
$this->mockDefaultSession();
$repository = $this->mock(TagRepositoryInterface::class);
$repository = $this->mock(TagRepositoryInterface::class);
Preferences::shouldReceive('mark')->atLeast()->once();
$repository->shouldReceive('findNull')->andReturn(null);
@ -341,8 +339,8 @@ class TagControllerTest extends TestCase
public function testUpdate(): void
{
$this->mockDefaultSession();
$repository = $this->mock(TagRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$repository = $this->mock(TagRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
Preferences::shouldReceive('mark')->atLeast()->once();

View File

@ -24,10 +24,8 @@ namespace Tests\Feature\Controllers\Transaction;
use Amount;
use FireflyIII\Models\AccountType;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface;
use FireflyIII\Repositories\TransactionGroup\TransactionGroupRepositoryInterface;
use FireflyIII\Repositories\User\UserRepositoryInterface;
@ -193,8 +191,6 @@ class ConvertControllerTest extends TestCase
$validator->shouldReceive('validateDestination')->atLeast()->once()->andReturn(true);
$data = ['source_account_id' => 1];
$this->be($this->user());
$response = $this->post(route('transactions.convert.index.post', ['transfer', $deposit->id]), $data);

View File

@ -26,9 +26,9 @@ use FireflyIII\Models\Preference;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\User\UserRepositoryInterface;
use Log;
use Mockery;
use Preferences;
use Tests\TestCase;
use Mockery;
/**
* Class CreateControllerTest
@ -56,7 +56,7 @@ class CreateControllerTest extends TestCase
$empty = new Preference;
$empty->data = [];
$userRepos->shouldReceive('hasRole')->atLeast()->once()->withArgs([Mockery::any(),'owner'])->andReturn(true);
$userRepos->shouldReceive('hasRole')->atLeast()->once()->withArgs([Mockery::any(), 'owner'])->andReturn(true);
$accountRepos->shouldReceive('getCashAccount')->atLeast()->once()->andReturn($cash);
Preferences::shouldReceive('get')->withArgs(['transaction_journal_optional_fields', []])->atLeast()->once()->andReturn($empty);

View File

@ -53,9 +53,9 @@ class IndexControllerTest extends TestCase
public function testIndex(): void
{
$this->mockDefaultSession();
$group = $this->getRandomWithdrawalGroup();
$userRepos = $this->mock(UserRepositoryInterface::class);
$collector = $this->mock(GroupCollectorInterface::class);
$group = $this->getRandomWithdrawalGroup();
$userRepos = $this->mock(UserRepositoryInterface::class);
$collector = $this->mock(GroupCollectorInterface::class);
// generic set for the info blocks:
$groupArray = [$this->getRandomWithdrawalAsArray()];
@ -95,9 +95,9 @@ class IndexControllerTest extends TestCase
public function testIndexAll(): void
{
$this->mockDefaultSession();
$group = $this->getRandomWithdrawalGroup();
$userRepos = $this->mock(UserRepositoryInterface::class);
$collector = $this->mock(GroupCollectorInterface::class);
$group = $this->getRandomWithdrawalGroup();
$userRepos = $this->mock(UserRepositoryInterface::class);
$collector = $this->mock(GroupCollectorInterface::class);
// role?
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true);

View File

@ -25,7 +25,6 @@ namespace Tests\Feature\Controllers\Transaction;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Models\TransactionJournalLink;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\Repositories\LinkType\LinkTypeRepositoryInterface;
use FireflyIII\Repositories\User\UserRepositoryInterface;
use Illuminate\Support\Collection;
@ -60,8 +59,6 @@ class LinkControllerTest extends TestCase
$userRepos = $this->mock(UserRepositoryInterface::class);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
$this->be($this->user());
@ -80,7 +77,6 @@ class LinkControllerTest extends TestCase
$linkRepos = $this->mock(LinkTypeRepositoryInterface::class);
$linkRepos->shouldReceive('get')->atLeast()->once()->andReturn(new Collection);
$this->be($this->user());
@ -94,8 +90,8 @@ class LinkControllerTest extends TestCase
public function testDestroy(): void
{
$this->mockDefaultSession();
$link = $this->getRandomLink();
$repository = $this->mock(LinkTypeRepositoryInterface::class);
$link = $this->getRandomLink();
$repository = $this->mock(LinkTypeRepositoryInterface::class);
Preferences::shouldReceive('mark')->once();
@ -203,7 +199,7 @@ class LinkControllerTest extends TestCase
$repository = $this->mock(LinkTypeRepositoryInterface::class);
$journalRepos = $this->mockDefaultSession();
$data = [
$data = [
'link_other' => $withdrawal->id,
'link_type' => '1_inward',
];
@ -224,8 +220,8 @@ class LinkControllerTest extends TestCase
public function testSwitchLink(): void
{
$this->mockDefaultSession();
$link = $this->getRandomLink();
$repository = $this->mock(LinkTypeRepositoryInterface::class);
$link = $this->getRandomLink();
$repository = $this->mock(LinkTypeRepositoryInterface::class);
$this->mock(UserRepositoryInterface::class);

View File

@ -172,13 +172,13 @@ class MassControllerTest extends TestCase
$this->session(['transactions.mass-edit.uri' => 'http://localhost']);
$data = [
'journals' => [$deposit->id],
'description' => [$deposit->id => 'Updated salary thing'],
'amount' => [$deposit->id => 1600],
'date' => [$deposit->id => '2014-07-24'],
'source_name' => [$deposit->id => 'Job'],
'destination_id' => [$deposit->id => 1],
'category' => [$deposit->id => 'Salary'],
'journals' => [$deposit->id],
'description' => [$deposit->id => 'Updated salary thing'],
'amount' => [$deposit->id => 1600],
'date' => [$deposit->id => '2014-07-24'],
'source_name' => [$deposit->id => 'Job'],
'destination_id' => [$deposit->id => 1],
'category' => [$deposit->id => 'Salary'],
];
$this->be($this->user());

View File

@ -25,15 +25,26 @@ namespace Tests\Unit\Middleware;
use Carbon\Carbon;
use FireflyIII\Helpers\FiscalHelperInterface;
use FireflyIII\Helpers\Fiscal\FiscalHelperInterface;
use FireflyIII\Http\Middleware\Binder;
use FireflyIII\Import\Prerequisites\PrerequisitesInterface;
use FireflyIII\Models\AccountType;
use FireflyIII\Models\AvailableBudget;
use FireflyIII\Models\Preference;
use FireflyIII\Models\Recurrence;
use FireflyIII\Models\Tag;
use FireflyIII\Models\TransactionGroup;
use FireflyIII\Repositories\Tag\TagRepositoryInterface;
use FireflyIII\Repositories\User\UserRepositoryInterface;
use Illuminate\Support\Collection;
use Log;
use Mockery;
use Preferences;
use Route;
use Symfony\Component\HttpFoundation\Response;
use Tests\TestCase;
/**
* Class BinderTest
* Per object: works, not existing, not logged in + existing
@ -76,6 +87,28 @@ class BinderTest extends TestCase
$response->assertSee('count: 2');
}
/**
* @covers \FireflyIII\Http\Middleware\Binder
* @covers \FireflyIII\Support\Binder\AccountList
*/
public function testAccountListAllAssets(): void
{
Route::middleware(Binder::class)->any(
'/_test/binder/{accountList}', function (Collection $accounts) {
return 'count: ' . $accounts->count();
}
);
$this->be($this->user());
$response = $this->get('/_test/binder/allAssetAccounts');
$count = $this->user()->accounts()
->leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id')
->where('account_types.type', AccountType::ASSET)
->orderBy('accounts.name', 'ASC')
->count();
$this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
$response->assertSee(sprintf('count: %d', $count));
}
/**
* @covers \FireflyIII\Http\Middleware\Binder
* @covers \FireflyIII\Support\Binder\AccountList
@ -357,6 +390,223 @@ class BinderTest extends TestCase
$this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
}
/**
* @covers \FireflyIII\Http\Middleware\Binder
* @covers \FireflyIII\Support\Binder\BudgetList
*/
public function testBudgetListEmpty(): void
{
Route::middleware(Binder::class)->any(
'/_test/binder/{budgetList}', function (Collection $budgets) {
return 'count: ' . $budgets->count();
}
);
$this->be($this->user());
$response = $this->get('/_test/binder/');
$this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
}
/**
* @covers \FireflyIII\Http\Middleware\Binder
* @covers \FireflyIII\Support\Binder\CLIToken
*/
public function testCLIToken(): void
{
$repos = $this->mock(UserRepositoryInterface::class);
$repos->shouldReceive('all')->andReturn(new Collection([$this->user()]))->atLeast()->once();
$token = new Preference;
$token->data = 'token';
Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'access_token', null])->atLeast()->once()->andReturn($token);
Route::middleware(Binder::class)->any(
'/_test/binder/{cliToken}', static function (string $token) {
return sprintf('token: %s', $token);
}
);
$response = $this->get('/_test/binder/token');
$this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
$response->assertSee('token');
}
/**
* @covers \FireflyIII\Http\Middleware\Binder
* @covers \FireflyIII\Support\Binder\CLIToken
*/
public function testCLITokenNotFound(): void
{
$repos = $this->mock(UserRepositoryInterface::class);
$repos->shouldReceive('all')->andReturn(new Collection([$this->user()]))->atLeast()->once();
$token = new Preference;
$token->data = 'token';
Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'access_token', null])->atLeast()->once()->andReturn($token);
Route::middleware(Binder::class)->any(
'/_test/binder/{cliToken}', static function (string $token) {
return sprintf('token: %s', $token);
}
);
$response = $this->get('/_test/binder/tokenX');
$this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
}
/**
* @covers \FireflyIII\Http\Middleware\Binder
* @covers \FireflyIII\Support\Binder\ConfigurationName
*/
public function testConfigName(): void
{
Route::middleware(Binder::class)->any(
'/_test/binder/{configName}', static function (string $name) {
return sprintf('configName: %s', $name);
}
);
$response = $this->get('/_test/binder/is_demo_site');
$this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
$response->assertSee('is_demo_site');
}
/**
* @covers \FireflyIII\Http\Middleware\Binder
* @covers \FireflyIII\Support\Binder\ConfigurationName
*/
public function testConfigNameNotFOund(): void
{
Route::middleware(Binder::class)->any(
'/_test/binder/{configName}', static function (string $name) {
return sprintf('configName: %s', $name);
}
);
$response = $this->get('/_test/binder/is_demoX_site');
$this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
}
/**
* Normal user can access file routine
*
* @covers \FireflyIII\Http\Middleware\Binder
* @covers \FireflyIII\Support\Binder\ImportProvider
*/
public function testImportProvider(): void
{
$repository = $this->mock(UserRepositoryInterface::class);
$this->mock(PrerequisitesInterface::class);
$repository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false)->atLeast()->once();
Route::middleware(Binder::class)->any(
'/_test/binder/{import_provider}', static function (string $name) {
return sprintf('import_provider: %s', $name);
}
);
$this->be($this->user());
$response = $this->get('/_test/binder/file');
$this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
$response->assertSee('file');
}
/**
* Normal user cannot access fake import routine.
*
* @covers \FireflyIII\Http\Middleware\Binder
* @covers \FireflyIII\Support\Binder\ImportProvider
*/
public function testImportProviderFake(): void
{
$repository = $this->mock(UserRepositoryInterface::class);
$this->mock(PrerequisitesInterface::class);
$repository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false)->atLeast()->once();
Route::middleware(Binder::class)->any(
'/_test/binder/{import_provider}', static function (string $name) {
return sprintf('import_provider: %s', $name);
}
);
$this->be($this->user());
$response = $this->get('/_test/binder/fake');
$this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
}
/**
* Nobody can access "bad" import routine.
*
* @covers \FireflyIII\Http\Middleware\Binder
* @covers \FireflyIII\Support\Binder\ImportProvider
*/
public function testImportProviderBad(): void
{
$repository = $this->mock(UserRepositoryInterface::class);
$this->mock(PrerequisitesInterface::class);
$repository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(false)->atLeast()->once();
Route::middleware(Binder::class)->any(
'/_test/binder/{import_provider}', static function (string $name) {
return sprintf('import_provider: %s', $name);
}
);
$this->be($this->user());
$response = $this->get('/_test/binder/bad');
$this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
}
/**
* Demo user cannot access file import routine.
*
* @covers \FireflyIII\Http\Middleware\Binder
* @covers \FireflyIII\Support\Binder\ImportProvider
*/
public function testImportProviderDemoFile(): void
{
$repository = $this->mock(UserRepositoryInterface::class);
$this->mock(PrerequisitesInterface::class);
$repository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->andReturn(true)->atLeast()->once();
Route::middleware(Binder::class)->any(
'/_test/binder/{import_provider}', static function (string $name) {
return sprintf('import_provider: %s', $name);
}
);
$this->be($this->user());
$response = $this->get('/_test/binder/file');
$this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
}
/**
* @covers \FireflyIII\Http\Middleware\Binder
* @covers \FireflyIII\Support\Binder\ImportProvider
*/
public function testImportProviderNotLoggedIn(): void
{
$this->mock(UserRepositoryInterface::class);
$this->mock(PrerequisitesInterface::class);
Route::middleware(Binder::class)->any(
'/_test/binder/{import_provider}', static function (string $name) {
return sprintf('import_provider: %s', $name);
}
);
$response = $this->get('/_test/binder/file');
$this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
}
/**
* @covers \FireflyIII\Http\Middleware\Binder
* @covers \FireflyIII\Models\Budget
@ -730,56 +980,6 @@ class BinderTest extends TestCase
$this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
}
/**
* @covers \FireflyIII\Http\Middleware\Binder
* @covers \FireflyIII\Models\ExportJob
*/
public function testExportJob(): void
{
Route::middleware(Binder::class)->any(
'/_test/binder/{exportJob}', function () {
return 'OK';
}
);
$this->be($this->user());
$response = $this->get('/_test/binder/testExport');
$this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
}
/**
* @covers \FireflyIII\Http\Middleware\Binder
* @covers \FireflyIII\Models\ExportJob
*/
public function testExportJobNotFound(): void
{
Route::middleware(Binder::class)->any(
'/_test/binder/{exportJob}', function () {
return 'OK';
}
);
$this->be($this->user());
$response = $this->get('/_test/binder/0');
$this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
}
/**
* @covers \FireflyIII\Http\Middleware\Binder
* @covers \FireflyIII\Models\ExportJob
*/
public function testExportJobNotLoggedIn(): void
{
Route::middleware(Binder::class)->any(
'/_test/binder/{exportJob}', function () {
return 'OK';
}
);
$response = $this->get('/_test/binder/testExport');
$this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
}
/**
* @covers \FireflyIII\Http\Middleware\Binder
* @covers \FireflyIII\Models\ImportJob
@ -836,16 +1036,15 @@ class BinderTest extends TestCase
*/
public function testJournalList(): void
{
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
Route::middleware(Binder::class)->any(
'/_test/binder/{journalList}', function (Collection $journals) {
return 'count: ' . $journals->count();
'/_test/binder/{journalList}', static function (array $journals) {
return 'count: ' . count($journals);
}
);
$this->be($this->user());
$response = $this->get('/_test/binder/1,2');
$withdrawal = $this->getRandomWithdrawal();
$deposit = $this->getRandomDeposit();
$response = $this->get(sprintf('/_test/binder/%d,%d', $withdrawal->id, $deposit->id));
$this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
$response->assertSee('count: 2');
}
@ -856,19 +1055,33 @@ class BinderTest extends TestCase
*/
public function testJournalListEmpty(): void
{
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
Route::middleware(Binder::class)->any(
'/_test/binder/{journalList}', function (Collection $journals) {
return 'count: ' . $journals->count();
}
);
'/_test/binder/{journalList}', static function (array $journals) {
return 'count: ' . count($journals);
});
$this->be($this->user());
$response = $this->get('/_test/binder/-1');
$this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
}
/**
* Not logged in.
*
* @covers \FireflyIII\Http\Middleware\Binder
* @covers \FireflyIII\Support\Binder\JournalList
*/
public function testJournalListNotLoggedIn(): void
{
Route::middleware(Binder::class)->any(
'/_test/binder/{journalList}', static function (array $journals) {
return 'count: ' . count($journals);
});
$response = $this->get('/_test/binder/-1');
$this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
}
/**
* @covers \FireflyIII\Http\Middleware\Binder
* @covers \FireflyIII\Models\LinkType
@ -936,6 +1149,141 @@ class BinderTest extends TestCase
$this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
}
/**
* @covers \FireflyIII\Http\Middleware\Binder
* @covers \FireflyIII\Models\Preference
*/
public function testPreference(): void
{
Route::middleware(Binder::class)->any(
'/_test/binder/{preference}', static function (?Preference $preference) {
return $preference->name ?? 'unknown';
}
);
$this->be($this->user());
$response = $this->get('/_test/binder/frontPageAccounts');
$this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
$response->assertSee('frontPageAccounts');
}
/**
* @covers \FireflyIII\Http\Middleware\Binder
* @covers \FireflyIII\Models\Recurrence
*/
public function testRecurrence(): void
{
Route::middleware(Binder::class)->any(
'/_test/binder/{recurrence}', static function (?Recurrence $recurrence) {
return $recurrence->description ?? 'unknown';
}
);
$this->be($this->user());
$response = $this->get('/_test/binder/1');
$this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
}
/**
* @covers \FireflyIII\Http\Middleware\Binder
* @covers \FireflyIII\Models\Recurrence
*/
public function testRecurrenceNotFound(): void
{
Route::middleware(Binder::class)->any(
'/_test/binder/{recurrence}', static function (?Recurrence $recurrence) {
return $recurrence->description ?? 'unknown';
}
);
$this->be($this->user());
$response = $this->get('/_test/binder/-1');
$this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
}
/**
* @covers \FireflyIII\Http\Middleware\Binder
* @covers \FireflyIII\Models\TransactionGroup
*/
public function testTransactionGroup(): void
{
Route::middleware(Binder::class)->any(
'/_test/binder/{transactionGroup}', static function (?TransactionGroup $transactionGroup) {
return $transactionGroup->title ?? 'unknown';
}
);
$this->be($this->user());
$response = $this->get('/_test/binder/1');
$this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
}
/**
* @covers \FireflyIII\Http\Middleware\Binder
* @covers \FireflyIII\Models\TransactionGroup
*/
public function testTransactionGroupNotFound(): void
{
Route::middleware(Binder::class)->any(
'/_test/binder/{transactionGroup}', static function (?TransactionGroup $transactionGroup) {
return $transactionGroup->title ?? 'unknown';
}
);
$this->be($this->user());
$response = $this->get('/_test/binder/-1');
$this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
}
/**
* @covers \FireflyIII\Http\Middleware\Binder
* @covers \FireflyIII\Models\AvailableBudget
*/
public function testAvailableBudget(): void
{
Route::middleware(Binder::class)->any(
'/_test/binder/{availableBudget}', static function (?AvailableBudget $availableBudget) {
return $availableBudget->id ?? 0;
}
);
$this->be($this->user());
$response = $this->get('/_test/binder/1');
$this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
}
/**
* @covers \FireflyIII\Http\Middleware\Binder
* @covers \FireflyIII\Models\AvailableBudget
*/
public function testAvailableBudgetNotFound(): void
{
Route::middleware(Binder::class)->any(
'/_test/binder/{availableBudget}', static function (?AvailableBudget $availableBudget) {
return $availableBudget->id ?? 0;
}
);
$this->be($this->user());
$response = $this->get('/_test/binder/-1');
$this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
}
/**
* @covers \FireflyIII\Http\Middleware\Binder
* @covers \FireflyIII\Models\Preference
*/
public function testPreferenceNotFound(): void
{
Route::middleware(Binder::class)->any(
'/_test/binder/{preference}', static function (?Preference $preference) {
return $preference->name ?? 'unknown';
}
);
$this->be($this->user());
$response = $this->get('/_test/binder/frontPageAccountsX');
$this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
}
/**
* @covers \FireflyIII\Http\Middleware\Binder
* @covers \FireflyIII\Models\PiggyBank
@ -1075,9 +1423,6 @@ class BinderTest extends TestCase
*/
public function testTJ(): void
{
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
Route::middleware(Binder::class)->any(
'/_test/binder/{tj}', function () {
return 'OK';
@ -1095,9 +1440,6 @@ class BinderTest extends TestCase
*/
public function testTJNotFound(): void
{
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
Route::middleware(Binder::class)->any(
'/_test/binder/{tj}', function () {
return 'OK';
@ -1115,9 +1457,6 @@ class BinderTest extends TestCase
*/
public function testTJNotLoggedIn(): void
{
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
Route::middleware(Binder::class)->any(
'/_test/binder/{tj}', function () {
return 'OK';
@ -1171,6 +1510,139 @@ class BinderTest extends TestCase
$response->assertSee('count: 2');
}
/**
* @covers \FireflyIII\Http\Middleware\Binder
* @covers \FireflyIII\Support\Binder\TagList
*/
public function testTagListWithId(): void
{
$tagRepos = $this->mock(TagRepositoryInterface::class);
$tagRepos->shouldReceive('setUser');
$tags = $this->user()->tags()->whereIn('id', [1, 2, 3])->get(['tags.*']);
$tagRepos->shouldReceive('get')->once()->andReturn($tags);
Route::middleware(Binder::class)->any(
'/_test/binder/{tagList}', function (Collection $tags) {
return 'count: ' . $tags->count();
}
);
$first = $tags->get(0);
$second = $tags->get(1);
$this->be($this->user());
$response = $this->get(sprintf('/_test/binder/%s,%d,bleep', $first->tag, $second->id));
$this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
$response->assertSee('count: 2');
}
/**
* @covers \FireflyIII\Http\Middleware\Binder
* @covers \FireflyIII\Support\Binder\TagOrId
*/
public function testTagOrIdByTag(): void
{
$tagRepos = $this->mock(TagRepositoryInterface::class);
$tag = $this->getRandomTag();
$tagRepos->shouldReceive('setUser');
$tagRepos->shouldReceive('findByTag')->withArgs([$tag->tag])->andReturn($tag)->atLeast()->once();
Route::middleware(Binder::class)->any(
'/_test/binder/{tagOrId}', static function (?Tag $tag) {
if ($tag) {
return $tag->tag;
}
return 'unfound';
}
);
$this->be($this->user());
$response = $this->get(sprintf('/_test/binder/%s', $tag->tag));
$this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
$response->assertSee($tag->tag);
}
/**
* @covers \FireflyIII\Http\Middleware\Binder
* @covers \FireflyIII\Support\Binder\TagOrId
*/
public function testTagOrIdById(): void
{
$tagRepos = $this->mock(TagRepositoryInterface::class);
$tag = $this->getRandomTag();
$tagRepos->shouldReceive('setUser');
$tagRepos->shouldReceive('findByTag')->withArgs([(string)$tag->id])->andReturnNull()->atLeast()->once();
$tagRepos->shouldReceive('findNull')->withArgs([$tag->id])->andReturn($tag)->atLeast()->once();
Route::middleware(Binder::class)->any(
'/_test/binder/{tagOrId}', static function (?Tag $tag) {
if ($tag) {
return $tag->tag;
}
return 'unfound';
}
);
$this->be($this->user());
$response = $this->get(sprintf('/_test/binder/%d', $tag->id));
$this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
$response->assertSee($tag->tag);
}
/**
* @covers \FireflyIII\Http\Middleware\Binder
* @covers \FireflyIII\Support\Binder\TagOrId
*/
public function testTagOrIdBothNull(): void
{
$tagRepos = $this->mock(TagRepositoryInterface::class);
$tag = $this->getRandomTag();
$tagRepos->shouldReceive('setUser');
$tagRepos->shouldReceive('findByTag')->withArgs([(string)$tag->id])->andReturnNull()->atLeast()->once();
$tagRepos->shouldReceive('findNull')->withArgs([$tag->id])->andReturnNull()->atLeast()->once();
Route::middleware(Binder::class)->any(
'/_test/binder/{tagOrId}', static function (?Tag $tag) {
if ($tag) {
return $tag->tag;
}
return 'unfound';
}
);
$this->be($this->user());
$response = $this->get(sprintf('/_test/binder/%d', $tag->id));
$this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
}
/**
* @covers \FireflyIII\Http\Middleware\Binder
* @covers \FireflyIII\Support\Binder\TagOrId
*/
public function testTagOrIdNotLoggedIn(): void
{
Route::middleware(Binder::class)->any(
'/_test/binder/{tagOrId}', static function (?Tag $tag) {
if ($tag) {
return $tag->tag;
}
return 'unfound';
}
);
$response = $this->get(sprintf('/_test/binder/%d', 4));
$this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
}
/**
* @covers \FireflyIII\Http\Middleware\Binder
* @covers \FireflyIII\Support\Binder\TagList
@ -1280,9 +1752,6 @@ class BinderTest extends TestCase
*/
public function testTransactionJournalLink(): void
{
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
Route::middleware(Binder::class)->any(
'/_test/binder/{journalLink}', function () {
return 'OK';
@ -1300,9 +1769,6 @@ class BinderTest extends TestCase
*/
public function testTransactionJournalLinkNotFound(): void
{
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
Route::middleware(Binder::class)->any(
'/_test/binder/{journalLink}', function () {
return 'OK';
@ -1320,9 +1786,6 @@ class BinderTest extends TestCase
*/
public function testTransactionJournalLinkNotLoggedIn(): void
{
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
Route::middleware(Binder::class)->any(
'/_test/binder/{journalLink}', function () {
return 'OK';
@ -1382,64 +1845,4 @@ class BinderTest extends TestCase
$response = $this->get('/_test/binder/withdrawal');
$this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
}
/**
* @covers \FireflyIII\Http\Middleware\Binder
* @covers \FireflyIII\Support\Binder\UnfinishedJournal
*/
public function testUnfinishedJournal(): void
{
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
$journal = $this->user()->transactionJournals()->where('completed', 0)->first();
Route::middleware(Binder::class)->any(
'/_test/binder/{unfinishedJournal}', function () {
return 'OK';
}
);
$this->be($this->user());
$response = $this->get('/_test/binder/' . $journal->id);
$this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
}
/**
* @covers \FireflyIII\Http\Middleware\Binder
* @covers \FireflyIII\Support\Binder\UnfinishedJournal
*/
public function testUnfinishedJournalFinished(): void
{
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
$journal = $this->user()->transactionJournals()->where('completed', 1)->first();
Route::middleware(Binder::class)->any(
'/_test/binder/{unfinishedJournal}', function () {
return 'OK';
}
);
$response = $this->get('/_test/binder/' . $journal->id);
$this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
}
/**
* @covers \FireflyIII\Http\Middleware\Binder
* @covers \FireflyIII\Support\Binder\UnfinishedJournal
*/
public function testUnfinishedJournalNotLoggedIn(): void
{
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
$journal = $this->user()->transactionJournals()->where('completed', 0)->first();
Route::middleware(Binder::class)->any(
'/_test/binder/{unfinishedJournal}', function () {
return 'OK';
}
);
$response = $this->get('/_test/binder/' . $journal->id);
$this->assertEquals(Response::HTTP_NOT_FOUND, $response->getStatusCode());
}
}