Improve test coverage.

This commit is contained in:
James Cole
2019-07-27 13:54:06 +02:00
parent d94d34ca63
commit 67c0ef6ec6
29 changed files with 788 additions and 346 deletions

View File

@@ -216,7 +216,7 @@ class AvailableBudgetControllerTest extends TestCase
// mock calls:
$repository->shouldReceive('setUser');
$repository->shouldReceive('updateAvailableBudget')->once()->andReturn($availableBudget);
$currencyRepository->shouldReceive('findNull')->andReturn(TransactionCurrency::find(1));
$currencyRepository->shouldReceive('findNull')->andReturn($this->getEuro());
// data to submit
$data = [

View File

@@ -62,7 +62,7 @@ class CurrencyControllerTest extends TestCase
public function testStore(): void
{
$currency = TransactionCurrency::first();
$currency = $this->getEuro();
$repository = $this->mock(CurrencyRepositoryInterface::class);
$transformer = $this->mock(CurrencyTransformer::class);
$this->mock(UserRepositoryInterface::class);
@@ -105,7 +105,7 @@ class CurrencyControllerTest extends TestCase
*/
public function testStoreWithDefault(): void
{
$currency = TransactionCurrency::first();
$currency = $this->getEuro();
$repository = $this->mock(CurrencyRepositoryInterface::class);
$transformer = $this->mock(CurrencyTransformer::class);
$userRepository = $this->mock(UserRepositoryInterface::class);
@@ -151,7 +151,7 @@ class CurrencyControllerTest extends TestCase
*/
public function testUpdate(): void
{
$currency = TransactionCurrency::first();
$currency = $this->getEuro();
$repository = $this->mock(CurrencyRepositoryInterface::class);
$transformer = $this->mock(CurrencyTransformer::class);
$this->mock(UserRepositoryInterface::class);
@@ -191,7 +191,7 @@ class CurrencyControllerTest extends TestCase
*/
public function testUpdateWithDefault(): void
{
$currency = TransactionCurrency::first();
$currency = $this->getEuro();
$repository = $this->mock(CurrencyRepositoryInterface::class);
$transformer = $this->mock(CurrencyTransformer::class);
$this->mock(UserRepositoryInterface::class);

View File

@@ -154,7 +154,7 @@ class PiggyBankControllerTest extends TestCase
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1');
$currencyRepos->shouldReceive('setUser');
$currencyRepos->shouldReceive('findNull')->withArgs([1])->andReturn(TransactionCurrency::first());
$currencyRepos->shouldReceive('findNull')->withArgs([1])->andReturn($this->getEuro());
$data = [
'name' => 'new pigy bank ' . $this->randomInt(),

View File

@@ -69,7 +69,7 @@ class SummaryControllerTest extends TestCase
$netWorth = $this->mock(NetWorthInterface::class);
// data
$euro = TransactionCurrency::find(1);
$euro = $this->getEuro();
$budget = $this->user()->budgets()->inRandomOrder()->first();
$account = $this->getRandomAsset();
$journals = [
@@ -162,7 +162,7 @@ class SummaryControllerTest extends TestCase
$date->addWeek();
// data
$euro = TransactionCurrency::find(1);
$euro = $this->getEuro();
$budget = $this->user()->budgets()->inRandomOrder()->first();
$account = $this->getRandomAsset();
$journals = [

View File

@@ -71,7 +71,7 @@ class ReportControllerTest extends TestCase
$netWorth->shouldReceive('getNetWorthByCurrency')->andReturn(
[
[
'currency' => TransactionCurrency::first(),
'currency' => $this->getEuro(),
'balance' => '123',
],
]

View File

@@ -111,8 +111,6 @@ class HomeControllerTest extends TestCase
$pref = new Preference;
$pref->data = [$account->id];
Preferences::shouldReceive('get')->withArgs(['frontPageAccounts', [$account->id]])->atLeast()->once()->andReturn($pref);
//Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
//FireflyConfig::shouldReceive('set')->withArgs(['last_update_check', Mockery::any()])->once()->andReturn(new Configuration);
Amount::shouldReceive('formatAnything')->atLeast()->once()->andReturn('x');
Steam::shouldReceive('balance')->atLeast()->once()->andReturn('5');
// mock stuff
@@ -123,9 +121,6 @@ class HomeControllerTest extends TestCase
$euro = $this->getEuro();
// $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
//
//
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
$accountRepos->shouldReceive('count')->andReturn(1)->atLeast()->once();
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1');

View File

@@ -128,6 +128,7 @@ class JobStatusControllerTest extends TestCase
$this->mockDefaultSession();
$importRepos->shouldReceive('countTransactions')->once()->andReturn(0);
$importRepos->shouldReceive('countByTag')->atLeast()->once()->andReturn(0);
// call thing.
$this->be($this->user());
@@ -155,6 +156,7 @@ class JobStatusControllerTest extends TestCase
$this->mockDefaultSession();
$importRepos->shouldReceive('countTransactions')->once()->andReturn(2);
$importRepos->shouldReceive('countByTag')->atLeast()->once()->andReturn(2);
$job = new ImportJob;
$job->user_id = $this->user()->id;
@@ -191,6 +193,7 @@ class JobStatusControllerTest extends TestCase
$this->mockDefaultSession();
$importRepos->shouldReceive('countTransactions')->once()->andReturn(1);
$importRepos->shouldReceive('countByTag')->atLeast()->once()->andReturn(1);
$job = new ImportJob;
$job->user_id = $this->user()->id;

View File

@@ -130,7 +130,7 @@ class PiggyBankControllerTest extends TestCase
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
// new account list thing.
$currency = TransactionCurrency::first();
$currency = $this->getEuro();
$currencyRepos->shouldReceive('findNull')->andReturn($currency);
Amount::shouldReceive('getDefaultCurrency')->andReturn($currency);
@@ -207,7 +207,7 @@ class PiggyBankControllerTest extends TestCase
// mock stuff for new account list thing.
$currency = TransactionCurrency::first();
$currency = $this->getEuro();
$account = $this->getRandomAsset();
$currencyRepos->shouldReceive('findNull')->andReturn($currency);

View File

@@ -41,6 +41,7 @@ use FireflyIII\Models\Configuration;
use FireflyIII\Models\CurrencyExchangeRate;
use FireflyIII\Models\PiggyBank;
use FireflyIII\Models\Preference;
use FireflyIII\Models\Recurrence;
use FireflyIII\Models\Rule;
use FireflyIII\Models\Tag;
use FireflyIII\Models\TransactionCurrency;
@@ -64,6 +65,15 @@ use RuntimeException;
*/
abstract class TestCase extends BaseTestCase
{
/**
* @return Recurrence
*/
public function getRandomRecurrence(): Recurrence
{
return $this->user()->recurrences()->inRandomOrder()->first();
}
/**
* @return CurrencyExchangeRate
*/

View File

@@ -27,7 +27,6 @@ use FireflyIII\Models\AccountMeta;
use FireflyIII\Models\Configuration;
use FireflyIII\Models\Preference;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\User\UserRepositoryInterface;
@@ -133,18 +132,24 @@ class AccountCurrenciesTest extends TestCase
* Perfect run with opening balance.
*
* TODO this method crashes some times but not sure why.
* 2019-07-27 should be fixed.
*
* @covers \FireflyIII\Console\Commands\Upgrade\AccountCurrencies
*/
public function testHandleOpeningBalance(): void
{
$false = new Configuration;
$false->data = false;
$pref = new Preference;
$pref->data = 'EUR';
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$journal = $this->getRandomWithdrawal();
$false = new Configuration;
$false->data = false;
$pref = new Preference;
$pref->data = 'EUR';
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$journal = $this->getRandomWithdrawal();
$euro = $this->getEuro();
$journal->transaction_currency_id = $euro->id;
$journal->save();
$journal->refresh();
$account = $this->getRandomAsset();
// mock calls
$accountRepos->shouldReceive('setUser')->atLeast()->once();
@@ -227,7 +232,7 @@ class AccountCurrenciesTest extends TestCase
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$account = $this->getRandomAsset();
$euro = TransactionCurrency::where('code', 'EUR')->first();
$euro = $this->getEuro();
// mock calls
$accountRepos->shouldReceive('setUser')->atLeast()->once();
$accountRepos->shouldReceive('getMetaValue')->atLeast()->once()->andReturn('0');

View File

@@ -117,146 +117,4 @@ class MonthReportGeneratorTest extends TestCase
$this->assertTrue($result['exists']);
$this->assertEquals('100', $result['endBalance']);
}
//
// /**
// * @covers \FireflyIII\Generator\Report\Audit\MonthReportGenerator
// */
// public function testBasicNoCurrency(): void
// {
// $this->markTestIncomplete('Needs to be rewritten for v4.8.0');
//
// return;
// /** @var Account $account */
// $account = $this->user()->accounts()->where('account_type_id', 3)->first();
// $date = new Carbon;
// $start = Carbon::now()->startOfMonth();
// $end = Carbon::now()->endOfMonth();
// $generator = new MonthReportGenerator();
// $generator->setStartDate($start);
// $generator->setEndDate($end);
//
// $collection = new Collection;
//
// // mock stuff
// $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
// $accountRepos = $this->mock(AccountRepositoryInterface::class);
// $collector = $this->mock(TransactionCollectorInterface::class);
// Steam::shouldReceive('balance')->times(1)->andReturn('100');
//
// // mock calls:
// $accountRepos->shouldReceive('setUser')->once();
// $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1')->once();
//
// $currencyRepos->shouldReceive('findNull')->withArgs([1])->andReturn(null)->once();
//
// $collector->shouldReceive('setAccounts')->andReturnSelf();
// $collector->shouldReceive('setRange')->andReturnSelf();
// $collector->shouldReceive('getTransactions')->andReturn($collection);
//
//
// try {
// $generator->getAuditReport($account, $date);
// } catch (FireflyException $e) {
// $this->assertEquals('Unexpected NULL value in account currency preference.', $e->getMessage());
// }
// }
//
// /**
// * @covers \FireflyIII\Generator\Report\Audit\MonthReportGenerator
// */
// public function testBasicWithForeign(): void
// {
// $this->markTestIncomplete('Needs to be rewritten for v4.8.0');
//
// return;
// /** @var Account $account */
// $account = $this->user()->accounts()->where('account_type_id', 3)->first();
// $date = new Carbon;
// $start = Carbon::now()->startOfMonth();
// $end = Carbon::now()->endOfMonth();
// $generator = new MonthReportGenerator();
// $generator->setStartDate($start);
// $generator->setEndDate($end);
//
// $collection = new Collection;
// $transaction = $this->user()->transactions()->first();
// $transaction->transaction_amount = '30';
// $transaction->foreign_currency_id = 1;
// $transaction->transaction_foreign_amount = '30';
// $collection->push($transaction);
//
// // mock stuff
// $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
// $accountRepos = $this->mock(AccountRepositoryInterface::class);
// $collector = $this->mock(TransactionCollectorInterface::class);
// Steam::shouldReceive('balance')->times(2)->andReturn('100');
//
// // mock calls:
// $accountRepos->shouldReceive('setUser')->once();
// $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1')->once();
//
// $currencyRepos->shouldReceive('findNull')->withArgs([1])->andReturn(TransactionCurrency::first())->once();
//
// $collector->shouldReceive('setAccounts')->andReturnSelf();
// $collector->shouldReceive('setRange')->andReturnSelf();
// $collector->shouldReceive('getTransactions')->andReturn($collection);
//
//
// try {
// $result = $generator->getAuditReport($account, $date);
// } catch (FireflyException $e) {
// $this->assertTrue(false, $e->getMessage());
// }
// $this->assertTrue($result['exists']);
// $this->assertEquals('100', $result['endBalance']);
// }
//
// /**
// * @covers \FireflyIII\Generator\Report\Audit\MonthReportGenerator
// */
// public function testBasicWithTransactions(): void
// {
// $this->markTestIncomplete('Needs to be rewritten for v4.8.0');
//
// return;
// /** @var Account $account */
// $account = $this->user()->accounts()->where('account_type_id', 3)->first();
// $date = new Carbon;
// $start = Carbon::now()->startOfMonth();
// $end = Carbon::now()->endOfMonth();
// $generator = new MonthReportGenerator();
// $generator->setStartDate($start);
// $generator->setEndDate($end);
//
// $collection = new Collection;
// $transaction = $this->user()->transactions()->first();
// $transaction->transaction_amount = '30';
// $collection->push($transaction);
//
// // mock stuff
// $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
// $accountRepos = $this->mock(AccountRepositoryInterface::class);
// $collector = $this->mock(TransactionCollectorInterface::class);
// Steam::shouldReceive('balance')->times(2)->andReturn('100');
//
// // mock calls:
// $accountRepos->shouldReceive('setUser')->once();
// $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1')->once();
//
// $currencyRepos->shouldReceive('findNull')->withArgs([1])->andReturn(TransactionCurrency::first())->once();
//
// $collector->shouldReceive('setAccounts')->andReturnSelf();
// $collector->shouldReceive('setRange')->andReturnSelf();
// $collector->shouldReceive('getTransactions')->andReturn($collection);
//
//
// try {
// $result = $generator->getAuditReport($account, $date);
// } catch (FireflyException $e) {
// $this->assertTrue(false, $e->getMessage());
// }
// $this->assertTrue($result['exists']);
// $this->assertEquals('100', $result['endBalance']);
// }
}

View File

@@ -0,0 +1,550 @@
<?php
/**
* CreateRecurringTransactionsTest.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/>.
*/
namespace Tests\Unit\Jobs;
use Carbon\Carbon;
use FireflyIII\Events\StoredTransactionGroup;
use FireflyIII\Factory\PiggyBankEventFactory;
use FireflyIII\Factory\PiggyBankFactory;
use FireflyIII\Jobs\CreateRecurringTransactions;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\Repositories\Recurring\RecurringRepositoryInterface;
use FireflyIII\Repositories\TransactionGroup\TransactionGroupRepositoryInterface;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Event;
use Log;
use Preferences;
use Tests\TestCase;
/**
* Class CreateRecurringTransactionsTest
*/
class CreateRecurringTransactionsTest extends TestCase
{
/**
*
*/
public function setUp(): void
{
parent::setUp();
Log::info(sprintf('Now in %s.', get_class($this)));
}
/**
* Submit nothing.
*
* @covers \FireflyIII\Jobs\CreateRecurringTransactions
*/
public function testBasic(): void
{
// mock classes
$recurringRepos = $this->mock(RecurringRepositoryInterface::class);
$this->mock(JournalRepositoryInterface::class);
$this->mock(TransactionGroupRepositoryInterface::class);
// mocks:
$recurringRepos->shouldReceive('getAll')->atLeast()->once()->andReturn(new Collection);
Preferences::shouldReceive('mark')->atLeast()->once();
$date = new Carbon();
$job = new CreateRecurringTransactions($date);
$job->setForce(false);
$job->handle();
$this->assertEquals(0, $job->created);
$this->assertEquals(0, $job->executed);
$this->assertEquals(0, $job->submitted);
}
/**
* Submit one, but offer no occurrences.
*
* @covers \FireflyIII\Jobs\CreateRecurringTransactions
*/
public function testSingle(): void
{
// mock classes
$recurrence = $this->getRandomRecurrence();
$recurringRepos = $this->mock(RecurringRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$groupRepos = $this->mock(TransactionGroupRepositoryInterface::class);
// mocks:
$groupRepos->shouldReceive('setUser')->atLeast()->once();
$journalRepos->shouldReceive('setUser')->atLeast()->once();
$recurringRepos->shouldReceive('setUser')->atLeast()->once();
$recurringRepos->shouldReceive('getOccurrencesInRange')->atLeast()->once()->andReturn([]);
$recurringRepos->shouldReceive('getAll')->atLeast()->once()->andReturn(new Collection([$recurrence]));
$recurringRepos->shouldReceive('getJournalCount')->atLeast()->once()->andReturn(0);
Preferences::shouldReceive('mark')->atLeast()->once();
$date = new Carbon();
$job = new CreateRecurringTransactions($date);
$job->handle();
$this->assertEquals(0, $job->created);
$this->assertEquals(1, $job->executed);
$this->assertEquals(1, $job->submitted);
}
/**
* Submit one, but has already fired today
*
* @covers \FireflyIII\Jobs\CreateRecurringTransactions
*/
public function testSingleFiredToday(): void
{
// mock classes
$recurrence = $this->getRandomRecurrence();
$recurrence->latest_date = new Carbon;
$recurrence->save();
$recurringRepos = $this->mock(RecurringRepositoryInterface::class);
$this->mock(JournalRepositoryInterface::class);
$this->mock(TransactionGroupRepositoryInterface::class);
// mocks:
$recurringRepos->shouldReceive('getAll')->atLeast()->once()->andReturn(new Collection([$recurrence]));
$recurringRepos->shouldReceive('getJournalCount')->atLeast()->once()->andReturn(0);
Preferences::shouldReceive('mark')->atLeast()->once();
$date = new Carbon();
$job = new CreateRecurringTransactions($date);
$job->handle();
$this->assertEquals(0, $job->created);
$this->assertEquals(0, $job->executed);
$this->assertEquals(1, $job->submitted);
$recurrence->latest_date =null;
$recurrence->save();
}
/**
* Submit one, but offer no occurrences.
*
* @covers \FireflyIII\Jobs\CreateRecurringTransactions
*/
public function testSingleFuture(): void
{
// mock classes
$future = new Carbon;
$future->addDays(4);
$recurrence = $this->getRandomRecurrence();
$recurrence->first_date =$future;
$recurrence->save();
$recurringRepos = $this->mock(RecurringRepositoryInterface::class);
$this->mock(JournalRepositoryInterface::class);
$this->mock(TransactionGroupRepositoryInterface::class);
// mocks:
$recurringRepos->shouldReceive('getAll')->atLeast()->once()->andReturn(new Collection([$recurrence]));
$recurringRepos->shouldReceive('getJournalCount')->atLeast()->once()->andReturn(0);
Preferences::shouldReceive('mark')->atLeast()->once();
$date = new Carbon();
$job = new CreateRecurringTransactions($date);
$job->handle();
$this->assertEquals(0, $job->created);
$this->assertEquals(0, $job->executed);
$this->assertEquals(1, $job->submitted);
$recurrence->first_date =$date;
$recurrence->save();
}
/**
* Submit one, but should no longer run.
*
* @covers \FireflyIII\Jobs\CreateRecurringTransactions
*/
public function testSingleOverDue(): void
{
// mock classes
$date = new Carbon();
$yesterday = clone $date;
$yesterday->subDays(3);
$recurrence = $this->getRandomRecurrence();
$recurrence->repeat_until =$yesterday;
$recurrence->save();
$recurringRepos = $this->mock(RecurringRepositoryInterface::class);
$this->mock(JournalRepositoryInterface::class);
$this->mock(TransactionGroupRepositoryInterface::class);
// mocks:
$recurringRepos->shouldReceive('getAll')->atLeast()->once()->andReturn(new Collection([$recurrence]));
$recurringRepos->shouldReceive('getJournalCount')->atLeast()->once()->andReturn(0);
Preferences::shouldReceive('mark')->atLeast()->once();
$job = new CreateRecurringTransactions($date);
$job->handle();
$this->assertEquals(0, $job->created);
$this->assertEquals(0, $job->executed);
$this->assertEquals(1, $job->submitted);
$recurrence->repeat_until =null;
$recurrence->save();
}
/**
* Submit one, but it has fired enough times already.
*
* @covers \FireflyIII\Jobs\CreateRecurringTransactions
*/
public function testSingleOccurrences(): void
{
// mock classes
$recurrence = $this->getRandomRecurrence();
$recurrence->repetitions = 1;
$recurrence->save();
$recurringRepos = $this->mock(RecurringRepositoryInterface::class);
$this->mock(JournalRepositoryInterface::class);
$this->mock(TransactionGroupRepositoryInterface::class);
// mocks:
$recurringRepos->shouldReceive('getAll')->atLeast()->once()->andReturn(new Collection([$recurrence]));
$recurringRepos->shouldReceive('getJournalCount')->atLeast()->once()->andReturn(1);
Preferences::shouldReceive('mark')->atLeast()->once();
$date = new Carbon();
$job = new CreateRecurringTransactions($date);
$job->handle();
$this->assertEquals(0, $job->created);
$this->assertEquals(0, $job->executed);
$this->assertEquals(1, $job->submitted);
$recurrence->repetitions = 0;
$recurrence->save();
}
/**
* Submit one, but it's inactive.
*
* @covers \FireflyIII\Jobs\CreateRecurringTransactions
*/
public function testSingleInactive(): void
{
// mock classes
$recurrence = $this->getRandomRecurrence();
$recurrence->active = false;
$recurrence->save();
$recurringRepos = $this->mock(RecurringRepositoryInterface::class);
$this->mock(JournalRepositoryInterface::class);
$this->mock(TransactionGroupRepositoryInterface::class);
// mocks:
$recurringRepos->shouldReceive('getAll')->atLeast()->once()->andReturn(new Collection([$recurrence]));
Preferences::shouldReceive('mark')->atLeast()->once();
$date = new Carbon();
$job = new CreateRecurringTransactions($date);
$job->handle();
$this->assertEquals(0, $job->created);
$this->assertEquals(0, $job->executed);
$this->assertEquals(1, $job->submitted);
$recurrence->active = true;
$recurrence->save();
}
/**
* Submit one, offer occurence for today.
*
* @covers \FireflyIII\Jobs\CreateRecurringTransactions
*/
public function testSingleToday(): void
{
Event::fake();
$date = new Carbon();
$this->expectsEvents([StoredTransactionGroup::class]);
$recurrence = $this->getRandomRecurrence();
$group = $this->getRandomWithdrawalGroup();
// overrule some fields in the recurrence to make it seem it hasnt fired yet.
$recurrence->latest_date = null;
$recurrence->save();
// mock classes
$recurringRepos = $this->mock(RecurringRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$groupRepos = $this->mock(TransactionGroupRepositoryInterface::class);
$piggyFactory = $this->mock(PiggyBankFactory::class);
$piggyEventFactory = $this->mock(PiggyBankEventFactory::class);
// mocks:
$groupRepos->shouldReceive('setUser')->atLeast()->once();
$journalRepos->shouldReceive('setUser')->atLeast()->once();
$recurringRepos->shouldReceive('setUser')->atLeast()->once();
$recurringRepos->shouldReceive('getOccurrencesInRange')->atLeast()->once()->andReturn([$date]);
$recurringRepos->shouldReceive('getAll')->atLeast()->once()->andReturn(new Collection([$recurrence]));
$recurringRepos->shouldReceive('getJournalCount')->atLeast()->once()->andReturn(0);
$recurringRepos->shouldReceive('getPiggyBank')->atLeast()->once()->andReturnNull();
Preferences::shouldReceive('mark')->atLeast()->once();
// return data:
$recurringRepos->shouldReceive('getBudget')->atLeast()->once()->andReturnNull();
$recurringRepos->shouldReceive('getCategory')->atLeast()->once()->andReturnNull();
$recurringRepos->shouldReceive('getTags')->atLeast()->once()->andReturn([]);
// store journal
$groupRepos->shouldReceive('store')->atLeast()->once()->andReturn($group);
//Event::assertDispatched(StoredTransactionGroup::class);
$job = new CreateRecurringTransactions($date);
$job->handle();
$this->assertEquals(1, $job->created);
$this->assertEquals(1, $job->executed);
$this->assertEquals(1, $job->submitted);
}
/**
* Submit one, offer occurence for today.
*
* @covers \FireflyIII\Jobs\CreateRecurringTransactions
*/
public function testForced(): void
{
Event::fake();
$date = new Carbon();
$this->expectsEvents([StoredTransactionGroup::class]);
$recurrence = $this->getRandomRecurrence();
$group = $this->getRandomWithdrawalGroup();
// overrule some fields in the recurrence to make it seem it hasnt fired yet.
$recurrence->latest_date = null;
$recurrence->save();
// mock classes
$recurringRepos = $this->mock(RecurringRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$groupRepos = $this->mock(TransactionGroupRepositoryInterface::class);
$piggyFactory = $this->mock(PiggyBankFactory::class);
$piggyEventFactory = $this->mock(PiggyBankEventFactory::class);
// mocks:
$groupRepos->shouldReceive('setUser')->atLeast()->once();
$journalRepos->shouldReceive('setUser')->atLeast()->once();
$recurringRepos->shouldReceive('setUser')->atLeast()->once();
$recurringRepos->shouldReceive('getOccurrencesInRange')->atLeast()->once()->andReturn([$date]);
$recurringRepos->shouldReceive('getAll')->atLeast()->once()->andReturn(new Collection([$recurrence]));
$recurringRepos->shouldReceive('getJournalCount')->atLeast()->once()->andReturn(3);
$recurringRepos->shouldReceive('getPiggyBank')->atLeast()->once()->andReturnNull();
Preferences::shouldReceive('mark')->atLeast()->once();
// return data:
$recurringRepos->shouldReceive('getBudget')->atLeast()->once()->andReturnNull();
$recurringRepos->shouldReceive('getCategory')->atLeast()->once()->andReturnNull();
$recurringRepos->shouldReceive('getTags')->atLeast()->once()->andReturn([]);
// store journal
$groupRepos->shouldReceive('store')->atLeast()->once()->andReturn($group);
//Event::assertDispatched(StoredTransactionGroup::class);
$job = new CreateRecurringTransactions($date);
$job->setForce(true);
$job->handle();
$this->assertEquals(1, $job->created);
$this->assertEquals(1, $job->executed);
$this->assertEquals(1, $job->submitted);
}
/**
* Submit one, offer occurence for today.
*
* @covers \FireflyIII\Jobs\CreateRecurringTransactions
*/
public function testBadJournalCount(): void
{
Event::fake();
$date = new Carbon();
$recurrence = $this->getRandomRecurrence();
$group = $this->getRandomWithdrawalGroup();
// overrule some fields in the recurrence to make it seem it hasnt fired yet.
$recurrence->latest_date = null;
$recurrence->save();
// mock classes
$recurringRepos = $this->mock(RecurringRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$groupRepos = $this->mock(TransactionGroupRepositoryInterface::class);
$piggyFactory = $this->mock(PiggyBankFactory::class);
$piggyEventFactory = $this->mock(PiggyBankEventFactory::class);
// mocks:
$groupRepos->shouldReceive('setUser')->atLeast()->once();
$journalRepos->shouldReceive('setUser')->atLeast()->once();
$recurringRepos->shouldReceive('setUser')->atLeast()->once();
$recurringRepos->shouldReceive('getOccurrencesInRange')->atLeast()->once()->andReturn([$date]);
$recurringRepos->shouldReceive('getAll')->atLeast()->once()->andReturn(new Collection([$recurrence]));
$recurringRepos->shouldReceive('getJournalCount')->atLeast()->once()->andReturn(3);
Preferences::shouldReceive('mark')->atLeast()->once();
$job = new CreateRecurringTransactions($date);
$job->handle();
$this->assertEquals(0, $job->created);
$this->assertEquals(1, $job->executed);
$this->assertEquals(1, $job->submitted);
}
/**
* @covers \FireflyIII\Jobs\CreateRecurringTransactions
*/
public function testSingleNotToday(): void
{
$date = new Carbon();
$tomorrow = new Carbon();
$tomorrow->addDays(2);
$recurrence = $this->getRandomRecurrence();
$group = $this->getRandomWithdrawalGroup();
// overrule some fields in the recurrence to make it seem it hasnt fired yet.
$recurrence->latest_date = null;
$recurrence->save();
// mock classes
$recurringRepos = $this->mock(RecurringRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$groupRepos = $this->mock(TransactionGroupRepositoryInterface::class);
$piggyFactory = $this->mock(PiggyBankFactory::class);
$piggyEventFactory = $this->mock(PiggyBankEventFactory::class);
// mocks:
$groupRepos->shouldReceive('setUser')->atLeast()->once();
$journalRepos->shouldReceive('setUser')->atLeast()->once();
$recurringRepos->shouldReceive('setUser')->atLeast()->once();
$recurringRepos->shouldReceive('getOccurrencesInRange')->atLeast()->once()->andReturn([$tomorrow]);
$recurringRepos->shouldReceive('getAll')->atLeast()->once()->andReturn(new Collection([$recurrence]));
$recurringRepos->shouldReceive('getJournalCount')->atLeast()->once()->andReturn(0);
Preferences::shouldReceive('mark')->atLeast()->once();
$job = new CreateRecurringTransactions($date);
$job->handle();
$this->assertEquals(0, $job->created);
$this->assertEquals(1, $job->executed);
$this->assertEquals(1, $job->submitted);
}
/**
* Submit one, offer occurence for today, with piggy
*
* @covers \FireflyIII\Jobs\CreateRecurringTransactions
*/
public function testSingleTodayPiggy(): void
{
Event::fake();
$date = new Carbon();
$this->expectsEvents([StoredTransactionGroup::class]);
$recurrence = $this->getRandomRecurrence();
$group = $this->getRandomWithdrawalGroup();
$piggy = $this->getRandomPiggyBank();
// overrule some fields in the recurrence to make it seem it hasnt fired yet.
$recurrence->latest_date = null;
$recurrence->save();
// mock classes
$recurringRepos = $this->mock(RecurringRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$groupRepos = $this->mock(TransactionGroupRepositoryInterface::class);
$piggyEventFactory = $this->mock(PiggyBankEventFactory::class);
// mocks:
$groupRepos->shouldReceive('setUser')->atLeast()->once();
$journalRepos->shouldReceive('setUser')->atLeast()->once();
$recurringRepos->shouldReceive('setUser')->atLeast()->once();
$recurringRepos->shouldReceive('getOccurrencesInRange')->atLeast()->once()->andReturn([$date]);
$recurringRepos->shouldReceive('getAll')->atLeast()->once()->andReturn(new Collection([$recurrence]));
$recurringRepos->shouldReceive('getJournalCount')->atLeast()->once()->andReturn(0);
$recurringRepos->shouldReceive('getPiggyBank')->atLeast()->once()->andReturn($piggy);
$piggyEventFactory->shouldReceive('create')->once();
Preferences::shouldReceive('mark')->atLeast()->once();
// return data:
$recurringRepos->shouldReceive('getBudget')->atLeast()->once()->andReturnNull();
$recurringRepos->shouldReceive('getCategory')->atLeast()->once()->andReturnNull();
$recurringRepos->shouldReceive('getTags')->atLeast()->once()->andReturn([]);
// store journal
$groupRepos->shouldReceive('store')->atLeast()->once()->andReturn($group);
//Event::assertDispatched(StoredTransactionGroup::class);
$job = new CreateRecurringTransactions($date);
$job->handle();
$this->assertEquals(1, $job->created);
$this->assertEquals(1, $job->executed);
$this->assertEquals(1, $job->submitted);
}
}

View File

@@ -352,7 +352,7 @@ class ChooseAccountsHandlerTest extends TestCase
$collection = new Collection;
$account = $this->user()->accounts()->first();
$euro = TransactionCurrency::first();
$euro = $this->getEuro();
$collection->push($account);
@@ -415,7 +415,7 @@ class ChooseAccountsHandlerTest extends TestCase
$collection = new Collection;
$account = $this->user()->accounts()->first();
$euro = TransactionCurrency::first();
$euro = $this->getEuro();
$collection->push($account);

View File

@@ -469,8 +469,8 @@ class ChooseAccountsHandlerTest extends TestCase
$currencyRepos->shouldReceive('setUser')->once();
$importRepos->shouldReceive('setUser')->once();
$euro = TransactionCurrency::where('code', 'EUR')->first();
$usd = TransactionCurrency::where('code', 'USD')->first();
$euro = $this->getEuro();
$usd = $this->getDollar();
$first = $this->user()->accounts()->where('account_type_id', 3)->first();
$second = $this->user()->accounts()->where('account_type_id', 3)->where('id', '!=', $first->id)->first();
$accountRepos->shouldReceive('getAccountsByType')->withArgs([[AccountType::ASSET, AccountType::DEBT, AccountType::LOAN, AccountType::MORTGAGE]])
@@ -622,8 +622,8 @@ class ChooseAccountsHandlerTest extends TestCase
$currencyRepos->shouldReceive('setUser')->once();
$importRepos->shouldReceive('setUser')->once();
$euro = TransactionCurrency::where('code', 'EUR')->first();
$usd = TransactionCurrency::where('code', 'USD')->first();
$euro = $this->getEuro();
$usd = $this->getDollar();
$first = $this->user()->accounts()->where('account_type_id', 3)->first();
$second = $this->user()->accounts()->where('account_type_id', 3)->where('id', '!=', $first->id)->first();
$accountRepos->shouldReceive('getAccountsByType')->withArgs([[AccountType::ASSET, AccountType::DEBT, AccountType::LOAN, AccountType::MORTGAGE]])

View File

@@ -53,7 +53,7 @@ class CurrencyTransformerTest extends TestCase
{
// mocks and prep:
$parameters = new ParameterBag;
$currency = TransactionCurrency::first();
$currency = $this->getEuro();
$transformer = app(CurrencyTransformer::class);
$transformer->setParameters($parameters);
@@ -75,7 +75,7 @@ class CurrencyTransformerTest extends TestCase
{
// mocks and prep:
$parameters = new ParameterBag;
$currency = TransactionCurrency::first();
$currency = $this->getEuro();
$parameters->set('defaultCurrency', $currency);
$transformer = app(CurrencyTransformer::class);
$transformer->setParameters($parameters);