Improve tests.

This commit is contained in:
James Cole 2018-12-17 07:09:44 +01:00
parent 89942ee49c
commit 454b3ebd97
19 changed files with 494 additions and 375 deletions

View File

@ -196,7 +196,11 @@ class BillController extends Controller
$parameters = new ParameterBag();
$parameters->set('start', $start);
$parameters->set('end', $end);
$transformer = new BillTransformer($parameters);
/** @var BillTransformer $transformer */
$transformer = app(BillTransformer::class);
$transformer->setParameters($parameters);
/** @var Collection $bills */
$bills = $paginator->getCollection()->map(
function (Bill $bill) use ($transformer) {
@ -294,7 +298,12 @@ class BillController extends Controller
$parameters = new ParameterBag();
$parameters->set('start', $start);
$parameters->set('end', $end);
$resource = new Item($bill, new BillTransformer($parameters), 'bill');
/** @var BillTransformer $transformer */
$transformer = app(BillTransformer::class);
$transformer->setParameters($parameters);
$resource = new Item($bill, $transformer, 'bill');
$object = $manager->createData($resource)->toArray();
$object['data']['currency'] = $bill->transactionCurrency;

View File

@ -244,9 +244,15 @@ class PiggyBankController extends Controller
// transform piggies using the transformer:
$parameters = new ParameterBag;
$parameters->set('end', $end);
$transformed = new Collection;
$transformer = new PiggyBankTransformer(new ParameterBag);
$accountTransformer = new AccountTransformer($parameters);
$transformed = new Collection;
/** @var PiggyBankTransformer $transformer */
$transformer = app(PiggyBankTransformer::class);
$transformer->setParameters(new ParameterBag);
/** @var AccountTransformer $accountTransformer */
$accountTransformer = app(AccountTransformer::class);
$accountTransformer->setParameters($parameters);
/** @var PiggyBank $piggy */
foreach ($collection as $piggy) {
$array = $transformer->transform($piggy);
@ -435,7 +441,10 @@ class PiggyBankController extends Controller
// transform piggies using the transformer:
$parameters = new ParameterBag;
$parameters->set('end', $end);
$transformer = new PiggyBankTransformer(new ParameterBag);
/** @var PiggyBankTransformer $transformer */
$transformer = app(PiggyBankTransformer::class);
$transformer->setParameters($parameters);
$piggy = $transformer->transform($piggyBank);
$events = $this->piggyRepos->getEvents($piggyBank);
$subTitle = $piggyBank->name;

View File

@ -81,7 +81,10 @@ class EditController extends Controller
*/
public function edit(Request $request, Recurrence $recurrence)
{
$transformer = new RecurrenceTransformer(new ParameterBag);
/** @var RecurrenceTransformer $transformer */
$transformer = app(RecurrenceTransformer::class);
$transformer->setParameters(new ParameterBag);
$array = $transformer->transform($recurrence);
$budgets = app('expandedform')->makeSelectListWithEmpty($this->budgets->getActiveBudgets());

View File

@ -86,7 +86,10 @@ class IndexController extends Controller
/** @var Collection $recurrences */
$recurrences = $collection->slice(($page - 1) * $pageSize, $pageSize);
$transformer = new RecurrenceTransformer(new ParameterBag);
/** @var RecurrenceTransformer $transformer */
$transformer = app(RecurrenceTransformer::class);
$transformer->setParameters(new ParameterBag);
$recurring = [];
/** @var Recurrence $recurrence */
foreach ($recurrences as $recurrence) {
@ -114,7 +117,10 @@ class IndexController extends Controller
*/
public function show(Recurrence $recurrence)
{
$transformer = new RecurrenceTransformer(new ParameterBag);
/** @var RecurrenceTransformer $transformer */
$transformer = app(RecurrenceTransformer::class);
$transformer->setParameters(new ParameterBag);
$array = $transformer->transform($recurrence);
$transactions = $this->recurring->getTransactions($recurrence);

View File

@ -142,7 +142,10 @@ class MassController extends Controller
$this->rememberPreviousUri('transactions.mass-edit.uri');
$transformer = new TransactionTransformer(new ParameterBag);
/** @var TransactionTransformer $transformer */
$transformer = app(TransactionTransformer::class);
$transformer->setParameters(new ParameterBag);
/** @var TransactionCollectorInterface $collector */
$collector = app(TransactionCollectorInterface::class);
$collector->setUser($user);

View File

@ -253,7 +253,11 @@ class TransactionController extends Controller
$collector->setJournals(new Collection([$journal]));
$set = $collector->getTransactions();
$transactions = [];
$transformer = new TransactionTransformer(new ParameterBag);
/** @var TransactionTransformer $transformer */
$transformer = app(TransactionTransformer::class);
$transformer->setParameters(new ParameterBag);
/** @var Transaction $transaction */
foreach ($set as $transaction) {
$transactions[] = $transformer->transform($transaction);

View File

@ -95,7 +95,7 @@ class SplitJournalFormRequest extends Request
'foreign_currency_code' => null,
'reconciled' => false,
'identifier' => $index,
'currency_id' => (int)$transaction['transaction_currency_id'],
'currency_id' => (int)$transaction['currency_id'],
'currency_code' => null,
'description' => $transaction['transaction_description'] ?? '',
'amount' => $transaction['amount'] ?? '',

View File

@ -230,7 +230,10 @@ trait RequestInformation
$collector->setJournals(new Collection([$journal]));
$set = $collector->getTransactions();
$transactions = [];
$transformer = new TransactionTransformer(new ParameterBag);
/** @var TransactionTransformer $transformer */
$transformer = app(TransactionTransformer::class);
$transformer->setParameters(new ParameterBag());
/** @var Transaction $transaction */
foreach ($set as $transaction) {
$res = [];

View File

@ -28,7 +28,7 @@ $factory->define(
FireflyIII\Models\Account::class,
function (Faker\Generator $faker) {
return [
//'id' => $faker->unique()->numberBetween(1000, 10000),
'id' => $faker->unique()->numberBetween(1000, 10000),
'user_id' => 1,
'created_at' => new Carbon,
'updated_at' => new Carbon,

View File

@ -56,7 +56,7 @@
<label for="ffInput_journal_amount" class="col-sm-4 control-label">{{ trans('form.amount') }}</label>
<div class="col-sm-8">
<p id="ffInput_journal_amount" class="form-control-static">
{{ formatAmountBySymbol(preFilled.journal_amount, preFilled.transactions[0].currency_symbol, preFilled.transactions[0].currency_dp) }}
{{ formatAmountBySymbol(preFilled.journal_amount|default("0"), preFilled.transactions[0].currency_symbol|default("x"), preFilled.transactions[0].currency_dp) }}
</p>
</div>
</div>

View File

@ -34,6 +34,7 @@ use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface;
use FireflyIII\Repositories\User\UserRepositoryInterface;
use FireflyIII\TransactionRules\TransactionMatcher;
use FireflyIII\Transformers\BillTransformer;
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\Collection;
use Illuminate\Support\MessageBag;
@ -168,6 +169,12 @@ class BillControllerTest extends TestCase
$ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$transformer = $this->mock(BillTransformer::class);
$transformer->shouldReceive('setParameters')->atLeast()->once();
$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(
['id' => 5, 'active' => true, 'name' => 'x', 'next_expected_match' => '2018-01-01']
);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
@ -175,7 +182,6 @@ class BillControllerTest extends TestCase
$repository->shouldReceive('getPaginator')->andReturn(new LengthAwarePaginator($collection, 1, 50))->once();
$repository->shouldReceive('setUser');
$repository->shouldReceive('getNoteText')->andReturn('Hi there');
$repository->shouldReceive('getPaidDatesInRange')->twice()->andReturn(new Collection([new Carbon, new Carbon, new Carbon]));
$repository->shouldReceive('getRulesForBills')->andReturn([]);
@ -254,33 +260,42 @@ class BillControllerTest extends TestCase
$ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$transformer = $this->mock(BillTransformer::class);
$transformer->shouldReceive('setParameters')->atLeast()->once();
$transformer->shouldReceive('setCurrentScope')->atLeast()->once();
$transformer->shouldReceive('getDefaultIncludes')->atLeast()->once();
$transformer->shouldReceive('getAvailableIncludes')->atLeast()->once();
$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(
['id' => 5, 'active' => true, 'name' => 'x', 'next_expected_match' => '2018-01-01',
'currency_symbol' => 'x','amount_min' => '10','amount_max' => '15'
]
);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
$repository->shouldReceive('getYearAverage')->andReturn('0');
$repository->shouldReceive('getOverallAverage')->andReturn('0');
$repository->shouldReceive('nextExpectedMatch')->andReturn(new Carbon);
// $repository->shouldReceive('nextExpectedMatch')->andReturn(new Carbon);
$repository->shouldReceive('getRulesForBill')->andReturn(new Collection);
$repository->shouldReceive('getNoteText')->andReturn('Hi there');
// $repository->shouldReceive('getNoteText')->andReturn('Hi there');
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
//
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf();
$collector->shouldReceive('setBills')->andReturnSelf();
$collector->shouldReceive('setLimit')->andReturnSelf();
$collector->shouldReceive('setPage')->andReturnSelf();
$collector->shouldReceive('withBudgetInformation')->andReturnSelf();
$collector->shouldReceive('withCategoryInformation')->andReturnSelf();
$collector->shouldReceive('getPaginatedTransactions')->andReturn(new LengthAwarePaginator([], 0, 10));
$repository->shouldReceive('getPaidDatesInRange')->twice()->andReturn(new Collection([new Carbon, new Carbon, new Carbon]));
$repository->shouldReceive('setUser');
// $repository->shouldReceive('getPaidDatesInRange')->twice()->andReturn(new Collection([new Carbon, new Carbon, new Carbon]));
// $repository->shouldReceive('setUser');
$this->be($this->user());
$response = $this->get(route('bills.show', [1]));
$response->assertStatus(200);
// has bread crumb
$response->assertSee('<ol class="breadcrumb">');
$response->assertSee('Hi there');
}
/**

View File

@ -23,7 +23,6 @@ declare(strict_types=1);
namespace Tests\Feature\Controllers;
use Amount;
use Carbon\Carbon;
use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType;
use FireflyIII\Models\PiggyBank;
@ -35,10 +34,11 @@ use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
use FireflyIII\Repositories\User\UserRepositoryInterface;
use FireflyIII\Transformers\AccountTransformer;
use FireflyIII\Transformers\PiggyBankTransformer;
use Illuminate\Support\Collection;
use Log;
use Mockery;
use Steam;
use Tests\TestCase;
/**
@ -225,37 +225,33 @@ class PiggyBankControllerTest extends TestCase
}
/**
* @covers \FireflyIII\Http\Controllers\PiggyBankController
* @covers \FireflyIII\Http\Controllers\PiggyBankController
*/
public function testIndex(): void
{
// mock stuff
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$repository = $this->mock(PiggyBankRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$repository = $this->mock(PiggyBankRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$transformer = $this->mock(PiggyBankTransformer::class);
$accountTransformer = $this->mock(AccountTransformer::class);
// mock transformer
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(
['id' => 5, 'current_amount' => '10', 'target_amount' => '10', 'currency_symbol' => 'x']
);
// mock transformer again
$accountTransformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
$accountTransformer->shouldReceive('transform')->atLeast()->once()->andReturn(
['id' => 5, 'current_balance' => '10', 'name' => 'Account', 'current_amount' => '5', 'currency_symbol' => 'x']
);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
$accountRepos->shouldReceive('setUser');
$currencyRepos->shouldReceive('setUser');
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1')->atLeast()->once();
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'accountRole'])->andReturn('defaultAsset')->atLeast()->once();
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'accountNumber'])->andReturn('1234')->atLeast()->once();
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'BIC'])->andReturn('1234')->atLeast()->once();
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'interest'])->andReturn('2')->atLeast()->once();
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'interest_period'])->andReturn('daily')->atLeast()->once();
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'include_net_worth'])->andReturn(true)->atLeast()->once();
$accountRepos->shouldReceive('getOpeningBalanceAmount')->withAnyArgs()->andReturn('10')->atLeast()->once();
$accountRepos->shouldReceive('getOpeningBalanceDate')->withAnyArgs()->andReturn(new Carbon())->atLeast()->once();
$accountRepos->shouldReceive('getNoteText')->withAnyArgs()->andReturn('Hello')->atLeast()->once();
$currencyRepos->shouldReceive('findNull')->withArgs([1])->andReturn(TransactionCurrency::find(1))->atLeast()->once();
$accountRepos->shouldReceive('getAccountType')->andReturn('Asset account')->atLeast()->once();
$accountRepos->shouldReceive('getAccountCurrency')->andReturn(TransactionCurrency::find(1))->atLeast()->once();
$first = $this->user()->transactionJournals()->inRandomOrder()->first();
$piggies = $this->user()->piggyBanks()->take(2)->get();
@ -267,8 +263,6 @@ class PiggyBankControllerTest extends TestCase
$repository->shouldReceive('getSuggestedMonthlyAmount')->andReturn('1');
Steam::shouldReceive('balance')->twice()->andReturn('1');
$this->be($this->user());
$response = $this->get(route('piggy-banks.index'));
$response->assertStatus(200);
@ -465,17 +459,16 @@ class PiggyBankControllerTest extends TestCase
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$transformer = $this->mock(PiggyBankTransformer::class);
// mock transformer
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(
['id' => 5,'current_amount' => '5','currency_symbol' => 'x','target_amount' => '5','left_to_save' => '5','save_per_month' => '5']);
$accountRepos->shouldReceive('setUser');
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1')->atLeast()->once();
$currencyRepos->shouldReceive('findNull')->withArgs([1])->andReturn(TransactionCurrency::find(1))->atLeast()->once();
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
$currencyRepos->shouldReceive('setUser');
$repository->shouldReceive('setUser')->once();
$journalRepos->shouldReceive('firstNull')->once()->andReturn($first);
$repository->shouldReceive('getEvents')->andReturn(new Collection);
$repository->shouldReceive('getSuggestedMonthlyAmount')->andReturn('1');
$repository->shouldReceive('getCurrentAmount')->andReturn('1');
$journalRepos->shouldReceive('firstNull')->andReturn($first)->atLeast()->once();
$repository->shouldReceive('getEvents')->andReturn(new Collection)->atLeast()->once();
$this->be($this->user());

View File

@ -32,6 +32,7 @@ use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
use FireflyIII\Repositories\Recurring\RecurringRepositoryInterface;
use FireflyIII\Repositories\User\UserRepositoryInterface;
use FireflyIII\Transformers\RecurrenceTransformer;
use Illuminate\Support\Collection;
use Log;
use Mockery;
@ -64,12 +65,14 @@ class EditControllerTest extends TestCase
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$categoryFactory = $this->mock(CategoryFactory::class);
$piggyRepos = $this->mock(PiggyBankRepositoryInterface::class);
$transformer = $this->mock(RecurrenceTransformer::class);
$transformer->shouldReceive('setParameters')->atLeast()->once();
$transformer->shouldReceive('transform')->atLeast()->once();
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
$recurringRepos->shouldReceive('setUser');
$categoryFactory->shouldReceive('setUser')->atLeast()->once();
$categoryFactory->shouldReceive('findOrCreate')->atLeast()->once()->andReturn(null);
$recurringRepos->shouldReceive('getNoteText')->andReturn('Note!');
$recurringRepos->shouldReceive('repetitionDescription')->andReturn('dunno');
$recurringRepos->shouldReceive('getXOccurrences')->andReturn([]);
@ -92,14 +95,15 @@ class EditControllerTest extends TestCase
*/
public function testUpdate(): void
{
$recurringRepos = $this->mock(RecurringRepositoryInterface::class);
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
$categoryRepos = $this->mock(CategoryRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$recurringRepos = $this->mock(RecurringRepositoryInterface::class);
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
$categoryRepos = $this->mock(CategoryRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$categoryFactory = $this->mock(CategoryFactory::class);
$piggyRepos = $this->mock(PiggyBankRepositoryInterface::class);
$transformer = $this->mock(RecurrenceTransformer::class);
$recurringRepos->shouldReceive('update')->once();

View File

@ -28,6 +28,7 @@ use FireflyIII\Models\Configuration;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use FireflyIII\Repositories\Recurring\RecurringRepositoryInterface;
use FireflyIII\Repositories\User\UserRepositoryInterface;
use FireflyIII\Transformers\RecurrenceTransformer;
use Illuminate\Support\Collection;
use Log;
use Mockery;
@ -58,14 +59,20 @@ class IndexControllerTest extends TestCase
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$categoryFactory = $this->mock(CategoryFactory::class);
$transformer = $this->mock(RecurrenceTransformer::class);
$categoryFactory->shouldReceive('setUser')->atLeast()->once();
$categoryFactory->shouldReceive('findOrCreate')->atLeast()->once()->andReturn(null);
$transformer->shouldReceive('setParameters')->atLeast()->once();
$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(
[
'id' => 5,
'first_date' => '2018-01-01',
'repeat_until' =>null,
'latest_date' => null,
]
);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
$budgetRepos->shouldReceive('findNull')->withAnyArgs()->andReturn($this->user()->budgets()->first())->atLeast()->once();
$config = new Configuration;
$config->data = 0;
@ -79,10 +86,6 @@ class IndexControllerTest extends TestCase
\FireflyConfig::shouldReceive('get')->withArgs(['is_demo_site', false])->once()->andReturn($falseConfig);
$repository->shouldReceive('get')->andReturn($collection)->once();
$repository->shouldReceive('setUser');
$repository->shouldReceive('getNoteText')->andReturn('Notes');
$repository->shouldReceive('repetitionDescription')->andReturn('Bla');
$repository->shouldReceive('getXOccurrences')->andReturn([]);
$this->be($this->user());
@ -97,20 +100,24 @@ class IndexControllerTest extends TestCase
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$categoryFactory = $this->mock(CategoryFactory::class);
$transformer = $this->mock(RecurrenceTransformer::class);
$categoryFactory->shouldReceive('setUser')->atLeast()->once();
$categoryFactory->shouldReceive('findOrCreate')->atLeast()->once()->andReturn(null);
$transformer->shouldReceive('setParameters')->atLeast()->once();
$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(
[
'id' => 5,
'first_date' => '2018-01-01',
'repeat_until' =>null,
'latest_date' => null,
'recurrence_repetitions' => [],
]
);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
$budgetRepos->shouldReceive('findNull')->withAnyArgs()->andReturn($this->user()->budgets()->first())->atLeast()->once();
$recurrence = $this->user()->recurrences()->first();
$repository->shouldReceive('setUser');
$repository->shouldReceive('getNoteText')->andReturn('Notes');
$repository->shouldReceive('repetitionDescription')->andReturn('Bla');
$repository->shouldReceive('getXOccurrences')->andReturn([]);
$repository->shouldReceive('getTransactions')->andReturn(new Collection);
$repository->shouldReceive('getTransactions')->andReturn(new Collection)->atLeast()->once();
$this->be($this->user());
$response = $this->get(route('recurring.show', [$recurrence->id]));

View File

@ -30,6 +30,7 @@ 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\User\UserRepositoryInterface;
use Illuminate\Support\Collection;
use Illuminate\Support\MessageBag;
@ -293,9 +294,14 @@ class ConvertControllerTest extends TestCase
{
Log::info(sprintf('Now in test %s', __METHOD__));
// mock stuff
$repository = $this->mock(JournalRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$repository = $this->mock(JournalRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class);
$ruleGroupRepos->shouldReceive('setUser')->atLeast()->once();
$ruleGroupRepos->shouldReceive('getActiveGroups')->atLeast()->once()->andReturn(new Collection);
// get journal:
$deposit = $this->getRandomDeposit();
@ -326,6 +332,10 @@ class ConvertControllerTest extends TestCase
$repository = $this->mock(JournalRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class);
$ruleGroupRepos->shouldReceive('setUser')->atLeast()->once();
$ruleGroupRepos->shouldReceive('getActiveGroups')->atLeast()->once()->andReturn(new Collection);
// get journal:
$deposit = $this->getRandomDeposit();
@ -356,6 +366,10 @@ class ConvertControllerTest extends TestCase
$repository = $this->mock(JournalRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class);
$ruleGroupRepos->shouldReceive('setUser')->atLeast()->once();
$ruleGroupRepos->shouldReceive('getActiveGroups')->atLeast()->once()->andReturn(new Collection);
// get journal:
$deposit = $this->getRandomDeposit();
@ -387,6 +401,7 @@ class ConvertControllerTest extends TestCase
$repository = $this->mock(JournalRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class);
// mock stuff
$messageBag = new MessageBag;
@ -422,6 +437,8 @@ class ConvertControllerTest extends TestCase
$repository = $this->mock(JournalRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class);
// get journal:
$withdrawal = $this->getRandomWithdrawal();
@ -467,9 +484,13 @@ class ConvertControllerTest extends TestCase
{
Log::info(sprintf('Now in test %s', __METHOD__));
// mock stuff
$repository = $this->mock(JournalRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$repository = $this->mock(JournalRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class);
$ruleGroupRepos->shouldReceive('setUser')->atLeast()->once();
$ruleGroupRepos->shouldReceive('getActiveGroups')->atLeast()->once()->andReturn(new Collection);
// mock stuff
@ -497,10 +518,15 @@ class ConvertControllerTest extends TestCase
*/
public function testPostIndexWithdrawalDeposit(): void
{
Log::info(sprintf('Now in test %s', __METHOD__));
// mock stuff
$repository = $this->mock(JournalRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$repository = $this->mock(JournalRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class);
$ruleGroupRepos->shouldReceive('setUser')->atLeast()->once();
$ruleGroupRepos->shouldReceive('getActiveGroups')->atLeast()->once()->andReturn(new Collection);
$withdrawal = $this->getRandomWithdrawal();
$source = $this->getRandomExpense();
@ -521,59 +547,69 @@ class ConvertControllerTest extends TestCase
$response->assertRedirect(route('transactions.show', [$withdrawal->id]));
}
/**
* @covers \FireflyIII\Http\Controllers\Transaction\ConvertController
*/
public function testPostIndexWithdrawalDepositEmptyName(): void
{
// mock stuff
$repository = $this->mock(JournalRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
/**
* @covers \FireflyIII\Http\Controllers\Transaction\ConvertController
*/
public function testPostIndexWithdrawalDepositEmptyName(): void
{
Log::info(sprintf('Now in test %s', __METHOD__));
// mock stuff
$repository = $this->mock(JournalRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class);
$withdrawal = $this->getRandomWithdrawal();
$source = $this->getRandomExpense();
$destination = $this->getRandomAsset();
$revenue = $this->getRandomRevenue();
$ruleGroupRepos->shouldReceive('setUser')->atLeast()->once();
$ruleGroupRepos->shouldReceive('getActiveGroups')->atLeast()->once()->andReturn(new Collection);
$repository->shouldReceive('convert')->andReturn(new MessageBag)->atLeast()->once();
$repository->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal)->atLeast()->once();
$repository->shouldReceive('getJournalSourceAccounts')->andReturn(new Collection([$source]))->atLeast()->once();
$repository->shouldReceive('getJournalDestinationAccounts')->andReturn(new Collection([$destination]))->atLeast()->once();
$accountRepos->shouldReceive('getCashAccount')->atLeast()->once()->andReturn($revenue);
$withdrawal = $this->getRandomWithdrawal();
$source = $this->getRandomExpense();
$destination = $this->getRandomAsset();
$revenue = $this->getRandomRevenue();
$data = ['source_account_revenue' => ''];
$this->be($this->user());
$response = $this->post(route('transactions.convert.index', ['deposit', $withdrawal->id]), $data);
$response->assertStatus(302);
$response->assertRedirect(route('transactions.show', [$withdrawal->id]));
}
$repository->shouldReceive('convert')->andReturn(new MessageBag)->atLeast()->once();
$repository->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal)->atLeast()->once();
$repository->shouldReceive('getJournalSourceAccounts')->andReturn(new Collection([$source]))->atLeast()->once();
$repository->shouldReceive('getJournalDestinationAccounts')->andReturn(new Collection([$destination]))->atLeast()->once();
$accountRepos->shouldReceive('getCashAccount')->atLeast()->once()->andReturn($revenue);
/**
* @covers \FireflyIII\Http\Controllers\Transaction\ConvertController
*/
public function testPostIndexWithdrawalTransfer(): void
{
// mock stuff
$repository = $this->mock(JournalRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$data = ['source_account_revenue' => ''];
$this->be($this->user());
$response = $this->post(route('transactions.convert.index', ['deposit', $withdrawal->id]), $data);
$response->assertStatus(302);
$response->assertRedirect(route('transactions.show', [$withdrawal->id]));
}
$withdrawal = $this->getRandomWithdrawal();
$source = $this->getRandomExpense();
$destination = $this->getRandomAsset();
$newDest = $this->getRandomAsset();
/**
* @covers \FireflyIII\Http\Controllers\Transaction\ConvertController
*/
public function testPostIndexWithdrawalTransfer(): void
{
Log::info(sprintf('Now in test %s', __METHOD__));
// mock stuff
$repository = $this->mock(JournalRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class);
$repository->shouldReceive('convert')->andReturn(new MessageBag)->atLeast()->once();
$repository->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal)->atLeast()->once();
$repository->shouldReceive('getJournalSourceAccounts')->andReturn(new Collection([$source]))->atLeast()->once();
$repository->shouldReceive('getJournalDestinationAccounts')->andReturn(new Collection([$destination]))->atLeast()->once();
$accountRepos->shouldReceive('findNull')->atLeast()->once()->andReturn($newDest);
$ruleGroupRepos->shouldReceive('setUser')->atLeast()->once();
$ruleGroupRepos->shouldReceive('getActiveGroups')->atLeast()->once()->andReturn(new Collection);
$data = ['destination_account_asset' => 2,];
$this->be($this->user());
$response = $this->post(route('transactions.convert.index', ['transfer', $withdrawal->id]), $data);
$response->assertStatus(302);
$response->assertRedirect(route('transactions.show', [$withdrawal->id]));
}
$withdrawal = $this->getRandomWithdrawal();
$source = $this->getRandomExpense();
$destination = $this->getRandomAsset();
$newDest = $this->getRandomAsset();
$repository->shouldReceive('convert')->andReturn(new MessageBag)->atLeast()->once();
$repository->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal)->atLeast()->once();
$repository->shouldReceive('getJournalSourceAccounts')->andReturn(new Collection([$source]))->atLeast()->once();
$repository->shouldReceive('getJournalDestinationAccounts')->andReturn(new Collection([$destination]))->atLeast()->once();
$accountRepos->shouldReceive('findNull')->atLeast()->once()->andReturn($newDest);
$data = ['destination_account_asset' => 2,];
$this->be($this->user());
$response = $this->post(route('transactions.convert.index', ['transfer', $withdrawal->id]), $data);
$response->assertStatus(302);
$response->assertRedirect(route('transactions.show', [$withdrawal->id]));
}
}

View File

@ -22,12 +22,15 @@ declare(strict_types=1);
namespace Tests\Feature\Controllers\Transaction;
use FireflyIII\Helpers\Collector\TransactionCollectorInterface;
use FireflyIII\Models\AccountType;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\Repositories\User\UserRepositoryInterface;
use FireflyIII\Transformers\TransactionTransformer;
use Illuminate\Support\Collection;
use Log;
use Mockery;
@ -59,7 +62,7 @@ class MassControllerTest extends TestCase
public function testDelete(): void
{
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
@ -87,7 +90,7 @@ class MassControllerTest extends TestCase
// mock deletion:
$repository = $this->mock(JournalRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$repository->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
$repository->shouldReceive('findNull')->andReturnValues([$deposits[0], $deposits[1]])->times(2);
@ -109,29 +112,50 @@ class MassControllerTest extends TestCase
*/
public function testEdit(): void
{
// mock things
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
$userRepos = $this->mock(UserRepositoryInterface::class);
$transformer = $this->mock(TransactionTransformer::class);
$collector = $this->mock(TransactionCollectorInterface::class);
// data:
$transfers = TransactionJournal::where('transaction_type_id', 3)->where('user_id', $this->user()->id)->take(2)->get();
$transfersArray = $transfers->pluck('id')->toArray();
$source = $this->user()->accounts()->first();
$transaction = new Transaction;
// mock calls:
$transformer->shouldReceive('setParameters')->atLeast()->once();
$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(
[
'amount' => '10',
'foreign_amount' => '',
'type' => 'transfer',
'id' => 3,
'journal_id' => 1,
]
);
$collector->shouldReceive('setUser')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withOpposingAccount')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withCategoryInformation')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withBudgetInformation')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('setJournals')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('addFilter')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('getTransactions')->atLeast()->once()->andReturn(new Collection([new Transaction]));
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
// mock data for edit page:
$journalRepos->shouldReceive('getJournalSourceAccounts')->andReturn(new Collection([$source]));
$journalRepos->shouldReceive('getJournalDestinationAccounts')->andReturn(new Collection([$source]));
$journalRepos->shouldReceive('getTransactionType')->andReturn('Transfer');
$journalRepos->shouldReceive('isJournalReconciled')->andReturn(false);
$journalRepos->shouldReceive('getFirstPosTransaction')->andReturn($transfers->first()->transactions()->first());
// get all kinds of meta fields (the transformer needs this)
$journalRepos->shouldReceive('getNoteText')->andReturn('Hello');
$journalRepos->shouldReceive('getMetaField')->withAnyArgs()->andReturnNull();
$journalRepos->shouldReceive('getMetaDateString')->withAnyArgs()->andReturnNull();
$journalRepos->shouldReceive('getJournalSourceAccounts')->andReturn(new Collection([$source]))->atLeast()->once();
$journalRepos->shouldReceive('getJournalDestinationAccounts')->andReturn(new Collection([$source]))->atLeast()->once();
$journalRepos->shouldReceive('getTransactionType')->andReturn('Transfer')->atLeast()->once();
$journalRepos->shouldReceive('isJournalReconciled')->andReturn(false)->atLeast()->once();
// mock stuff:
$repository = $this->mock(AccountRepositoryInterface::class);
@ -139,7 +163,7 @@ class MassControllerTest extends TestCase
// mock more stuff:
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
$budgetRepos->shouldReceive('getBudgets')->andReturn(new Collection);
$budgetRepos->shouldReceive('getBudgets')->andReturn(new Collection)->atLeast()->once();
$this->be($this->user());
@ -155,35 +179,51 @@ class MassControllerTest extends TestCase
*/
public function testEditMultiple(): void
{
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
$budgetRepos->shouldReceive('getBudgets')->andReturn(new Collection);
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
$transformer = $this->mock(TransactionTransformer::class);
$collector = $this->mock(TransactionCollectorInterface::class);
// mock calls:
$transformer->shouldReceive('setParameters')->atLeast()->once();
$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(
[
'amount' => '10',
'foreign_amount' => '',
'type' => 'transfer',
'id' => 3,
'journal_id' => 1,
]
);
$collector->shouldReceive('setUser')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withOpposingAccount')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withCategoryInformation')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withBudgetInformation')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('setJournals')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('addFilter')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('getTransactions')->atLeast()->once()->andReturn(new Collection([new Transaction]));
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
$budgetRepos->shouldReceive('getBudgets')->andReturn(new Collection)->atLeast()->once();
// mock stuff:
$repository = $this->mock(AccountRepositoryInterface::class);
$repository->shouldReceive('getAccountsByType')->once()->withArgs([[AccountType::DEFAULT, AccountType::ASSET]])->andReturn(new Collection);
$journalRepos->shouldReceive('firstNull')->andReturn(new TransactionJournal);
$journalRepos->shouldReceive('firstNull')->andReturn(new TransactionJournal)->atLeast()->once();
$journalRepos->shouldReceive('getJournalSourceAccounts')
->andReturn(new Collection([1, 2, 3]), new Collection, new Collection, new Collection, new Collection([1]));
->andReturn(new Collection([1, 2, 3]), new Collection, new Collection, new Collection, new Collection([1]))->atLeast()->once();
$journalRepos->shouldReceive('getJournalDestinationAccounts')
->andReturn(new Collection, new Collection([1, 2, 3]), new Collection, new Collection, new Collection([1]));
->andReturn(new Collection, new Collection([1, 2, 3]), new Collection, new Collection, new Collection([1]))->atLeast()->once();
$journalRepos->shouldReceive('getTransactionType')
->andReturn('Withdrawal', 'Opening balance', 'Withdrawal', 'Withdrawal', 'Withdrawal');
->andReturn('Withdrawal', 'Opening balance', 'Withdrawal', 'Withdrawal', 'Withdrawal')->atLeast()->once();
$journalRepos->shouldReceive('isJournalReconciled')
->andReturn(true, false, false, false, false);
// get all kinds of meta fields (the transformer needs this)
$journalRepos->shouldReceive('getNoteText')->andReturn('Hello');
$journalRepos->shouldReceive('getMetaField')->withAnyArgs()->andReturnNull();
$journalRepos->shouldReceive('getMetaDateString')->withAnyArgs()->andReturnNull();
->andReturn(true, false, false, false, false)->atLeast()->once();
// default transactions
$collection = $this->user()->transactionJournals()->take(5)->get();
@ -212,7 +252,7 @@ class MassControllerTest extends TestCase
// mock stuff
$repository = $this->mock(JournalRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$repository->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
$repository->shouldReceive('update')->once();

View File

@ -28,6 +28,7 @@ use Exception;
use FireflyIII\Events\StoredTransactionJournal;
use FireflyIII\Events\UpdatedTransactionJournal;
use FireflyIII\Helpers\Attachments\AttachmentHelperInterface;
use FireflyIII\Helpers\Collector\TransactionCollectorInterface;
use FireflyIII\Models\AccountType;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionCurrency;
@ -40,6 +41,7 @@ use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\Repositories\LinkType\LinkTypeRepositoryInterface;
use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
use FireflyIII\Repositories\User\UserRepositoryInterface;
use FireflyIII\Transformers\TransactionTransformer;
use Illuminate\Database\Query\JoinClause;
use Illuminate\Support\Collection;
use Illuminate\Support\MessageBag;
@ -79,6 +81,8 @@ class SingleControllerTest extends TestCase
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$transformer = $this->mock(TransactionTransformer::class);
$collector = $this->mock(TransactionCollectorInterface::class);
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
@ -113,6 +117,9 @@ class SingleControllerTest extends TestCase
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$transformer = $this->mock(TransactionTransformer::class);
$collector = $this->mock(TransactionCollectorInterface::class);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
@ -142,6 +149,9 @@ class SingleControllerTest extends TestCase
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$transformer = $this->mock(TransactionTransformer::class);
$collector = $this->mock(TransactionCollectorInterface::class);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
@ -996,14 +1006,28 @@ class SingleControllerTest extends TestCase
public function testUpdate(): void
{
$attachmentRepos = $this->mock(AttachmentRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
$piggyRepos = $this->mock(PiggyBankRepositoryInterface::class);
$attRepos = $this->mock(AttachmentHelperInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$linkRepos = $this->mock(LinkTypeRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
$piggyRepos = $this->mock(PiggyBankRepositoryInterface::class);
$attRepos = $this->mock(AttachmentHelperInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$linkRepos = $this->mock(LinkTypeRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$transformer = $this->mock(TransactionTransformer::class);
$collector = $this->mock(TransactionCollectorInterface::class);
$transformer->shouldReceive('setParameters')->atLeast()->once();
$collector->shouldReceive('setUser')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withOpposingAccount')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withCategoryInformation')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withBudgetInformation')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('setJournals')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('getTransactions')->atLeast()->once()->andReturn(new Collection);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
$journalRepos->shouldReceive('firstNull')->andReturn(new TransactionJournal);

View File

@ -23,6 +23,7 @@ declare(strict_types=1);
namespace Tests\Feature\Controllers\Transaction;
use FireflyIII\Helpers\Attachments\AttachmentHelperInterface;
use FireflyIII\Helpers\Collector\TransactionCollectorInterface;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Models\TransactionJournal;
@ -33,6 +34,7 @@ use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface;
use FireflyIII\Repositories\User\UserRepositoryInterface;
use FireflyIII\Transformers\TransactionTransformer;
use Illuminate\Support\Collection;
use Illuminate\Support\MessageBag;
use Log;
@ -69,36 +71,31 @@ class SplitControllerTest extends TestCase
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$attHelper = $this->mock(AttachmentHelperInterface::class);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
$transformer = $this->mock(TransactionTransformer::class);
$collector = $this->mock(TransactionCollectorInterface::class);
$deposit = $this->getRandomDeposit();
$destination = $deposit->transactions()->where('amount', '>', 0)->first();
$account = $destination->account;
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1');
$currencyRepository->shouldReceive('findNull')->withArgs([1])->andReturn(TransactionCurrency::find(1));
$deposit = TransactionJournal::where('transaction_type_id', 2)->where('user_id', $this->user()->id)->first();
$destination = $deposit->transactions()->where('amount', '>', 0)->first();
$account = $destination->account;
$transactions = factory(Transaction::class, 3)->make();
$array = $transactions->toArray();
$array[0]['category'] = '';
// mock calls
$journalRepos->shouldReceive('firstNull')->once()->andReturn($deposit);
$journalRepos->shouldReceive('getJournalSourceAccounts')->andReturn(new Collection([$account]));
$journalRepos->shouldReceive('getJournalDestinationAccounts')->andReturn(new Collection([$account]));
$currencyRepository->shouldReceive('get')->once()->andReturn(new Collection);
$budgetRepository->shouldReceive('getActiveBudgets')->andReturn(new Collection)->atLeast()->once();
$transformer->shouldReceive('setParameters')->atLeast()->once();
$collector->shouldReceive('setUser')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withOpposingAccount')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withCategoryInformation')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withBudgetInformation')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('setJournals')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('getTransactions')->atLeast()->once()->andReturn(new Collection);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
$journalRepos->shouldReceive('getJournalSourceAccounts')->andReturn(new Collection([$account]))->atLeast()->once();
$journalRepos->shouldReceive('getJournalDestinationAccounts')->andReturn(new Collection([$account]))->atLeast()->once();
$journalRepos->shouldReceive('getTransactionType')->once()->andReturn('Deposit');
$journalRepos->shouldReceive('getJournalDate')->andReturn('2018-01-01')->once();
$journalRepos->shouldReceive('getMetaField')->andReturn('');
$journalRepos->shouldReceive('getMetaField')->andReturn('')->atLeast()->once();
$journalRepos->shouldReceive('getNoteText')->andReturn('Some note')->atLeast()->once();
$journalRepos->shouldReceive('getJournalBudgetId')->andReturn(0);
$journalRepos->shouldReceive('getCategoryName')->andReturn('');
$journalRepos->shouldReceive('getJournalTotal')->andReturn('0');
$journalRepos->shouldReceive('getJournalCategoryName')->andReturn('Some');
$journalRepos->shouldReceive('getMetaDateString')->andReturn('2018-01-01')->atLeast()->once();
$currencyRepository->shouldReceive('get')->once()->andReturn(new Collection);
$budgetRepository->shouldReceive('getActiveBudgets')->andReturn(new Collection);
$this->be($this->user());
$response = $this->get(route('transactions.split.edit', [$deposit->id]));
@ -118,81 +115,79 @@ class SplitControllerTest extends TestCase
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$attHelper = $this->mock(AttachmentHelperInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
$deposit = TransactionJournal::where('transaction_type_id', 2)->where('user_id', $this->user()->id)->first();
$destination = $deposit->transactions()->where('amount', '>', 0)->first();
$account = $destination->account;
$transactions = factory(Transaction::class, 3)->make();
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1');
$currencyRepository->shouldReceive('findNull')->withArgs([1])->andReturn(TransactionCurrency::find(1));
$currencyRepository->shouldReceive('get')->once()->andReturn(new Collection);
$budgetRepository->shouldReceive('getActiveBudgets')->andReturn(new Collection);
$transformer = $this->mock(TransactionTransformer::class);
$collector = $this->mock(TransactionCollectorInterface::class);
$deposit = $this->getRandomDeposit();
$destination = $deposit->transactions()->where('amount', '>', 0)->first();
$account = $destination->account;
// mock calls
$journalRepos->shouldReceive('firstNull')->once()->andReturn($deposit);
$journalRepos->shouldReceive('getJournalSourceAccounts')->andReturn(new Collection([$account]));
$journalRepos->shouldReceive('getJournalDestinationAccounts')->andReturn(new Collection([$account]));
$currencyRepository->shouldReceive('get')->once()->andReturn(new Collection);
$budgetRepository->shouldReceive('getActiveBudgets')->andReturn(new Collection)->atLeast()->once();
$transformer->shouldReceive('setParameters')->atLeast()->once();
$collector->shouldReceive('setUser')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withOpposingAccount')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withCategoryInformation')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withBudgetInformation')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('setJournals')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('getTransactions')->atLeast()->once()->andReturn(new Collection);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
$journalRepos->shouldReceive('getJournalSourceAccounts')->andReturn(new Collection([$account]))->atLeast()->once();
$journalRepos->shouldReceive('getJournalDestinationAccounts')->andReturn(new Collection([$account]))->atLeast()->once();
$journalRepos->shouldReceive('getTransactionType')->once()->andReturn('Deposit');
$journalRepos->shouldReceive('getJournalDate')->andReturn('2018-01-01')->once();
$journalRepos->shouldReceive('getMetaField')->andReturn('');
$journalRepos->shouldReceive('getJournalBudgetId')->andReturn(0);
$journalRepos->shouldReceive('getCategoryName')->andReturn('');
$journalRepos->shouldReceive('getJournalTotal')->andReturn('0');
$journalRepos->shouldReceive('getMetaField')->andReturn('')->atLeast()->once();
$journalRepos->shouldReceive('getNoteText')->andReturn('Some note')->atLeast()->once();
$journalRepos->shouldReceive('getMetaDateString')->andReturn('2018-01-01')->atLeast()->once();
$old = [
'transactions' => [
[
'transaction_currency_id' => 1,
'transaction_currency_code' => 'AB',
'transaction_currency_symbol' => 'X',
'foreign_amount' => '0',
'foreign_currency_id' => 2,
'foreign_currency_code' => 'CD',
'foreign_currency_symbol' => 'Y',
'currency_id' => 1,
'currency_code' => 'AB',
'currency_symbol' => 'X',
'foreign_amount' => '0',
'foreign_currency_id' => 2,
'foreign_currency_code' => 'CD',
'foreign_currency_symbol' => 'Y',
],
[
'transaction_currency_id' => 1,
'transaction_currency_code' => 'AB',
'transaction_currency_symbol' => 'X',
'foreign_amount' => '0',
'foreign_currency_id' => 2,
'foreign_currency_code' => 'CD',
'foreign_currency_symbol' => 'Y',
'currency_id' => 1,
'currency_code' => 'AB',
'currency_symbol' => 'X',
'foreign_amount' => '0',
'foreign_currency_id' => 2,
'foreign_currency_code' => 'CD',
'foreign_currency_symbol' => 'Y',
],
[
'transaction_currency_id' => 1,
'transaction_currency_code' => 'AB',
'transaction_currency_symbol' => 'X',
'foreign_amount' => '0',
'foreign_currency_id' => 2,
'foreign_currency_code' => 'CD',
'foreign_currency_symbol' => 'Y',
'currency_id' => 1,
'currency_code' => 'AB',
'currency_symbol' => 'X',
'foreign_amount' => '0',
'foreign_currency_id' => 2,
'foreign_currency_code' => 'CD',
'foreign_currency_symbol' => 'Y',
],
[
'transaction_currency_id' => 1,
'transaction_currency_code' => 'AB',
'transaction_currency_symbol' => 'X',
'foreign_amount' => '0',
'foreign_currency_id' => 2,
'foreign_currency_code' => 'CD',
'foreign_currency_symbol' => 'Y',
'currency_id' => 1,
'currency_code' => 'AB',
'currency_symbol' => 'X',
'foreign_amount' => '0',
'foreign_currency_id' => 2,
'foreign_currency_code' => 'CD',
'foreign_currency_symbol' => 'Y',
],
[
'transaction_currency_id' => 1,
'transaction_currency_code' => 'AB',
'transaction_currency_symbol' => 'X',
'foreign_amount' => '0',
'foreign_currency_id' => 2,
'foreign_currency_code' => 'CD',
'foreign_currency_symbol' => 'Y',
'currency_id' => 1,
'currency_code' => 'AB',
'currency_symbol' => 'X',
'foreign_amount' => '0',
'foreign_currency_id' => 2,
'foreign_currency_code' => 'CD',
'foreign_currency_symbol' => 'Y',
],
],
@ -227,50 +222,6 @@ class SplitControllerTest extends TestCase
$response->assertStatus(302);
}
/**
* @covers \FireflyIII\Http\Controllers\Transaction\SplitController
*/
public function testEditSingle(): void
{
$currencyRepository = $this->mock(CurrencyRepositoryInterface::class);
$accountRepository = $this->mock(AccountRepositoryInterface::class);
$budgetRepository = $this->mock(BudgetRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$attHelper = $this->mock(AttachmentHelperInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
$transactions = factory(Transaction::class, 1)->make();
$deposit = TransactionJournal::where('transaction_type_id', 2)->where('user_id', $this->user()->id)->first();
$destination = $deposit->transactions()->where('amount', '>', 0)->first();
$account = $destination->account;
$accountRepository->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1');
$currencyRepository->shouldReceive('findNull')->withArgs([1])->andReturn(TransactionCurrency::find(1));
$journalRepos->shouldReceive('firstNull')->once()->andReturn($deposit);
$journalRepos->shouldReceive('getJournalSourceAccounts')->andReturn(new Collection([$account]));
$journalRepos->shouldReceive('getJournalDestinationAccounts')->andReturn(new Collection([$account]));
$journalRepos->shouldReceive('getTransactionType')->once()->andReturn('Deposit');
$journalRepos->shouldReceive('getJournalDate')->once()->andReturn('2018-01-01');
$journalRepos->shouldReceive('getMetaField')->andReturn('');
$journalRepos->shouldReceive('getJournalBudgetId')->andReturn(0);
$journalRepos->shouldReceive('getCategoryName')->andReturn('');
$journalRepos->shouldReceive('getJournalTotal')->andReturn('1');
$journalRepos->shouldReceive('getNoteText')->andReturn('Some note')->atLeast()->once();
$journalRepos->shouldReceive('getMetaDateString')->andReturn('2018-01-01')->atLeast()->once();
$currencyRepository->shouldReceive('get')->once()->andReturn(new Collection);
$budgetRepository->shouldReceive('getActiveBudgets')->andReturn(new Collection);
$this->be($this->user());
$response = $this->get(route('transactions.split.edit', [$deposit->id]));
$response->assertStatus(200);
// has bread crumb
$response->assertSee('<ol class="breadcrumb">');
}
/**
* @covers \FireflyIII\Http\Controllers\Transaction\SplitController
@ -308,7 +259,7 @@ class SplitControllerTest extends TestCase
[
'transaction_description' => 'Split #1',
'source_name' => 'Job',
'transaction_currency_id' => 1,
'currency_id' => 1,
'amount' => 1591,
'category_name' => '',
],
@ -359,7 +310,7 @@ class SplitControllerTest extends TestCase
[
'transaction_description' => 'Split #1',
'source_name' => 'Job',
'transaction_currency_id' => 1,
'currency_id' => 1,
'amount' => 1591,
'category_name' => '',
],
@ -410,7 +361,7 @@ class SplitControllerTest extends TestCase
'transaction_description' => 'Split #1',
'source_id' => '1',
'destination_id' => '2',
'transaction_currency_id' => 1,
'currency_id' => 1,
'amount' => 1591,
'category_name' => '',
],
@ -469,7 +420,7 @@ class SplitControllerTest extends TestCase
'transaction_description' => 'Split #1',
'source_id' => '1',
'destination_name' => 'some expense',
'transaction_currency_id' => 1,
'currency_id' => 1,
'amount' => 1591,
'category_name' => '',
],

View File

@ -32,6 +32,7 @@ use FireflyIII\Repositories\Attachment\AttachmentRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\Repositories\LinkType\LinkTypeRepositoryInterface;
use FireflyIII\Repositories\User\UserRepositoryInterface;
use FireflyIII\Transformers\TransactionTransformer;
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\Collection;
use Log;
@ -69,12 +70,12 @@ class TransactionControllerTest extends TestCase
$this->session(['start' => $date, 'end' => clone $date]);
// mock stuff
$transfer = $this->user()->transactionJournals()->inRandomOrder()->where('transaction_type_id', 3)->first();
$repository = $this->mock(JournalRepositoryInterface::class);
$collector = $this->mock(TransactionCollectorInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$attRepos = $this->mock(AttachmentRepositoryInterface::class);
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
$transfer = $this->user()->transactionJournals()->inRandomOrder()->where('transaction_type_id', 3)->first();
$repository = $this->mock(JournalRepositoryInterface::class);
$collector = $this->mock(TransactionCollectorInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$attRepos = $this->mock(AttachmentRepositoryInterface::class);
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
$repository->shouldReceive('firstNull')->twice()->andReturn($transfer);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
@ -107,12 +108,12 @@ class TransactionControllerTest extends TestCase
$this->session(['start' => $date, 'end' => clone $date]);
// mock stuff
$transfer = $this->user()->transactionJournals()->inRandomOrder()->where('transaction_type_id', 3)->first();
$repository = $this->mock(JournalRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$collector = $this->mock(TransactionCollectorInterface::class);
$attRepos = $this->mock(AttachmentRepositoryInterface::class);
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
$transfer = $this->user()->transactionJournals()->inRandomOrder()->where('transaction_type_id', 3)->first();
$repository = $this->mock(JournalRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$collector = $this->mock(TransactionCollectorInterface::class);
$attRepos = $this->mock(AttachmentRepositoryInterface::class);
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
$repository->shouldReceive('firstNull')->twice()->andReturn($transfer);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
@ -153,15 +154,15 @@ class TransactionControllerTest extends TestCase
// mock stuff
$transfer = $this->getRandomTransfer();
$repository = $this->mock(JournalRepositoryInterface::class);
$collector = $this->mock(TransactionCollectorInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$attRepos = $this->mock(AttachmentRepositoryInterface::class);
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
$transfer = $this->getRandomTransfer();
$repository = $this->mock(JournalRepositoryInterface::class);
$collector = $this->mock(TransactionCollectorInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$attRepos = $this->mock(AttachmentRepositoryInterface::class);
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
$date = new Carbon;
$date = new Carbon;
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
@ -205,17 +206,17 @@ class TransactionControllerTest extends TestCase
// mock stuff
$transfer = $this->getRandomTransfer();
$repository = $this->mock(JournalRepositoryInterface::class);
$collector = $this->mock(TransactionCollectorInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$attRepos = $this->mock(AttachmentRepositoryInterface::class);
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
$transfer = $this->getRandomTransfer();
$repository = $this->mock(JournalRepositoryInterface::class);
$collector = $this->mock(TransactionCollectorInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$attRepos = $this->mock(AttachmentRepositoryInterface::class);
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
$repository->shouldReceive('firstNull')->once()->andReturn($transfer);
$repository->shouldReceive('firstNull')->once()->andReturn($transfer);
$date = new Carbon;
$date = new Carbon;
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
@ -256,12 +257,12 @@ class TransactionControllerTest extends TestCase
$collection = new Collection([$transaction]);
// mock stuff
$transfer = $this->getRandomTransfer();
$repository = $this->mock(JournalRepositoryInterface::class);
$collector = $this->mock(TransactionCollectorInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
$attRepos = $this->mock(AttachmentRepositoryInterface::class);
$transfer = $this->getRandomTransfer();
$repository = $this->mock(JournalRepositoryInterface::class);
$collector = $this->mock(TransactionCollectorInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
$attRepos = $this->mock(AttachmentRepositoryInterface::class);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
$repository->shouldReceive('firstNull')->once()->andReturn($transfer);
$repository->shouldReceive('firstNull')->once()->andReturn($transfer);
@ -303,12 +304,12 @@ class TransactionControllerTest extends TestCase
$collection = new Collection([$transaction]);
// mock stuff
$transfer = $this->getRandomTransfer();
$repository = $this->mock(JournalRepositoryInterface::class);
$collector = $this->mock(TransactionCollectorInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$attRepos = $this->mock(AttachmentRepositoryInterface::class);
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
$transfer = $this->getRandomTransfer();
$repository = $this->mock(JournalRepositoryInterface::class);
$collector = $this->mock(TransactionCollectorInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$attRepos = $this->mock(AttachmentRepositoryInterface::class);
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
$repository->shouldReceive('firstNull')->once()->andReturn($transfer);
$repository->shouldReceive('firstNull')->once()->andReturn($transfer);
@ -338,11 +339,11 @@ class TransactionControllerTest extends TestCase
*/
public function testReconcile(): void
{
$data = ['transactions' => [1, 2]];
$repository = $this->mock(JournalRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$attRepos = $this->mock(AttachmentRepositoryInterface::class);
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
$data = ['transactions' => [1, 2]];
$repository = $this->mock(JournalRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$attRepos = $this->mock(AttachmentRepositoryInterface::class);
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
$repository->shouldReceive('firstNull')->times(1)->andReturn(new TransactionJournal);
$repository->shouldReceive('findTransaction')->andReturn(new Transaction)->twice();
@ -363,7 +364,7 @@ class TransactionControllerTest extends TestCase
$journal->date = new Carbon('2016-01-01');
$repository = $this->mock(JournalRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$attRepos = $this->mock(AttachmentRepositoryInterface::class);
$attRepos = $this->mock(AttachmentRepositoryInterface::class);
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
$repository->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
$repository->shouldReceive('findNull')->once()->andReturn($journal);
@ -385,24 +386,36 @@ class TransactionControllerTest extends TestCase
public function testShow(): void
{
// mock stuff
$linkRepos = $this->mock(LinkTypeRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$attRepos = $this->mock(AttachmentRepositoryInterface::class);
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
$linkRepos = $this->mock(LinkTypeRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$attRepos = $this->mock(AttachmentRepositoryInterface::class);
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
$collector = $this->mock(TransactionCollectorInterface::class);
$transformer = $this->mock(TransactionTransformer::class);
$transformer->shouldReceive('setParameters')->atLeast()->once();
$collector->shouldReceive('setUser')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withOpposingAccount')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withCategoryInformation')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withBudgetInformation')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('setJournals')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('getTransactions')->atLeast()->once()->andReturn(new Collection);
$linkRepos->shouldReceive('get')->andReturn(new Collection);
$linkRepos->shouldReceive('getLinks')->andReturn(new Collection);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('getAttachments')->andReturn(new Collection)->once();
$journalRepos->shouldReceive('getPiggyBankEvents')->andReturn(new Collection);
$journalRepos->shouldReceive('firstNull')->andReturn(new TransactionJournal);
$journalRepos->shouldReceive('getMetaField')->andReturn('');
$journalRepos->shouldReceive('getJournalSourceAccounts')->andReturn(new Collection);
$journalRepos->shouldReceive('getJournalDestinationAccounts')->andReturn(new Collection);
$journalRepos->shouldReceive('getNoteText')->andReturn('Some note')->atLeast()->once();
$journalRepos->shouldReceive('getMetaDateString')->andReturn('2018-01-01')->atLeast()->once();
$journalRepos->shouldReceive('firstNull')->andReturn(new TransactionJournal)->atLeast()->once();
$journalRepos->shouldReceive('getAttachments')->andReturn(new Collection)->atLeast()->once();
$journalRepos->shouldReceive('getPiggyBankEvents')->andReturn(new Collection)->atLeast()->once();
$journalRepos->shouldReceive('getJournalSourceAccounts')->andReturn(new Collection)->atLeast()->once();
$journalRepos->shouldReceive('getJournalDestinationAccounts')->andReturn(new Collection)->atLeast()->once();
$journalRepos->shouldReceive('getMetaField')->andReturn('')->atLeast()->once();
// $journalRepos->shouldReceive('getNoteText')->andReturn('Some note')->atLeast()->once();
// $journalRepos->shouldReceive('getMetaDateString')->andReturn('2018-01-01')->atLeast()->once();
$this->be($this->user());
$response = $this->get(route('transactions.show', [1]));
@ -411,17 +424,16 @@ class TransactionControllerTest extends TestCase
}
/**
* @covers \FireflyIII\Http\Controllers\Controller
* @covers \FireflyIII\Http\Controllers\TransactionController
*/
public function testShowOpeningBalance(): void
{
$linkRepos = $this->mock(LinkTypeRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$attRepos = $this->mock(AttachmentRepositoryInterface::class);
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
$linkRepos = $this->mock(LinkTypeRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$attRepos = $this->mock(AttachmentRepositoryInterface::class);
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
$linkRepos->shouldReceive('get')->andReturn(new Collection);
$linkRepos->shouldReceive('getLinks')->andReturn(new Collection);